Skip to content

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

Closed

Description

@alpergundogdu

Goal

Let multiple streams on one (pool_id, signer, provider) lane settle out of order / concurrently, by making vouchers self-describing instead of reconstructing bytes_delivered from per-stream state.

Background

Today the wire Voucher carries only {signature, amount}; the node reconstructs cumulative bytes_delivered as shared_counter + this_stream's_delta (voucher.rs::verify_voucher). That reconstruction depends on stream-processing order, so an out-of-order / skip-ahead voucher recovers the wrong signer and is rejected — pinned by skip_ahead_voucher_on_a_concurrent_lane_is_rejected (#1698). Correctly-ordered concurrent settlement already works (#1690). This issue removes the ordering dependency.

Core change

Add bytes_delivered to the wire Voucher (it is already in the EIP-712 signed payload — just transmit it). The node verifies the signature against the wire-provided (amount, bytes_delivered) — identical to what the client signed — so verification is order-independent, and a higher cumulative supersedes lower ones.

Chosen over deriving bytes from amount: min_payment is many-to-one (~MB/rate ambiguity), so amount → bytes is not exact without a canonical-inverse spec plus a rounding residual, and on-chain redeem's floor check needs a signed byte count (or rate) regardless. Transmitting the already-signed value is simpler and exact.

Design rules (decided)

  1. Paid frontier correct-by-construction, not a clamp. The node advances a per-lane aggregate paid frontier from its own authoritative delivered count, capped by what the voucher amount covers — so paid cannot exceed delivered because it is derived from it. No removable guard.
  2. Attribution proportional to per-stream unbilled delivered, not equal — the serve leg knows its own delivered bytes, so per-hash / per-region receipts stay accurate. Advance each stream toward its own delivered.
  3. Credit window fixed at admission; refuse, never resize (ties to feat(payments): bound per-lane credit exposure with a concurrent-stream admission cap #1697). A new same-lane stream must fit the remaining budget or be refused (BudgetExhausted); a drop frees budget for future admissions only. Live streams' windows never shrink (50+50 → refuse the third, not 33+50+50).
  4. Single-signer invariant. No nonce; highest-cumulative-wins is only safe with one monotone signer per lane. Make it explicit (reject divergent vouchers at equal amount; constrain delegated-signer setups).

Footguns to close

Open question

Delivery-vs-receipt lag: the node's delivered count runs ahead of what the client has received-and-signed. Bytes-on-the-wire resolves the signature side (both verify the client's signed value); the node still caps its paid frontier at its own delivered.

Wire / on-chain

Adding bytes_delivered to the postcard Voucher is a wire break — pre-launch, so change every side in one PR and delete the old shape (no compat shim). On-chain redeem already takes a signed (amount, bytes), so it is unaffected; confirm the floor path.

Acceptance

MUST flip skip_ahead_voucher_on_a_concurrent_lane_is_rejected (client_loopback.rs) — that test's scenario becomes accepted, landing the correct aggregate watermark — while keeping #1690's ordered-settlement correctness. Add coverage for: concurrent out-of-order settlement, drop-mid-flight continuation, admission refusal, proportional attribution.

Relationship

Complementary to #1697 (which bounds exposure via refuse-not-resize admission). This issue enables concurrent settlement; #1697 makes concurrent delivery safe.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions