Repository navigation
fix(node): retry a recovery topUp whose nonce the redeemer took - #2725
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the nonce-loss funding recovery change.
No open issues 🎉
What changed in this PR
Fixes node-to-node funding recovery when the seller redeemer consumes a buyer top-up’s nonce. The funding task retries only after settlement proves that nothing escrowed, preserving the protection against double funding.
Changes:
- Adds a typed nonce-loss error and up to two retries while retaining the funding slot.
- Adds regression tests for successful retry and retry exhaustion.
- Adds a retry counter and updates funding documentation.
| File | Description |
|---|---|
crates/node/src/metrics.rs |
Adds the top-up nonce-loss retry counter. |
crates/node/src/buyer_pool/tests.rs |
Tests typed errors, retry success, limits, accounting, and slot release. |
crates/node/src/buyer_pool.rs |
Separates sending and settlement from bounded nonce-loss retries. |
crates/client/src/buyer_pool.rs |
Updates documentation to describe the node’s funding-task retry. |
CHANGELOG.md |
Records the recovery fix and new counter. |
adr/appendix-observability.md |
Documents the retry counter and its operational meaning. |
Review effort: Balanced
The node signs its sellers' redeemMany and its buyer topUp with one key. A redemption that mined at the nonce the topUp had read made the topUp fail `nonce too low`. TopUpSettling::spent proved from the chain that the nonce was spent and the deposit did not grow, but returned an untyped error, so fund_pool reported it as final, the funding recovery step failed, and the node-to-node fetch died (#2721). spent now returns a typed TopUpNonceLost. fund_pool splits into top_up_and_settle and a loop that sends a fresh topUp on that error, at most twice, after a 250 ms backoff, inside the same funding task and SlotGuard. Every copy of the lost topUp was signed at the spent nonce, so none can mine later, and the fresh one cannot escrow twice. Each retry warns and ticks the new decdn_buyer_topup_nonce_lost_total counter. Closes #2721 Co-Authored-By: Claude Opus 5.5 <[email protected]>
thiras
force-pushed
the
fix/2721-topup-nonce-lost-retry
branch
from
October 28, 2026 22:06
f751c5c to
d378961
Compare
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.
Root cause
In
node_pull_larger_than_working_deposit_tops_up_once_and_completes, the server node buys from its provider and sells to the client. Two services on it sign with one key, through stateless simple-nonce wallet providers (wallet()incrates/node/src/runtime/mod.rs):redeemMany(crates/node/src/payment_settlement.rs) and gets a hint on every accepted voucher;topUp(send_top_up,crates/client/src/buyer_pool.rs).The failure runs like this:
send_top_upreads thependingnonce N.redeemManymines at N first.topUpsubmit getsnonce too lowand no hash, so it becomes aTopUpUnconfirmedat N.TopUpSettling::spentproves from the chain that N is spent at block B and that the pool's deposit at B did not grow, so thetopUpescrowed nothing. It returned an untyped error.fund_poolreported that error as final, andtop_up_at_leastdoes not retry a spawned failure.recover_poolthen failed, andnode_originturned the failed recovery step intoPullMiss::LocalFault, which ended the fetch.Reproduced locally: 1 of 15 baseline runs failed with the same log (
topUp submit (nonce 11) returned no tx hash ... escrowed nothing, thenfunding recovery step failed). AredeemManyfrom the same node loggedlandedwithin 1 ms of thetopUp's settle. The redeemer was sending oneredeemManyper voucher every 30 to 300 ms at the time.#2563 removed the old nonce-collision retry, because a retry at a fresh nonce could escrow a second time beside a copy that still mines. In this case the settle has already proved that no copy can mine.
Fix
TopUpSettling::spentnow returns a typedTopUpNonceLosterror from its escrowed-nothing branch. The error carries the nonce, the block, both deposits and the original error. ThePoolNotOpenpath inconfirm_closedis unchanged.fund_poolis split into two parts.top_up_and_settlesends thetopUpand settles it. A loop around it sends a freshtopUponTopUpNonceLost, at mostMAX_TOPUP_NONCE_LOST_RETRIES(2) times, after a 250 ms backoff. The retry runs inside the same funding task andSlotGuard, so:pendingread sees the redemption;decdn_node_pull_recovery_step_totalstill ticks once.warn!and ticks a new sibling counter,decdn_buyer_topup_nonce_lost_total. Its row is added toadr/appendix-observability.md. A call that runs out of retries still ticksdecdn_buyer_topup_failure_totalonce.top_updoc incrates/client/src/buyer_pool.rssaid the next low-water refill retries. It now describes the funding task's retry.Why the retry cannot escrow twice
Every copy of the lost
topUpwas signed at nonce N, including any copy a gateway retried on another backend. The settle reachesspentonly after it reads N as spent at block B, so no copy can mine after B. The deposit at B is not above the row's, so no copy mined before B either. A freshtopUpat a later nonce is therefore the only one that can escrow.Tests
a_top_up_whose_nonce_a_redemption_took_is_sent_again(new) scripts this sequence:nonce too low;topUpat nonce 6 escrows.It asserts that the row is credited once,
okis 1,failureis 0,nonce_lostis 1, and the slot and hold are released.a_settled_top_up_that_escrowed_nothing_frees_the_slot(updated): every try loses its nonce. The call fails after the bound, with one failure metered andnonce_lostat 2.a_hashless_top_up_waits_out_the_colliding_tx_then_escrowed_nothingnow also asserts the typed error.Mutation check: with the retry disabled, both
fund_pooltests fail. The file was restored from a copy andtouched afterwards.Verification
node_pull_topupwas looped aftercargo build -p decdn-cli -p decdn-node, with--retries 0:warn, so the race did not recur in them.cargo nextest run -p decdn-node --no-fail-fast: 1865 of 1865 passed.node_pull_topup,node_pull_pool_adopt,node_pull_pool_redeploy,anvil_pool_redeemand the decdn-nodeanvil_settlement_e2e(e2e_onchain_payment_pool_settlement) passed.cli_fetch_topupfetch_of_blob_far_exceeding_deposit_settles_whole_wire_cost_oncefailed 4 of 4 times, withunder-pay: settled 18083. It fails the same way 4 of 4 times on the unchanged baseline. This is e2e: deposit-short top-up fetch under-pays by about two intervals in CI since #2709 #2718 and is not related to this change.cargo clippy --workspace --all-targets --all-features -- -D warnings,cargo fmt -- --check,CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-itemsandmake -C adr check-refsare all clean. The pre-commit hooks passed.Optional follow-up (not in this PR)
A per-signer send mutex, shared by the redeemer and the buyer, would stop the two services from reading the same
pendingnonce at all. This PR does not add it.Closes #2721
🤖 Generated with Claude Code