Skip to content

Speed up first sync of the EVM-reader for new applications #686

@vfusco

Description

@vfusco

Context / Problem

At first startup the EVM-reader issues an eth_getLogs filter-log scan from the block where the InputBox contract was deployed all the way to the latest L1 block.
For a brand-new dApp this huge fromBlock … toBlock range contains hundreds of thousands of empty blocks, so the node burns JSON-RPC quota and spends minutes waiting for results even though no relevant logs exist.


Suggested Solution

  1. Fast “probe-and-decide” flow
    Let
    current = latest L1 block,
    appDeploy = dApp contract deployment block,
    inputDeploy = InputBox deployment block.

    Step A – probe current

    • Call eth_getLogs for this dApp only at current.
      • No inputs: set last_checked_block = current and finish (zero-cost start).
      • Some inputs: continue to Step B.

    Step B – probe appDeploy − 1

    • Call eth_getLogs at block appDeploy − 1.
      • No inputs: sync the shorter range [appDeploy … current].
      • Some inputs: fall back to the full scan [inputDeploy … current].

    The optimisation costs at most two extra RPC calls.

  2. State & restart safety
    Persist last_checked_block in the DB so restarts reuse the determined range.


Acceptance Criteria

# Scenario Expected result
1 Brand-new dApp, no inputs Sync finishes after ≤ 2 RPC calls; node ready in < 2 s.
2 Inputs only after deploy Scans [appDeploy … latest]; RPC/time drop ≥ 80 %.
3 Inputs before deploy Falls back to full scan; behaviour identical to current.

This optimisation slashes first-run synchronisation time and RPC usage for new applications while preserving correctness for existing ones.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

📋 Backlog

Relationships

None yet

Development

No branches or pull requests

Issue actions