Skip to content

Conversation

@iuwqyir
Copy link
Contributor

@iuwqyir iuwqyir commented Jan 30, 2025

TL;DR

Improved reorg handler block range calculation to support both forward and backward scanning based on the current sync state.

What changed?

  • Added getReorgCheckRange function to dynamically determine the block range for reorg checks
  • When catching up (large gap between latest checked and committed blocks), the handler scans forward
  • When caught up (small gap), the handler looks backward from the latest committed block
  • Added protection to prevent negative block numbers when scanning backward
  • Added early exit when the latest checked block equals the target block

How to test?

  • Run the new test cases:
    • TestReorgHandlerRangeIsForwardLookingWhenItIsCatchingUp
    • TestReorgHandlerRangeIsBackwardLookingWhenItIsCaughtUp
    • TestReorgHandlerRangeStartIs0WhenRangeIsLargerThanProcessedBlocks
  • Verify the reorg handler correctly determines scan ranges in different sync states

Why make this change?

The previous implementation always scanned forward, which could miss reorgs when the system was caught up with the chain head. This change ensures more thorough reorg detection by adapting the scan direction based on the current sync state, improving the reliability of reorg detection.

@zeet-co
Copy link

zeet-co bot commented Jan 30, 2025

We're building your pull request over on Zeet.
Click me for more info about your build and deployment.
Once built, this branch can be tested at: https://insight-api-gcp-7s7h-01-30-make-r-bd08ea.insight-prod-gke.zeet.app before merging 😉

Copy link
Contributor Author

iuwqyir commented Jan 30, 2025

@iuwqyir iuwqyir changed the title make reorg backward looking if it has caught up with the chain make reorg handling backward looking if it has caught up with the chain Jan 30, 2025
@iuwqyir iuwqyir requested review from a team and nischitpra and removed request for nischitpra January 30, 2025 18:20
@iuwqyir iuwqyir marked this pull request as ready for review January 30, 2025 18:20
Copy link
Contributor Author

iuwqyir commented Jan 30, 2025

Merge activity

  • Jan 30, 2:01 PM EST: A user started a stack merge that includes this pull request via Graphite.
  • Jan 30, 2:04 PM EST: Graphite rebased this pull request as part of a merge.
  • Jan 30, 2:06 PM EST: A user merged this pull request with Graphite.

@iuwqyir iuwqyir changed the base branch from 01-30-find_all_reorgs_in_current_batch to graphite-base/143 January 30, 2025 19:01
@iuwqyir iuwqyir changed the base branch from graphite-base/143 to main January 30, 2025 19:03
@iuwqyir iuwqyir force-pushed the 01-30-make_reorg_backward_looking_if_it_has_caught_up_with_the_chain branch from ab04d5c to 0c2d50b Compare January 30, 2025 19:04
@iuwqyir iuwqyir merged commit 4bc1da4 into main Jan 30, 2025
5 of 6 checks passed
@iuwqyir iuwqyir deleted the 01-30-make_reorg_backward_looking_if_it_has_caught_up_with_the_chain branch January 30, 2025 19:06
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.

3 participants