Skip to content

Commit ceddf3c

Browse files
graph: Revert earliest_block off-by-one fix from #6340 (#6403)
The +1 introduced in fa6d677 broke two things for deployments with history_blocks = reorg_threshold + 1: - strategy() returned None (earliest_block == final_block), so pruning silently did nothing even though set_earliest_block had already advanced earliest_block_number in the database - revert_block_ptr then failed for any reorg because earliest_block_number > ptr.number - reorg_threshold Both revert_block_ptr and strategy rely on earliest_block < final_block, which requires reorg_threshold + 2 actual blocks on disk. The old formula (earliest_block = latest_block - history_blocks) keeps history_blocks + 1 blocks, providing exactly that buffer when history_blocks >= reorg_threshold + 1. The copy_nonfinal_entities fix from 46367e7 is preserved.
1 parent 587aa9e commit ceddf3c

File tree

1 file changed

+10
-3
lines changed
  • graph/src/components/store

1 file changed

+10
-3
lines changed

graph/src/components/store/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,9 +1059,16 @@ impl PruneRequest {
10591059
));
10601060
}
10611061

1062-
// We need to add + 1 to `earliset_block` because the lower bound is inclusive
1063-
// and otherwise we would end up with `history_blocks + 1` blocks of history instead of `history_blocks`
1064-
let earliest_block = latest_block - history_blocks + 1;
1062+
// Note: this intentionally keeps `history_blocks + 1` blocks on disk.
1063+
// The range [earliest_block, latest_block] is inclusive on both ends,
1064+
// so it contains `history_blocks + 1` entries. The extra block is a
1065+
// required buffer: `revert_block_ptr` requires at least
1066+
// `reorg_threshold + 2` actual blocks on disk to allow even a
1067+
// single-block reorg after pruning, and `strategy` requires
1068+
// `earliest_block < final_block`. Both conditions are satisfied when
1069+
// `history_blocks >= reorg_threshold + 1`, which gives
1070+
// `reorg_threshold + 2` blocks on disk.
1071+
let earliest_block = latest_block - history_blocks;
10651072
let final_block = latest_block - reorg_threshold;
10661073

10671074
Ok(Self {

0 commit comments

Comments
 (0)