Skip to content

fix: clamp finalized block to oldest available in world-state#21650

Closed
AztecBot wants to merge 2 commits intonextfrom
claudebox/8e97449f22ba9343-3
Closed

fix: clamp finalized block to oldest available in world-state#21650
AztecBot wants to merge 2 commits intonextfrom
claudebox/8e97449f22ba9343-3

Conversation

@AztecBot
Copy link
Collaborator

Cherry-pick of #21643 (merged to merge-train/spartan) onto next.

Summary

PR #21597 increased the finalized block lookback from epochDuration*2 to epochDuration*2*4, which caused the finalized block number to jump backwards past blocks already pruned from world-state. The native advance_finalized_block then failed trying to read pruned block data, crashing the block stream.

Two fixes:

  • TypeScript: Clamp the finalized block number to oldestHistoricalBlock before calling setFinalized
  • C++: Reorder checks in advance_finalized_block to check the no-op condition before attempting read_block_data

Plus an integration test that validates the clamping behavior.

Full analysis: https://gist.github.com/AztecBot/6221fb074ed7bbd8a753ec3602133b42

ClaudeBox log: https://claudebox.work/s/8e97449f22ba9343?run=3

PR #21597 increased the finalized block lookback from epochDuration*2
to epochDuration*2*4. This caused the finalized block number to jump
backwards past blocks that had already been pruned from world-state,
causing advance_finalized_block to fail with 'Failed to read block data'.

Two fixes:
1. TypeScript: clamp blockNumber to oldestHistoricalBlock before calling
   setFinalized, so we never request a pruned block.
2. C++: reorder checks in advance_finalized_block to check the no-op
   condition (already finalized past this block) before attempting to
   read block data. This makes the native layer resilient to receiving
   a stale finalized block number.
…uned blocks

Tests that handleBlockStreamEvent with chain-finalized for a block
older than the oldest available block does not throw, validating
the clamping fix in handleChainFinalized.
@AztecBot AztecBot added the claudebox Owned by claudebox. it can push to this PR. label Mar 17, 2026
@PhilWindle PhilWindle closed this Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claudebox Owned by claudebox. it can push to this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants