Skip to content

Conversation

@yug49
Copy link
Contributor

@yug49 yug49 commented Dec 7, 2025

Resolves #227

Description

This PR optimizes the historic/sync scanning modes by deferring reorg checks until after all block ranges have been streamed.

Changes

  1. stream_historical_range in common.rs:
  • Phase 1: Stream all finalized blocks without any reorg checks (unchanged)
  • Phase 2: Stream all non-finalized block ranges without intermediate reorg checks
  • After streaming the last range, check if the end block still exists (single reorg check)
  • If a reorg is detected (BlockNotFound), send ReorgDetected notification and re-stream all non-finalized blocks
  • Repeat until stable (end block exists or has become finalized)
  1. handle_historical in block_range_scanner.rs:
  • Removed ReorgHandler instantiation and parameter passing (no longer needed for historic mode)
  1. sync_handler.rs:
  • catchup_historical_blocks no longer requires reorg_handler parameter
  • Reorg handling during sync's historical phase now uses the optimized approach

@yug49 yug49 changed the title perf(historic): optimized reorg handling by deferring checks to end of stream enhancement: optimized reorg handling by deferring checks to end of stream (historic) Dec 7, 2025
@LeoPatOZ
Copy link
Collaborator

Hi @yug49 thanks for the contribution.

Do you mind updating this PR (merging main) and using the new range_iterator for the looping logic

T_EDITOR=true git rebase --continue 2>&1
o "" | git rebase --continue
t status
TOR=":" git rebase --continue
@yug49 yug49 force-pushed the enhancement/reorg-check branch from 7b8ea49 to 2424da5 Compare January 21, 2026 06:53
@yug49 yug49 force-pushed the enhancement/reorg-check branch from be91793 to d522302 Compare January 21, 2026 07:03
@yug49
Copy link
Contributor Author

yug49 commented Jan 21, 2026

Hi @yug49 thanks for the contribution.

Do you mind updating this PR (merging main) and using the new range_iterator for the looping logic

Hello @LeoPatOZ
I have merged and updated it.

@yug49 yug49 requested a review from LeoPatOZ January 21, 2026 07:47
@LeoPatOZ LeoPatOZ mentioned this pull request Jan 27, 2026
@LeoPatOZ
Copy link
Collaborator

LeoPatOZ commented Jan 28, 2026

Hey @yug49 sorry for the delayed response re this PR.

Looking a lot better - I had the idea of refactoring this and creating a historical_range_handler.rs similar to sync_handler.rs. I made a PR (which i closed given its a refactor of this one), where you can take some inspo.

The major difference is

  1. Creating the historical handler
  2. Splitting up this function into two / three smaller ones. I ended up having, stream_finalized_blocks, stream_non_finalized_blocks and check_reorg. I think it splits this flow nicely and makes the intention clearer

@yug49
Copy link
Contributor Author

yug49 commented Jan 28, 2026

Hey @yug49 sorry for the delayed response re this PR.

Looking a lot better - I had the idea of refactoring this and creating a historical_range_handler.rs similar to sync_handler.rs. I made a PR (which i closed given its a refactor of this one), where you can take some inspo.

The major difference is

  1. Creating the historical handler

  2. Splitting up this function into two / three smaller ones. I ended up having, stream_finalized_blocks, stream_non_finalized_blocks and check_reorg. I think it splits this flow nicely and makes the intention clearer

No problem @LeoPatOZ
I will refactor it.

@yug49
Copy link
Contributor Author

yug49 commented Jan 29, 2026

Hey @LeoPatOZ
I have refactored it, please review

@yug49 yug49 requested a review from LeoPatOZ January 29, 2026 12:01
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.

Historic: Perform Reorg Check Only After Streaming Last Block Range

3 participants