Repository navigation
feat(client-pull): optimistic paid-fetch loop, pipelined vouchers (#1484) - #1486
Conversation
) The client used to block on `VoucherAck` after sending each voucher, and `ChannelLedger::issue` held the per-channel lock across the whole send→ack exchange. That cost a full RTT of dead latency per voucher interval and serialized parallel range streams to one provider behind each other's round trips — the binding constraint for large-file delivery on a geographically distributed CDN. Make the loop optimistic: issue the voucher and keep receiving; the `VoucherAck` is read off the critical path by the receive loop and fed back into the ledger. - `ChannelLedger`: the issuance lock now spans compute → sign → send only, not the ack wait, so several vouchers can be outstanding at once. `in_flight` becomes an ordered set (`VecDeque`); `settlement()` settles high across the whole set, `resolve_ack`/`resolve_reject` drain it FIFO. Strict nonce ordering is preserved by serializing issuance. - Bound the outstanding set at `DEFAULT_MAX_OUTSTANDING_VOUCHERS` (16) so a silent provider cannot make the client pay unboundedly ahead; the cap surfaces the typed `TooManyOutstandingVouchers`, classified `OurDeadline` (exonerating). - `self_pay` → `send_voucher` (send only); the buffered `receive_and_pay`, the progressive `next_chunk`, and `finish` gain a voucher-slot arm (`resolve_voucher_slot`) that resolves acks and types a `VoucherRejected` as `UpstreamVoucherRejected` wherever it lands. The client still never pays for bytes it has not received (vouchers are cumulative over delivered bytes) and drop-safety / settle-high on ambiguity is preserved for multiple outstanding vouchers. No ADR change (the client's per-voucher commit is in-memory; no durability constraint). Extends the ledger tests to the pipelined case (ordered issue, FIFO acks, ambiguous drop settles at the highest armed, reject keeps later armed vouchers, the outstanding bound). Updates the shared-ledger concurrent-pull test: both pulls now persist the shared settle-high watermark, so the evidence of sharing is the nonce reaching the full voucher total rather than the two settlements differing. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Warning Review limit reached
Next review available in: 2 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (6)
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Coverage reportTotal: 81.22% (was 81.20%, ▲ +0.02%) — 52852/65073 lines
History
|
The `DEFAULT_MAX_OUTSTANDING_VOUCHERS = 16` ceiling was a footgun: to avoid aborting honest transfers it had to stay above the operator-tunable serve-side credit window (#1477, now 8 MiB by default), so a hardcoded client constant silently had to track someone else's config — and would break interop the moment an operator raised their window past it. Its stated job is already covered without it: - no overpay — vouchers are cumulative over DELIVERED bytes, so the client never signs for bytes it did not receive; - bounded memory — the receive loop stops issuing at `expected_wire_bytes`, which the open stage caps against `max_blob_size`, so the outstanding set is bounded by `max_blob_size / interval` regardless (each entry a small `Cumulative`); - liveness — a provider that delivers but never acks never sends its closing ack / `StreamEnd`, so the pull dies on the `stall` timeout. Removes `TooManyOutstandingVouchers`, `max_outstanding` / `with_max_outstanding`, `DEFAULT_MAX_OUTSTANDING_VOUCHERS`, and the `OurDeadline` classification for it. Replaces the bound test with one asserting a deep pipeline stays ordered and exact. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Closes #1484.
What
Make the client-side paid-fetch loop optimistic. Previously the client blocked on
VoucherAckafter sending each voucher, andChannelLedger::issueheld the per-channel lock across the whole send→ack exchange. That was a full RTT of dead latency per voucher interval, and it serialized parallel range streams to one provider behind each other's round trips — the binding constraint for large-file delivery at the RTTs that matter for a geographically distributed CDN.Now the loop issues the voucher and keeps receiving; the
VoucherAckis read off the critical path and fed back into the ledger.How
ChannelLedger(ledger.rs) — the issuance lock now spans compute → sign → send only, not the ack wait, so several vouchers can be outstanding at once and parallel streams no longer serialize their payments. The singlein_flightslot becomes an ordered set (VecDeque):settlement()settles high across the whole outstanding set (drop-safety preserved for multiple vouchers).resolve_ack()/resolve_reject()drain it FIFO; ack advancescommitted, reject drops the front without committing.lib.rs) —self_pay→send_voucher(send only). The bufferedreceive_and_pay, the progressivenext_chunk, andfinishgain a voucher-slot arm (resolve_voucher_slot) that resolves acks and types a mid-streamVoucherRejectedasUpstreamVoucherRejectedwherever it lands (unifying what used to be a split between the ack wait and the mid-stream receive sites).No outstanding-voucher cap
An earlier revision added a
DEFAULT_MAX_OUTSTANDING_VOUCHERS = 16ceiling, but it was a footgun and has been removed (second commit): to avoid aborting honest transfers it had to stay above the operator-tunable serve-side credit window (#1477, now 8 MiB default), so a hardcoded client constant would silently have to track someone else's config and break interop the moment an operator raised their window. Its job is covered without it:expected_wire_bytes, which the open stage already caps againstmax_blob_size, so the outstanding set is bounded bymax_blob_size / intervalregardless (each entry a smallCumulative).StreamEnd, so the pull dies on thestalltimeout.Guarantees preserved
#1477/ fsync#1483reasoning does not apply here.Tests
decdn-client-pulltests pass.two_concurrent_pulls_to_one_provider_share_the_channel_ledger): both pulls now persist the shared settle-high watermark, so the evidence of a shared ledger is the nonce reaching the full four-voucher total rather than the two settlements differing. The money-bug guards (both blobs arrive, nothing retired) are unchanged; verified green 10/10.cargo clippy --workspace --all-targets,cargo fmt --check, and thedecdn-client-pull+decdn-nodesuites are green (one unrelated pre-existing flakydht_loopbackrate-limit test aside, which passes in isolation).🤖 Generated with Claude Code