Skip to content

fix: detect reorged sidechain blocks by canonical hash - #354

Merged
0xNeshi merged 1 commit into
OpenZeppelin:mainfrom
YoGhurt111:fix-reorg-canonical-hash-signed
Jun 1, 2026
Merged

fix: detect reorged sidechain blocks by canonical hash#354
0xNeshi merged 1 commit into
OpenZeppelin:mainfrom
YoGhurt111:fix-reorg-canonical-hash-signed

Conversation

@YoGhurt111

Copy link
Copy Markdown
Contributor

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 0xNeshi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks !

@0xNeshi

0xNeshi commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Replaces #352

@0xNeshi 0xNeshi added priority: high Important for MVP/core features type: bug Something isn't working labels May 29, 2026
@0xNeshi
0xNeshi merged commit 62de185 into OpenZeppelin:main Jun 1, 2026
9 checks passed
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: high Important for MVP/core features type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants