Skip to content

feat(payments): self-describing vouchers for concurrent same-lane settlement (#1699) - #1702

Merged
alpergundogdu merged 5 commits into
mainfrom
claude/issue-1699-spec-impl-b5a274
Aug 17, 2026
Merged

alpergundogdu merged 5 commits into
mainfrom
claude/issue-1699-spec-impl-b5a274

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #1699.

Puts the client-signed bytes_delivered on the wire Voucher so the node verifies against exactly what the client signed, making same-lane voucher settlement independent of processing order.

What changed

  • Wire: Voucher gains bytes_delivered: [u8;32] (big-endian uint256, mirroring amount). Wire break, no shim — every side updated in this PR.
  • Bridge: signed_to_wire_voucher emits it; wire_voucher_to_signed reads it from the wire (drops its bytes_delivered parameter).
  • Node verify: reconstructs the signed payload from the wire bytes and rate-checks the aggregate span, so a skip-ahead voucher recovers the correct signer and advances the lane watermark regardless of arrival order.
  • Benign-stale: a superseded (below-watermark) voucher is reclassified from a fatal regression to an already-satisfied no-op-that-continues, so an honest lagging stream is not killed. A divergent voucher at equal amount with more bytes stays a single-signer fault.
  • Rule Add devcontainer for secure Claude Code sessions #1 cap: a monotone lane-level 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)

  • Settlement is lane-level and order-independent; per-stream delivery headroom is gated by each stream's own vouchers and capped at the settled watermark; per-hash receipts stay per-stream own-delta to own-hash.
  • Accepted limitation: a stream settled only by a sibling's aggregate voucher (never sending its own) is money-correct but unreceipted — deliberately not closed.

Tests

  • Flipped skip_ahead_voucher_on_a_concurrent_lane_is_rejected → ..._is_accepted.
  • Added: out-of-order already-satisfied loopback test; benign-supersede and divergent-equal-amount unit tests; watermark-cap unit tests (benign_commit_with_no_slack_credits_zero, advance_commit_credits_full_delta) pinning the leech block; bridge round-trip/prop tests updated for bytes_delivered on the wire.
  • Full workspace green: 2770/2770, clippy/fmt clean, e2e compile gate passes, cargo deny passes.

No contract change — on-chain redeem already takes a signed (amount, bytes).

🤖 Generated with Claude Code

alpergundogdu and others added 3 commits August 17, 2026 11:44
…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]>
Copilot AI lite review requested due to automatic review settings August 17, 2026 12:15
…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]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Voucher to include bytes_delivered (big-endian uint256) and update serialization tests accordingly.
  • Update the incentive “bridge” helpers to round-trip bytes_delivered via 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_bytes is described as “bytes this voucher pays for”, but with skip-ahead / aggregate vouchers the voucher’s bytes_delivered delta 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.

Comment thread crates/protocol/src/client.rs Resolved
…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]>
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 80.71% (was 80.63%, ▲ +0.08%) — 59052/73170 lines

File Coverage Lines Δ
crates/incentive/src/client_bridge.rs 98.86% 173/175 ▲ +0.01%
crates/node/src/handlers/client/mod.rs 88.68% 713/804 ▲ +0.04%
crates/node/src/handlers/client/serve_leg.rs 90.58% 125/138 ▲ +4.25%
crates/node/src/handlers/client/voucher.rs 91.38% 583/638 ▲ +2.49%
crates/protocol/src/client.rs 99.04% 722/729 ● 0.00%
History
Commit Total Δ vs base
27a19fa (HEAD) 80.71% ▲ +0.08%

@alpergundogdu
alpergundogdu merged commit ea12f8c into main Aug 17, 2026
26 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-1699-spec-impl-b5a274 branch August 17, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(payments): self-describing vouchers to enable concurrent same-lane settlement

2 participants