Repository navigation
feat(payments): credit-window pipelined paid delivery (#1477) - #1485
Conversation
|
Warning Review limit reached
Next review available in: 11 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 (15)
WalkthroughAdds a configurable downstream credit window for paid delivery, resolves and wires the setting through runtime configuration, updates delivery and voucher handling to support pipelining, adjusts pull-through bounds, and adds loopback coverage. ChangesCredit window delivery
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant ClientHandler
participant VoucherStore
Client->>ClientHandler: request paid stream
ClientHandler->>Client: deliver chunks within credit window
Client->>ClientHandler: submit cumulative voucher
ClientHandler->>VoucherStore: durably commit voucher
VoucherStore-->>ClientHandler: commit succeeds
ClientHandler-->>Client: send VoucherAck
ClientHandler->>Client: resume delivery
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.24% (was 81.22%, ▲ +0.02%) — 52933/65155 lines
History
|
9a052d8 to
f25367a
Compare
Code reviewThree non-blocking items — all documentation / consistency, none block merge. The core change (delivered/paid/pending accounting, one-interval floor, deliver→recoup ordering, deposit-guard sizing, backward-compat collapse to stop-and-wait) verified clean. 1. Takedown detection latency now scales with the credit window, not the interval. decdn/crates/node/src/handlers/client/delivery.rs Lines 169 to 178 in f25367a Suggest: add a line to ADR 003 §Credit Window acknowledging that takedown latency is bounded by the window (one-interval floor as the mitigation), and update the comment. 2. Comment overstates the credit-exposure bound. decdn/crates/node/src/handlers/client/delivery.rs Lines 104 to 112 in f25367a 3. decdn/crates/node/src/handlers/client/window.rs Lines 450 to 454 in f25367a versus the guarded decdn/crates/node/src/handlers/client/delivery.rs Lines 176 to 178 in f25367a 🤖 Generated with Claude Code |
Paid delivery was stop-and-wait at every voucher boundary: the node delivered one `voucher_interval_mb` batch, then blocked on the voucher read + verify + fsync + ack before sending more — zero bytes in flight for a full RTT + fsync per interval, so single-stream throughput was RTT-bound, not link-bound. The serve side now streams behind a credit window: it keeps delivering while `delivered - paid <= credit_window`, collecting cumulative vouchers as they arrive instead of stalling at one interval. Client exposure stays zero (vouchers are cumulative over delivered bytes); node credit exposure is bounded to exactly the window and enforced there. The same shape is applied to the fused cache-miss serve path (its window is widened to include the credit window). Credit window and voucher interval are independent, config-driven knobs (defaults 8 MiB / 4 MiB). The voucher-collection seam is split into verify / commit-and-ack (`commit_and_ack_voucher`) so group-commit fsync (#1483) can batch the fsync and ack-after-commit without re-plumbing the deliver loop. Amends ADR 003 (new §Credit Window) and ADR 005 for the decoupled pay/deliver cadence. No wire-format change: an unconfigured window resolves to one interval (stop-and-wait), which keeps a not-yet-pipelined requester (#1484) interoperable with a pipelined node. Co-Authored-By: Claude Opus 4.8 <[email protected]>
f25367a to
6d23558
Compare
|
Thanks — all three verified. Addressed in 1. Takedown latency (comment + ADR). Fixed the stale "next MB boundary" comment in 2. Exposure bound (comment). Softened to the honest "≤ window + one chunk", matching 3. 🤖 Addressed by Claude Code |
Closes #1477.
Problem
Paid delivery was stop-and-wait at every voucher boundary. The node delivered one
voucher_interval_mbbatch, then blocked oncollect_voucher(read → verify → fsync → ack) before sending more — zero bytes in flight for a full RTT + fsync per interval. Throughput was thereforeinterval / (RTT + service_time), latency-bound rather than link-bound, and the repeated idle gaps kept QUIC's congestion window from reaching steady state.Change
The serve side now streams behind a credit window: it keeps delivering while
delivered − paid ≤ credit_window, consuming cumulative vouchers as they arrive instead of stalling at one interval — the same bounded-credit shape the node already uses upstream (pull_ahead_bytes).delivered − paid < windowbefore each chunk, so it never streams past the bound.delivery.rs(deliver, cache-hit path): rewritten as a deliver/recoup loop mirroring the fused window path. One-interval floor guarantees progress and rules out a spin-without-await.window.rs(fused cache-miss serve): its single fused window is widened tomax(pull_ahead_bytes, credit_window, interval), and the deposit guard tracks the same effective window.payment.credit_window_bytes(default 8 MiB); node-advertisedpayment.voucher_interval_mbdefault raised to 4 MiB. Both are independent, config-driven knobs — window bounds exposure, interval bounds per-voucher overhead and the per-channel fsync-serialized voucher rate.#1483 seam
collect_voucheris split into verify and commit-and-ack (commit_and_ack_voucher). The fsync +VoucherAcknow live in one isolated method, so group-commit fsync (#1483) can batch the fsync and ack-after-commit without re-plumbing the deliver loop or the verify path. Durability is unchanged: each voucher is committed before its ack.Wire compatibility
No wire-format change — same
ChunkData/Voucher/VoucherAck/StreamEndmessages, only the cadence differs. The credit window is purely local server policy (nothing negotiated). Adding a negotiation field was rejected: appending anOptiontoStreamRequestExtbreaks old-sender→new-receiver under postcard (DeserializeUnexpectedEnd), i.e. it would itself be a wire break.An unconfigured window resolves to one interval (stop-and-wait), so the pre-#1477 cadence is reproduced exactly and a not-yet-pipelined requester keeps working. Pipelining a node against an un-updated stop-and-wait requester is the two-sided barrier #1477 describes; the requester half is #1484 and ships in the same release.
ADR
Amends ADR 003 (new §Credit Window) and ADR 005 (self-enforcing threshold generalized from one interval to the credit window) for the decoupled pay/deliver cadence.
Tests (TDD)
New loopback tests drive a raw read-ahead client:
serve_streams_a_full_credit_window_ahead_of_payment— reads a full 8 MiB window before any voucher (pipelining past one interval), then asserts the server is parked (exposure bounded to exactly the window).serve_without_a_credit_window_is_stop_and_wait— unconfigured window delivers exactly one interval, then parks.paying_a_voucher_slides_the_credit_window_forward— one voucher frees exactly one interval of fresh credit.Assertions are byte-count-based with absence-based park checks, so they are deterministic under parallel load.
Verified green:
cargo nextest run -p decdn-node(893),-p decdn-common/-p decdn-cli(800),cargo clippy --workspace --all-targets -- -D warnings,cargo fmt --all --check,cargo doc.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation