Repository navigation
fix(node,client): settle an unconfirmed topUp instead of freeing the top-up slot - #2492
Merged
Merged
Conversation
…top-up slot (#2489) A node topUp whose receipt read failed, or whose submit failed in transport, freed the top-up slot, so the next low-water refill sent a second topUp beside one that could still mine. A recovery top-up that joined it sent its own too. A dropped topUp instead held the slot forever, and the node funded no pool until a restart. The receipt wait now ends after RECEIPT_TIMEOUT, and the funding task settles the unconfirmed topUp against the chain while it keeps the slot: a receipt credits the row, a vacant nonce gets a re-send at that nonce, and a spent nonce with no receipt credits what the pool's on-chain deposit holds above the row. retryable_join_error treats TopUpUnconfirmed as final. The reclaim sweep's receipt wait is bounded too, so one dropped reclaim no longer stalls it. decdn-client adds buyer_pool::send_top_up_at and buyer_pool::topped_up_from_receipt for the settle step. Closes #2489 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0123DU1V2G3UnrwF2o9g4XHa
There was a problem hiding this comment.
🟡 Changes recommended
Permanently rejected resends can hold the node-wide funding slot indefinitely, and timeout-to-settlement integration coverage remains incomplete.
2 open issues
What changed in this PR
Prevents duplicate buyer-pool funding by keeping unconfirmed top-ups under settlement until their outcome is known.
Changes:
- Bounds top-up and reclaim receipt waits.
- Adds same-nonce resend and receipt-decoding helpers.
- Adds settlement tests and updates API documentation.
| File | Description |
|---|---|
| crates/node/src/buyer_pool/tests.rs | Adds settlement and joined-refill tests. |
| crates/node/src/buyer_pool.rs | Implements top-up settlement and bounded receipt waits. |
| crates/client/tests/snapshots/public_api__public_api.snap | Records the new public helpers. |
| crates/client/src/buyer_pool/tests.rs | Tests resend and receipt decoding. |
| crates/client/src/buyer_pool.rs | Exposes resend and receipt-decoding helpers. |
| CHANGELOG.md | Documents funding recovery changes. |
Review effort: Balanced
Comment on lines
+850
to
+856
| Err(err) => { | ||
| let seen = format!( | ||
| "no transaction holds the nonce, and the re-send failed: {}", | ||
| sanitize_err_chain(&err) | ||
| ); | ||
| debug!(nonce = self.nonce, last = %seen, "could not re-send the topUp"); | ||
| seen |
Contributor
Author
There was a problem hiding this comment.
Fixed in 7cd33c4 and a0912d4, in TopUpSettling::resend:
PoolNotOpen: the settle no longer ends on the revert alone.confirm_closedreads the confirmed nonce andgetPoolstatus at one block B.- Unspent nonce and
Closing/Closedat B: the settle ends with thePoolNotOpenmarker, sorecover_poolopens the replacement. Nothing at the nonce mined by B, and atopUpthat mines after B reverts, because a pool never reopens. - Spent nonce at B: waits, and the next tick credits the deposit growth.
- Pool still open at B (a lagging backend): waits.
- Unspent nonce and
AllowanceShortfall: the settle sends an unlimitedapproveat the vacant nonce. That restores the allowance and fills the nonce, so the settle then resolves through the deposit comparison. AtopUpat that nonce would revert on the allowance anyway, so theapprovecannot strand an escrow.- Tests:
a_re_send_into_a_closed_pool_ends_the_settle(including the lagging-open read),a_closed_pool_whose_nonce_is_spent_still_credits_the_escrow(the original mines between the vacant read and the revert), anda_re_send_short_of_allowance_approves_at_the_nonce.
Comment on lines
+3858
to
+3860
| assert!( | ||
| matches!(again, TopUpClaim::Joined { .. }), | ||
| "a refill meanwhile joins the held topUp instead of sending a second one" |
Contributor
Author
There was a problem hiding this comment.
Agreed: the parked receipt read keeps the slot under both versions. Fixed in a0912d4.
ScriptedRpc::dropped(block)answers receipt reads with "not mined" untilmine()is called, answers the block number, and records the nonce of each send. alloy's block watcher still parks, so the receipt wait itself never returns.a_dropped_top_up_is_re_sent_at_its_nonce_and_credited_onceruns the realjoin_or_spawn_topup→fund_poolpath pastRECEIPT_TIMEOUT. It asserts:- the slot stays held;
- two or more sends, all at the topUp's nonce (the same-nonce re-send);
- after
mine(), one credit (row atROW + TOP_UP,decdn_buyer_topup_ok_total 1) and a freed slot.
- I checked it fails with the bound reverted to
None: no re-send happens. - 7cd33c4 also added
fund_pool-level settle tests for a submit that returns no hash: one credit, escrowed nothing, and a row replaced mid-settle.
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 |
- A re-send that reverts PoolNotOpen at a vacant nonce ends the settle with the PoolNotOpen marker, so a closed pool no longer holds the top-up slot and the recovery step opens its replacement. - The settle reads the row's deposit once, before its first tick, so a replacement open or the reclaim sweep cannot move the baseline the escrow is measured against. - An EscrowedUntracked settle outcome logs the "ESCROWED AND UNTRACKED" error instead of "pool not topped up", and the resolve line names the outcome instead of a bool. - SettledTopUp carries a TopUpProof: a receipt's tx, or the nonce, block and known txs a deposit-growth credit was read at, which a failed credit names. Growth other than the request is warned. - A funding task that dies mid-settle is metered and marked EscrowedUntracked, so no joiner funds over it. - topped_up_from_receipt reads the tx from the receipt; Tick is generic over the open and top-up settles. - Docs: tx-less credits, the deposit-growth assumption, # Errors of fund_pool and top_up_pool_by, the marker docs, send_top_up_at's transport failure. - Tests: fund_pool end to end (credits the row once, escrowed nothing, row replaced mid-settle), a PoolNotOpen re-send, and transient faults on each settle read. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0123DU1V2G3UnrwF2o9g4XHa
A re-send's PoolNotOpen revert reads the head, while the settle read the nonce vacant at an earlier block, so the original topUp could mine into the still-open pool in between. The settle now ends only once one block shows the nonce unspent and the pool Closing or Closed; a spent nonce or a pool still open there (a lagging backend) waits for the next tick. A re-send that reverts on the allowance sends an unlimited approve at the nonce. It restores the standing allowance and fills the nonce, so the settle resolves through the deposit; a topUp at that nonce would revert on the allowance anyway. ScriptedRpc gains a dropped-transaction mode (receipt reads answer "not mined" until mine(), the block number is answered) and records the nonce of each send. A service-level test drives a dropped topUp through the receipt bound into the settle, asserts the same-nonce re-sends, then delivers the receipt and asserts one credit and a freed slot; it fails without the bound. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0123DU1V2G3UnrwF2o9g4XHa
This was referenced Oct 17, 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.


Summary
A node
topUpwhose outcome the funding task did not see either freed the top-up slot or held it forever:TopUpUnconfirmed.fund_poolwarned "pool not topped up" and freed the slot, so the next low-water refill sent a secondtopUpbeside one that could still mine.topUp.topUpdropped from the mempool waited on an unbounded receipt and held the slot, so the node funded no pool until a restart.This mirrors
settle_unconfirmed_open(#2415) for the top-up path:fund_poolbounds the receipt wait atRECEIPT_TIMEOUT. An unconfirmedtopUpgoes tosettle_unconfirmed_top_up, which runs inside the funding task, so itsSlotGuardkeeps the slot until the chain resolves thetopUp:topped_up_from_receiptcredits the event amount; a revert escrowed nothing;send_top_up_atre-sends at that nonce (two txs at one nonce cannot both mine);getPoolat that block. On-chaindepositonly grows and the row mirrors it, so what the chain holds above the row is what escrowed. Zero means nothing escrowed. A row that no longer tracks the pool is escrowed-but-untracked.retryable_join_errortreatsTopUpUnconfirmedas final.reclaim_oncebounds thereclaimreceipt wait. A lapse defers to the next sweep, which either finds the poolClosedor re-sends.resolve_unconfirmed_open/OpenResolutionbecomeresolve_unconfirmed_tx/NonceResolution, shared by both settle loops.decdn-clientaddsbuyer_pool::send_top_up_atandbuyer_pool::topped_up_from_receipt(public-api snapshot regenerated).Out of scope, possible follow-ups:
decdn_buyer_topup_unresolvedgauge;OpenHold-style fail-fast for recovery callers that join a settling top-up. The miss-pull deadline already bounds them.Test plan
a_top_up_that_never_mines_keeps_the_top_up_slot: afterRECEIPT_TIMEOUT * 10the slot is held and a second refill joins it. Fails without the fix.top_up_at_least_unconfirmed_join_is_not_retried: fails without the fix.send_top_up_at, andtopped_up_from_receipt(pool's own event, a forged log from another address ignored, fallback, revert).cargo nextest run -p decdn-client -p decdn-node: 2616 passed.cargo clippy --workspace --all-targets --all-features -- -D warnings, the rustdoc gate, and the public-api test.Closes #2489
🤖 Generated with Claude Code
https://claude.ai/code/session_0123DU1V2G3UnrwF2o9g4XHa