Skip to content

fix(client): bill the credit-window tail after a funding stop and top up the overdraft - #2662

Merged
thiras merged 2 commits into
mainfrom
fix/2629-deflake
Oct 28, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/2629-deflake

Conversation

@thiras

@thiras thiras commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

What

Fixes the cli_fetch_topup::fetch_of_blob_far_exceeding_deposit_settles_whole_wire_cost_once flake. It was two real client payment bugs on the deposit-short path, not a test artifact.

  1. Under-pay after a gate stop. A node writes PoolExhausted / SignerCapExhausted from its mid-stream solvency re-check, after it has accepted proofs on the stream. The client rewound its last proof on every VoucherRejected, so it ended up one chunk behind the node. The resumed stream re-sent that proof and drew AmountRegression. The reseed then re-anchored the leg at the delivered frontier, so the credit-window tail past the node's watermark was never billed. That is the 996 µUSDC short in the issue.
    • VoucherRejectReason::refuses_proof() (new, decdn-protocol): the client rewinds a proof only when the reason refuses it.
    • driver::fill_gap: only a rebase re-anchors the leg. A reseed or a stale heal keeps the leg's anchor, so the next leg re-delivers and bills everything past the node's watermark.
  2. Top-up too small after an overdraft. The solvency check reads the on-chain balance, which moves only on redemption, and runs on a cadence. A fast stream can therefore sign past the deposit (seen: 15.6 MiB on an 8000 µUSDC deposit). The recovery step topped up only toward the working deposit, the node redeemed the overdraft out of it, and the pool stayed below the open gate, so the fetch ended "funding needed". PoolFunder::recover now adds the overdraft. If the pool read fails, it takes the overdraft from the run's lanes and the stored deposit. ADR 003 § Funding recovery states this.

Closes #2629

Reviewer notes

  • Read first: crates/protocol/src/client.rs (refuses_proof), crates/client/src/lib.rs (voucher_rejection), the heal branch in crates/client/src/driver.rs, and chain_remaining in crates/client/src/funding.rs.
  • Keeping the last proof on a gate stop can leave the client ahead of the node by at most one proof, when the node stopped before reading it. That is the settle-high direction: the chunk was delivered, and a later reveal on the same chain covers it.
  • Intentionally unchanged: the Rebased heal still resumes at the delivered frontier (the node chose to stop there).
  • Known bounded over-pay: a sibling stream's rebase followed by this stream's stale heal re-pays up to the rebase delta.

Verification

  • e2e: deposit-short top-up fetch under-pays by one interval under parallel load #2629 repro: the 12-binary e2e batch from the issue, --retries 0, with DECDN_NODE_LOG debug logging for extra load.
    • main: failed 3/3. With only fix 1: failed 4/5, in the "funding needed" mode. With both fixes: 7/7 green, 161/161 tests.
  • Regression tests, each mutation-checked so it fails when its own fix is reverted:
    • a_gate_stop_keeps_the_reveal_the_node_accepted and a_refused_proof_still_rewinds_its_reveal
    • a_reseed_… / a_stale_heal_does_not_mark_the_delivered_tail_paid and a_rebase_resumes_at_the_delivered_frontier
    • an_overdrawn_pool_tops_up_by_its_overdraft_too and a_failed_pool_read_still_tops_up_the_runs_overdraft
    • only_the_gate_stops_keep_the_last_proof
  • pre-commit run --all-files
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features
  • cargo nextest run --workspace: 5965 passed, before the review follow-ups. After them: decdn-client + decdn-protocol 1334 passed, plus two e2e batches.
  • PR title type fix, lowercase subject
  • Public API: decdn-protocol .snap regenerated; decdn-client snapshot unchanged
  • adr/: make -C adr check-refs; architecture.md has no top-up summary to update
  • CHANGELOG: two Fixed entries

🤖 Generated with Claude Code

… up the overdraft

A node's mid-stream solvency gate writes PoolExhausted or
SignerCapExhausted after it has accepted the stream's proofs. The client
rewound its last proof on every VoucherRejected, so it fell one chunk
behind the node. The resumed stream then re-sent that proof, drew
AmountRegression, and the reseed re-anchored the leg at the delivered
frontier, so the credit-window tail past the node's watermark was never
billed (#2629).

- VoucherRejectReason::refuses_proof (decdn-protocol) names the reasons
  that refuse the proof; the client rewinds only for those.
- The driver re-anchors a leg only on a rebase. A reseed or a stale heal
  keeps the leg's anchor, so the next leg bills past the node's watermark.
- The funding recovery top-up adds the pool's overdraft: the lanes' spend
  past the on-chain deposit, which the node redeems out of the top-up.
  A failed pool read takes it from the run's lanes and stored deposit.
  ADR 003 § Funding recovery says so.

Closes #2629

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

Voucher recovery can mark a new blob complete without accepted payment, while stale pool reads can inflate funding requirements and trigger false wallet shortfalls.

2 open issues
What changed in this PR

Fixes client payment recovery for deposit-short downloads in #2629, addressing unpaid credit-window tails and undersized top-ups.

Changes:

  • Preserves the last proof on funding gate stops and retains payment anchors across reseeds and stale heals.
  • Includes pool overdrafts in recovery top-ups, with a local fallback when chain reads fail.
  • Adds regression tests and updates payment documentation and the protocol API snapshot.
File Description
crates/​protocol/​tests/​snapshots/​public_api__public_api.snap Records the new refuses_proof API.
crates/​protocol/​src/​client/​tests.rs Tests proof-refusal classification.
crates/​protocol/​src/​client.rs Distinguishes gate stops from proof refusals.
crates/​client/​src/​tests.rs Tests proof retention and rollback.
crates/​client/​src/​lib.rs Rewinds only explicitly refused proofs.
crates/​client/​src/​ledger.rs Clarifies proof rollback documentation.
crates/​client/​src/​funding/​adoption_tests.rs Tests overdraft-aware recovery and read failures.
crates/​client/​src/​funding.rs Adds overdrafts to recovery top-ups.
crates/​client/​src/​driver/​tests.rs Tests payment frontiers after healing.
crates/​client/​src/​driver.rs Preserves anchors except on rebases.
CHANGELOG.md Documents both payment fixes.
adr/​003-payments.md Specifies overdraft-aware funding recovery.

Review effort: Balanced

Comment thread crates/client/src/driver.rs Resolved
Comment thread crates/client/src/funding.rs Resolved
@github-code-quality

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

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main a86c912 fix/2629-deflake 25f1aab +/-
77% 77% 0%
View coverage of the 7 most impacted files.
File main a86c912 fix/2629-deflake 25f1aab +/-
crates/protocol/src/framing.rs 93% 92% -1%
crates/client/src/scheduler.rs 94% 94% 0%
crates/client/src/funding.rs 84% 84% 0%
crates/node/src...gin/pull_leg.rs 84% 84% 0%
crates/client/src/driver.rs 96% 96% 0%
crates/client/src/lib.rs 89% 89% 0%
crates/protocol/src/client.rs 90% 91% +1%

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


Updated October 28, 2026 02:15 UTC

…ger deposit

- A reseed's jump is the node's watermark catching up with vouchers our
  record lost, which can predate the leg (a restarted payer). The driver
  raises the leg's baseline by the jump, so it pays for none of the leg's
  content, on retry and in the owed span an ended lane records. A leg
  rejected after delivery is re-opened and billed instead of marked paid.
- The funding recovery step takes the larger of the recorded and the
  on-chain deposit, so a lagging getPool read from before a credited
  top-up invents no overdraft and no false wallet shortfall.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 3225d68 into main Oct 28, 2026
37 checks passed
@thiras
thiras deleted the fix/2629-deflake branch October 28, 2026 02:20
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.

e2e: deposit-short top-up fetch under-pays by one interval under parallel load

2 participants