Skip to content

fix(node): pin boot enumeration snapshots below the reported head - #2165

Merged
thiras merged 3 commits into
mainfrom
fix/2164-snapshot-lag-margin
Sep 25, 2026
Merged

thiras merged 3 commits into
mainfrom
fix/2164-snapshot-lag-margin

Conversation

@thiras

@thiras thiras commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Boot enumeration snapshots pinned every eth_call to the exact head from HeadSource::head(). A load-balanced RPC such as dRPC reports its freshest upstream's head, then routes each pinned call to any upstream. Upstreams that lag by 40–200 blocks reject the call, and each BootRetry attempt re-reads a fresh head, so boot spent its 600s budget and exited.

  • Adds SNAPSHOT_LAG_MARGIN_BLOCKS = 256 (about 64s on Arbitrum) and snapshot_block() in chain_events::shared_head.
  • Deploy floor: snapshot_block checks eth_getCode(contract, head − 256). If there's no code there, the contract was deployed inside the margin (a dev-deploy.sh chain, or a boot right after a deploy), so it pins at head instead and logs it.
  • Boot: the slash, blacklist and CapacityBond registry enumerations pin every read (including every getRegisteredNodes page) to that block, and seed their tail cursors there. The tail replays [snapshot, head]; every sink is idempotent.
  • Periodic resyncs: all three read the same lagged block, so they no longer fail on every attempt behind a load balancer. Each sink records the block of its latest tail change per key. The fold keeps every change above the snapshot block on top of the snapshot: blacklist origins and removed hash entries, every registry projection of a changed node, and every tail-seen slash. This holds for any snapshot block, including a head that goes backwards between upstreams.
  • Metrics: new decdn_blacklist_reenumeration_failures_total and decdn_slash_resync_failures_total, with ADR appendix rows and alert rules. Before this, those failures only logged a warn!.
  • Docs: ADR 011 and ADR 019 describe the snapshot block, the fold, and the readiness trade-off. The blacklist readiness gate now opens on the deny-set as of head − 256, and the first tail tick enforces a takedown inside that window.
  • e2e: anvil keeps no state at or below an anvil_loadState head, and errors rather than returning empty code there. So ChainFixture::launch mines margin + 1 blocks after the load. anvil_bringup_shutdown_e2e boots a fresh anvil without mining, which exercises the getCode fallback.

The margin is a constant, not a config knob. 256 would have passed every probe in the issue.

Test plan

  • Unit tests:
    • snapshot_block: the margin below head when the contract has code there, and head when it doesn't.
    • Slash boot: every read tag and the cursor seed are head − 256.
    • Registry boot (wiremock): the code check and every page are head − 256, and so is the cursor seed.
    • Blacklist, registry and slash folds keep tail changes above the snapshot block and take the snapshot at or below it.
    • A stalled slash contract read times out.
  • cargo nextest run -p decdn-node: 1363/1363
  • anvil_bringup_shutdown_e2e passed on a fresh anvil with no mining (the getCode fallback)
  • Full decdn-e2e --features anvil-e2e: 69/69. node_pull_pool_adopt failed once under the parallel suite, then passed 4/4 in isolation.
  • clippy (incl. --features anvil-e2e), rustdoc -D warnings, pre-commit hooks
  • Deploy to one dRPC-backed testnet node and confirm the first boot attempt logs slash enumeration complete, and that decdn_*_resync_failures_total / decdn_blacklist_reenumeration_failures_total stay flat

Closes #2164

🤖 Generated with Claude Code

)

A load-balanced RPC reports its freshest upstream's head, then routes each
pinned eth_call to any upstream. Upstreams behind that head reject it, and
every BootRetry attempt re-reads a fresh head, so boot never converges and
spends its whole budget.

The slash and blacklist enumerations now pin their reads at
head - SNAPSHOT_LAG_MARGIN_BLOCKS (256, ~64s on Arbitrum). The CapacityBond
registry seeds its cursor there too, which also closes a gap: its `latest`
reads can resolve below the reported head on a lagging upstream. Each tail
cursor is seeded at the snapshot block and every sink is idempotent, so the
first tick replays the margin harmlessly.

The e2e ChainFixture and the bring-up e2e mine past the margin, because anvil
holds no state at or below a loaded head.

Closes #2164

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 25, 2026 20:49
@thiras thiras self-assigned this Sep 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Critical snapshot consistency issues remain in blacklist re-enumeration and registry boot reads, plus a deployment-floor issue.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity · 1 Medium severity

Open (3)
What changed in this PR

This PR makes boot-time chain enumeration resilient to lagging load-balanced RPC upstreams by using a 256-block snapshot margin.

Changes:

  • Adds shared snapshot calculation and tests.
  • Updates slash, blacklist, and registry cursor initialization.
  • Adjusts Anvil E2E fixtures to mine beyond the margin.
File Summary
crates/​node/​tests/​anvil_bringup_shutdown_e2e.rs Mines beyond the snapshot margin after deployment.
crates/​node/​src/​slash_watcher.rs Pins slash enumeration to the lagged snapshot.
crates/​node/​src/​dht/​capacity_bond_registry.rs Seeds the cursor below head; registry reads may still precede that cursor.
crates/​node/​src/​chain_events/​shared_head.rs Adds snapshot margin logic; saturation can precede contract deployment.
crates/​node/​src/​chain_events/​resumable_watcher.rs Updates cursor documentation.
crates/​node/​src/​blacklist_watcher.rs Pins blacklist enumeration; periodic re-enumeration can replace newer tail state.
crates/​e2e/​src/​time.rs Adds multi-block mining support.
crates/​e2e/​src/​chain.rs Mines beyond the margin after state loading.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/node/src/blacklist_watcher.rs Resolved
@github-code-quality

github-code-quality Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit b317a0b in the fix/2164-snapshot-la... branch is 86%. The line coverage in commit ce98e34 in the main branch is 85%.

Show a line coverage summary of the most impacted files.
File main ce98e34 fix/2164-snapshot-la... b317a0b +/-
crates/incentiv...eth_identity.rs 99% 98% -1%
crates/node/src...gin/pull_leg.rs 89% 89% 0%
crates/node/src...list_watcher.rs 93% 93% 0%
crates/node/src...ond_registry.rs 95% 95% 0%
crates/client/src/scheduler.rs 95% 95% 0%
crates/cache/src/engine.rs 94% 94% 0%
crates/e2e/src/chain.rs 14% 14% 0%
crates/node/src.../shared_head.rs 95% 96% +1%
crates/node/src...lash_watcher.rs 81% 87% +6%

Updated September 25, 2026 22:10 UTC

thiras and others added 2 commits September 26, 2026 00:09
…ry pages; deploy-floor fallback

- The blacklist periodic re-enumeration pins the head again (SnapshotPin::Head).
  Its fold replaces the origin set wholesale, so a snapshot from the lag
  margin would drop an origin the tail had already blacklisted inside it.
  Only the boot pass takes the lagged block.
- The CapacityBond registry boot enumeration pins every getRegisteredNodes
  page to the snapshot block, so the pages agree with each other and with the
  seeded cursor even on an upstream lagging past the margin.
- boot_snapshot_block checks eth_getCode at the lagged block and pins the
  head when the contract has no code there (deployed inside the margin), so a
  dev-deploy.sh chain or a boot right after a deploy no longer decodes an
  empty return and fails boot. The bring-up e2e now boots without mining to
  exercise that path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The blacklist, registry and slash periodic resyncs read the same lagged
snapshot block as boot, so they no longer fail on every attempt behind a
load-balanced RPC. Each sink records the block of its latest tail change
per key, and the fold keeps every change above the snapshot block on top of
the snapshot: blacklist origins and removed hash entries, every registry
projection of a changed node, and every tail-seen slash. The fold is
correct for any snapshot block, including one below blocks the tail has
already applied when the reported head goes backwards.

- snapshot_block (renamed from boot_snapshot_block) logs when it falls back
  to head for a contract younger than the margin, and documents that the
  margin is a block count sized for Arbitrum.
- New counters decdn_blacklist_reenumeration_failures_total and
  decdn_slash_resync_failures_total, with ADR rows and alert rules.
- Tests: registry boot pins its pages and cursor to the snapshot block;
  registry, blacklist and slash folds keep tail changes above the block;
  a stalled slash contract read times out; the slash boot seeds its cursor
  at the pinned block.
- Prose: ADR 011 and ADR 019 describe the snapshot block and the fold;
  stale "at head" / `latest` wording and an off-by-one replay range fixed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit e834ccd into main Sep 25, 2026
30 checks passed
@thiras
thiras deleted the fix/2164-snapshot-lag-margin branch September 25, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node: boot enumeration snapshots pinned to exact head fail behind load-balanced RPCs with lagging upstreams

2 participants