Skip to content

fix(node,client,cli): keep the credit ramp across back-to-back pulls and widen bundle lanes - #2176

Merged
thiras merged 3 commits into
mainfrom
fix/2168-2169-ramp-carry-lane-width
Sep 27, 2026
Merged

thiras merged 3 commits into
mainfrom
fix/2168-2169-ramp-carry-lane-width

Conversation

@thiras

@thiras thiras commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Summary

#2168: a range-deduped bundle entry served through a cold two-leg miss pulled its complement at ~1 MiB/s.

  • Node: lane ramp-credit pool (crates/node/src/handlers/client/ramp.rs). Every new stream restarted the credit window at the 1 MiB floor, on both the serve loop and the pull-leg RampPacer. Now:
    • A stream takes its lane's banked credit and ramps on carried + own paid. This covers the serve loop, the cache-hit loop, RampPacer.paid_carried and PrimeLeg.
    • A stream that ends fully paid returns carried + own paid before StreamEnd. Any other end forfeits the credit, so abandoning streams one after another cannot recycle it.
    • The pool is capped at credit_max × divisor, is kept in memory only, and resets on restart.
    • Deposit and floor reservations still price the floor.
  • Client: bundle lanes widen mid-drive. RangeLane.grow (LaneGrowth) lets drive_range_lanes add gap workers. Bundle pull's LaneGrant hands it freed per-provider permits without waiting, up to --max-lane-streams.
  • Client: recovery read after a failed proof write skips the ChunkData already in flight ahead of the node's StreamError. Any opening window wider than one frame used to turn an UnderFold heal into a transport error: a carried ramp does this, and credit_ramp_divisor = 0 already did.

#2169: the suspected path (a reveal whose send fails locally but still reaches the node) is unreachable. PoolLedger::meter counts a reveal only after quinn accepted its whole frame.

  • The real path is a payer process that exits after it sends reveals and before it persists them. Examples: a second Ctrl-C (process::exit), SIGKILL, or a timeout during a bundle pull that already persisted earlier entries on the same chain.
  • ADR 003 and the lane/voucher docs now name that path, and a loopback test drives it with real reveals.

ADRs 003, 005 and 037 now describe the pool and its forfeit rule. ADR 005's claim that the node pauses all of a lane's streams together is corrected to the per-stream window the code enforces.

Test plan

  • cargo clippy --workspace --all-targets -D warnings, cargo doc -D warnings, pre-commit
  • cargo nextest run -p decdn-client -p decdn-node -p decdn-cli -p decdn-incentive -p decdn-cache: 3377 passed before the review fix; -p decdn-client -p decdn-node -p decdn-cli rerun after it: 2627 passed
  • anvil e2e (-p decdn-e2e --features anvil-e2e): 69 passed
  • a_back_to_back_stream_opens_at_the_lanes_banked_ramp fails without the carry (1 MiB vs 4.2 MiB unpaid)
  • a_process_that_exits_before_its_last_persist_heals_in_one_rejection fails without the drain fix
  • Testnet, after deploy: rerun bundle pull --hash 9194000d… --namespace 1. Expect entry 7cbb4846… well above 1 MiB/s, and bcl serve_stream legs above the floor from the second run on. Watch decdn_serve_stream_voucher_rejected_total.

Closes #2168
Closes #2169

🤖 Generated with Claude Code

…and widen bundle lanes (#2168, #2169)

#2168: a range-deduped bundle entry served through a cold two-leg miss
pulled its complement (147 runs, median 11.6 MiB) at about 1 MiB/s.

- Node: every new `cdn/client/v1` stream restarted the credit window at
  the one-chunk floor, on the serve loop and on the pull leg's
  `RampPacer`. Each lane now keeps an in-memory ramp-credit pool
  (`handlers/client/ramp.rs`). A stream takes the whole pool when it
  starts and uses `carried + own paid` as its ramp input on the serve
  loop, the cache-hit loop, the pull-leg `RampPacer.paid_carried` and
  the handshake `PrimeLeg`. A stream that ends fully paid returns
  `carried + own paid` just before `StreamEnd`; any other end forfeits
  it, so a payer that abandons stream after stream gets no more unpaid
  bytes than `paid / credit_ramp_divisor` plus one floor per stream. The
  pool caps at `credit_max × credit_ramp_divisor`, is never persisted,
  and the deposit guard and floor reservations still price the floor.
- Client: `bundle pull` sized each provider lane once from the permits
  free at drive start. `RangeLane.grow` (`LaneGrowth`) lets
  `drive_range_lanes` add gap workers mid-drive, and bundle pull's
  `LaneGrant` hands it freed permits without waiting, up to
  `--max-lane-streams`.
- Client: after a proof write fails, `terminal_after_write_failure` now
  reads past the `ChunkData` the node sent ahead of its `StreamError`.
  Any opening window wider than one frame (a carried ramp, or
  `credit_ramp_divisor = 0`) otherwise turned an `UnderFold` rejection
  into a transport error. A `StreamEnd` behind skipped data confirms
  nothing.

#2169: a reveal whose send fails locally cannot reach the node — the
ledger counts a reveal only after quinn accepted its whole frame. The
trailing watermark comes from a payer process that exits after it sends
reveals and before it persists them (a second Ctrl-C, SIGKILL, a
timeout), e.g. a bundle pull that already persisted earlier entries on
the same chain. ADR 003 and the lane/voucher docs now name that path,
and a loopback test drives it with real reveals.

ADRs 003, 005 and 037 describe the lane ramp-credit pool; ADR 005's
"pauses all streams collectively" claim now matches the per-stream
window the code enforces.

Tests: ramp pool units (take/cap/return/forfeit/conservation), a handler
test for an empty loaded lane, RampPacer and PrimeLeg carried-credit
cases, a `client_loopback` back-to-back stream that opens at ~4 MiB
unpaid where a fresh lane gets one chunk (fails without the carry), a
`drive_range_lanes` growth test, a `LaneGrant` test, and the #2169
exit-before-persist heal test (which fails without the drain fix).

Closes #2168
Closes #2169

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 27, 2026 03:10
@thiras thiras self-assigned this Sep 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unbounded recovery draining and wire/content credit mismatches remain unresolved.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

This PR preserves ramp credit across back-to-back pulls, widens bundle lanes dynamically, and improves recovery after failed voucher writes.

Changes:

  • Adds per-lane credit pooling with forfeiture rules.
  • Adds dynamic bundle lane growth.
  • Updates recovery handling, tests, documentation, and changelog.
File Reviewed changes
crates/​node/​tests/​client_loopback.rs Adds ramp and persistence-recovery regression tests.
crates/​node/​src/​node_origin/​pull_leg.rs Applies carried credit to pull pacing; wire/content units need conversion.
crates/​node/​src/​handlers/​client/​window.rs Passes carried credit into request windows; unit mismatch remains.
crates/​node/​src/​handlers/​client/​voucher.rs Updates lane initialization and related documentation.
crates/​node/​src/​handlers/​client/​serve_leg.rs Applies and returns ramp credit.
crates/​node/​src/​handlers/​client/​ramp.rs Implements lane ramp-credit pooling.
crates/​node/​src/​handlers/​client/​mod.rs Stores and exposes credit pools.
crates/​node/​src/​handlers/​client/​dispatch.rs Documents floor interaction.
crates/​node/​src/​handlers/​client/​delivery.rs Applies and returns credit for cache hits.
crates/​incentive/​src/​lane.rs Updates payment and under-fold documentation.
crates/​incentive/​src/​credit.rs Documents carried ramp input.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Updates the public API snapshot.
crates/​client/​src/​pacer.rs Adds carried credit to pacing; unit conversion and documentation remain unresolved.
crates/​client/​src/​lib.rs Adds recovery draining; skipped frames lack bounded byte validation.
crates/​client/​src/​driver.rs Supports dynamically growing range lanes.
crates/​cli/​src/​commands/​fetch.rs Threads lane-growth hooks through fetch lanes.
crates/​cli/​src/​commands/​bundle_pull.rs Grants dynamically released provider permits.
crates/​cache/​src/​fill_session.rs Documents carried credit and content frontiers.
CHANGELOG.md Records fixes for issues #2168 and #2169.
adr/​037-regional-proxy-warming.md Updates pull-through ramp behavior.
adr/​005-protocol.md Corrects per-stream window documentation.
adr/​003-payments.md Specifies credit pooling and forfeiture.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/client/src/lib.rs Resolved
Comment thread crates/client/src/pacer.rs Resolved
@github-code-quality

github-code-quality Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit 734dd46 in the fix/2168-2169-ramp-c... branch remains at 86%, unchanged from commit e862222 in the main branch.

Show a line coverage summary of the most impacted files.
File main e862222 fix/2168-2169-ramp-c... 734dd46 +/-
crates/client/src/lib.rs 93% 92% -1%
crates/incentiv...eth_identity.rs 99% 98% -1%
crates/node/src...lient/window.rs 71% 71% 0%
crates/cli/src/...mmands/fetch.rs 52% 52% 0%
crates/client/src/driver.rs 97% 97% 0%
crates/cli/src/.../bundle_pull.rs 77% 77% 0%
crates/node/src...nt/serve_leg.rs 90% 90% 0%
crates/node/src...gin/pull_leg.rs 89% 90% +1%
crates/node/src...s/client/mod.rs 95% 96% +1%
crates/node/src.../client/ramp.rs 0% 97% +97%

Updated September 27, 2026 03:53 UTC

thiras and others added 2 commits September 27, 2026 06:22
…l on carried content

Review follow-up on #2176.

- The recovery read that passes over in-flight ChunkData after a failed
  proof write now holds those frames to the request's promised wire
  length and the received-byte ceiling, the same limits next_chunk
  applies. A peer that sends past them fails the recovery read instead
  of streaming until the 5 s bound.
- The pull leg's RampPacer and PrimeLeg paced on the carried ramp credit
  in wire bytes against content frontiers. They now take
  RampCarry::carried_content, which removes 1/128 for the bao parent
  nodes (at most 64 bytes per 16 KiB group), so the pull never runs past
  its content window.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…re-delivery refusals

Review follow-up on #2176.

- The lane ramp-credit pool counts paid content bytes. A fully paid
  stream returns the aligned content of its request, not its wire
  count. Content never exceeds the wire that paid for it, so the pool
  never overstates revenue, and the pull leg's RampPacer uses it with no
  derate. The 1/128 derate did not hold for small ranges, whose bao
  encoding carries the ancestor parents of the range.
- A stream the node refuses before its first byte (no upstream, a
  withdrawn fill, a failed spawn) returns its carry whole. Only a stream
  that ends unpaid after its first byte forfeits it.
- The recovery drain keeps the received-byte ceiling typed as
  BlobTooLarge, which is terminal, instead of folding it into the write
  error, and names the bound that tripped.
- LaneGrowth hooks receive the number of waiting gaps, and the driver
  never adds more workers than that.
- ADR 003/037 and CHANGELOG: per-stream stop wording, "unless another
  stream took the pool first", content units, the pre-delivery return.

Tests: loopback tests for a mid-blob proof-write failure that reads past
in-flight frames to the typed rejection, and for a StreamEnd behind
skipped frames failing the leg (both fail without the drain); an
abandoned stream forfeiting its lane's ramp (fails if abandonment
returns the carry); a pre-delivery refusal returning the carry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants