Repository navigation
fix(node): keep a partly paid chunk owed so the serve loop cannot spin (#2132) - #2133
Merged
Merged
Conversation
#2132) A proof credits at most the lane headroom it finds, so a sealed voucher that moves the watermark by a sliver pays a sliver of the chunk. Both recoup loops added that sliver to `paid` but popped the whole chunk, so the unpaid rest was tracked nowhere. On a cache hit, once it filled the credit window, `deliver` looped without awaiting and held one tokio worker per stream; two such streams wedged a 2-vCPU testnet node. - `OwedChunk { len, remaining }` replaces the bare delta in both queues. A chunk leaves the queue only when proofs have paid all of it, and `MAX_PROOFS_PER_CHUNK` counts every proof that leaves it unsettled. - `voucher_credit_delta` classifies by the chunk's delivered length, so a metering voucher still pays no part of a whole chunk (#2124). - Both loops check after each recoup that `delivered - paid` equals the bytes not yet cut into a chunk, and `settle` refuses an over-credit. Either break fails the stream as a node fault. - The no-progress guard in both loops is a node fault. The miss path filed it as a client abandon; `ServeStop::ClientAbandoned` is gone. - ADR 003/005: the payer anchors a stream immediately before its first reveal, not at stream open, and an honest payer never gets a partial credit. Both statements match the client and are now load-bearing. - `two_hashes_reuse_one_warm_connection` reused a zero-based context for a second fetch on one lane and relied on the leak; it now seeds the second fetch from the lane's totals. Tests: sliver credit, proof budget and last-proof settle on the cache hit; sliver credit and proof budget on the miss path; a sub-chunk stream on a live chain sends only its closing voucher (mutation-checked). Closes #2132 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The payment-accounting and serve-loop changes span core serving paths and protocol behavior, warranting final human review.
Review effort: Lite
Findings: None
What changed in this PR
Fixes a node liveness vulnerability caused by partially paid chunks being removed from serve queues, which could trigger busy-spinning workers.
Changes:
- Tracks owed chunk remainders and bounds partial-proof attempts.
- Adds accounting and no-progress fault checks.
- Updates tests, ADRs, and changelog documentation.
| File | Description |
|---|---|
crates/node/tests/node_origin_pull.rs |
Adds pull-through partial-payment regression coverage. |
crates/node/tests/client_loopback.rs |
Adds cache-hit payment and ordering regressions. |
crates/node/src/handlers/client/wire.rs |
Updates payment-fault documentation. |
crates/node/src/handlers/client/voucher.rs |
Adds owed-chunk and accounting primitives. |
crates/node/src/handlers/client/serve_leg.rs |
Applies owed-chunk accounting to pull-through serving. |
crates/node/src/handlers/client/outcome.rs |
Removes the obsolete client-abandon outcome. |
crates/node/src/handlers/client/mod.rs |
Documents proof-budget semantics. |
crates/node/src/handlers/client/delivery.rs |
Fixes cache-hit owed-chunk handling and serve-loop progress. |
CHANGELOG.md |
Records the runtime-wedge fix. |
adr/005-protocol.md |
Aligns protocol rules with implementation. |
adr/003-payments.md |
Documents partial-payment and anchoring rules. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Code Coverage OverviewLanguages: Rust Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit acf7e85 in the Show a line coverage summary of the most impacted files.
|
alpergundogdu
added a commit
that referenced
this pull request
Sep 24, 2026
…serve-loop starvation (#2145) * feat(node): heartbeat the systemd watchdog from the runtime and test serve-loop starvation A serve loop that goes around without awaiting holds a tokio worker. Once every worker is held, the node serves nothing, logs nothing and answers no /metrics scrape, but its systemd unit stays `active`, so nothing restarts it. #2133 fixed the sliver-credit loop that did this (#2132). This change makes the failure class recoverable and pins the fixed case. - `systemd_watchdog`: when systemd passes `WATCHDOG_USEC` and `NOTIFY_SOCKET`, a runtime task sends `WATCHDOG=1` every half period. The heartbeat runs on the runtime, so it stops when no worker is free, and systemd restarts the node. No node setting: the unit's `WatchdogSec=` turns it on. Honors `WATCHDOG_PID`; supports path and abstract sockets; the socket is non-blocking so a full queue cannot block a worker. - `a_sliver_voucher_does_not_starve_the_runtime`: runs the #2132 sliver case on a one-worker runtime and fails if a heartbeat task on it stops ticking. It fails in ~2 s against the parent of #2133 (0 ticks) and passes on main. A starved runtime is leaked, not dropped, because the drop would wait forever for the worker to yield. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(node): build the watchdog notifier once and reuse it per heartbeat Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2132. Two testnet nodes (fra1, lon1) wedged at 100% CPU. A proof that paid only part of an outstanding chunk made the cache-hit serve loop spin without awaiting, one tokio worker per stream.
Root cause.
credit_advancecaps a credit at lane headroom, so a sealed voucher that moves the watermark by a sliver credits a sliver. Both recoup loops added the sliver topaidbut popped the whole chunk frompending. That brokeΣ pending + unvouchered == delivered − paid. Oncedelivered − paidfilled the window withpendingempty, no branch ofdeliverawaited. Any paying client could trigger it on purpose.Changes
OwedChunk { len, remaining }(voucher.rs) replaces the bare delta in both queues (delivery.rs,serve_leg.rs).MAX_PROOFS_PER_CHUNKcounts every proof that leaves the chunk unsettled, so sliver after sliver hits the bound.voucher_credit_deltaclassifies bylen, notremaining, so a metering voucher still pays no part of a whole chunk (the fix: unstall bundle pull (runtime I/O, lane credit, ingest fsync, probe limits, boundary legs) #2124 anti-starvation rule).delivered − paidequals the bytes not yet cut into a chunk (ensure_unpaid_bytes_tracked), andsettlerefuses an over-credit. Either break fails the stream as a node fault.error!and counted indecdn_serve_stream_node_fault_total. The miss path used to file it as a client abandon, soServeStop::ClientAbandonedis removed.Why no "wake on headroom" mechanism
An honest payer never meets a partial credit. Every voucher on a lane is issued from one shared
PoolLedgeras the lane frontier plus the stream's own delta, and the node's byte claim is exact. So each proof finds headroom for its own chunk. After a stream's last reveal, the payer sends only that stream's closing voucher.Only a payer that claims fewer bytes than it received can get a partial credit: a sliver attacker, or a lane seeded from a stale base. Such a payer now stalls and then faults, instead of taking bytes it did not pay for.
a_sub_chunk_stream_on_a_live_chain_sends_only_its_closing_voucherpins the client ordering this depends on. A mutation that sends an eager anchor fails it.Tests
a_sliver_voucher_leaves_the_rest_of_the_chunk_owedsliver_vouchers_exhaust_the_per_chunk_proof_budget, which also asserts no node faulta_chunk_settled_by_the_last_proof_of_its_budget_is_paidwindow_pull_through_sliver_voucher_leaves_the_rest_owed, which runs to a fully paidStreamEndwindow_pull_through_sliver_vouchers_exhaust_the_proof_budgetOwedChunksettle and over-credit, the accounting check, and the whole-chunk rule on a partly paid chunk.two_hashes_reuse_one_warm_connectionreused a zero-basedPoolContextfor a second fetch on one lane, so it underpaid by about 400 KB and relied on the leak. It now seeds the second fetch from the lane's totals. The production client already does this through its shared ledgers.cargo nextest run -p decdn-nodepasses all 1258 tests. Workspace clippy,cargo doc -D warningsand fmt are clean.Operational note
A wedged node still looks
activeto systemd. fra1 and lon1 need a manual restart until this ships.🤖 Generated with Claude Code