fix: detect reorged sidechain blocks by canonical hash - #352
Closed
YoGhurt111 wants to merge 6 commits into
Closed
Conversation
YoGhurt111
marked this pull request as ready for review
May 25, 2026 12:43
Collaborator
|
Confirmed the finding that Geth can return a non-canonical block by hash, if the block is still in the node's DB. Sources:
@YoGhurt111 feel free to list other clients that do the same |
0xNeshi
reviewed
May 27, 2026
0xNeshi
reviewed
May 28, 2026
0xNeshi
reviewed
May 28, 2026
0xNeshi
reviewed
May 28, 2026
0xNeshi
reviewed
May 28, 2026
0xNeshi
reviewed
May 28, 2026
Co-authored-by: Nenad <xinef.it@gmail.com>
…m candidate block
Co-authored-by: Nenad <xinef.it@gmail.com>
Collaborator
|
We have a signed commit requirement, so closing this PR with unsigned commits in favor of #354 |
0xNeshi
pushed a commit
that referenced
this pull request
Jun 1, 2026
## Summary - Detect reorgs by comparing a previously scanned block against the current canonical block at the same height. - Store buffered block numbers alongside hashes so common ancestor lookup uses a single canonical block-by-number request. - Add regression coverage for providers that keep reorged sidechain blocks queryable by hash. ## Root Cause Some execution clients can still return a reorged sidechain block from `eth_getBlockByHash` after the canonical block at the same height has changed. Treating a successful hash lookup as proof that a buffered/scanned block is still canonical can miss same-height replacements, so the affected range is not replayed. ## Fix This change compares the saved block hash with the canonical block returned by `eth_getBlockByNumber` at the saved height. The reorg buffer stores `(BlockNumber, BlockHash)`, allowing common ancestor detection to validate canonicality with one RPC call per buffered candidate. ## Testing - `cargo test --features test-utils detects_reorg_when_old_hash_is_available_but_not_canonical` - `cargo check --features test-utils` This PR replaces #352 with a single signed commit.
0xNeshi
pushed a commit
that referenced
this pull request
Jun 1, 2026
## Summary - Detect reorgs by comparing a previously scanned block against the current canonical block at the same height. - Store buffered block numbers alongside hashes so common ancestor lookup uses a single canonical block-by-number request. - Add regression coverage for providers that keep reorged sidechain blocks queryable by hash. ## Root Cause Some execution clients can still return a reorged sidechain block from `eth_getBlockByHash` after the canonical block at the same height has changed. Treating a successful hash lookup as proof that a buffered/scanned block is still canonical can miss same-height replacements, so the affected range is not replayed. ## Fix This change compares the saved block hash with the canonical block returned by `eth_getBlockByNumber` at the saved height. The reorg buffer stores `(BlockNumber, BlockHash)`, allowing common ancestor detection to validate canonicality with one RPC call per buffered candidate. ## Testing - `cargo test --features test-utils detects_reorg_when_old_hash_is_available_but_not_canonical` - `cargo check --features test-utils` This PR replaces #352 with a single signed commit. (cherry picked from commit 62de185)
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.
Summary
Root Cause
Some execution clients can still return a reorged sidechain block from
eth_getBlockByHashafter the canonical block at the same height has changed. The previous reorg check treated a successful hash lookup as proof that the buffered/scanned block was still canonical, so same-height replacements could be missed and the affected range would not be replayed.Testing
cargo test --features test-utils detects_reorg_when_old_hash_is_available_but_not_canonicalcargo check --features test-utilsNote:
cargo fmt --checkon this machine reports unrelated formatting diffs in existing files (src/block_range_scanner/common.rsandsrc/event_scanner/block_range_handler.rs) due to the stable rustfmt handling of the repository rustfmt config. Those unrelated files were not changed in this PR.