Skip to content

fix(node): keep an abandoned stream's free floor as floor debt - #2779

Merged
thiras merged 5 commits into
mainfrom
fix/2767-floor-debt
Nov 1, 2026
Merged

thiras merged 5 commits into
mainfrom
fix/2767-floor-debt

Conversation

@thiras

@thiras thiras commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

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's Drop released 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:

  • Charging debt. An unrepaid drop charges 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) report delivered − paid to the guard after each frame write and each credited voucher.
  • Admission. try_reserve_floor counts live floor plus debt at both levels:
    • Pool: remaining − M, refused as PoolExhausted (Unfunded on the wire). Rotating signer keys therefore runs into the pool bound.
    • Signer: k · one_window, refused as SignerAtCap (NotFound on the wire).
  • Clearing debt. Only payment clears debt; time never does. In 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.
  • Unchanged on purpose. The in-flight re-checks (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_windows keeps its name but now bounds live floor plus floor debt.
  • A signer that abandons about k windows at one node, and never pays there again, is refused NotFound at that node until the node restarts or the pool is reclaimed. The CHANGELOG entry is under Security.

Reviewer notes

  • Start with crates/node/src/handlers/client/mod.rs: SignerFloorState / PoolFloorState, FloorReservation::{track_unpaid, release_live, clear_debt, abandon_debt}, Drop, and try_reserve_floor.
  • Debt is capped at the reservation. Unpaid bytes above the floor came from the lane's ramp carry, which earlier paid streams backed, and an abandoned stream already forfeits that carry (ADR 003 §Credit window).
  • On a miss, pull-through fronts about two floors upstream, but the debt is sized from the downstream unpaid credit, because the fronted bytes stay in the cache.
  • Memory adds one U256 per 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.
  • ADR 003 drops the "sequential abuse is not gated" position and lists the new residuals: cross-node fan-out 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 deny reports RUSTSEC-2026-0387 (crypto-bigint 0.5.5). It is a new upstream advisory, unrelated to this PR, and non-blocking in CI.

Verification

  • Pre-commit hooks on every changed file pass. cargo-deny is warn-only and reports only the advisory above.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: clean
  • cargo nextest run -p decdn-node -p decdn-client: 3093 passed
  • cargo nextest run -p decdn-cli -p decdn-common -E 'test(config)': 444 passed
  • cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(pool_floor_ceiling_aggregate)': passed
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items, cargo fmt -- --check, make -C adr check-refs: clean
  • New tests:
    • 6 unit tests in handlers/client/tests.rs;
    • loopback: 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;
    • pull-through: window_pull_through_never_paying_leaf_is_refused_after_its_floor.
  • Mutation checks:
    • Making Drop charge no debt fails the bounded-free-total, rotating-signers and pull-through tests.
    • Removing the clear in release_if_repaid fails the clears-debt test.
  • adr/ changed: make -C adr check-refs, and the adr/architecture.md threat row is updated.
  • CHANGELOG entry added.

🤖 Generated with Claude Code

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]>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 18:16
@thiras thiras self-assigned this Oct 30, 2026
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]>

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.

🟡 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

Comment thread crates/node/src/handlers/client/mod.rs Resolved
@thiras

thiras commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Debt clearing stays as implemented: payment past a stream's own floor clears debt, which bounds a paying client's free bytes to about P/2 + P + k·F per node. The tighter explicit-repayment variant is tracked in #2780. The partial-write gap found in review is fixed in 693d074: each frame now counts as unpaid before its write.

@github-code-quality

github-code-quality Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 4ebf92d fix/2767-floor-debt 81fa851 +/-
77% 77% 0%
View coverage of the 6 most impacted files.
File main 4ebf92d fix/2767-floor-debt 81fa851 +/-
crates/node/src/dht/publish.rs 80% 78% -2%
crates/node/src...ient/outcome.rs 99% 99% 0%
crates/node/src...nt/serve_leg.rs 92% 92% 0%
crates/node/src...ent/delivery.rs 95% 95% 0%
crates/client/src/scheduler.rs 94% 95% +1%
crates/node/src...s/client/mod.rs 91% 94% +3%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 01, 2026 09:49 UTC

thiras and others added 2 commits October 30, 2026 21:35
…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]>
@thiras

thiras commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Review round (code, tests, comments, types, silent failures) addressed in 834d700:

  • Strict lockout kept. A key whose floor debt fills its cap stays refused at that node until restart or pool reclaim. ADR 003 now says so, including the node's own buyer signer as a case. Explicit repayment (payments: explicit floor-debt repayment instead of clearing by surplus payment #2780) is the recovery path.
  • Debt only for the client's own conduct. settle_end forgives the unpaid floor when the node, its store or upstream, a takedown, the size cap or a funding stop ends the stream.
  • Paid-floor-then-left streams owe debt. A stream that pays its floor and then leaves a window unpaid is charged up to its reservation.
  • Clearing-arithmetic tests. They pin no double offer, the pool clearing only what the signer cleared, and fully paid small streams owing nothing. Each was mutation-checked.
  • Observability. Floor refusal logs carry live and debt parts, a debt-driven pool refusal gets its own line, and runbook cause 4 covers it.
  • Type tidy-ups. charge_live/release_live on PoolFloorState, a debug sum check, one epoch-filtered entry helper, and the surplus tally updated under the lock.
  • Stale text fixed. The "live cap" and "clears as the signer pays" wording, ADR 039, and the e2e module doc.

@thiras
thiras requested a review from alpergundogdu October 30, 2026 19:22
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.

node: the per-stream credit floor is free, with no cross-stream debt, so a client can download without ever paying

2 participants