Repository navigation
fix(client): refuse every escrow of a run after an untracked one - #2514
Merged
Merged
Conversation
When a run's topUp mined and its local credit failed, the build failed as EscrowUntracked, but a sibling lane build of the same run could escrow again. It waited on open_lock, then ran before the acquire loop handled the first error (the now_or_never batch) or in the drain after it. It read the uncredited row, saw the pool low, and sent a second topUp: the receipt read had already cleared the first one from UnconfirmedEscrows. A failed record after a mined openPool let the next build open a second pool the same way. - RunFunding holds the run's first untracked escrow (note_untracked, a OnceLock). Every site in funding.rs that builds EscrowUntracked notes it, with no await after the failed write. - escrow_top_up (under top_up_serial), the fresh open in open_or_reuse_pool and PoolFunder::open_replacement refuse with UntrackedEscrowHeld before their allowance read or send. classify makes it Fatal(Command); it is not escrow_untracked, so drain_builds does not report it as a second escrow. - refill_if_low and recover return the refusal without the wallet-balance diagnosis (escrow_held). - An openPool that mined with no PoolOpened event for the owner now fails as EscrowUntracked, not a plain error the acquire loop retried into a second open. Follow-ups: #2508, #2509, #2511, #2513. Closes #2506 Closes #2507 Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The guards and error classification match the intended scope, with focused regression coverage and no identified blocking issues.
No open issues 🎉
What changed in this PR
Prevents repeat client funding after a run encounters a mined escrow that cannot be tracked locally, addressing #2506 and #2507.
Changes:
- Records the run’s first untracked escrow and refuses subsequent funding attempts.
- Classifies refusals and missing
PoolOpenedevents as command-fatal errors. - Adds regression tests and a changelog entry.
| File | Description |
|---|---|
| crates/client/src/funding/adoption_tests.rs | Tests escrow failures and subsequent funding refusals. |
| crates/client/src/funding.rs | Records untracked escrows and guards funding paths. |
| crates/client/src/fault/tests.rs | Tests fatal classification and refusal reporting. |
| crates/client/src/fault.rs | Classifies escrow refusals as command-fatal. |
| crates/client/src/buyer_pool.rs | Returns EscrowUntracked for missing pool-open events. |
| CHANGELOG.md | Documents the client funding fixes. |
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. |
7 of 9 tasks
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
When a run's
topUpmined and its local credit failed, the build failed asEscrowUntracked, but a sibling lane build of the same run could still escrow again. The sibling waited onopen_lock, then ran in one of two places: in the acquire loop'snow_or_neverbatch, before the loop handled the first error, or indrain_buildsafter it. It read the uncredited row, saw the pool low, and sent a secondtopUp. Nothing refused it, because the receipt read had already removed the firsttopUpfromUnconfirmedEscrows. A failed record after a minedopenPoollet the next build open a second pool the same way.RunFundingholds the run's first untracked escrow (note_untracked, aOnceLock<String>of the sanitized error chain). Every site infunding.rsthat buildsEscrowUntrackednotes it, with no.awaitafter the failed write. The sites are the refill credit, the vanished credited row, the recovery-step credit, both pool records, and bothopen_poolcalls.escrow_top_up(undertop_up_serial), the fresh open inopen_or_reuse_poolandPoolFunder::open_replacementrefuse with the newpub(crate)UntrackedEscrowHeld. They refuse before their allowance read or send.classifymakes the refusalFatal(Command). It is deliberately not part ofescrow_untracked(), sodrain_buildsdoes not report a refused build as a second escrow. The refusal text carries the held escrow, including its tx.refill_if_lowandrecoverreturn the refusal without running the wallet-balance check (escrow_held). Without this, a refusal ran abalanceOfread and logged a WARN that blamed the top-up.openPoolthat mined with noPoolOpenedevent for the owner now fails asEscrowUntracked, not a plainbail!. The acquire loop treated the plain error as transient and retried, and the retry opened a second pool. The node and CLI do not downcast it, so their behavior is unchanged.Closes #2506, Closes #2507
Reviewer notes
Read first:
RunFunding::note_untracked/refuse_after_untrackedand theRunFundingdoc incrates/client/src/funding.rs. Every other change is a call site.The hold is per
RunFunding, not on the sharedUnconfirmedEscrowshandle. That follows the issue's first fix direction. An untracked escrow is fatal to the command, so no later pass runs. When a fetch or bundle group is dropped before it reports the escrow, nothing names the escrow at the end. That is fix(client): a bundle pull drops sibling entries mid-drain, losing a late escrow and allowing exit 75 #2509 for the bundle pull and fix(client,cli): an interrupted or dropped run does not name the untracked escrow it holds #2511 for Ctrl-C during the drain and the end-of-run read. fix(client,cli): an interrupted or dropped run does not name the untracked escrow it holds #2511 suggests moving the hold to the shared handle.What the guarantee covers. A
topUpchecks undertop_up_serial, which an earliertopUpholds until its outcome, so it always sees thattopUp's note. AnopenPoolthat passed its check before a concurrent call's escrow went untracked still sends. The open and the refill use different locks. Thenote_untrackeddoc says so, and the review found no practical path to it.Not done here: the issue's second direction, cancelling drained builds that have not submitted. It would also stop the unneeded refill after a completed fetch (fix(client): the build drain starts a refill after the fetch ended #2513). fix(client): a fatal lane build drops the rest of its batch, and an escrow in it goes unnamed #2508 (a fatal batch drops the rest of its batch) is unchanged too.
Tests are in
funding/adoption_tests.rs, built on a newStoreFaultsstore wrapper that fails one write per test: credit, record, or the row after a credit.topUpparked ontop_up_serialwhile an earlier one goes untracked. The test holds the lock itself, so the order is fixed.PoolOpenedevent.I removed each note and refusal site in turn, moved the check above
top_up_serial, and narrowedescrow_held. Each mutation fails its own test. Not covered: the two notes insideopen_replacementafter its ownopen_pooland record. They have the same shape as the fresh-open notes, which are tested.Verification
cargo fmt -- --checkCARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features(run as-- -D warnings)cargo nextest run --workspace: 5097 passedCARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-itemscontracts/changed: n/aCHANGELOG.mdentry addedpub(crate).🤖 Generated with Claude Code