Skip to content

Event watchers re-scan full history on every start; needs persisted cursor / bounded backfill #1108

Closed

Description

@thiras

Summary

The from_block-seeded event watchers (slash_watcher, blacklist_watcher, chain_origin_directory) re-scan the entire range [from_block, head] on every process start, with no cursor persisted across restarts. When from_block is the contract deploy block, that is a multi-hundred-million-block scan on each boot — tens of thousands of eth_getLogs calls in a burst. On any rate- or quota-limited RPC endpoint this exceeds the limit immediately; we observed it crash-loop a node against a keyed free tier. We should find a cheaper way to establish watcher state at startup.

Observed impact (Arbitrum Sepolia, 2026-07-12)

Internal instance node bcl, onboarded today:

  • from_block (config) = deploy block 11,249,862; head 286,533,334 → gap 275,283,472 blocks.
  • Backfill window = MAX_BACKFILL_BLOCK_SPAN (10,000), so ~27,528 eth_getLogs calls per genesis-seeded watcher, ×3 watchers ≈ ~82,000 calls per process start.
  • Pointed at a keyed Infura free endpoint (needed for eth_newFilter, see Node event watchers hard-depend on eth_newFilter; switch to eth_getLogs polling #1106), the startup burst tripped Infura's rate limit → 429 Too Many Requests on the startup reachability check → process exit → systemd restart → repeat. Restart counter climbed past 30; the burst re-rate-limited every attempt.
  • The previous public endpoint (sepolia-rollup.arbitrum.io) only tolerated this because it does not throttle — but it lacks eth_newFilter, so it is not a real option (Node event watchers hard-depend on eth_newFilter; switch to eth_getLogs polling #1106).

Net: a correctly-registered node cannot stay up against a rate-limited RPC purely because of startup backfill volume.

Where it comes from

  • crates/node/src/slash_watcher.rs — rebuilds its in-memory slash store "from from_block on every process start" (no persisted cursor); scans [from_block, head] on the first cycle. The doc comment intends from_block to be the "30-day appeal window," but the shipped/config default seeds it at the SlashJudge deploy block.
  • crates/node/src/blacklist_watcher.rs — windowed HashBlacklisted replay from from_block (REPLAY_WINDOW_BLOCKS = 9_000), checkpoint held in memory only.
  • crates/node/src/dht/chain_origin_directory.rs — same pattern from origin_directory_from_block.
  • crates/node/src/payment_settlement.rs — NOTE: this one already does the right thing (resolve_backfill_start(last_seen, head, margin) bounds the scan to a recent window), and is the model to generalize from.
  • Config knobs (all default to the deploy block in the internal-devops inventory): slash_judge_from_block, content_blacklist_from_block, origin_directory_from_block.

Directions to explore

  1. Persist the scan cursor/checkpoint to disk so restarts resume incrementally instead of re-scanning [from_block, head] every boot. (Biggest win — turns an O(chain age) startup into O(downtime).)
  2. Bound each watcher's default lookback to what it actually needs. Slash only needs the ~30-day appeal window, not genesis. Generalize payment_settlement's recent-window approach.
  3. Seed from current state instead of replaying all history where a state read exists — e.g. read ContentBlacklist's current version + enumerate active entries once, then only stream new events, rather than replaying every historical HashBlacklisted.
  4. Rate-aware backfill — cap in-flight getLogs concurrency / add pacing so a cold start degrades gracefully under a throttling provider instead of tripping a fatal reachability failure.
  5. Make the startup RPC reachability preflight resilient to a transient 429 (retry/backoff) rather than exiting the process.

Acceptance criteria

  • A cold start against a rate-limited free RPC (e.g. Infura free) completes without tripping the rate limit or crash-looping.
  • A restart does not re-scan the full [from_block, head] range (cursor persisted, or state-seeded).
  • Historical correctness is preserved (no missed blacklist/origin entries) via a state snapshot or persisted cursor rather than a shortened from_block.
  • Startup reachability check tolerates a transient 429/5xx with backoff instead of exiting.

Context

Found while bringing up the internal instance node bcl (decdn/internal-devops). Related: #1106 (the eth_newFilter dependency that forces a keyed/rate-limited provider in the first place) and #1092 (chain_events watcher refactor — a natural home for a shared, cursor-persisting backfill+stream helper). The operator-side stopgap is to raise from_block to a recent block, but that trades away historical replay and shouldn't be the permanent answer.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions