-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Brief Sync Mode Logic Description
- Get the current latest block number
- Run live mode in the background and buffer all incoming blocks for later processing
- Invoke historic mode, streaming all logs from
from_blocktolatest - Stream
ScannerStatus::SwitchingToLive - Start processing live mode blocks — i.e. stream events from buffered live blocks and all newly incoming blocks
Example: Current Behavior
Assume the current chain blocks are:
1 - 2 - 3 - 4 - 5
Steps:
-
Scanner initiated with:
sync::from_block(2)
-
The latest block is still
5. -
The scanner starts streaming logs from:
2 3 -
A new block
6is added to the chain. -
The scanner continues streaming:
4 -
Another block
7is added — the chain is now:... - 5 - 6 - 7 -
The scanner streams:
5 SwitchingToLive 6 7 ...
Problem
At this point, the scanner is not technically live — it still has buffered blocks (6 and 7) to process before it’s actually synced with the latest chain tip.
Expected Behavior
The SwitchingToLive notification should be emitted only after the scanner has processed all historic and buffered live blocks — i.e. once it reaches the latest chain tip.
The scanner should stream:
5 logs
6 logs
7 logs
If no new blocks have been added in the meantime, only then should it stream:
SwitchingToLive
Main Challenge
Determine when the scanner has reached the latest chain tip, i.e. when it has processed:
- All buffered live blocks, and
- Is now processing only newly incoming live blocks.