Skip to content

fix(node,client): settle an unconfirmed topUp instead of freeing the top-up slot - #2492

Merged
thiras merged 3 commits into
mainfrom
fix/node-settle-unconfirmed-topup
Oct 17, 2026
Merged

thiras merged 3 commits into
mainfrom
fix/node-settle-unconfirmed-topup

Conversation

@thiras

@thiras thiras commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Summary

A node topUp whose outcome the funding task did not see either freed the top-up slot or held it forever:

  • A failed receipt read, or a submit that failed in transport, returned TopUpUnconfirmed. fund_pool warned "pool not topped up" and freed the slot, so the next low-water refill sent a second topUp beside one that could still mine.
  • A recovery caller that joined that failed refill sent its own topUp.
  • A topUp dropped 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_pool bounds the receipt wait at RECEIPT_TIMEOUT. An unconfirmed topUp goes to settle_unconfirmed_top_up, which runs inside the funding task, so its SlotGuard keeps the slot until the chain resolves the topUp:
    • receipt → topped_up_from_receipt credits the event amount; a revert escrowed nothing;
    • pending / queued → wait;
    • vacant nonce → send_top_up_at re-sends at that nonce (two txs at one nonce cannot both mine);
    • spent nonce, no receipt → getPool at that block. On-chain deposit only 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_error treats TopUpUnconfirmed as final.
  • reclaim_once bounds the reclaim receipt wait. A lapse defers to the next sweep, which either finds the pool Closed or re-sends.
  • resolve_unconfirmed_open/OpenResolution become resolve_unconfirmed_tx/NonceResolution, shared by both settle loops.
  • decdn-client adds buyer_pool::send_top_up_at and buyer_pool::topped_up_from_receipt (public-api snapshot regenerated).

Out of scope, possible follow-ups:

  • a decdn_buyer_topup_unresolved gauge;
  • an 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: after RECEIPT_TIMEOUT * 10 the 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.
  • Settle unit tests on scripted RPC replies: pending → receipt, vacant → re-send → receipt, spent nonce credits the deposit growth, spent nonce with no growth, replaced row, mined revert.
  • Client: send_top_up_at, and topped_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

…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
Copilot AI balanced review requested due to automatic review settings October 17, 2026 10:05
@thiras thiras self-assigned this Oct 17, 2026

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

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 thread crates/node/src/buyer_pool.rs Outdated
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7cd33c4 and a0912d4, in TopUpSettling::resend:

  • PoolNotOpen: the settle no longer ends on the revert alone. confirm_closed reads the confirmed nonce and getPool status at one block B.
    • Unspent nonce and Closing/Closed at B: the settle ends with the PoolNotOpen marker, so recover_pool opens the replacement. Nothing at the nonce mined by B, and a topUp that 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.
  • AllowanceShortfall: the settle sends an unlimited approve at the vacant nonce. That restores the allowance and fills the nonce, so the settle then resolves through the deposit comparison. A topUp at that nonce would revert on the allowance anyway, so the approve cannot 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), and a_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"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed: the parked receipt read keeps the slot under both versions. Fixed in a0912d4.

  • ScriptedRpc::dropped(block) answers receipt reads with "not mined" until mine() 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_once runs the real join_or_spawn_topup → fund_pool path past RECEIPT_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 at ROW + 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.

@github-code-quality

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

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 8127fe6 fix/node-settle-unco... a0912d4 +/-
75% 76% +1%
View coverage of the 6 most impacted files.
File main 8127fe6 fix/node-settle-unco... a0912d4 +/-
crates/client/src/sink.rs 95% 93% -2%
crates/node/src...s/client/mod.rs 90% 89% -1%
crates/client/src/streamer.rs 84% 83% -1%
crates/incentiv...src/test_rpc.rs 97% 98% +1%
crates/node/src/buyer_pool.rs 74% 79% +5%
crates/client/s...c/buyer_pool.rs 89% 95% +6%

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


Updated October 17, 2026 10:55 UTC

thiras and others added 2 commits October 17, 2026 13:32
- 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
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.

fix(node): settle an unconfirmed topUp instead of freeing the top-up slot

2 participants