Repository navigation
Description
What's happening
Paid delivery is stop-and-wait at every voucher boundary. The provider holds the next chunk until the client's voucher arrives, is verified, is fsynced, and is acked — with zero bytes in flight for the whole round trip.
- Server blocks on
read_voucherat each interval:crates/node/src/handlers/client/delivery.rs:78-94 - Client mirrors it, blocking on
VoucherAckbefore reading the next chunk:crates/client-pull/src/lib.rs:1604-1620 - A cache-miss serve stacks two of these in series —
window_forward_loop's upstreamnext_chunkpays with its own stop-and-wait (crates/client-pull/src/lib.rs:2053) inside the outer downstream barrier.
Throughput is therefore latency-bound, not link-bound: 1 MiB / (RTT + service_time).
Measured
- Fsynced redb voucher commit (
Durability::Immediate): 3.18 ms, local SSD. Cloud network storage is typically 5-20 ms. It sits on the critical path. - Framing at
CHUNK_SIZE = 1024: 3.1 GiB/s; serve-side per-chunk encode 1.3 GiB/s. Chunk size is not the bottleneck — resizing it would not help.
Resulting ceiling at the default 1 MiB interval, regardless of link capacity:
| RTT | 1 ms | 5 ms | 20 ms | 50 ms | 100 ms | 200 ms |
|---|---|---|---|---|---|---|
| MiB/s | 238 | 122 | 43 | 19 | 9.7 | 4.9 |
Going idle for ≥1 RTT every MiB also prevents QUIC's congestion window from reaching steady state, so real throughput lands below these numbers.
Recommendation
Credit-window pipelining. Keep streaming while delivered − paid ≤ credit_window instead of stalling at one interval; client issues the voucher and keeps receiving rather than blocking on the ack. This is the same bounded-credit shape the node already uses for the upstream leg (pull_ahead_bytes).
Nonce ordering is preserved by serializing issuance in ChannelLedger — the server only requires increasing nonces, never ack-before-next.
Proposed defaults: 8 MiB credit window, 4 MiB voucher interval → ~150 MiB/s at 50 ms RTT.
The interval matters independently: vouchers on a channel are serialized by the per-channel mutex at 3.2 ms each, capping a 1 MiB interval at ~313 MiB/s per channel no matter how large the window. Raising the interval lifts that cap linearly; it does not raise exposure, which is the window.
Risk is one-sided. Client exposure stays at zero — vouchers are cumulative over bytes already received, so the client never pays ahead. Server exposure rises from 1 MiB to the window: unbilled egress already served, strictly cheaper than the 1 MiB of speculative USDC the node already fronts upstream per request (DEFAULT_PULL_AHEAD_BYTES, crates/common/src/config/mod.rs:253).
Needs an ADR 003 / ADR 005 amendment for the cadence semantics. No wire break.
Related, found during the same investigation
- Whole-blob materialization on both ends (Payment channels aren't resilient to a fetch exiting early: it strands the channel + deposit (durable watermark, resumable fetch, resync, coop-close reconciliation) #1122 / Buffered origin pull-through loads the whole blob into memory before serving #1132):
export_bao_rangereturns an ownedBytes, so the server builds the entire bao encoding before chunk Add devcontainer for secure Claude Code sessions #1; the client accumulates the whole blob before decoding. TTFB and memory both scale with blob size — severe for large-model delivery. - Per-voucher fsync. Off the latency path once pipelined, but still per-interval IO. Group-commit would help; trades against the incentive: no replay-protection window enforced on incoming voucher nonces, allowing a client to resubmit a previously accepted voucher after a node restart and receive a second byte-delivery for the same payment #527 strict-durability invariant.
The barrier is two-sided — and the client side is separate work (#1484)
The client mirrors this stop-and-wait: after sending a voucher it blocks on VoucherAck before reading the next chunk (crates/client-pull/src/lib.rs:2212, :1604-1620, :2053). Unlike the server, the client's per-voucher commit is purely in-memory (ChannelLedger, crates/client-pull/src/ledger.rs:213) — no fsync, no durability constraint. It is tracked separately in #1484 and can land independently of this issue. The 3.18 ms measured here is server-side only.
Related follow-ups
- Group-commit voucher fsyncs (ack after commit): amortise the 3.18 ms per-voucher commit #1483 — group-commit voucher fsyncs (ack after commit). The chosen plan for the serve-side fsync: batch vouchers into one fsync and ack the batch after the commit returns. Preserves ADR 003 verbatim (nothing acked before it is durable) and adds no replay exposure; the ack-then-commit alternative was rejected. Depends on this issue — the credit window is what takes the ack off the critical path so a delayed ack costs nothing.
- Client blocks on VoucherAck for nothing: pure dead latency, and it serializes parallel streams to one provider #1484 — client-side pipelining. The other end of the same barrier; no durability constraint, no ADR change, no dependency on this issue.
Metadata
Metadata
Assignees
Type
Fields
Priority
Activity
feat(payments): credit-window pipelined paid delivery (#1477)
refactor(client-pull): drop the outstanding-voucher cap (#1484)
feat(client-pull): optimistic paid-fetch loop, pipelined vouchers (#1484
feat(payments): credit-window pipelined paid delivery (#1477)
feat(payments): group-commit voucher fsyncs, ack after commit (#1483)
feat(payments): credit-window pipelined paid delivery (#1477) (#1485)
feat(payments): group-commit voucher fsyncs, ack after commit (#1483)
feat(payments): group-commit voucher fsyncs, ack after commit (#1483)
feat(payments): group-commit voucher fsyncs, ack after commit (#1483) (…
feat(node): refuse a stream when the deposit cannot cover the first c…
feat: enforce the seller-side deposit floor before serving, drop the …