Skip to content

graph: Revert earliest_block off-by-one fix from #6340#6403

Open
dimitrovmaksim wants to merge 1 commit intographprotocol:masterfrom
dimitrovmaksim:fix/revert-earliest-block-calculation
Open

graph: Revert earliest_block off-by-one fix from #6340#6403
dimitrovmaksim wants to merge 1 commit intographprotocol:masterfrom
dimitrovmaksim:fix/revert-earliest-block-calculation

Conversation

@dimitrovmaksim
Copy link
Member

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.

@dimitrovmaksim dimitrovmaksim requested a review from lutter March 2, 2026 09:43
@dimitrovmaksim dimitrovmaksim force-pushed the fix/revert-earliest-block-calculation branch from 3d22063 to 95f293b Compare March 2, 2026 18:50
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.
@dimitrovmaksim dimitrovmaksim force-pushed the fix/revert-earliest-block-calculation branch from 95f293b to 413c613 Compare March 2, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant