Skip to content

feat: ScannerStatus::SwitchingToLive Should be Emitted Only When Scanner Catches Up with Latest Chain Tip #155

@0xNeshi

Description

@0xNeshi

Brief Sync Mode Logic Description

  1. Get the current latest block number
  2. Run live mode in the background and buffer all incoming blocks for later processing
  3. Invoke historic mode, streaming all logs from from_block to latest
  4. Stream ScannerStatus::SwitchingToLive
  5. 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:

  1. Scanner initiated with:

    sync::from_block(2)
  2. The latest block is still 5.

  3. The scanner starts streaming logs from:

    2
    3
    
  4. A new block 6 is added to the chain.

  5. The scanner continues streaming:

    4
    
  6. Another block 7 is added — the chain is now:

    ... - 5 - 6 - 7
    
  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.

Metadata

Metadata

Assignees

Labels

priority: highImportant for MVP/core featurestype: enhancementImprovement to existing functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions