Repository navigation
docs(adr)!: the payer fronts credit - #2877
Conversation
Floor debt charged an abandoned stream's unpaid floor to the capability signer. Signer keys are free, so a cheater rotates and starts clean, while an honest client that drops stalled lanes fills its cap and is locked out of the node until a restart. The per-stream credit window already bounds what one stream can take, and the pool ceiling and the per-signer live cap bound concurrent floor. The default redeem threshold drops from 1 USDC to 0.05 USDC, which caps the value a lane can leave unredeemed at capability expiry near the gas of one first-time redemption lane. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A relay-routed connection carries no client address, so an attacker that
dials through a relay skips a source-address layer for free, while
honest peers behind one NAT share one bucket. The rate limiters key on
the NodeId and a global bucket; the connection limiter is the global
concurrency cap.
Removed config keys: security.per_source_rate_per_sec,
security.per_source_burst, security.max_tracked_sources, and
{dht,probe,serve}.rate_limit.{per_ip_rate_per_sec,per_ip_burst,
max_tracked_per_ip}.
Closes #2505
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ream Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
A node sends a frame only when the lane's confirmed payment covers it. The payer pays ahead within a credit window that is payer policy: a cap in USDC for each node, a ramp on verified delivery, and a write-off weight for credit that a node keeps. Credit belongs to the lane and carries across streams and a node restart. On a cache miss a node pays its upstream only up to the credit that its downstream lane holds. ADR 003 loses the node-side credit window, the floor-credit accumulator and per-signer floor isolation. Voucher withholding is closed by construction, and data withholding states the payer's bound. ADR 005 adds a size proof to StreamResponse and ProbeResponse, so total_bytes is verified against the content hash. Refs #2876 Co-Authored-By: Claude Fable 5.2 <[email protected]>
The size proof is proposed in #2879 and does not depend on the credit direction. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The node counts a frame as delivered when it sends it, so a frame that a dropped connection never carried is still counted, and the payer would pay twice for it on resume. A resume that follows a stream with no clean close gets the gap back as lane credit, within an allowance of the lane's paid bytes over a divisor, capped at a small window. The allowance comes from the lane's own payments, so a fresh signer key has none, and the node enforces it without a wire field. Refs #2876 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…credit-impl-9a0a60
WIP: node side of the payer-fronted credit design (#2876). The node debits a lane-wide credit before each frame and reads proofs while credit falls short. The lane persists its delivered count, a backfill returns the gap of an unfinished stream within an allowance, and the miss pull draws only what the downstream lane has paid for. The node-fronted floor, ramp and per-signer machinery and their config keys are removed. Not built or tested yet: the integration suites (client_loopback, node_origin_pull) still target the old direction. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The client pays ahead of delivery up to a payer-local window, min(pay_ahead_cap, max(chunk + chunk group, (verified - loss_weight * lost) / pay_ahead_divisor)), keyed per node operator address and capped across every signer of the process. A lane's held credit is a ledger counter that payment grows and every received byte spends. Completion and resume follow the verified frontier, so the delivered-but-unpaid span machinery is gone. A node that ends a stream without delivering against held credit, or sends provably corrupt bytes, has the credit written off at reconciliation; a disconnect is not a write-off. A rebase never moves below price times the bytes the lane verified. PullConfig is non_exhaustive and gains the window knobs, the CLI gains --pay-ahead-cap, --pay-ahead-divisor, --loss-weight and --write-off-budget, and the peer store persists each operator's counts. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…nted-credit-impl-9a0a60
Gateway test allowances cover the larger drop penalty. Node unit tests no longer reference the removed floor and ramp machinery. The client_loopback and node_origin_pull integration suites still target the old direction. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟡 Changes recommended
The change still has an unresolved moderate issue where PullConfig::apply_pay_ahead() is invoked within Streamer::open_range, potentially causing process-global payer window policy to be silently overwritten across concurrent pulls, along with minor documentation nits.
3 open issues
What changed in this PR
Implements the payer-fronted credit model: nodes only send frames when confirmed lane credit covers them, while clients pay ahead within a per-node, payer-controlled window; removes the legacy floor/ramp machinery and updates configuration, tests, and docs/specs accordingly.
Changes:
- Switch serving/payment gating to lane credit computed as paid minus delivered, with delivered bytes persisted so credit survives restarts.
- Add client pay-ahead window policy (including per-operator trust) plus pacing, reconciliation, and write-off semantics across streams.
- Simplify rate limiting from per-peer+per-IP+global to per-peer+global and update handlers/metrics/tests/ADRs to match.
| File | Description |
|---|---|
| docs/runbook.md | Updates operational guidance for the new payer-fronted credit behavior and the simplified rate-limiting model. |
| crates/protocol/src/lib.rs | Refines protocol documentation around error/close semantics (notably RATE_LIMITED). |
| crates/node/tests/support/mod.rs | Adjusts shared node test support utilities and config fixtures to the updated limiter/config shapes. |
| crates/node/tests/sighup_signal.rs | Updates SIGHUP/reload tests to reflect the revised runtime configuration surface. |
| crates/node/tests/probe_warm_reconnect.rs | Updates probe warm-reconnect test expectations/config for the simplified limiter layering. |
| crates/node/tests/node_origin_pull.rs | Updates node-origin pull integration tests to align with the new credit-gated serving rules and removed mechanisms. |
| crates/node/tests/dht_loopback.rs | Updates DHT loopback tests/fixtures for the revised per-peer/global rate limiting. |
| crates/node/tests/dht_lookup.rs | Updates DHT lookup tests/fixtures to match the new limiter and handler behavior. |
| crates/node/tests/dht_integration.rs | Updates DHT integration tests to the simplified limiter model and updated request admission behavior. |
| crates/node/tests/dht_bootstrap.rs | Updates DHT bootstrap tests/fixtures for the new limiter configuration and behavior. |
| crates/node/tests/anvil_bringup_shutdown_e2e.rs | Updates Anvil bringup/shutdown E2E test setup for the changed resolved config fields and payment semantics. |
| crates/node/src/runtime/tests.rs | Updates runtime tests and fixtures for the revised resolved configuration structure and reload behavior. |
| crates/node/src/runtime/reload/tests.rs | Updates reload tests to reflect which fields are reloadable and the new config layout. |
| crates/node/src/runtime/reload.rs | Adjusts reload logic and messaging to match removed/renamed configuration keys and updated restart requirements. |
| crates/node/src/prune_guard.rs | Updates prune-guard implementation/docs to align with the post-refactor runtime/limiter behavior. |
| crates/node/src/pool_store/tests.rs | Adds/updates persistence tests for lane state needed by the paid-minus-delivered credit model. |
| crates/node/src/pool_store.rs | Updates pool storage to persist the delivered-bytes lane counter required for restart-safe credit. |
| crates/node/src/payment_settlement.rs | Updates settlement logic to remove references to deleted floor/ramp accounting and align with the new credit model. |
| crates/node/src/node_origin/ranged_pull.rs | Updates ranged pull documentation/behavior to match the new credit and backpressure terminology. |
| crates/node/src/node_origin/pull_leg/local_pull_leg_tests.rs | Updates local pull-leg tests/fixtures to reflect credit pacing and new pull behavior. |
| crates/node/src/node_origin/mod.rs | Updates node-origin module documentation and behavior descriptions for the updated pull/credit flow. |
| crates/node/src/metrics/tests.rs | Updates metrics tests to reflect removed metrics/series and the revised limiter/credit instrumentation. |
| crates/node/src/lib.rs | Updates crate-level documentation/exports to match the refactored limiter and credit architecture. |
| crates/node/src/handlers/serve_rate_limit.rs | Refactors the serve-path rate limiter wrapper to the simplified layered model and updated metrics labeling. |
| crates/node/src/handlers/probe.rs | Updates the probe handler to use the simplified limiter layering and revised close behavior semantics. |
| crates/node/src/handlers/probe_rate_limit/tests.rs | Updates probe rate-limit tests to match the new two-layer limiter behavior and labels. |
| crates/node/src/handlers/probe_rate_limit.rs | Refactors probe rate limiting to the simplified layering and updated metrics/error reporting. |
| crates/node/src/handlers/dht.rs | Updates DHT handler admission/rate-limit wiring to remove per-IP tracking and match the new limiter model. |
| crates/node/src/handlers/client/ramp/tests.rs | Removes or updates ramp-related handler tests now obsolete under the payer-fronted credit design. |
| crates/node/src/handlers/client/ramp.rs | Removes the legacy ramp/floor machinery from the node client handler implementation. |
| crates/node/src/handlers/client/outcome/tests.rs | Updates outcome classification tests to reflect removed refusal paths and updated close reason semantics. |
| crates/node/src/handlers/client/outcome.rs | Updates client outcome mapping/metrics to remove floor/ramp paths and align with the new credit/limiter behavior. |
| crates/node/src/dht/rate_limit.rs | Refactors DHT rate limiting implementation to the simplified per-peer+global model. |
| crates/node/src/dht/bucket_refresh.rs | Updates bucket refresh behavior/docs to align with per-peer (not per-IP) limiter semantics. |
| crates/node/src/admin/tests.rs | Updates admin RPC/tests to match the revised configuration fields and limiter model. |
| crates/incentive/src/rate/tests.rs | Updates incentive rate tests for the removal of legacy floor/ramp mechanisms. |
| crates/incentive/src/rate.rs | Updates incentive rate logic by removing obsolete helpers tied to the previous credit model. |
| crates/incentive/src/lib.rs | Updates module exports/docs to reflect the new lane credit/delivered accounting structure. |
| crates/incentive/src/lane/tests.rs | Adds/updates lane tests covering delivered-bytes persistence and credit/debit behavior. |
| crates/incentive/src/lane.rs | Implements lane delivered-bytes tracking and exposes credit/debit/refund operations needed by the new model. |
| crates/incentive/src/credit/tests.rs | Removes/updates credit-window tests that were specific to the deprecated ramped-window design. |
| crates/incentive/src/credit.rs | Removes the deprecated ramped credit-window implementation in favor of the delivered-based credit approach. |
| crates/e2e/src/node/tests.rs | Updates E2E node tests to reflect removed knobs and the new credit/rate-limit behavior. |
| crates/e2e/src/node.rs | Updates E2E node harness/fixtures to match the revised config and removed legacy fields. |
| crates/common/src/config/resolved.rs | Updates resolved config types/defaults to add pay-ahead/backfill knobs and remove obsolete floor/per-IP settings. |
| crates/common/src/config/errors/tests.rs | Updates configuration error/notice tests for the new/renamed fields and validation messages. |
| crates/common/src/config/errors.rs | Updates configuration error/notice documentation and examples for the new fields. |
| crates/common/src/cli/fetch.rs | Wires new client pay-ahead policy options into the common fetch CLI configuration surface. |
| crates/client/tests/snapshots/public_api__public_api.snap | Updates the client public API snapshot to reflect the new pay-ahead window and config surface. |
| crates/client/src/streamer.rs | Integrates pay-ahead policy application into the streaming/open-range flow and related pull behavior. |
| crates/client/src/source_set.rs | Updates source-set documentation/behavior to match revised terminology and credit/backpressure semantics. |
| crates/client/src/rate_limited/tests.rs | Updates client rate-limited close-label tests to match revised semantics and labels. |
| crates/client/src/rate_limited.rs | Updates client-side rate-limited handling and associated close reason labeling/docs. |
| crates/client/src/peer_store/tests.rs | Adds/updates tests for persisting pay-ahead trust/window state across runs. |
| crates/client/src/peer_store.rs | Persists per-operator trust stats and payer window state used to size/pay ahead per node. |
| crates/client/src/payer_window/tests.rs | Adds unit/property tests for payer window sizing, clamping, and trust-driven adjustments. |
| crates/client/src/pacer.rs | Implements credit-based pacing logic for pulls (including miss-path pacing) under the pay-ahead model. |
| crates/client/src/ledger/tests.rs | Adds/updates ledger tests for prepaid credit accounting, claims/clamps, and write-off semantics. |
| crates/client/src/lanes.rs | Updates lane ledger structures to incorporate per-operator trust and shared lane credit accounting. |
| crates/client/src/driver.rs | Updates the client driver to use the new credit/write-off model and revised completion/resume behavior. |
| crates/client/src/credential/tests.rs | Updates credential-related tests to match pay-ahead cap/divisor behavior and funding projection changes. |
| crates/client/src/credential.rs | Updates credential funding/projection logic to account for pay-ahead window sizing constraints. |
| crates/client/src/config/tests.rs | Adds/updates client config tests for new pay-ahead settings and defaults. |
| crates/client/src/config.rs | Extends client configuration with pay-ahead policy knobs and related builder/apply behavior. |
| crates/client/Cargo.toml | Updates client crate dependencies/dev-dependencies to support the new payer-window test suite. |
| crates/cli/tests/doctor_cli.rs | Updates doctor CLI tests to validate notices/output for new config keys and removed fields. |
| crates/cli/tests/config_validate.rs | Updates CLI config validation tests for renamed/removed keys and new pay-ahead/backfill settings. |
| crates/cli/tests/admin_rpc.rs | Updates admin RPC CLI tests to reflect new config shapes and removed legacy knobs. |
| crates/cli/src/commands/gateway/tests.rs | Updates gateway command tests to reflect changed allowance/exposure behavior under pay-ahead. |
| crates/cli/src/commands/gateway.rs | Updates gateway command logic to account for pay-ahead credit exposure in its computations. |
| crates/cli/src/commands/fetch/tests.rs | Updates fetch command tests to include/validate new pay-ahead policy flags and wiring. |
| crates/cli/src/commands/fetch.rs | Wires fetch CLI pay-ahead flags into PullConfig and persists policy/trust through the peer store. |
| crates/cli/src/commands/doctor/config/tests.rs | Updates doctor config subcommand tests for revised findings/notices around new keys. |
| crates/cli/src/commands/config/tests.rs | Updates config command tests for template/output changes and new/removed keys. |
| crates/cli/src/commands/config.rs | Updates config command output/templates to include pay-ahead/backfill settings and remove obsolete fields. |
| Cargo.toml | Updates workspace configuration/metadata to reflect the refactor and dependency changes. |
| Cargo.lock | Updates lockfile to include dependency graph changes introduced by the client/test updates. |
| adr/architecture.md | Updates architecture documentation to reflect the payer-fronted credit model and limiter changes. |
| adr/039-multi-source-parallel-fetch.md | Updates ADR text to align multi-source/parallel fetch behavior with the new credit semantics. |
| adr/038-bao-verified-range-streaming.md | Updates ADR guidance around verified range streaming to reflect pay-ahead credit behavior and constraints. |
| adr/022-content-discovery.md | Updates content discovery ADR text for the simplified DHT rate limiting model. |
| adr/013-schema-evolution.md | Updates schema evolution ADR text for revised RATE_LIMITED semantics and related protocol behavior. |
| .claude/skills/decdn-spec-discipline/references/decdn-precedents.md | Updates internal precedent notes to reflect the new payer-fronted credit approach and removed legacy mechanisms. |
Review effort: Balanced
…credit Brings in #2879 (the size proof is the only statement of a blob size), #2900 and the squash of #2873, whose code this branch already carries. Conflict resolutions: - node window.rs: main's new unproven-size and out-of-bounds refusals release a floor reservation; this branch has none, so those calls go. - node dispatch.rs, window.rs imports: drop both the floor types and StreamResponseBody. - cli fetch.rs: keep the PayerTrust guard; drop prove_size, which main removes. - client streamer.rs: apply the pay-ahead policy, then read the proven size. - client public_api snapshot regenerated. - e2e pool_floor_ceiling_aggregate.rs stays deleted. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Kpvr4Hsh3j4uw3sPiHpYkv
… links Drop the removed ramp knobs from the client_loopback harness and the ramp-only tests, bound the non-paying leaf in node_origin_pull by the leaf's payment, remove two unused imports, and fix the decdn-client intra-doc links that clippy and cargo doc reject.
…ee serve gaps Node fixes: - serve_leg: wait for lane credit only while wire remains, so a payer that paid exactly for the range is not left waiting after the last frame. - dispatch: run the stateless pre-spend pool gate at the top of the miss path again, before any fill tier reads the origin (#1519). Client fix: refuse a stream whose proven wire runs past the received-byte cap at the open, before paying for bytes the cap would refuse. Tests: client_loopback and node_origin_pull pay ahead of delivery. Tests whose property was the removed floor reservation, committed-floor ledger or per-stream ramp are deleted.
…de tests Node: - A stale sealed voucher on a lane with no credit, or a stale reveal on a stream anchored below the lane's signed watermark, is rejected AmountRegression with the watermark bundle at once, so a restarted payer reseeds instead of waiting out the proof timeout. Client: - An AmountRegression heal retires the chain the node did not adopt, as an UnderFold heal does. - Every VoucherRejected forgets the lane's prepaid credit: a gate stop leaves the proofs in flight unread, so the node may not hold that credit. Tests: origin_range_pull, partial_serve and node_to_node_pull_through pay ahead of delivery; client_loopback's remaining payer, heal and split tests follow the credit model. Deleted: the closing-voucher send-stop race tests (a payer's last proof now precedes the node's last frame) and the last floor-reservation race test.
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 10 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
Node: - Each lane carries a credit watch that ticks when a proof credits it or a backfill returns credit. A stream waiting for credit races its own proof read against it, once its payer has paid on it, so a sibling's proof wakes it instead of leaving it to the proof timeout. A wake refunds the proof attempt. - The stale sealed-voucher reject applies only to a stream no proof has credited, on a connection other than the one that last credited the lane: a restarted payer, not a sibling whose late voucher crossed a deeper one. Client: a stream counts lane credit only once it has paid on itself, so a lane's second stream pays its own first window and the node can wake it.
Node: after a clean StreamEnd, read and credit the proofs the payer sent past the last frame before draining to FIN. The node reads a proof only while credit falls short, so a stream that finished on a sibling's credit left its own proofs unread while the payer counted them as lane credit. Client: - A stream blocked on a read pays again when the lane's prepaid credit falls (a sibling received bytes, or credit was dropped), without dropping the pinned read. - After such a sibling spend, a shortfall below one chunk pays one chunk, or a closing residual for exactly the rest: the node sends a frame it cut to earlier credit whole or not at all.
CI fix: what the last five commits change, and whyCI is green on 8ff61fe. Locally: 6302/6302 workspace tests, 139/139 anvil e2e journeys (the CI command), and fmt, clippy and doc are clean. The first CI run failed on clippy, cargo doc, test and anvil e2e (journeys). The lint and doc failures were small. The test failures were not: the node integration tests had never been ported to payer-fronted credit, so they did not compile. Once they compiled, about 120 of them failed. Porting them turned up several places where the code did not do what this PR's description says it does. Those are real behaviour fixes, listed per commit below. dfea871: compile the node integration tests, fix doc links
ea57a75: port the tests to lane credit, fix three serve gapsMost tests read the old unpaid floor first and paid afterwards. They now pay ahead. Tests whose whole property was a removed mechanism are deleted: the floor reservation, the committed-floor ledger, and per-stream ramp or credit isolation. Behaviour fixes:
aeb6688: restore the stale-proof heal, port the remaining node tests
8b6df67: wake a paid stream on a sibling's creditThis is the anvil
8ff61fe: keep concurrent same-lane streams payingThis fixes
Not part of this PR
|
…licy The payer window policy is process-wide. open_range applied the config it was given, so the CLI's streamed fetch, which builds a default PullConfig, reset the user's --pay-ahead-* and loss flags to the defaults for every pull in the process. The CLI already applies the user's policy at its entry point (discovery_options), so open_range no longer applies one. Also restore the space after a comma in the incentive crate-root doc table.
… refusal entry The signer floor-cap refusal and its decdn_serve_stream_rejected_signer_floor_at_cap_total counter no longer exist, and neither does blockchain.pool_floor_signer_live_windows. The admission gate prices one chunk against the pool's remaining deposit less M.
ADR 037 still described the removed ramped credit window (credit_max, credit_ramp_divisor, RampPacer) and the per-signer floor refusal. It now states what the code does: the pull leg's CreditPacer draws only what the downstream lane has paid for, plus PULL_AHEAD_BYTES, so a request that pays nothing makes the node pull nothing. The deposit gate prices one chunk, the parameters table names backfill_window and backfill_divisor, and the pipelined look-ahead deferral is gone because the payer pays ahead. The same stale wording goes from ADR 005, 022, 038, 039, the architecture overview and the observability appendix.
A mid-stream PoolExhausted, PoolClosed or SignerCapExhausted stop left the proofs the payer had already sent unread, and the client forgot its prepaid credit on every rejection. When the node had credited those proofs, the next stream paid the same chunk again: cli_fetch_topup settled about one chunk over the whole-blob wire cost. The node now reads and credits the proofs still in flight before it closes a stream on a pool or signer stop, as it does after a clean StreamEnd. The client forgets its prepaid credit only when the node refused a proof, so the credit it counts after a gate stop is the credit the lane holds.
Multi-agent review summaryFive review passes (code, tests, silent failures, type design, comments/ADRs) over the full diff; every critical claim below was verified by reading the code at the PR head (236a8dd). Overall: the core accounting is disciplined — saturations all money-safe, atomic debit sound, no lost wakeup in Critical — should block merge1. Superseded sibling proofs kill a healthy concurrent stream with 2. The payer never deducts in-flight loss, so its credit view drifts above the lane's and stalls it. 3. Proof-budget exhaustion sends no 4. The PR description misstates the implementation (all three verified). Important
The three judgment calls
Strengths
Suggested order: fix 1–3 (all in the credit-liveness layer; 2 together with the primed-leg gap), correct the PR body (4), add the backfill test suite, sweep ADR 005 + the stale comment list, then the gateway drop penalty and the observability warns. |
…write off silent stalls Three credit-liveness fixes from the PR 2877 review: The serve loop reads, without waiting, the proofs the payer already delivered on a stream before each frame (credit_buffered_proofs), so a funded stream's proofs are committed near arrival instead of waiting unread until a sibling's higher proof supersedes them and they spend the proof budget crediting nothing. Each drained proof spends the frame's proof budget, so a payer that slivers a frame across many proofs is cut at the same bound as before. A stream that spends its proof budget while the lane's credit does not cover its next frame now ends with an AmountRegression reject carrying the lane's watermark bundle, so a restarted payer whose ledger trails the node's reseeds and resumes instead of retrying a superseded chain forever. The payer reconciles in-flight loss: a live stream that reads nothing for a full floor window while the books hold lane credit writes that credit off (ADR 003's first write-off case, observed), which books the loss, shrinks the node's window, and unsticks the lane. A retired ledger releases its counted credit from the operator's outstanding total on drop, so stranded credit no longer ratchets the per-node cap shut. The two previously flaky node_origin_pull tests pass 10/10 with these fixes.
Code: - The public gateway's drop penalty is capped by the dropped request's span, so aborted range requests no longer charge the flat pay-ahead bound against the shared daily allowance; a test pins the locally priced pay-ahead constant to the documented 64 MiB default. - The unclean-ends map evicts one remembered end at its bound instead of clearing all 64, and its doc says so. - Crossing the run's write-off budget logs a warning naming the consequence; the zero-budget boundary is documented. The HashMismatch write-off and a failed sibling-spend repayment are logged; the post-end proof drain tells a fault and its timeout apart from a FIN. - LaneState.delivered_bytes is private: refund clamps to the bytes sent and returns the applied amount (take_backfill drops its re-derived clamp), and the on-disk decoder restores the count through a named setter. - The peer store's verified/lost counts are required fields: a record without them fails to decode instead of silently resetting an operator's track record (pre-mainnet, no dual-format readers). Tests: - A backfill unit suite (allowance, window, fresh-signer, divisor-off, refund clamp, eviction), the negative credit-wake test, the zero-byte StreamEnd write-off pair, the AmountRegression heal and retire-chain tests, a single-cover payment bound on the concurrent same-lane test, the write-off-budget boundary tests, and a disconnect-leaves-trust assertion. - The tail-billing e2e test passes with exact billing (3/3): the 576-byte over-bill is gone with the proof-drain fix, so its assertion stays exact. Docs: - ADR 003/005/039, architecture, appendix-observability and every code comment that still described the node-fronts-credit model (ramped windows, floor reservation, per-signer floor caps, RampPacer, delivered-but-unpaid re-billing) now state the payer-fronts-credit design; write_off_budget is in ADR 003 § Credit Window with the other payer knobs. The steal pay-ahead clamp is deferred to #2902.
|
Review findings addressed in eef70e2 and a9dbead:
|
The ledger releases its counted credit from the operator's outstanding total when it retires; the Drop impl is part of the public surface. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… drain and backfill - The one-chunk exemption from the per-node pay-ahead cap reads the lane's credit and applies below one chunk group (`payer_window::lane_room`), so a lane holding a sliver no frame can use is never starved, and a lane that opens many streams takes the exemption once. - `PeerStore::save_windows` adds the progress a process has not saved to the stored track record, so concurrent fetches no longer overwrite each other's verified and lost counts. - The node's upstream buyer ledgers attach the operator's shared trust record, so the per-node cap and window ramp span its pools at one operator. - The pre-frame proof drain ends the stream on a frame the reader consumed and could not use (`UnusableProofFrame`), as the waiting read does. - Only a stream that ends on a fault leaves an unclean end for backfill; an in-band stop closes cleanly and grants none (ADR 003 § Credit Window). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aim on each proof A node sends a frame only when the payment on that stream covers it. Each proof states the share of the lane's payment it assigns to its stream: a ChunkPreimage pays one chunk to its stream, and Voucher carries a new unsigned `stream_bytes` field (the residual on a closing voucher, 0 on anchor and rollover vouchers). The node credits min(share, lane paid - lane claimed), with `claimed` held in memory per lane, so out-of-order sibling reveals still pay the stream they were meant for and a replayed or overstated share can only move the payer's own payment between its streams. A lane loaded from disk starts with every paid byte claimed. Removed with it: lane-level credit and its persisted delivered count, the per-frame lane record, sibling credit wakes, the pre-frame proof drain and the trailing settle, backfill and its [payment] keys, the payer's lane prepaid counter, silent-stall write-off, reconcile_empty, sibling-spend payment sizing and the per-run write-off budget (--write-off-budget). The payer books each stream's end once: a delivery the node failed (a read fault, stall, short delivery, refusal, rejected proof, or bytes the decoder rejects) writes off paid - verified for that stream; a stream the payer chose to stop or drop books no loss. Wire-breaking: the Voucher encoding gains a field. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # crates/cli/src/commands/fetch.rs # crates/cli/src/commands/gateway/tests.rs # crates/client/src/sink.rs # crates/client/tests/snapshots/public_api__public_api.snap # crates/node/src/node_origin/admit_store.rs # crates/node/src/node_origin/pull_leg.rs
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Takes main's pay-ahead credit design (#2877): the node-side floor accumulator, per-signer live cap and credit ramp are gone, along with pool_floor_signer_live_windows. The branch's per-pool routing stays: lanes are keyed by LaneId (contract + LaneKey), redeem hints and lane stores go through PoolRoute, and the voucher domain is the lane's pool route. Co-Authored-By: Claude Opus 5.5 <[email protected]>


Implements #2876: the payer fronts credit. A node sends a frame only when the payment on that stream covers it, and the payer pays ahead within a per-node window that is payer policy. Trust moves one way. #2873 is merged and this branch is merged with it.
The ADR text (
adr/003-payments.md§ Credit Window, Pool solvency, Attack Vectors;adr/005-protocol.md;adr/037,adr/038) is the spec. Verified blob size is a separate change (#2879).Credit belongs to the stream
A lane's proofs are cumulative, so the proofs of sibling streams fold into each other: a later reveal on one stream folds an earlier reveal a sibling has in flight. Each proof therefore states its share of the lane's payment for the stream that carries it:
ChunkPreimagepays one chunk to its stream;Vouchercarries a new unsigned field,stream_bytes: the residual on a closing voucher,0on anchor and rollover vouchers.The node credits the stream
min(share, lane paid − lane claimed), withclaimedheld in memory per lane. Out-of-order sibling reveals still pay the stream they were meant for. A replayed or overstated share can only move the payer's own payment between its streams, never past what the lane paid. Credit never carries from one stream to another, and a stream that ends strands its unused credit (at most one window). A lane loaded from disk starts with every paid byte claimed.Write-offs
The payer books each stream's end once. When the node failed the delivery (a read fault, a stall, a short delivery, a mid-stream refusal, a rejected proof, or bytes the decoder rejects), it writes off
paid − verifiedfor that stream; the node's account of why does not count. When the payer chose to stop or drop the stream, nothing is written off.loss_weightshrinks the node's window by the loss.Changes per crate
decdn-protocol:Voucher.stream_bytes(unsigned, last field).decdn-nodehandlers/client/credit.rs:acquire_creditwaits until the stream'spaid − deliveredcovers the frame, reading one proof at a time while it falls short. The takedown check runs before every frame; the pool and signer re-checks run on a wall-clock cadence and stop in-band withPoolExhaustedorSignerCapExhausted.LaneDeliveryState::claimgrants each proof's share out of the lane's unclaimed payment.AmountRegressionreject carrying the lane's watermark bundle, so a restarted payer reseeds and resumes.CreditPacer, so a never-paying client costs the node nothing.decdn-clientpayer_window:PayAheadPolicy,NodeTrust(per operator address) andPayerWindows. The window ismin(pay_ahead_cap, max(floor, (verified − loss_weight × lost) / pay_ahead_divisor)), with the floor clamping last.min(window, bytes it still needs); the per-node cap bounds all of the payer's streams at one node. A stream holding less than one chunk group may take one chunk past the cap, so other streams' credit cannot starve it.UpstreamPullkeepspaidper stream and settles the write-off at its end; decode failures reach it throughStashedFault::note_failed_delivery.verified_bytes/lost_bytespersist per operator address in the peer store as required fields. Saves add each process's own progress to the stored counts, so concurrent fetches never overwrite each other.PULL_AHEAD_BYTES(48 KiB slack) pairs with the node'sframe_targetroom floor, pinned by a cross-crate test.decdn-common,decdn-cli: pay-ahead knobs are client CLI flags (--pay-ahead-cap,--pay-ahead-divisor,--loss-weight). The floor-debt and per-IP keys that #2873 removed stay removed. The public gateway's drop penalty is capped by the dropped request's span.decdn-e2e: fixtures follow the node's credit rules.pool_floor_ceiling_aggregate.rsis deleted (it tested floor accumulation, which no longer exists).Docs: ADRs 003, 005, 022, 037, 038, 039 and
architecture.mddescribe per-stream credit.Decisions taken
StreamResponse. Pipelining that proof behind the request is out of scope here (see Replace cdn/probe/v1 with a voucher-less stream-open; retire rate-manipulation slashing #2901's "Not in this issue").PULL_AHEAD_BYTES(48 KiB) matches the room floor offrame_target. Changing one without the other parks the serve leg; a cross-crate test pins them together.Known gaps
Compatibility
Wire-breaking:
Vouchergains a field, and an old client and a new node deadlock by design (the old client waits for bytes before it pays). The network is pre-mainnet, so there is no shim.Checks
Run locally:
cargo fmt -- --check,cargo clippy --workspace --all-targets --all-features -- -D warnings,CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items,python3 .github/scripts/check_crate_edges.py: pass.cargo nextest run --workspace: 6304 tests pass, including the claim suite (out-of-order sibling claims, replay and overstated shares, loaded lanes), below-frontier reveals claiming their own chunk, a sibling that never paid drawing nothing, the aggregate-voucher split across two streams, and the write-off rules (zero-byte and partial earlyStreamEndwritten off, payer drop and disconnect not).cargo test --no-run -p decdn-e2e --features anvil-e2e: compiles.decdn-protocolanddecdn-client: regenerated and pass.Not run locally: the anvil e2e tests themselves,
gateway_sdkandgateway_sdk_python(sdk-e2e), and the Solidity gates (no contract change). The gateway HTTP contract (paths, headers) is unchanged, so no SDK pin moves are expected. CI runs these.🤖 Generated with Claude Code