Skip to content

fix(node): stop a top-up for one pool from joining a topUp for another - #2498

Merged
thiras merged 2 commits into
mainfrom
fix/topup-slot-pool-scoped
Oct 17, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/topup-slot-pool-scoped

Conversation

@thiras

@thiras thiras commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Summary

The node's single top-up slot did not record which pool its topUp funds, so join_or_spawn_topup(pool_id, ..) joined a topUp for any pool.

#2497 already refuses a recovery while a settle holds the slot. The window it leaves open is the normal receipt wait (up to RECEIPT_TIMEOUT). If the store replaced the pool in that window:

  • A recovery top-up for the new pool joined the old pool's topUp and claimed its refill amount as headroom. When that topUp escrowed, the credit found the row replaced, and the recovery failed as EscrowedUntracked, which is final.
  • A fill on the new pool could wait on a sibling's recovery for the old pool. It then failed, or, when that topUp reverted PoolNotOpen, called replace_pool on the new pool, which was still open.

The fix (option 1 from the issue):

  • InFlightTopUp records its pool_id.
  • join_or_spawn_topup returns Result. A caller for another pool gets TopUpForOtherPool { pool_id, in_flight }, marked LocalPullFault, and the slot is untouched. A recovery step fails at once, and NodeFunder meters it on decdn_node_pull_recovery_step_refused_total. A low-water refill skips.
  • recovery_in_flight(pool_id) hands a fill only a sibling's recovery for the same pool.
  • Unchanged on purpose:
    • The hold check in top_up_pool_by still runs first, so a settling topUp for any pool still answers TopUpHeld.
    • The slot is not keyed by pool. One wallet sends every topUp, so a second topUp beside it could not mine before the first one's nonce is spent.

Docs that said a refill or recovery joins any in-flight topUp now say "the same pool". The metric doc lists the new refusal cause. The CHANGELOG has a Fixed entry.

Tests

New tests in buyer_pool/tests.rs. Each puts a never-resolving topUp for another pool in the slot:

  • a_recovery_does_not_join_a_top_up_for_another_pool: top_up_pool_by fails on its first poll with TopUpForOtherPool, which names both pools, plus LocalPullFault. The slot keeps the old pool's entry, and its unclaimed stays at the refill's full amount.
  • a_fill_does_not_wait_on_a_siblings_recovery_for_another_pool: recover_pool returns at once with the same error, and no replacement open begins.

Mutation checks by hand: removing the pool check in join_or_spawn_topup fails both tests, and removing the recovery_in_flight filter fails the second. There is no refill test, because a refill join claims nothing, so it would pass with or without the guard.

cargo nextest run -p decdn-node --all-features: 1690 passed. Workspace clippy --all-features -D warnings, cargo doc with warnings denied, cargo fmt --check and pre-commit are green.

Not in this PR

  • LocalPullFault is added twice on the recovery path, once in buyer_pool and once in funder.rs, so the warning repeats "local buyer-side fault". TopUpHeld on main does the same.
  • The plain RPC calls in fund_pool have no time limit, so a hung call holds the slot with no gauge set. That predates this branch. It is now more visible, because recovery fails at once with a warning instead of hanging.

Closes #2496

🤖 Generated with Claude Code

https://claude.ai/code/session_0123DU1V2G3UnrwF2o9g4XHa

thiras and others added 2 commits October 17, 2026 17:03
The top-up slot did not record which pool its topUp funds, so
join_or_spawn_topup joined any topUp in flight. When the store replaced
the pool while a topUp for the old one waited for its receipt, a
recovery top-up for the new pool joined it, counted the old pool's
escrow as its own headroom, and then failed as EscrowedUntracked. A
fill could also wait on a sibling's recovery top-up for the old pool
and take that pool's deposit as its own.

InFlightTopUp now records its pool. join_or_spawn_topup refuses a
caller for another pool with TopUpForOtherPool, marked LocalPullFault,
so a recovery step fails at once and a low-water refill skips.
recovery_in_flight only hands a fill a sibling's top-up for the same
pool. The settle hold check still runs first, so a settling topUp still
answers TopUpHeld.

Closes #2496

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0123DU1V2G3UnrwF2o9g4XHa
TopUpForOtherPool now carries the caller's pool and the slot's pool, so
the recovery step's warning names both: the only other line that did
was a debug!. The docs that said a refill or recovery joins any
in-flight topUp now say the same pool, and the join_or_spawn_topup and
top_up_pool_by Errors no longer assume the slot's pool is the stale
one. The recovery-step-refused metric doc lists the new cause. A test
assertion on an empty mock queue that could not fail now checks that no
replacement open began.

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 14:18
@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.

🟢 Approval recommended

The focused guards preserve same-pool behavior, and regression tests cover both cross-pool recovery paths with no unresolved findings.

No open issues 🎉

What changed in this PR

Prevents node funding recovery from joining a top-up for the wrong pool while preserving the single-wallet transaction slot.

Changes:

  • Records pool identity and rejects cross-pool joins without changing slot ownership or claims.
  • Restricts sibling recovery waits to the same pool.
  • Adds regression tests and updates funding documentation.
File Description
crates/​node/​src/​metrics.rs Documents cross-pool recovery refusals.
crates/​node/​src/​buyer_pool/​tests.rs Tests immediate refusal and preservation of the existing slot.
crates/​node/​src/​buyer_pool.rs Adds pool-aware join and recovery guards.
CHANGELOG.md Describes the cross-pool funding fix.

Review effort: Balanced

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main f521155 fix/topup-slot-pool-... 51fb54d +/-
76% 76% 0%

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

@thiras
thiras merged commit 4dd5306 into main Oct 17, 2026
32 checks passed
@thiras
thiras deleted the fix/topup-slot-pool-scoped branch October 17, 2026 14:27
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): stop a top-up for one pool from joining a settling topUp for another

2 participants