Repository navigation
fix(node): persist buyer voucher progress after pull-through (#852) - #872
Conversation
On a cache-miss pull-through the node pays the upstream by signing cumulative vouchers, but `BuyerChannelService::record_progress` had zero production callers: `stream_fetch` discarded the signed totals and `pull_from_candidate` never persisted them. The buyer channel is reused per-provider (~90 days), so on reuse `ChannelContext::for_buyer_channel` rebuilt context from the open-time zeros and re-signed `nonce=1` with a regressed cumulative `bytes_delivered`; the upstream rejected it (`StaleNonce`/`BytesRegression`) and delivery aborted. The headline #834 channel-reuse feature worked exactly once per provider, then that provider was permanently unusable until channel expiry. Thread a `VoucherProgress` acked-watermark out-param through the pull path, advanced only after each `VoucherAck`, and persist it after every stream: - client_requester: add `VoucherProgress` (encapsulated — `seed`, `commit_ack`, `acked`); `self_pay`/`fetch_inner` advance it post-ack; keep `stream_fetch -> Result<Bytes>` for the many simple callers via a thin wrapper, add `stream_fetch_tracked` carrying the out-param. - buyer_channel: expose `record_progress` on the `ChannelOpener` seam. - node_origin: `pull_from_candidate` persists progress on both Ok and Err paths when a voucher was acked (a mid-stream failure or paid-but-corrupt delivery still advanced the upstream's watermark). A persist failure does not fail the already-paid pull — it warns and bumps a new `node_pull_progress_persist_failures` counter. Because the watermark only reflects *acked* vouchers, a lost ack after the upstream commits under-records by one (self-corrects on rotation); this residual is documented, not closed here. Tests: extend `StubOpener` to model the persist→reuse loop; add a two-pull resume regression test, a persist-failure test (pull still delivers, counter increments), exact-total assertions on the success/corruption paths, and empty-log assertions on the no-pull paths. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to persist cumulative voucher totals (nonce, bytes delivered, and amount) paid on a buyer channel, addressing issue #852. This ensures that subsequent channel reuses or restarts resume from the correct watermark rather than re-signing stale vouchers. It introduces the VoucherProgress struct to track acked watermarks, updates the fetching logic to thread this progress, adds metrics to track persistence failures, and integrates progress recording into the node origin pull process. Comprehensive tests have also been added to verify correct progress persistence, channel reuse, and error handling. No review comments were provided, so there is no feedback to address.
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.
There was a problem hiding this comment.
Pull request overview
This PR fixes a production bug in node-to-node pull-through where buyer-side payment voucher progress wasn’t persisted, causing reused buyer channels to re-sign stale cumulative vouchers (nonce/bytes regression) and get rejected by the upstream on subsequent pulls.
Changes:
- Add a
VoucherProgressout-param flow to track the last acked cumulative voucher totals duringstream_fetch, and persist those totals after the pull. - Expose
record_progressvia theChannelOpenerseam and call it frompull_from_candidateon both success and failure paths when at least one voucher was acked. - Add a new metric (
node_pull_progress_persist_failures) and expand tests to cover persistence, reuse/resume, and persist-failure behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/client_requester.rs | Introduces VoucherProgress and stream_fetch_tracked to report acked voucher watermark to callers. |
| crates/node/src/node_origin.rs | Persists acked voucher progress after pull attempts and emits a persist-failure metric. |
| crates/node/src/buyer_channel.rs | Extends ChannelOpener with record_progress and wires it to BuyerChannelService. |
| crates/node/src/metrics.rs | Adds the node_pull_progress_persist_failures counter and an increment helper. |
| crates/node/tests/node_origin_pull.rs | Updates harness to record persisted progress, adds regression + persist-failure tests, and asserts persisted watermarks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 85.85% (was 85.85%, ● 0.00%) — 34232/39874 lines
History
|
Address review: `record_progress` does a blocking fsync'd redb write, and it ran before `started.elapsed()` was captured for the `Outcome::Delivered` reputation signal — inflating the delivery-speed measurement with disk I/O unrelated to the network pull. Capture `elapsed` immediately after `stream_fetch_tracked` returns, before persistence. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Fixes #852. On a cache-miss pull-through the node pays the upstream by signing cumulative payment vouchers, but
BuyerChannelService::record_progresshad zero production callers —stream_fetchdiscarded the signed(nonce, bytes_delivered, amount)andpull_from_candidatenever persisted them. The buyer channel is reused per-provider (~90 days viatry_reuse_live), so on reuseChannelContext::for_buyer_channelrebuilt context from the open-time zeros and re-signednonce=1with a regressed cumulativebytes_delivered→ the upstream rejected it (StaleNonce/BytesRegression) and delivery aborted at the first voucher boundary. The headline #834 channel-reuse feature worked exactly once per provider, then that provider was permanently unusable to this buyer until channel expiry. Same shape after a restart.Approach
Thread a
VoucherProgressacked-watermark out-param through the pull path, advanced only after eachVoucherAck(matching the upstream's committed watermark — ADR 003: the seller persists before it acks), and persist it after every stream.client_requester.rs— addVoucherProgress(encapsulated: private fields +seed/commit_ack/acked, so the "advance the quadruple atomically, only on ack" invariant is structural).self_pay/fetch_inneradvance it post-ack.stream_fetch -> Result<Bytes>is kept unchanged for the ~25 simple callers via a thin wrapper; the newstream_fetch_trackedcarries the out-param.buyer_channel.rs— exposerecord_progresson theChannelOpenerseam.node_origin.rs—pull_from_candidatepersists progress on both Ok and Err paths when a voucher was acked (a mid-stream failure or a paid-but-corrupt/hash-mismatch delivery still advanced the upstream's watermark). A persist failure does not fail the already-paid pull — itwarn!s and bumps a newnode_pull_progress_persist_failurescounter.metrics.rs— newnode_pull_progress_persist_failurescounter.Tests
crates/node/tests/node_origin_pull.rs(lightweight, no-chain harness):StubOpenerto model the real persist→reuse loop (seedsprior_*from recorded progress);FailingRecordOpener): the pull still delivers the bytes and the counter increments;acked()guard).Reviewed
Ran the multi-agent PR review (code / tests / silent-failures / type-design / comments). No critical correctness bugs; the four actionable findings (untested persist-failure branch, over-stated doc guarantee, a stale
paid_amountdoc reference, andVoucherProgressencapsulation) are all addressed in this PR.Residuals (documented, out of scope for #852)
VoucherAckafter the upstream commits under-records the watermark by one voucher (self-corrects on channel rotation) — inherent to one-sided ack loss; a full fix needs a reconciliation read of the upstream's committed nonce on reuse.top_up(deposit exhaustion) is likewise uncalled — separate.Verification
cargo clippy -p decdn-node --all-targetsclean (default and--features anvil-e2e)cargo fmt -- --checkcleancargo nextest run -p decdn-node→ 566 passed🤖 Generated with Claude Code