Skip to content

fix(node): retry transient boot-time chain reads instead of exiting - #2160

Merged
thiras merged 4 commits into
mainfrom
fix/2159-boot-chain-read-retry
Sep 25, 2026
Merged

thiras merged 4 commits into
mainfrom
fix/2159-boot-chain-read-retry

Conversation

@thiras

@thiras thiras commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2159. A transient JSON-RPC error during a boot-time chain read exited the daemon, so a flaky shared provider turned every restart into a crash-loop (2–87 restarts per node per deploy).

  • BootRetry (crates/node/src/chain_events/boot_retry.rs): the four fail-closed bootstraps — CapacityBond registry, slash enumeration, PaymentPool usdc() self-check, blacklist enumeration + enforcement — retry their read phase on the watcher backoff (1 s → 60 s) under one shared 10-minute boot deadline. Each retry logs boot chain read failed; retrying after backoff and bumps the new decdn_chain_boot_read_retries_total.
  • Deterministic faults stay fatal at once (deterministic failure, not retried): ZeroData, ABI mismatch, revert, -32600..-32602, HTTP 4xx except 408/429 (a 4xx with Retry-After, or with a JSON-RPC error body, is judged as retryable / by its JSON-RPC code), registry page/active length mismatch (BootFault), local eviction error at boot.
  • Shared classifier in decdn-client (provider::is_permanent_contract_error / is_permanent_rpc_error) — a denylist, since alloy's is_retry_err allowlists miss outage codes like 1 and 19. Client registry discovery uses it too (public-API snapshot updated; ADR 012 updated).
  • Supporting fixes: SharedHead keeps the typed provider error through its cache (so the first read of every bootstrap is classifiable); slash boot reads are pinned to the snapshot block (a lagging LB backend now answers "header not found" instead of a fatal revert); registry/slash/usdc() reads get the 10 s per-call timeout.
  • Fee-share boot reads (fee_shares::seed_from_chain): PaymentPool.feeRouter() / FeeRouter.getShares() retry on a 1-minute sub-budget of the boot deadline (BootRetry::capped, so they cannot starve the later fail-closed reads), carry the per-call timeout and log sanitized errors. A new decdn_fee_shares_watcher_unregistered gauge reads 1 if feeRouter() still fails and the watcher never starts. They stay non-fatal (floor share fallback), but a transient feeRouter() error — immutable on-chain — no longer leaves the fee-shares watcher unregistered for the life of the process.
  • Blacklist boot enforcement stops at its first failed scope read (the attempt is lost anyway), and the attempt's cause prefers an eviction (disk) failure, which is permanent, over a scope failure.
  • Deadline scope: the boot deadline bounds retry sleeps, not a running attempt. A failing attempt ends at its first timed read (10 s), so only a slow but healthy provider can stretch one; a hard in-attempt cutoff would turn that into an exit. Safety rests on the enforcement gate, not the deadline (see the review thread).
  • Fail-closed preserved: the ALPN router still waits on the blacklist enumeration and a clean enforcement pass; the readiness gate is signalled exactly once on every path. The issue's unlisted fifth exit (an unclean boot enforcement pass) is now retried too.
  • Docs: ADR 019 gains a "Boot-time chain reads" section (STE); observability appendix row, runbook and CHANGELOG updated.

Test plan

  • cargo clippy --workspace --all-targets -- -D warnings (+ --features anvil-e2e build)
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items
  • cargo fmt -- --check
  • cargo nextest run -p decdn-node -p decdn-client — 1730 passed
  • public-API snapshot (--features public-api-test)
  • anvil_bringup_shutdown_e2e + anvil_settlement_e2e against a rebuilt decdn-node
  • New tests: classifier tables (issue codes 1/19, reverts incl. "Reverted", HTTP 408/429); BootRetry (retry-until-success, permanent not retried, shared budget across reads, 543 s dead-endpoint cap, real empty eth_call → ZeroData); blacklist bootstrap (transient retried, permanent keeps gate shut with 0 retries, unclean enforcement retried before gate opens, exhausted budget keeps gate shut); registry length-mismatch BootFault; slash bootstrap retry; SharedHead typed-cause propagation; stalled-provider bounds for slash/registry/fee reads; slash reads pinned to the snapshot block (stub + wiremock); permanent head error fails boot at once; boot eviction error is a permanent BootFault; boot pass stops at first scope failure; failed live enforcement forces a prompt rescan; usdc() self-check; fee-share seed (transient feeRouter() retried, ZeroData falls back at once, failed getShares() keeps the router).

🤖 Generated with Claude Code

A single transient JSON-RPC error (e.g. code 1 "no available upstreams",
code 19 "Temporary internal error") during any of the four fail-closed
boot reads propagated out of run() and exited the daemon, turning every
restart against a flaky provider into a crash-loop.

- New chain_events::boot_retry::BootRetry: each bootstrap (CapacityBond
  registry, slash enumeration, PaymentPool usdc() self-check, blacklist
  enumeration + enforcement) retries its read phase on the watcher backoff
  (1 s doubling to 60 s) under one shared 10-minute boot deadline. Each
  retry logs a WARN and bumps decdn_chain_boot_read_retries_total.
- Deterministic faults stay fatal at once: no contract (ZeroData), ABI
  mismatch, revert, -32600..-32602, HTTP 4xx other than 408/429, a registry
  page/active length mismatch, a local eviction error at boot.
- Shared classifier in decdn-client (provider::is_permanent_contract_error /
  is_permanent_rpc_error), a denylist of deterministic failures; client
  registry discovery uses it too, so provider outages are retried there.
- SharedHead keeps the typed provider error through its cache; slash boot
  reads are pinned to the snapshot block; registry/slash/usdc() reads carry
  the per-call RPC timeout.
- Startup stays fail-closed: the ALPN router still waits on the blacklist
  enumeration and a clean enforcement pass.
- ADR 019 gains a boot-time chain reads section; ADR 012, the
  observability appendix, runbook and CHANGELOG are updated.

Closes #2159

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 25, 2026 17:23
@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

Moderate issues remain in blacklist failure precedence, retry-pass duration, and enforcement of the shared deadline; provider documentation also needs correction.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

This PR adds fail-closed retries for transient boot-time chain reads, preventing provider failures from causing daemon crash loops.

Changes:

  • Adds shared retry/backoff, deadlines, error classification, and metrics.
  • Applies retries to registry, slash, settlement, and blacklist bootstraps.
  • Updates tests, client discovery, documentation, ADRs, and changelog.

The review leaves three moderate issues involving blacklist failure handling and deadline enforcement, plus one provider-classifier documentation nit.

File Summary
docs/​runbook.md Documents boot retry behavior
crates/​node/​tests/​anvil_settlement_e2e.rs Updates settlement test setup
crates/​node/​src/​slash_watcher.rs Adds pinned, retryable slash reads
crates/​node/​src/​runtime/​mod.rs Wires the shared boot retry budget
crates/​node/​src/​payment_settlement.rs Retries the PaymentPool self-check
crates/​node/​src/​metrics.rs Adds boot retry metrics
crates/​node/​src/​dht/​node_address.rs Updates bootstrap documentation
crates/​node/​src/​dht/​capacity_bond_registry.rs Adds retryable registry bootstrap
crates/​node/​src/​chain_events/​shared_head.rs Preserves typed head-read errors
crates/​node/​src/​chain_events/​mod.rs Exposes the retry module
crates/​node/​src/​chain_events/​boot_retry.rs Implements shared retry and classification
crates/​node/​src/​buyer_channel.rs Clarifies bootstrap behavior
crates/​node/​src/​blacklist_watcher.rs Retries blacklist enumeration and enforcement
crates/​client/​tests/​snapshots/​public_api__public_api.snap Updates the public API snapshot
crates/​client/​src/​provider.rs Adds shared RPC error classification
crates/​client/​src/​discovery.rs Reuses the shared classifier
CHANGELOG.md Records the fix
adr/​appendix-observability.md Documents the new metric
adr/​019-node-onboarding.md Specifies boot-time retry behavior
adr/​012-client.md Documents classifier behavior

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

Comment thread crates/client/src/provider.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 7fa83f5 in the fix/2159-boot-chain-... branch remains at 85%, unchanged from commit e229c2b in the main branch.

Show a line coverage summary of the most impacted files.
File main e229c2b fix/2159-boot-chain-... 7fa83f5 +/-
crates/node/src...gin/pull_leg.rs 89% 89% 0%
crates/node/src...t_settlement.rs 71% 72% +1%
crates/node/src/runtime/mod.rs 49% 50% +1%
crates/client/src/streamer.rs 91% 92% +1%
crates/node/src...n_staker_set.rs 87% 92% +5%
crates/node/src...ond_registry.rs 82% 95% +13%
crates/node/src...list_watcher.rs 74% 93% +19%
crates/node/src...lash_watcher.rs 59% 81% +22%
crates/client/src/provider.rs 73% 96% +23%
crates/node/src...s/boot_retry.rs 0% 99% +99%

Updated September 25, 2026 18:47 UTC

thiras and others added 3 commits September 25, 2026 20:48
PaymentPool.feeRouter() is immutable, so a single transient error at boot
left the fee-shares watcher unregistered and the operator share on the
floor for the life of the process. The reads also had no per-call timeout
and logged unsanitized alloy errors (the RPC URL can carry an API key).

Move the reads into fee_shares::seed_from_chain: both retry transient
errors through BootRetry on the shared boot deadline, carry the per-call
timeout, and log with sanitize_err_chain. They stay non-fatal: a
deterministic error or an exhausted budget seeds the floor share, and a
failed getShares() still keeps the router so the watcher's re-read can
recover the share. ADR 019 and the CHANGELOG entry cover the change.

Refs #2159

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Cap the best-effort fee-share reads at a 1-minute sub-budget of the boot
  deadline (BootRetry::capped) so a flapping provider cannot spend the time
  the later fail-closed usdc() and blacklist reads need.
- Blacklist boot enforcement stops at its first failed scope read, and the
  attempt's cause prefers an eviction (disk) failure over a scope failure,
  so a disk fault is not hidden behind an RPC blip. Each scope_check caller
  logs what the failure means on its path; eviction logs carry the full
  I/O cause.
- New decdn_fee_shares_watcher_unregistered gauge: 1 when the startup
  feeRouter() read failed and the watcher never started.
- The fee-shares watcher's periodic getShares() carries the per-call
  timeout and logs a sanitized error.
- Extract the PaymentPool usdc() self-check so it is testable.
- Tests: stalled-provider bounds for the slash, registry and fee reads;
  registry bootstrap retry wiring; slash reads pinned to the snapshot block
  (stub + wiremock block-tag check); permanent head error fails boot at
  once; eviction error at boot is a permanent BootFault; a reverting scope
  read fails at once; the boot pass stops at the first scope failure; a
  failed live enforcement forces a prompt rescan; a failed scope read on
  HashRemoved keeps the deny; capped sub-budget; usdc() self-check.
- Docs: retry-counter scope, HeadSource/SharedHead docs, the serve gate
  comment, enforcement-failure metric wording, ADR 019/012 STE fixes and
  the 4xx/Retry-After/JSON-body nuance, runbook, CHANGELOG.

Refs #2159

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- provider.rs: state that alloy reports a 4xx carrying Retry-After as
  HttpErrorWithRetryAfter, which the classifier treats as transient, and
  pin it with a test.
- boot_retry.rs: explain why the boot deadline bounds retry sleeps but not
  a running attempt: a failing attempt ends at its first timed read, so
  only a slow but healthy provider can stretch one, and fail-closed rests
  on the enforcement gate, not the deadline.

Refs #2159

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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 and moderate blacklist-enforcement correctness findings remain unresolved, with an additional documentation nit.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (2)

Comment thread crates/node/src/blacklist_watcher.rs Resolved
@thiras
thiras merged commit 88861ff into main Sep 25, 2026
31 checks passed
@thiras
thiras deleted the fix/2159-boot-chain-read-retry branch September 25, 2026 18:48
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: a transient RPC error during a boot-time chain read exits the daemon, so a flaky provider turns every restart into a crash-loop

2 participants