Repository navigation
feat(payments): self-describing vouchers for concurrent same-lane settlement (#1699) - #1702
Merged
Merged
Conversation
…ependent settlement (#1699) The node reconstructed a voucher's cumulative bytes from stream-processing order, so a skip-ahead voucher recovered the wrong signer and was rejected. Transmit the already-signed bytes_delivered and verify against it directly, so concurrent same-lane vouchers settle regardless of arrival order. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…fied, not a fatal regression (#1699) Once vouchers carry their own cumulative, a lower voucher processed after a higher sibling is superseded, not a fault. Stage this stream's own delta (headroom + receipt) without moving the watermark and keep serving, so an honest lagging stream is not killed. A divergent voucher at equal amount with more bytes stays a single-signer fault. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ouchers cannot leech (#1699) The benign already-satisfied branch advanced a stream's paid window by its real delivered delta even though a benign voucher raises the watermark by nothing, so a client could deliver a window, pay a (0,0) voucher to reopen it, and repeat to download an entire blob for zero. Restore design rule #1: track a monotone lane-level paid_credited bounded by the settled watermark, and advance the serve loop's paid by the watermark-capped credit. An advance voucher credits its full delta (no change); a benign voucher a sibling already settled still credits (the watermark covers it); a benign voucher with no slack credits nothing. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…vered field (#1699) The feature-gated public-api-test snapshot pins decdn-protocol's exported surface; adding bytes_delivered to the wire Voucher is the reviewable API diff. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR updates the payments/voucher flow to support order-independent settlement across concurrent streams on the same lane by making vouchers self-describing on the wire (adding bytes_delivered) and adjusting node-side verification + paid-window crediting to handle skip-ahead and already-satisfied vouchers safely.
Changes:
- Extend the client wire
Voucherto includebytes_delivered(big-endianuint256) and update serialization tests accordingly. - Update the incentive “bridge” helpers to round-trip
bytes_deliveredvia the wire voucher and simplify reconstruction of the signed payload. - Update node voucher verification/commit + serve loop accounting to (a) verify against wire-provided bytes for concurrency safety, (b) treat stale/superseded vouchers as already-satisfied, and (c) cap per-stream paid credit by the lane watermark advance (“rule #1 cap”), with loopback/unit tests updated.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/protocol/src/client.rs | Add bytes_delivered to wire Voucher and update postcard encoding expectations/tests. |
| crates/incentive/src/client_bridge.rs | Encode/decode bytes_delivered in the wire voucher; remove now-unneeded bytes_delivered parameter when rebuilding the signed voucher. |
| crates/node/src/handlers/client/voucher.rs | Verify vouchers using wire-provided bytes, accept already-satisfied stale vouchers, and implement watermark-capped paid crediting in commit_batch with new unit tests. |
| crates/node/src/handlers/client/serve_leg.rs | Consume the new credited_bytes from voucher collection and advance paid by the watermark-capped credit. |
| crates/node/src/handlers/client/mod.rs | Track per-lane paid_credited to prevent benign vouchers from reopening credit windows beyond the settled watermark. |
| crates/node/tests/client_loopback.rs | Flip skip-ahead concurrent-lane test to accepted; add an out-of-order “already-satisfied” loopback test. |
Suppressed comments (1)
crates/node/src/handlers/client/voucher.rs:18
delta_bytesis described as “bytes this voucher pays for”, but with skip-ahead / aggregate vouchers the voucher’sbytes_delivereddelta can be larger than this stream’s interval delta. This field is really the stream-local delivered delta used for per-stream crediting/receipts, so the comment should avoid implying it matches the voucher’s aggregate span.
/// Bytes this voucher pays for (its interval delta) — for `paid` accounting,
/// the audit receipt, and per-region / seed-leech crediting.
delta_bytes: u64,
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…dit conversion (#1699) - Voucher doc: amount is the sole ordering/replay key; bytes_delivered is an additional signed monotone field the node verifies against — matching stage_voucher, which the prior "together they order" phrasing did not. - commit_batch: convert the capped credit with a hard error instead of saturating to u64::MAX. The value provably fits u64, but a broken invariant must fail the batch rather than advance paid catastrophically; paid_credited advances only after the conversion holds. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Coverage reportTotal: 80.71% (was 80.63%, ▲ +0.08%) — 59052/73170 lines
History
|
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.
Closes #1699.
Puts the client-signed
bytes_deliveredon the wireVoucherso the node verifies against exactly what the client signed, making same-lane voucher settlement independent of processing order.What changed
Vouchergainsbytes_delivered: [u8;32](big-endian uint256, mirroringamount). Wire break, no shim — every side updated in this PR.signed_to_wire_voucheremits it;wire_voucher_to_signedreads it from the wire (drops itsbytes_deliveredparameter).paid_credited, bounded by the settled watermark, gates how far a stream's paid credit window advances — so a benign voucher (which raises the watermark by nothing) cannot reopen the window for unsettled bytes.Why the cap
Without it, the benign path advanced a stream's paid window on its real delivered delta even though a benign voucher settles nothing, letting a client deliver a window, pay a
(0,0)voucher to reopen it, and repeat to download an entire blob for zero. The cap credits at most the amount the watermark advanced: an advance voucher credits its full delta (no change); a benign voucher a sibling already settled still credits (the watermark covers it); a benign voucher with no slack credits nothing.Design (three concerns kept separate)
Tests
skip_ahead_voucher_on_a_concurrent_lane_is_rejected→..._is_accepted.benign_commit_with_no_slack_credits_zero,advance_commit_credits_full_delta) pinning the leech block; bridge round-trip/prop tests updated forbytes_deliveredon the wire.cargo denypasses.No contract change — on-chain
redeemalready takes a signed(amount, bytes).🤖 Generated with Claude Code