Skip to content

Refactor: Reorg detection with parent hash verification#338

Open
yug49 wants to merge 4 commits intoOpenZeppelin:mainfrom
yug49:refactor/reorg-detection-v2
Open

Refactor: Reorg detection with parent hash verification#338
yug49 wants to merge 4 commits intoOpenZeppelin:mainfrom
yug49:refactor/reorg-detection-v2

Conversation

@yug49
Copy link
Contributor

@yug49 yug49 commented Mar 23, 2026

Resolves #214
Supersedes #224

Rewrites reorg detection from scratch based on the reviews and pseudocode in #224

@yug49 yug49 requested a review from 0xNeshi as a code owner March 23, 2026 08:02
Copilot AI review requested due to automatic review settings March 23, 2026 08:02
@yug49 yug49 requested a review from pepebndc as a code owner March 23, 2026 08:02
@yug49 yug49 changed the title Refactor reorg detection with parent hash verification Refactor: Reorg detection with parent hash verification Mar 23, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors block reorg detection to use parent-hash verification against a rolling buffer of (block_number, block_hash) entries, aligning the implementation with the ring-buffer approach described in #214 (and superseding #224).

Changes:

  • Replaced hash-existence RPC checks with parent-hash verification backed by a BlockNumHash ring buffer.
  • Added gap handling logic that fetches intermediate blocks to bridge non-sequential incoming blocks.
  • Minor formatting adjustments to conditionals in stream handling code.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/event_scanner/block_range_handler.rs Minor conditional formatting; no behavior change.
src/block_range_scanner/ring_buffer.rs Refactors buffer to store BlockNumHash and adds lookup/truncation helpers + tests.
src/block_range_scanner/reorg_handler.rs Rewrites reorg detection using parent-hash verification with buffer, including gap and deep-reorg handling.
src/block_range_scanner/common.rs Minor conditional formatting; no behavior change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@0xNeshi
Copy link
Collaborator

0xNeshi commented Mar 23, 2026

Thanks @yug49 , we will review the PR over the next couple of days/weeks

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.

Refactor reorg detection to use ring buffer parent hash verification

3 participants