Repository navigation
fix(node): keep an abandoned stream's free floor as floor debt - #2779
Conversation
Every stream opens with a free credit floor of one interval plus the verify lag. An unpaid stream's guard released its reservation on drop and kept nothing, so the pool ceiling and the per-signer cap bounded only concurrent floors. A client that never paid could take a floor, reset, and repeat: about 100 MiB/s of free download per peer at the default serve limit, with upstream USDC fronted on every miss. An unrepaid FloorReservation now charges its unpaid bytes, capped at the reserved floor, as floor debt on the signer and the pool row, in the same lock hold that releases its live reservation. Admission counts live floor plus debt at both levels, so rotating signer keys meets the pool bound (Unfunded) and one key meets its k-window cap (NotFound). Payment past a stream's own floor clears debt; time does not, so it is not the signer-keyed rate #1957 removed. The in-flight re-checks stay live-only. No wire, config or persistence change: a restart or a pool reclaim forgives debt. ADR 003 states the floor-debt bound and its residuals (cross-node fan-out, restart forgiveness, honest-key lockout at about k unrepaid windows) and drops the "sequential abuse is not gated" position. Closes #2767 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A client controls its stream receive window, so it can read part of a frame and then stop the stream. The write fails, `delivered` never counts the frame, and the abandoned stream charged no floor debt for bytes that left the node. Both serve loops now report the frame's exposure to the floor guard before the write. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Partial opening-frame writes can escape debt accounting and bypass both floor caps, while repayment-accounting flaws can incorrectly consume paying signers’ admission budgets.
2 open issues
What changed in this PR
This PR addresses repeated unpaid downloads by retaining abandoned streams’ free credit as in-memory floor debt in the node’s existing admission accounting.
Changes:
- Counts live reservations plus debt against pool and signer limits, with payment beyond a stream’s own floor clearing debt.
- Tracks unpaid bytes in both serving paths and adds unit, loopback, and pull-through tests.
- Updates specifications and operator guidance without changing wire formats, configuration schema, or storage.
| File | Description |
|---|---|
docs/runbook.md |
Explains debt-related refusals and recovery. |
crates/node/tests/node_origin_pull.rs |
Tests repeated unpaid pull-through refusal. |
crates/node/tests/client_loopback.rs |
Tests signer limits, key rotation, and debt clearing. |
crates/node/src/runtime/mod.rs |
Updates floor-cap wiring comments. |
crates/node/src/metrics.rs |
Updates signer-cap metric documentation. |
crates/node/src/handlers/client/tests.rs |
Tests debt accounting, admission, and pool generations. |
crates/node/src/handlers/client/serve_leg.rs |
Reports unpaid bytes during pull-through delivery. |
crates/node/src/handlers/client/mod.rs |
Implements debt charging, clearing, and admission checks. |
crates/node/src/handlers/client/dispatch.rs |
Updates reservation lifecycle comments. |
crates/node/src/handlers/client/delivery.rs |
Reports unpaid bytes during cached delivery. |
crates/e2e/src/node.rs |
Updates fixture documentation for floor-cap semantics. |
crates/common/src/config/types.rs |
Documents debt in the existing signer cap. |
crates/common/src/config/resolved.rs |
Updates resolved configuration documentation. |
crates/common/src/config/mod.rs |
Updates default-cap documentation and comments. |
crates/cli/src/commands/config.rs |
Updates generated configuration guidance. |
CHANGELOG.md |
Records the security change and lockout behavior. |
adr/architecture.md |
Adds floor debt to the withholding defense summary. |
adr/005-protocol.md |
Documents debt-related NotFound refusals. |
adr/003-payments.md |
Defines floor debt, repayment, and accepted residual risks. |
.claude/skills/decdn-spec-discipline/references/decdn-precedents.md |
Explains the distinction between floor debt and signer rate limits. |
Review effort: Balanced
|
Debt clearing stays as implemented: payment past a stream's own floor clears debt, which bounds a paying client's free bytes to about |
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 6 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
…ng debt The serve loops reconciled the floor reservation only after a whole recoup batch. A stream that paid past its floor and then failed a later proof in the same batch left before the reconcile, so its drop charged debt and its surplus cleared none. Both loops now reconcile at each credited proof through `FloorReservation::reconcile_paid`. A paying guard also latched "owes nothing" after its first clear, so a sibling stream that abandoned later never had its debt cleared by that guard's further surplus. The latch is gone; the surplus tally alone keeps the lock to reconciles where the surplus grew. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A strict lockout makes a wrong charge permanent, so who ended the stream now decides the debt. Both serve wrappers judge the end through `FloorReservation::settle_end`: a peer-attributable error, a rejected voucher or a spent proof budget keeps the unpaid floor as debt; a node or upstream fault, a takedown, the size cap or a funding stop forgives it. The drop also charges a stream that paid its floor and then left a window unpaid, so pay-a-floor-take-a-floor no longer escapes the bound. `PoolFloorState` gains `charge_live`/`release_live` and a debug-build sum check, so every two-level change lives in one impl. The guard reads its entry through one epoch-filtered helper and updates the surplus tally under the lock. Floor refusal logs carry the live and debt parts, and a debt-driven pool refusal gets its own line. Tests pin the clearing arithmetic (no double offer, pool clears only what the signer cleared, fully paid small streams owe nothing), the end classification, the stale-guard clear, and the repaid-then-left charge. ADR 003/005/039, the runbook (new cause 4), the CHANGELOG and stale "live cap" comments match the behaviour. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review round (code, tests, comments, types, silent failures) addressed in 834d700:
|
# Conflicts: # CHANGELOG.md

What
Every stream opens with a free credit floor (one interval plus the verify lag, 1 MiB + 16 KiB). When an unpaid stream ended,
FloorReservation'sDropreleased the reservation and kept nothing, so the pool ceiling and the per-signer cap bounded only concurrent floors. A client that never paid could take a floor, reset, and repeat: about 100 MiB/s of free download per peer at the default serve limit. On a cache miss, the node also fronted upstream USDC every time.This PR adds floor debt to the existing in-memory floor accumulator:
min(reserved, min_payment(unpaid_bytes, rate))as debt on the signer row and on the pool row. This happens in the same lock hold that releases the live reservation. The serve loops (delivery.rs,serve_leg.rs) reportdelivered − paidto the guard after each frame write and each credited voucher.try_reserve_floorcounts live floor plus debt at both levels:remaining − M, refused asPoolExhausted(Unfundedon the wire). Rotating signer keys therefore runs into the pool bound.k · one_window, refused asSignerAtCap(NotFoundon the wire).release_if_repaid, payment past the stream's own reserved floor clears the signer's debt, and the pool's debt by the same amount. A stream's own floor never repays old debt. So this is not the signer-keyed rate that refactor(node): cut per-signer abandonment subsystem; reduce #1697 to a heal-path counter #1957 removed.pool_budget_covers_reserve,pool_funds_committed, the hit-path re-validation) still count live reservations only, so a stream already under way is never slowed.Closes #2767
Breaking
There is no wire, config-schema or storage change. Two behaviour changes:
blockchain.pool_floor_signer_live_windowskeeps its name but now bounds live floor plus floor debt.kwindows at one node, and never pays there again, is refusedNotFoundat that node until the node restarts or the pool is reclaimed. The CHANGELOG entry is under Security.Reviewer notes
crates/node/src/handlers/client/mod.rs:SignerFloorState/PoolFloorState,FloorReservation::{track_unpaid, release_live, clear_debt, abandon_debt},Drop, andtry_reserve_floor.U256per signer row. Rows already exist for every admitted signer's lane until the pool is reclaimed. A row that still owes debt is not pruned.K × (remaining − M), restart and reclaim forgiveness, and honest-key lockout. The spec-discipline precedent for refactor(node): cut per-signer abandonment subsystem; reduce #1697 to a heal-path counter #1957 now records why floor debt passes the gates the leaky bucket failed.cargo denyreports RUSTSEC-2026-0387 (crypto-bigint0.5.5). It is a new upstream advisory, unrelated to this PR, and non-blocking in CI.Verification
cargo clippy --workspace --all-targets --all-features -- -D warnings: cleancargo nextest run -p decdn-node -p decdn-client: 3093 passedcargo nextest run -p decdn-cli -p decdn-common -E 'test(config)': 444 passedcargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(pool_floor_ceiling_aggregate)': passedCARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items,cargo fmt -- --check,make -C adr check-refs: cleanhandlers/client/tests.rs;a_never_paying_client_gets_a_bounded_free_total,rotating_signers_on_one_pool_meet_the_pool_bound,a_paying_stream_clears_the_signers_floor_debt;window_pull_through_never_paying_leaf_is_refused_after_its_floor.Dropcharge no debt fails the bounded-free-total, rotating-signers and pull-through tests.release_if_repaidfails the clears-debt test.adr/changed:make -C adr check-refs, and theadr/architecture.mdthreat row is updated.🤖 Generated with Claude Code