zebra icon indicating copy to clipboard operation
zebra copied to clipboard

Refactor ScanTask in zebra-scan

Open arya2 opened this issue 1 year ago • 2 comments

Motivation

The scan task in zebra-scan is could be simplified and more maintainable if it were refactored, possibly into a new tower service or by adding some of its logic to the existing ScanService.

This would make it easier to:

  • Implement efficient batch scanning
  • Register keys immediately (it's currently only checking for new registered keys before scanning a block in the root scan task, but not while it's scanning a block)
  • Subscribe to results for a block height while it's still being scanned (so that simultaneous Results and SubscribeResults requests will catch any results for a given key without extra logic)

Possible Design

A design meeting could be worthwhile to discuss possible designs. We may want to consider the Downloads service in the inbound service and/or the QueuedBlocks struct in the state service.

Example:

We could replace the scan_task field on the ScanService with scan_tasks


struct ScanTasks {
    /// Watch channel of senders for subscribed clients
    result_senders: tokio::sync::watch::Sender<HashMap<String, Sender<()>>>,

    /// Scan tasks by id
    tasks_by_id: HashMap<ScanTaskId, ScanTask>,

    /// tasks scanning transactions for a given key
    by_key: HashMap<String, Vec<ScanTaskId>>,

    /// tasks by the next block height that they will scan
    by_height: BTreeMap<Height, ScanTaskId>,
}

arya2 avatar Feb 08 '24 22:02 arya2

We may want to do #7934 in the same PR as this one to avoid changing a lot of the scan task twice, we can do #7927 first to prepare for #7934.

arya2 avatar Feb 12 '24 21:02 arya2

There's a discussion about the new design in #8271.

upbqdn avatar Feb 14 '24 20:02 upbqdn

@arya2 is this still relevant in light of #8581 ?

mpguerra avatar Jul 05 '24 10:07 mpguerra

@arya2 is this still relevant in light of #8581 ?

Yeah, it's not affected by #8581, though it doesn't seem like a priority right now.

arya2 avatar Jul 05 '24 13:07 arya2