Skip to content

feat(client-pull): optimistic paid-fetch loop, pipelined vouchers (#1484) - #1486

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/modest-feistel-300ac8
Jul 28, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/modest-feistel-300ac8

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1484.

What

Make the client-side paid-fetch loop optimistic. Previously the client blocked on VoucherAck after sending each voucher, and ChannelLedger::issue held 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 VoucherAck is 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 single in_flight slot 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 advances committed, reject drops the front without committing.
    • Strict nonce ordering is preserved by serializing issuance.
  • Loops (lib.rs) — 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 mid-stream VoucherRejected as UpstreamVoucherRejected wherever 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 = 16 ceiling, 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:

  • No overpay — vouchers are cumulative over delivered bytes, so the client never signs for bytes it didn't receive.
  • Bounded memory — the receive loop stops issuing at expected_wire_bytes, which the open stage already 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.

Guarantees preserved

  • The client still never pays for bytes it has not received.
  • Drop-safety / settle-high on ambiguity holds for multiple outstanding vouchers.
  • No ADR change: the client's per-voucher commit is in-memory (no fsync) — the serve-side #1477 / fsync #1483 reasoning does not apply here.

Tests

  • Extends the ledger unit tests to the pipelined case: ordered issue + settle-high, FIFO acks, ambiguous drop settles at the highest armed, reject keeps later armed vouchers, and a deep (100-voucher) pipeline stays ordered and exact. All 101 decdn-client-pull tests pass.
  • Updates the shared-ledger concurrent-pull integration test (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 the decdn-client-pull + decdn-node suites are green (one unrelated pre-existing flaky dht_loopback rate-limit test aside, which passes in isolation).

🤖 Generated with Claude Code

)

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]>
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@alpergundogdu, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 4f24e269-635a-45ab-9589-3721eccd798a

📥 Commits

Reviewing files that changed from the base of the PR and between a2778a4 and 99cff5f.

📒 Files selected for processing (6)
  • crates/client-pull/src/ledger.rs
  • crates/client-pull/src/lib.rs
  • crates/node/src/node_origin.rs
  • crates/node/tests/client_loopback.rs
  • crates/node/tests/node_origin_pull.rs
  • crates/node/tests/node_to_node_pull_through.rs

Note

🎁 Summarized by CodeRabbit Free

Your 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 @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.22% (was 81.20%, ▲ +0.02%) — 52852/65073 lines

File Coverage Lines Δ
crates/client-pull/src/ledger.rs 100.00% 348/348 ● 0.00%
crates/client-pull/src/lib.rs 88.44% 1071/1211 ▲ +0.23%
crates/node/src/node_origin.rs 91.21% 923/1012 ▼ 0.10%
History
Commit Total Δ vs base
d7313d2 81.21% ▲ +0.01%
99cff5f (HEAD) 81.22% ▲ +0.02%

@alpergundogdu
alpergundogdu requested a review from thiras July 28, 2026 11:59
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]>
@alpergundogdu
alpergundogdu merged commit 370157a into main Jul 28, 2026
24 checks passed
@alpergundogdu
alpergundogdu deleted the claude/modest-feistel-300ac8 branch July 28, 2026 12:41
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.

Client blocks on VoucherAck for nothing: pure dead latency, and it serializes parallel streams to one provider

1 participant