Repository navigation
fix(node,common): bound every sink-internal chain read (#1228) - #1233
Conversation
`chain_events::timed` bounded only the calls it wrapped — the loop's own `get_logs` and `shared_head`'s `get_block_number`. A follow-up RPC issued from inside a `LogSink` stayed unbounded, and the alloy HTTP provider has no request timeout of its own, so a provider that holds the connection open and never responds wedged the tick forever: no cursor movement, no backoff, no metric, and no graceful-shutdown path. Five such reads existed (#1228 lists three; `slash_watcher`'s `get_block` and `chain_origin_directory`'s `node_id_of` were missed). All five now route through `timed`, and each keeps the semantics its own contract already documented: - `payment_settlement::getChannel` — fail the tick, back off. The payment-critical leg; `reconcile_closing_channel`'s doc already specified this recovery path, so a timeout simply joins it. - `reputation_indexer::nodeIdOf` — fail the tick, back off, so the settlement is retried rather than silently un-credited. - `chain_origin_directory::getOrigins` / `nodeIdOf` — fail into the existing defer/retry path. Bounded inside the production `OriginChainReads` impl, so `StubReads` is untouched. - `slash_watcher::get_block` — soft-degrade to an unknown appeal deadline, its existing behaviour on any read failure. `blacklist_watcher::scope_check` moves off its raw `tokio::time::timeout` onto the same helper, leaving one bounding mechanism. It loses a structured `timeout_secs` field; the information survives in `timed`'s message text, and the `sanitize_rpc_display` redaction still applies (`timed` adds no context, so the alloy error's URL tail reaches the scrubber unchanged). `timed`'s doc is rewritten as the enforcement point: every sink read routes through it, and what a timeout *means* stays the call site's decision. Notably `nodeIdOf` appears under both policies deliberately — reputation fails the tick because a skipped settlement is a silent accounting gap, while the registry counts-and-skips because its projection self-heals on the operator's next event. Testing: asserting `timed` in isolation proves the mechanism but not the wiring — exactly the gap that let `confirmations` ship documented-but- disabled. So each site is driven against a provider that genuinely stalls. alloy's `Asserter` cannot express that (`map_request` pops a queued response or errors on an empty queue; it never pends), so `chain_events::test_support` adds a `tower::Service` transport returning `pending()`, modelled on alloy's own `MockTransport`. It is in-process, which is load-bearing: `start_paused` auto-advances an idle runtime to the deadline, whereas a wiremock response delay would park on the I/O driver where the paused clock does not advance. Each test is verified to fail when its wrap is removed. Unguarded that failure is a hang, and there is no `slow-timeout` configured to cut it short, so `bounded` adds a virtual backstop: the same regression now fails in ~0.2s naming the site instead of stalling CI. `alloy-json-rpc` arrives as a dev-dep rather than via alloy's `json-rpc` feature, which is workspace-wide and would widen `decdn-cli`'s surface (#578). cargo unifies it onto the instance alloy-network already pulls, so no extra crate compiles. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Warning Review limit reached
Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (7)
WalkthroughWatcher RPC reads are routed through the shared ChangesWatcher RPC timeout hardening
Estimated code review effort: 3 (Moderate) | ~25 minutes Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 88.92% (2488/2798 lines) |
There was a problem hiding this comment.
Pull request overview
This PR closes #1228 by enforcing a consistent timeout boundary for watcher-path chain RPC reads, including sink-internal follow-up calls, preventing stalled HTTP providers from wedging watcher ticks and blocking progress/shutdown.
Changes:
- Routed previously unbounded sink-internal RPCs (
getChannel,getOrigins,nodeIdOf,get_block) throughchain_events::timed, preserving each call site’s existing failure semantics. - Unified
blacklist_watcher::scope_checkontotimed(removing a bespoketokio::time::timeout). - Added a “hanging provider” test seam plus per-site wiring tests to prove the bounds are actually applied (not just that
timedworks in isolation).
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/chain_events/mod.rs | Clarifies timed as the bounding helper, adds test_support with a hanging provider/guard harness, and pins the seam with a dedicated test. |
| crates/node/src/payment_settlement.rs | Bounds getChannel via timed and adds a wiring test asserting a stalled provider fails the tick instead of hanging. |
| crates/node/src/reputation_indexer.rs | Bounds nodeIdOf via timed, documents the deliberate policy asymmetry vs. the registry watcher, and adds a wiring test. |
| crates/node/src/dht/chain_origin_directory.rs | Bounds production OriginChainReads (getOrigins + nodeIdOf) via timed and adds wiring tests against the hanging provider. |
| crates/node/src/slash_watcher.rs | Bounds get_block via timed while keeping the existing soft-degrade-to-None behavior; adds a wiring test. |
| crates/node/src/blacklist_watcher.rs | Replaces an ad-hoc tokio::time::timeout with timed for isHashBlacklistedForOperator. |
| crates/node/Cargo.toml | Adds dev-deps (tower, alloy-json-rpc) used by the hanging-transport test seam. |
| Cargo.toml | Adds workspace test-only deps (tower = 0.5, alloy-json-rpc = 2) to support the hanging transport. |
| Cargo.lock | Lockfile updates for the added dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request introduces a timed wrapper for RPC calls across the codebase to prevent the watcher tick from stalling when a provider becomes unresponsive. It also adds a hanging_provider test utility and regression tests to verify that these timeouts are correctly wired and effectively prevent wedging. The review feedback suggests using None for the timeout parameter in blacklist_watcher.rs to maintain consistency with other call sites and rely on the default timeout.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Coverage reportTotal: 81.13% (was 80.96%, ▲ +0.17%) — 48494/59775 lines
History
|
…timeout Review follow-ups on #1233. `timed`'s summary still claimed a timeout "is a retryable error (the tick backs off)" — a universal policy the paragraph added directly below contradicts, naming four degrade-and-continue counterexamples. The summary predates the rewrite; drop the claim and leave the policy paragraph as the single statement. `blacklist_watcher::RPC_CALL_TIMEOUT` was a byte-identical duplicate of `DEFAULT_RPC_CALL_TIMEOUT` (10s), and blacklist the sole watcher passing `Some(..)` where the other five pass `None`. Its doc also claimed it bounded the head read, which `resumable_watcher` explicitly denies — the head is issued by the shared `HeadSource`, which carries its own timeout. Collapse both usages onto the default and delete the constant. No behaviour change: same 10s at both sites. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Multi-agent review follow-ups on #1233. `resolve_node_id` is shared by two callers with opposite policies, so bounding it inside the helper applied one policy to both. `resolve_and_store_operators` degrades, but `bootstrap_cache` propagates with `?` and `runtime` treats that as fatal — so a single slow (>10s) call on a congested or rate-limited endpoint (#1108) became a node that will not start, where before it completed. That also contradicted the module's own policy for the replay floor 70 lines up: a one-shot startup path must degrade, not crash. Bootstrap now counts-and-skips like the sink path; the binding self-heals on the operator's next event. The loop moves to `resolve_bootstrap_bindings` (bootstrap_cache tripped `cognitive_complexity` otherwise), which makes the policy testable — the new test is verified to fail both when the metric bump is dropped and when the `timed` wrap is removed. Three doc corrections, all in text this PR introduced: - `timed`'s taxonomy filed "origin's reads" under fail-the-tick. True for `getOrigins`, false for `nodeIdOf`, which counts-and-skips. There are three `nodeIdOf` sites under two policies, not two; the note now reconciles all three. The origin test carried the same false label and is renamed to `..._is_bounded_rather_than_wedging`. - The wiremock rationale was inverted. A paused tokio clock *does* auto-advance while waiting on I/O — only `spawn_blocking` inhibits it (sole caller of `inhibit_auto_advance`; `park_thread_timeout` otherwise polls the I/O driver with a zero timeout, then advances). The real hazard is the opposite of what was written: the clock races to the deadline mid-round-trip and the test passes vacuously. `HangingTransport` stays; its justification is now correct. - `.config/nextest.toml` does not exist. The conclusion held; the citation pointed at nothing. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…chain Review follow-ups on #1233. **Leak.** `slash_watcher`'s block-read warn logged `%err` raw — the only chain error log in the tree that did not scrub, and the module never imported a sanitizer at all. `timed` folds in the transport leg, whose Display carries reqwest's ` for url (…)` tail, i.e. the `rpc_url` with any credentials. **Truncation.** `sanitize_rpc_display` is `strip_urls(&err.to_string())`, and an `anyhow` Display renders only the *outermost* context. Five sites wrap `timed` in `.with_context(…)`, so the timeout this PR exists to produce never reached the operator: the log read `err="getOrigins(namespace=1)"` — what was attempted, never why it failed. The tests missed it because they assert on `format!("{e:#}")`, the alternate form, which no production log site uses; they passed while the log said nothing. `shared_head` already worked around this at one site, which is what makes it a class rather than an oversight. Chain-RPC errors in watchers now render via `sanitize_err_chain` uniformly — including the two sites that add no context today, since the bug comes from having to re-derive "does anything above add context?" per site. The three `resumable_watcher` sites that log a `StoreError` keep `sanitize_rpc_display`: they carry no chain, and the compiler rejects the alternative. A new test pins the render rather than the error, and is verified to fail when it regresses to Display. `sanitize_err_chain`'s doc drops its "use at `main()`" scoping and states why the chain is load-bearing here. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Closes #1228.
Problem
chain_events::timedbounded only the calls it wrapped — the loop's ownget_logsandshared_head'sget_block_number. A follow-up RPC issued from inside aLogSinkstayed unbounded. The alloy HTTP provider has no request timeout of its own, so a provider that holds the connection open and never responds wedges the tick forever: no cursor movement, no backoff, no metric, and no graceful-shutdown path.timed's own doc has admitted this since #1106.The issue undercounts. It lists three unbounded sites; there are five — it misses
slash_watcher.rs:300(get_block) andchain_origin_directory.rs:739(node_id_of, alongside thegetOriginsit does list).What changed
All five now route through
timed. Each keeps the semantics its own contract already documented — no new policy invented:payment_settlement::getChannelreconcile_closing_channel:854-861already specified this recovery path; a timeout just joins it.reputation_indexer::nodeIdOfchain_origin_directory::getOriginsOriginChainReadsimpl;StubReadsuntouched.chain_origin_directory::node_id_ofslash_watcher::get_blockNoneAlso:
blacklist_watcher::scope_checkmoves off its rawtokio::time::timeoutonto the same helper, leaving one bounding mechanism; andtimed's doc is rewritten as the enforcement point for the invariant that now actually holds.Review follow-up (c41dea5) finished that collapse.
blacklist_watchercarried a privateRPC_CALL_TIMEOUTbyte-identical toDEFAULT_RPC_CALL_TIMEOUT(10s), making it the one watcher passingSome(..)where the other five passNone— and its doc claimed it bounded the head read, whichresumable_watcher.rs:202-204explicitly denies (the head comes from the sharedHeadSource, which carries its own timeout). Both usages now take the default and the constant is gone; same 10s either way. Thetimedsummary line also still asserted a timeout "is a retryable error (the tick backs off)" — the universal policy the new paragraph below it exists to refute — so that stale claim is dropped.nodeIdOfappears under both policies deliberately — reputation fails the tick, the registry counts-and-skips because its projection self-heals on the operator's next event. That asymmetry was previously unexplained, so a reader would "fix" one of them; it's now documented atresolve_binding.Rejected: the
LogSinkbounded-provider refactorThe issue floats giving
LogSinka bounded provider handle. Three reasons not to, ascending:chain_origin_directoryalready hasOriginChainReads+ a production impl +StubReads— the identical shape tocapacity_bond_registry's, which already callstimed. Origin's two sites are one added line each in an impl that exists.TimedProvider<P>: Providernewtype — and alloy 2'sProviderrequiresfn root(&self) -> &RootProvider, which hands out the unbounded inner provider and makes the guarantee escapable.Review follow-up (26675e4)
A multi-agent review caught a regression in the first cut.
resolve_node_idis shared by two callers with opposite policies, so bounding it inside the helper applied one policy to both:resolve_and_store_operatorsdegrades, butbootstrap_cachepropagates with?andruntime/mod.rs:912treats that as fatal. A single slow (>10s) call on a congested or rate-limited endpoint (#1108) therefore became a node that will not start, where before it completed — andbootstrap_cacheissues one call per authorised operator. It also contradicted the module's own policy for the replay floor 70 lines up: "a fatal startup crash is strictly worse than graceful degradation."Bootstrap now counts-and-skips like the sink path (the binding self-heals on the operator's next event). The loop moved to
resolve_bootstrap_bindings—bootstrap_cachetrippedcognitive_complexityotherwise — which made the policy testable; the new test is verified to fail both when the metric bump is dropped and when thetimedwrap is removed.Also three doc corrections, all in text this PR introduced:
timed's taxonomy misfiled origin'snodeIdOfunder fail-the-tick (there are threenodeIdOfsites under two policies, not two); the wiremock rationale was inverted (a paused tokio clock does auto-advance while waiting on I/O — onlyspawn_blockinginhibits it — so the real hazard is the clock racing to the deadline and the test passing vacuously, not a hang); and.config/nextest.tomldoes not exist.Both known gaps are now fixed too (4b8da73):
slash_watcher's block-read warn logged%errraw — the only chain-error log in the tree that didn't scrub, in the only watcher module that never imported a sanitizer.timedfolds in the transport leg, whose Display carries reqwest'sfor url (…)tail: therpc_url, credentials and all.sanitize_rpc_displayisstrip_urls(&err.to_string()), and ananyhowDisplay renders only the outermost context. Five sites wraptimedin.with_context(…), so the timeout this PR exists to produce never reached the operator — the log readerr="getOrigins(namespace=1)": what was attempted, never why it failed. The tests missed this because they assert onformat!("{e:#}"), the alternate form, which no production log site uses — they passed while the log said nothing.shared_headalready carried a hand-rolled workaround for exactly this, which is what makes it a class rather than a one-off.Watcher chain-RPC errors now render via
sanitize_err_chainuniformly, including the two sites that add no context today — the bug comes from having to re-derive "does anything above add context?" at each site, so the rule is now uniform rather than per-site. (The threeresumable_watchersites logging aStoreErrorkeepsanitize_rpc_display: no chain to render, and the compiler rejects the alternative — it caught that overreach.) A new test pins the render rather than the error and is verified to fail when it regresses to Display.Testing
Asserting
timedin isolation proves the mechanism but not the wiring — precisely the gap that letconfirmationsship documented-but-disabled (#1227). So each site is driven against a provider that genuinely stalls.alloy's
Assertercannot express a stall (map_requestpops a queued response or errors on an empty queue — it never pends), sochain_events::test_supportadds atower::Servicetransport returningpending(), modelled on alloy's ownMockTransport. Being in-process is load-bearing:start_pausedauto-advances an idle runtime to the deadline, whereas a wiremock response delay parks on the I/O driver where the paused clock does not advance — it would hang or burn real wall-clock.Each test is verified to fail when its wrap is removed. Unguarded, that failure is a hang (~180s, killed), and nothing cuts it short (the repo carries no nextest config, and the built-in
slow-timeoutonly warns) — soboundedadds a virtual backstop. The same mutation now fails in 0.24s:7 tests, ~13ms each (all deadlines virtual).
Verification
cargo nextest run -p decdn-node— 815/815 passcargo clippy --workspace --all-targets— clean (hitmatch_wild_err_arm, fatal under-D warnings; restructured)cargo fmt --check,cargo deny check— passpre-commit run --all-files— all Rust hooks passNotes for review
getChannelused to hang; it now fails the tick and backs off. That is the intent, but it's the one site touching payment-critical code.anvil_settlement_e2e.rs:1331-1373exercises this path against local anvil (10s deadline never trips) — free regression coverage.blacklist_watcherloses a structuredtimeout_secslog field when the two match arms collapse. The information survives intimed's message text. Thesanitize_rpc_displayredaction still applies: it takesimpl Display, andtimedadds no context, so the alloy error's URL tail reaches the scrubber unchanged.alloy-json-rpcis a dev-dep, not alloy'sjson-rpcfeature. The feature is workspace-wide and would widendecdn-cli's surface (CLI binary-split regression: publisher links cache crate (iroh-blobs/AWS SDK) #578); the dev-dep is test-only and cargo unifies it onto the instance alloy-network already pulls, so no extra crate compiles.Follow-up from #1110 / #1226. First of four PRs in the watcher-hygiene batch (#1228 → #1231 → #1227 → #1230); bug first, and #1230 last since it's the only one touching runtime shutdown ordering.
🤖 Generated with Claude Code
Summary by CodeRabbit