Skip to content

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

Closed

Description

@thiras

Problem

The node can send a second topUp while an earlier one may still mine. Both escrow into the same pool, and the local row credits only one.

Three paths reach this:

  1. A failed receipt read frees the top-up slot. fund_pool (crates/node/src/buyer_pool.rs) runs inside the task that join_or_spawn_topup spawns, and that task holds topup_in_flight through a SlotGuard. When top_up returns TopUpUnconfirmed { tx: Some(..) } because the receipt read failed, fund_pool warns "topUp failed; pool not topped up" and returns. The slot frees, the row is not credited, and the next low-water spawn_refill_if_low sends a fresh topUp.
  2. A joined top-up that failed unconfirmed is retried. retryable_join_error treats only Spawned and EscrowedUntracked as final. A recovery caller that joined a refill which failed with TopUpUnconfirmed sends its own topUp.
  3. A submit that fails in transport (TopUpUnconfirmed { tx: None }) follows path 1 or 2.

#2433 kept the node's top_up receipt wait unbounded (receipt_timeout: None) so that a timeout cannot make path 1 routine. A dropped topUp therefore waits forever and holds the top-up slot, so node-wide funding stops until a restart.

The node's reclaim sweep (reclaim_once, crates/node/src/buyer_pool.rs) also awaits reclaim's receipt with no bound. One dropped reclaim stalls the sweep.

Fix direction

  • Settle an unconfirmed topUp the way settle_unconfirmed_open settles an open:
    • Keep the top-up slot held.
    • Re-poll by hash and nonce.
    • Credit the row from the mined receipt.
    • Re-send at the same nonce when the chain holds no transaction there.
  • After that, fund_pool can pass Some(RECEIPT_TIMEOUT).
  • Treat TopUpUnconfirmed as final in retryable_join_error.
  • Bound the reclaim sweep's receipt wait. A lapse only defers the reclaim to the next sweep, so it needs no settle step.

Checks

  • A paused-clock test on a ScriptedRpc transport whose topUp never mines:
    • the slot stays held after the bound;
    • a refill meanwhile sends no second topUp;
    • a receipt that arrives later credits the row once.
  • A joined recovery whose refill fails with TopUpUnconfirmed does not send its own topUp.

Follow-up from the #2433 review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions