WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@yug49
Copy link
Contributor

@yug49 yug49 commented Dec 4, 2025

Resolves #214

Description

Refactors reorg detection from on-chain hash existence checks to parent hash verification against a ring buffer.

Changes

  • ring_buffer.rs: Added BlockInfo<H> struct storing block number + hash, with find_by_number() and truncate_from() methods
  • reorg_handler.rs: Replaced hash existence checks with parent hash verification; added handle_gap() for intermediate block fetching

Scenarios

Scenario Before After
Direct reorg (1→2→3→REORG→2) 3 RPC calls 0 RPC calls
Block past fork (1→2→3→(2 reorged)→3) 3 RPC calls 1 RPC call
Gap with reorg (1→2→3→(6 reorged)→8) 1 RPC call 5 RPC calls (but maintains fuller buffer)

Edge cases handled

  • Empty buffer (first block)
  • Reorg deeper than buffer size → fallback to finalized block
  • Gaps in block numbers → fetch intermediate blocks

@0xNeshi
Copy link
Collaborator

0xNeshi commented Dec 5, 2025

Hey @yug49 thanks for contributing!
Our team is currently working though some priority items, so we'll get to reviewing this as soon as our schedule allows.
We appreciate your patience and the contribution!

@yug49
Copy link
Contributor Author

yug49 commented Dec 5, 2025

Sure, it was my pleasure to contribute

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

2 participants