Repository navigation
fix(node): heal a restarted client whose watermark fell behind - #1954
Conversation
A client that crashes mid-stream persists its voucher watermark only once, at end of fetch, so on restart it re-seeds from a stale watermark and re-signs from a stale anchor. Its first voucher lands strictly below the node's last_amount, so the node classifies it as a benign already-satisfied AmountRegression: it credits zero, the credit window stays pinned at the one-chunk floor, and the stream wedges at ~1 MiB until the 10s voucher-read timeout drops it. The WatermarkBundle recovery path existed but was unreachable, because the benign-swallow never emitted a bundle. Emit the authoritative watermark on the wedge. In commit_one_proof, when a voucher is strictly below our watermark on the lane's SOLE stream, hand back a gated AmountRegression rejection carrying the WatermarkBundle so the payer reseeds and resumes (both the buffered and progressive client paths already consume it). The reject is terminal; the reopened leg pays forward from the healed anchor. Preserve out-of-order same-lane concurrency: the heal is gated on active_streams <= 1. A concurrent sibling (#1697) legitimately sends out-of-order sub-watermark vouchers whose bytes another stream's advance already covers, and a terminal reject would tear down that honest stream. A genuinely wedged multi-stream lane still recovers via the read-timeout backstop. To make that gate correct off-chain, maintain active_streams whenever the lane is known; only the solvency surcharge still requires a live pool status. Add a loopback repro: advance the node lane, then fetch again from a stale prior_* watermark. Its budget sits below the 10s timeout, so it fails unless recovery fires fast. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The new stale-resume reject path currently stamps last_voucher_at before it may reject the voucher, making the “last accepted voucher” diagnostic inaccurate, and one doc comment in the new helper contradicts the actual call order.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes a restart wedge where a client resumes with a persisted voucher watermark that has fallen behind the node’s authoritative lane watermark. It does so by having the node emit a WatermarkBundle on a gated AmountRegression rejection (sole-stream only), enabling the client to reseed and reopen using existing recovery machinery; it also adjusts lane active-stream tracking so the sole-stream gate works even without pool_status, and adds an integration test that reproduces the crash-restart desync.
Changes:
- Add a sole-stream “stale resume” path in voucher handling to return a
WatermarkBundlewhen a voucher amount is strictly below the lane watermark. - Maintain
active_streamswhenever the lane is known (even without on-chainpool_status) so the wallet-less-resume gate can distinguish lone-stream vs concurrent-sibling cases off-chain. - Add an integration test reproducing the restarted-client stale-watermark wedge and asserting fast recovery.
File summaries
| File | Description |
|---|---|
| crates/node/src/handlers/client/voucher.rs | Adds stale-resume detection and a watermark-bearing rejection to trigger client reseed/reopen. |
| crates/node/src/handlers/client/dispatch.rs | Updates lane admission to maintain the active-stream counter without requiring pool_status. |
| crates/node/tests/client_loopback.rs | Adds an integration regression test covering crash-restart stale-watermark recovery. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Address Copilot review on #1954: - Decide the wallet-less-resume heal before stamping `last_voucher_at`, so a voucher we reject no longer advances the admin "seconds since last voucher" diagnostic. - Correct the `stale_resume_bundle` doc: the caller swaps in the verified state BEFORE this runs; a benign sub-watermark swap leaves the watermark unchanged, so the bundle still reports the true frontier. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Coverage reportTotal: 82.71% (was 82.70%, ▲ +0.01%) — 75522/91305 lines
History
|
Problem
A client killed mid-stream and restarted gets stuck: it downloads ~1 MiB, then times out. The client persists its voucher watermark to disk only once, at end of fetch (fetch.rs:1896), committing in memory as it goes. A crash before that write loses every voucher the node already accepted, so on restart the client re-seeds its ledger from the stale watermark and re-signs from a stale anchor.
Its first voucher then lands strictly below the node's
last_amount. The node classifies that as a benign already-satisfiedAmountRegression(voucher.rs): it credits zero, so the per-stream credit window stays pinned at its one-chunk floor, delivery wedges at ~1 MiB, and the stream dies on the 10s voucher-read timeout. TheWatermarkBundlerecovery path already existed end-to-end on the client, but was unreachable — the benign-swallow never emitted a bundle, andBytesRegressionnever fires because the amount check runs first.Fix
Emit the node's authoritative watermark on the wedge, reusing the existing recovery machinery (no new wire message).
voucher.rs— Incommit_one_proof, a newstale_resume_bundlehelper fires when a voucher is strictly below our watermark on the lane's sole stream. It returns a gatedAmountRegressionrejection carrying theWatermarkBundle; the client reseeds and reopens, paying forward from the healed anchor. Both client paths already consume it — bufferedfetch_innerand the progressive driver (lib.rs:2904 → driver.rs:807). The pure, unit-testedverify_voucheris untouched.dispatch.rs—active_streamsis now maintained whenever the lane is known, not only when on-chainpool_statusis present; only the solvency surcharge still requirespool_status. This makes the sole-stream gate correct off-chain.client_loopback.rs—client_restart_with_stale_watermark_heals_and_resumesreproduces the wedge (advance the lane, then fetch from a staleprior_*). Its 8s budget sits below the 10s timeout backstop, so it fails unless recovery fires fast.Concurrency is preserved
The heal is gated on
active_streams <= 1. A concurrent same-lane sibling (#1697) legitimately sends out-of-order sub-watermark vouchers whose bytes another stream's advance already covers; a terminal reject would tear down that honest stream. Those stay under the benign-swallow, and a genuinely wedged multi-stream lane still recovers via the 10s read-timeout backstop.lower_voucher_after_higher_sibling_is_already_satisfiedstill passes.Verification
decdn-node: 1113 passed / 0 failed.client-pull+incentive: 502 passed / 0 failed.--all-targets --all-features,fmt --check, and the doc-link gate (RUSTDOCFLAGS=-D warnings) all clean.Reviewer notes
🤖 Generated with Claude Code