Repository navigation
fix(client): bill the credit-window tail after a funding stop and top up the overdraft - #2662
Merged
Merged
Conversation
… 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]>
This was referenced Oct 28, 2026
There was a problem hiding this comment.
🟡 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
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 7 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
…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]>
This was referenced Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


What
Fixes the
cli_fetch_topup::fetch_of_blob_far_exceeding_deposit_settles_whole_wire_cost_onceflake. It was two real client payment bugs on the deposit-short path, not a test artifact.PoolExhausted/SignerCapExhaustedfrom its mid-stream solvency re-check, after it has accepted proofs on the stream. The client rewound its last proof on everyVoucherRejected, so it ended up one chunk behind the node. The resumed stream re-sent that proof and drewAmountRegression. 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.PoolFunder::recovernow 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
crates/protocol/src/client.rs(refuses_proof),crates/client/src/lib.rs(voucher_rejection), the heal branch incrates/client/src/driver.rs, andchain_remainingincrates/client/src/funding.rs.Rebasedheal still resumes at the delivered frontier (the node chose to stop there).Verification
--retries 0, withDECDN_NODE_LOGdebug 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.a_gate_stop_keeps_the_reveal_the_node_acceptedanda_refused_proof_still_rewinds_its_reveala_reseed_…/a_stale_heal_does_not_mark_the_delivered_tail_paidanda_rebase_resumes_at_the_delivered_frontieran_overdrawn_pool_tops_up_by_its_overdraft_tooanda_failed_pool_read_still_tops_up_the_runs_overdraftonly_the_gate_stops_keep_the_last_proofpre-commit run --all-filesCARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-featurescargo nextest run --workspace: 5965 passed, before the review follow-ups. After them:decdn-client+decdn-protocol1334 passed, plus two e2e batches.fix, lowercase subjectdecdn-protocol.snapregenerated;decdn-clientsnapshot unchangedadr/:make -C adr check-refs;architecture.mdhas no top-up summary to update🤖 Generated with Claude Code