Repository navigation
feat: credit slow-start — ramped credit window (start at floor, ramp with paid) (#1669) - #1691
Conversation
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…cer to spec Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
… on the ramped window (#1669)
…1669) Rewrite the two STALE(#1669) comment blocks in cli_fetch_topup.rs left by an earlier pass: the pre-serve deposit gate now prices a cold request at the ramp floor (one 4 MiB voucher interval, 8 USDC at the test rate), not the old flat two-interval 8 MiB window (16 USDC). Both test deposits are still comfortably over-provisioned against the corrected floor, so only the explanatory comments change, not the numeric constants. Full verification gate is green: build, clippy, fmt, nextest (2768/2768), cargo deny, and the anvil-e2e compile check all pass, and the sweep grep for retired credit-window/leech-governor identifiers is empty outside adr/_history/.
… convention) (#1669) Co-Authored-By: Claude Opus 4.8 <[email protected]>
…te-exposure bound (#1669)
There was a problem hiding this comment.
Pull request overview
This PR implements the “credit slow-start” design by replacing the fixed per-stream credit window and the ADR 037 seed-leech caps with a single, stateless mechanism: a per-stream credit window that ramps as a pure function of that stream’s cumulative paid bytes (plus a floor and ceiling). This aligns downstream delivery pacing and upstream pull-through pacing under the same ramp logic, while simplifying the configuration surface and deleting the leech governor layer.
Changes:
- Introduces shared
ramped_credit_window()logic indecdn-incentiveand reuses it across node serve loops and node pull-leg pacing (RampPacer). - Removes ADR 037 seed-leech caps and their config/metrics (
LeechGovernor, related cache knobs, and counters), updating runtime wiring and tests accordingly. - Updates CLI behavior/config templates plus multiple ADRs to reflect the ramped credit-window model and the new config knobs (
credit_max,credit_ramp_divisor).
Reviewed changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/protocol/src/client.rs | Updates StreamError::NotFound documentation to reference the new pull-through policy framing. |
| crates/node/tests/sighup_signal.rs | Updates resolved config fixture to new payment knobs and removes retired cache knobs. |
| crates/node/tests/node_origin_pull.rs | Refactors test harness wiring for pull-through to remove leech governor and use ramp-based window assumptions. |
| crates/node/tests/client_loopback.rs | Reworks loopback tests to cover ramp behavior (floor, ramp growth, divisor=0 instant ceiling) and updates handler wiring. |
| crates/node/tests/anvil_bringup_shutdown_e2e.rs | Updates config fixture to new payment knobs and removes retired cache knobs. |
| crates/node/src/runtime/reload.rs | Removes restart-required detection for deleted cache knobs and updates payment restart-required warning text. |
| crates/node/src/runtime/mod.rs | Removes leech governor / pull-ahead wiring and sets handler deps to credit_max + credit_ramp_divisor. |
| crates/node/src/node_origin/pull_leg.rs | Replaces LeechPacer with RampPacer and updates pull-leg pacing/scoring behavior accordingly. |
| crates/node/src/metrics.rs | Removes seed-leech cap pause counters; updates window-paused documentation to ramped window terminology. |
| crates/node/src/lib.rs | Removes leech_governor module export. |
| crates/node/src/leech_governor.rs | Deletes the leech governor implementation (caps + accounting + tests). |
| crates/node/src/handlers/client/window.rs | Updates pull-through reservation/pacing to use the ramp floor and passes ramp params to the pull leg. |
| crates/node/src/handlers/client/voucher.rs | Removes leech governor “served” crediting from voucher path. |
| crates/node/src/handlers/client/mod.rs | Replaces downstream credit_window_bytes with credit_max + credit_ramp_divisor and routes credit window computation through shared ramp function. |
| crates/node/src/handlers/client/fill.rs | Removes leech_admit helper and associated leech-governor wiring. |
| crates/node/src/handlers/client/dispatch.rs | Updates pre-serve deposit gate to price the ramp floor at paid = 0 and adjusts documentation accordingly. |
| crates/node/src/handlers/client/delivery.rs | Recomputes effective window per loop iteration based on paid; updates batching cap to size against the ceiling. |
| crates/incentive/src/lib.rs | Adds credit module and re-exports ramped_credit_window. |
| crates/incentive/src/credit.rs | Adds the shared ramped credit window function with unit tests. |
| crates/e2e/tests/cli_fetch_topup.rs | Updates E2E top-up test documentation/math to the new “floor-priced” gate behavior. |
| crates/common/src/config/types.rs | Removes seed-leech cache knobs and replaces payment credit window config with credit_max + credit_ramp_divisor. |
| crates/common/src/config/resolved.rs | Updates resolved config types to match new payment knobs and removes retired cache knobs. |
| crates/common/src/config/mod.rs | Updates defaults and resolver logic for new payment knobs; removes seed-leech defaults and cross-field checks. |
| crates/client-pull/src/pacer.rs | Adds RampPacer and unit tests; updates pacer docs to match new model. |
| crates/client-pull/src/lib.rs | Re-exports RampPacer. |
| crates/cli/tests/config_validate.rs | Updates resolved config fixture to new payment knobs and removes retired cache knobs. |
| crates/cli/src/commands/fetch.rs | Updates shortfall estimation to use a voucher-interval floor estimate rather than the prior fixed credit window default. |
| crates/cli/src/commands/config.rs | Updates config template, validation summary, and tests to reflect removed cache knobs and new payment knobs. |
| crates/cache/src/engine.rs | Updates origin range-pull documentation to reflect new exposure framing and terminology. |
| adr/architecture.md | Updates ADR 037 index entry to reflect ramped-window pacing instead of seed-leech caps. |
| adr/039-multi-source-parallel-fetch.md | Updates ADR references from seed-leech caps to ramped credit window + deposit guard. |
| adr/038-bao-verified-range-streaming.md | Updates ADR references from seed-leech caps to ramped credit window. |
| adr/037-regional-proxy-warming.md | Rewrites ADR 037 to replace seed-leech caps with the ramped credit-window mechanism and updates commitments/risks accordingly. |
| adr/022-content-discovery.md | Updates cache warming abuse-bound references to the ramped credit window. |
| adr/005-protocol.md | Updates cdn/client/v1 narrative to refer to ramped credit window policy instead of seed-leech caps. |
| adr/003-payments.md | Rewrites ADR 003 credit window section to document the ramped window mechanism and new configuration knobs. |
Suppressed comments (1)
crates/cache/src/engine.rs:2362
- The origin-egress metering here is correct, but the comment currently implies ADR 037’s ramped credit window “counts” these bytes directly. The ramp/window pacing is defined in content bytes; the metered value here includes outboard overhead. Rewording would prevent readers from assuming the pacing window includes outboard bytes 1:1.
// Meter the actually-pulled bytes (span + outboard) as origin egress —
// the bytes really did leave an origin. This is what ADR 037's ramped
// credit window counts against: the pulled side, not the whole blob.
if let Some(m) = &self.inner.metrics {
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…ed VOUCHER_INTERVAL_BYTES (#1669) Co-Authored-By: Claude Opus 4.8 <[email protected]>
…x outboard-vs-window accounting wording (#1669) Addresses PR #1691 review: the 'exposure at most paid/divisor' claim now names the one-interval floor (and paid=0) and the divisor=0 instant-ceiling case; the origin range-pull comments distinguish the content span the ramped window paces from the outboard's additional origin egress. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Coverage reportTotal: 80.70% (was 80.76%, ▼ 0.05%) — 58897/72980 lines
History
|
|
Re: the coverage report (▼0.05% total) — this is expected and not a gap in new code. Every file that dropped is one this PR deletes code from: removing the fully-tested The new ramp logic is well exercised:
No untested new logic, so no fix warranted — adding tests around the deleted paths would just game the metric. 🤖 Addressed by Claude Code |
Reconcile the node-origin pull port with main's credit-slow-start ramped credit window (#1691) and fixed voucher cadence (#1676), and the present-tense comment rewrite (#1687). - Delete resume.rs (the buffered loop this branch already replaced); main only rewrote its comments. - Keep the collapsed SettleOnDrop (no SettleDeps enum / lifetime), our driver delivered_frontier completion clamp, and the AlreadyAdmitted + typed-fault-recovery ingest changes, alongside main's RampPacer rework. - Restore the AtomicBool import dropped with main's LeechPacer removal. - Resize the concurrent-resume fixture to span several VOUCHER_INTERVAL_BYTES so it still exercises mid-pull exhaustion under the ramped credit window. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Closes #1669.
What
Replaces the flat per-stream credit window (
credit_window_bytes, default 8 MiB) and the ADR 037 seed-leech caps (LeechGovernor+ the three[cache]knobs) with a single mechanism: a credit window that ramps linearly with each stream's own cumulative bytes paid.credit_max— window ceiling, node config, default 64 MiB.credit_ramp_divisor— paid-bytes-per-window divisor, node config, default 2 (0= instant fullcredit_max).A stream starts at the floor and grows its window to
paid / credit_ramp_divisor, capped atcredit_max. A non-paying stream stays pinned at the floor. Per-stream and stateless —windowis a pure function of that stream'spaidcounter, which resets every stream. No client history, no graduation ledger.Why linear in paid, not exponential in vouchers
Risk (unbilled egress the node may never collect) is linear in bytes; payments are linear in bytes. Tying the window linearly to cumulative paid bytes makes the node's exposure a fixed fraction of confirmed revenue:
At the default divisor of 2, an attacker must pay for two bytes to extract one byte of free-ride, so the node nets positive on every stream — including a pure pay-a-little-then-abandon attack.
Retires the seed-leech caps (ADR 037)
On the fused serve-miss path the upstream pull and the downstream serve are one stream, so one ramped window governs both. The new
RampPacer(inclient-pull) recomputes the same window from the downstream served-paid frontier, keeping pull and serve in lockstep — a non-paying client fronts at most one interval of speculative upstream spend, never the ceiling.LeechGovernor,pull_ahead_bytes,max_unrecouped_leech_bytes, andpull_share_ratio_percentare deleted; the pre-flight deposit guard (now pricing the floor) plus pool solvencyMare the retained bound, so aggregate node exposure is bounded by real capital (Σ pool deposits / credit_ramp_divisorin the ramped regime, per-stream one interval at the floor).Changes
decdn-incentive: sharedramped_credit_window(divisor, floor, credit_max, paid)— one formula, used by both the serve loop and the pacer.decdn-node: serve loop recomputes the window from livepaideach iteration; deposit guards price the floor;LeechGovernordeleted;RampPacerreplacesLeechPaceron the pull leg.decdn-common: config surface —credit_max+credit_ramp_divisorreplacecredit_window_bytes; three[cache]knobs removed.decdn-cli: client shortfall estimate bases on the floor; config template/dump updated.Scope / sequencing
batch_caprefactor is left to design: best-effort async voucher-watermark persistence (chain-floored) — drop fsync-before-ack #1672;batch_caphere changes only enough to size correctly againstcredit_max.Verification
cargo build,cargo clippy(0 warnings),cargo fmt --check,cargo nextest run(2768 passed),cargo deny check,cargo test --no-run -p decdn-e2e --features anvil-e2e— all green. Grep for every retired identifier is empty outsideadr/_history/.🤖 Generated with Claude Code