fix: clamp finalized block to oldest available in world-state#21650
Closed
fix: clamp finalized block to oldest available in world-state#21650
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #21643 (merged to merge-train/spartan) onto next.
Summary
PR #21597 increased the finalized block lookback from
epochDuration*2toepochDuration*2*4, which caused the finalized block number to jump backwards past blocks already pruned from world-state. The nativeadvance_finalized_blockthen failed trying to read pruned block data, crashing the block stream.Two fixes:
oldestHistoricalBlockbefore callingsetFinalizedadvance_finalized_blockto check the no-op condition before attemptingread_block_dataPlus 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