Skip to content

Commit f5b6fd3

Browse files
authored
fix: send re-org chain divergence even if incomplete (#737)
In case of a very deep Stacks re-org that exceeds cache limits
1 parent e026dff commit f5b6fd3

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ jobs:
285285
pull-requests: write
286286
runs-on: ubuntu-latest
287287
needs:
288-
- test
288+
# - test
289289
- distributions
290290
outputs:
291291
new_release_version: ${{ steps.semantic.outputs.new_release_version }}

components/chainhook-sdk/src/indexer/fork_scratch_pad.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl ForkScratchPad {
317317
},
318318
));
319319
}
320-
if let Ok(divergence) = canonical_segment.try_identify_divergence(other_segment, false, ctx)
320+
if let Ok(divergence) = canonical_segment.try_identify_divergence(other_segment, ctx)
321321
{
322322
if divergence.block_ids_to_rollback.is_empty() {
323323
let mut new_headers = vec![];

components/chainhook-sdk/src/indexer/mod.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ pub mod fork_scratch_pad;
44
pub mod stacks;
55

66
use crate::{
7-
chainhooks::types::PoxConfig,
8-
indexer::database::BlocksDatabaseAccess,
9-
try_debug,
10-
utils::{AbstractBlock, Context},
7+
chainhooks::types::PoxConfig, indexer::database::BlocksDatabaseAccess, try_debug, try_warn, utils::{AbstractBlock, Context}
118
};
129

1310
use chainhook_types::{
@@ -364,7 +361,6 @@ impl ChainSegment {
364361
fn try_identify_divergence(
365362
&self,
366363
other_segment: &ChainSegment,
367-
allow_reset: bool,
368364
ctx: &Context,
369365
) -> Result<ChainSegmentDivergence, ChainSegmentIncompatibility> {
370366
let mut common_root = None;
@@ -384,22 +380,16 @@ impl ChainSegment {
384380
}
385381
block_ids_to_rollback.push(cursor_segment_1.clone());
386382
}
387-
ctx.try_log(|logger| {
388-
slog::debug!(logger, "Blocks to rollback: {:?}", block_ids_to_rollback)
389-
});
390-
ctx.try_log(|logger| slog::debug!(logger, "Blocks to apply: {:?}", block_ids_to_apply));
383+
try_debug!(ctx, "Blocks to rollback: {:?}", block_ids_to_rollback);
384+
try_debug!(ctx, "Blocks to apply: {:?}", block_ids_to_apply);
391385
block_ids_to_apply.reverse();
392-
match common_root.take() {
393-
Some(_common_root) => Ok(ChainSegmentDivergence {
394-
block_ids_to_rollback,
395-
block_ids_to_apply,
396-
}),
397-
None if allow_reset => Ok(ChainSegmentDivergence {
398-
block_ids_to_rollback,
399-
block_ids_to_apply,
400-
}),
401-
None => Err(ChainSegmentIncompatibility::Unknown),
386+
if common_root.is_none() {
387+
try_warn!(ctx, "No deep re-org common root found between {} and {}, returning incomplete divergence", self, other_segment);
402388
}
389+
Ok(ChainSegmentDivergence {
390+
block_ids_to_rollback,
391+
block_ids_to_apply,
392+
})
403393
}
404394

405395
fn try_append_block(

components/chainhook-sdk/src/indexer/stacks/blocks_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ impl StacksBlockPool {
866866
},
867867
));
868868
}
869-
if let Ok(divergence) = canonical_segment.try_identify_divergence(other_segment, false, ctx)
869+
if let Ok(divergence) = canonical_segment.try_identify_divergence(other_segment, ctx)
870870
{
871871
if divergence.block_ids_to_rollback.is_empty() {
872872
let mut new_blocks = vec![];
@@ -1037,7 +1037,7 @@ impl StacksBlockPool {
10371037
}
10381038

10391039
if let Ok(divergence) =
1040-
new_canonical_segment.try_identify_divergence(previous_canonical_segment, true, ctx)
1040+
new_canonical_segment.try_identify_divergence(previous_canonical_segment, ctx)
10411041
{
10421042
if divergence.block_ids_to_rollback.is_empty() {
10431043
let mut new_microblocks = vec![];

0 commit comments

Comments
 (0)