Skip to content

fix: hold the open slot until an unconfirmed openPool resolves - #2419

Merged
thiras merged 5 commits into
mainfrom
fix/2415-unresolved-open-pool
Oct 10, 2026
Merged

thiras merged 5 commits into
mainfrom
fix/2415-unresolved-open-pool

Conversation

@thiras

@thiras thiras commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

run_open returned on an openPool RpcError and freed the open slot. The next cache miss could then send a second openPool while the first could still mine (#2415). Two cases lead there: a receipt read that fails after broadcast, and a submit that fails in transport with no hash.

Invariant: the open slot is released only when a receipt is in hand, or the open's nonce is confirmed spent at a pinned block. No timer decides.

  • Client (crates/client/src/buyer_pool.rs)
    • open_pool reads the pending nonce and sends openPool with it, as top_up does. When the outcome is unknown, the error carries OpenUnconfirmed { tx: Option<TxHash>, nonce }.
    • New send_open_pool sends at a fixed nonce and returns the hash without waiting for a receipt.
    • New opened_from_receipt builds the OpenedPool from a receipt read later.
    • The CLI treats OpenUnconfirmed as fatal to the command, and its message says what to wait for.
  • Node (crates/node/src/buyer_pool.rs, settle_unconfirmed_open)
    • The open task keeps the slot and reads the chain every 5 s:
      • a receipt for any hash sent at the nonce yields the pool, or the revert;
      • the confirmed nonce read at block B passing the open's runs reconcile_with_chain with getPools/getPool pinned to B. Adopted means the pool is recorded; NoneHeld means it escrowed nothing; Unrecorded means escrowed but untracked;
      • a nonce the account has reached and no transaction holds gets a re-send at that same nonce, so at most one of them mines;
      • a pending tx at the nonce, an earlier unconfirmed nonce (Queued), a failed read, a failed re-send, or a reconciliation that cannot answer all mean wait. A reconciliation that cannot answer backs the next one off from 5 s to 5 min.
    • While the slot is held:
      • open_or_reuse_pool and open_replacement fail at once as LocalPullFault;
      • decdn_buyer_pool_open_unresolved reads 1;
      • a warning repeats every minute with the elapsed time and the last chain answer.
  • Reconciliation:
    • reconcile_with_chain returns Adopted / KeptTracked / NoneHeld / Unknown / Unrecorded, and bootstrap logs which one.
    • A settle run meters no buyer_pool_adoption_failures and logs at debug.
    • New enumerate_owned_pools_at pins the enumeration to a block.
  • Docs: ADR observability row, runbook paragraph, CHANGELOG.

Not covered

Test plan

  • Node tests:
    • the resolver table: receipt, re-send receipt, pending, queued behind an earlier nonce, nonce spent, mined between reads, vacant, no-hash;
    • waits out a pending tx;
    • a vacant nonce is re-sent at that nonce, a failed re-send keeps waiting;
    • a spent nonce adopts at a pinned block, through a getPools fault and an unreadable pool, with a backed-off tick that reads no pools;
    • a replacement through settle;
    • escrowed nothing ends as a resolved RpcError with no marker;
    • a mined revert ends as ContractRevert;
    • an unrecordable pool ends as LocalPullFault;
    • a stale row that won't drop is Unknown;
    • the slot is held, misses fail fast, and the gauge reads 1;
    • end to end on the no-hash path, through adoption to the slot release.
  • Reconcile tests assert the exact Reconciled variant.
  • Mutation checks: releasing on vacant, an unreadable pool counted as none, undecided collapsed to keep, fail-fast removed, settle metering adoption failures, no reconcile backoff, and no Queued check each fail a test. The settle test helper runs under a paused-time bound, so a loop that never settles fails in seconds. Dropping KeptTracked from the settle match fails to compile.
  • Client tests: the marker on receipt and transport failures, its absence on a rejection, send_open_pool, and the fault classifier.
  • cargo nextest run -p decdn-client -p decdn-node -p decdn-cli -p decdn-incentive: 3515 passed.
  • anvil e2e: cli_fetch_topup, pool_floor_ceiling_aggregate, node_to_node_coalesce, node_pull_pool_adopt, node_pull_pool_redeploy (9 passed).
  • clippy (--all-targets --all-features -D warnings), rustdoc (-D warnings), fmt, and the regenerated decdn-client public-api snapshot.
  • Not unit-testable with the mock RPC, because it ignores request parameters: the .block(B) pinning and the explicit .nonce(n) on re-send. Both are visible in the code.

Closes #2415

🤖 Generated with Claude Code

When the openPool receipt read failed, or its submit failed in
transport, run_open returned and freed the open slot. The next cache
miss re-checked only the local store and sent a second openPool while
the first could still mine, escrowing a second deposit.

open_pool now sends with an explicit pending nonce and, when the
outcome is unknown, returns OpenUnconfirmed { tx, nonce }. The node's
open task keeps the slot and polls the chain: a receipt yields the
pool (opened_from_receipt), a spent nonce asks getPools and adopts the
pool that appeared, and a nonce no transaction holds ends the open so
the next one is sent on that same nonce. The CLI treats
OpenUnconfirmed as fatal to the command, as it does TopUpUnconfirmed.

Closes #2415

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 10, 2026 15:41
@thiras thiras self-assigned this Oct 10, 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

The vacancy check can release the slot while a higher-nonce open remains queued, allowing duplicate deposits.

3 open findings
What changed in this PR

This PR prevents duplicate openPool deposits by retaining the node’s open slot until an uncertain transaction resolves.

Changes:

  • Adds nonce-aware OpenUnconfirmed errors and receipt reconstruction.
  • Polls receipts/nonces and reconciles mined pools before releasing the slot.
  • Adds client, node, and fault-classification coverage.
File Description
CHANGELOG.md Documents the fix.
crates/​client/​src/​buyer_pool.rs Adds nonce tracking and unconfirmed-open handling.
crates/​client/​src/​buyer_pool/​tests.rs Tests uncertain and rejected submissions.
crates/​client/​src/​fault.rs Makes uncertain opens fatal to CLI operations.
crates/​client/​src/​fault/​tests.rs Tests fault classification.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Updates the public API snapshot.
crates/​cli/​src/​commands/​fetch/​adoption_tests.rs Updates RPC expectations for nonce reads.
crates/​node/​src/​buyer_pool.rs Holds the slot and reconciles uncertain opens.
crates/​node/​src/​buyer_pool/​tests.rs Tests settlement and slot retention.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/node/src/buyer_pool.rs Resolved
Comment thread crates/node/src/buyer_pool.rs Resolved
Comment thread crates/client/src/buyer_pool.rs Resolved
@github-code-quality

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

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit b325190 in the fix/2415-unresolved-... branch remains at 75%, unchanged from commit 62d640b in the main branch.

Show a line coverage summary of the most impacted files.
File main 62d640b fix/2415-unresolved-... b325190 +/-
crates/client/src/lib.rs 88% 88% 0%
crates/protocol/src/framing.rs 93% 93% 0%
crates/incentiv...payment_pool.rs 97% 97% 0%
crates/node/src/metrics.rs 91% 91% 0%
crates/client/src/fault.rs 96% 96% 0%
crates/node/src...s/client/mod.rs 89% 90% +1%
crates/client/src/streamer.rs 83% 84% +1%
crates/client/src/sink.rs 93% 95% +2%
crates/node/src/buyer_pool.rs 65% 73% +8%
crates/client/s...c/buyer_pool.rs 69% 81% +12%

Updated October 10, 2026 17:32 UTC

thiras and others added 4 commits October 10, 2026 19:26
Review of #2419 found two paths that still released the open slot while
the first openPool could mine: a "vacant" nonce read from one lagging
backend, after which the next open read a later pending nonce; and a
spent nonce answered "no new pool" by a getPools read on a backend
behind the nonce read.

- A vacant nonce now re-sends openPool at that same nonce
  (send_open_pool), so at most one of the two mines; the slot is
  released only on a receipt or a spent nonce.
- A spent nonce is read at one block B, and getPools / getPool read at
  B (enumerate_owned_pools_at), so "adopted" and "holds no pool" answer
  about the same chain state.
- reconcile_with_chain returns Adopted / KeptTracked / NoneHeld /
  Unknown / Unrecorded; only NoneHeld ends the open as "escrowed
  nothing", and an unrecordable pool fails as escrowed-but-untracked. A
  settle run meters no adoption failure and logs at debug.
- While the slot is held, open_or_reuse_pool and open_replacement fail
  at once as a LocalPullFault, decdn_buyer_pool_open_unresolved reads 1,
  and a warning repeats every minute with the elapsed time.
- Resolved errors drop the OpenUnconfirmed marker; the CLI message says
  what to wait for.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
open_or_reuse_pool and open_replacement share one unless_held select;
open_pool builds its submit error the way top_up does; the #2415 tests
share reply helpers; two test docs name the Reconciled answer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Addresses the Copilot review on #2419:

- A confirmed nonce below the open's now reads as Queued, not Vacant.
  The pending count stops at the first gap, so it cannot say whether a
  transaction waits at the open's nonce; re-sending into the gap does
  nothing.
- A reconciliation that cannot answer doubles the wait before the next
  one, from 5 s up to 5 min, since each walks every pool the owner has
  opened.
- Funder::recover documents OpenUnconfirmed for a transport-failed or
  receipt-less openPool.
- The settle test helper runs under a paused-time bound, so a loop that
  never settles fails in seconds instead of timing out the test run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 23845c2 into main Oct 10, 2026
30 checks passed
@thiras
thiras deleted the fix/2415-unresolved-open-pool branch October 10, 2026 17:36
thiras added a commit that referenced this pull request Oct 12, 2026
* fix: warn when a failed pool send may have broadcast (#2416)

A `closePool` or `reclaim` send that fails in transport may have reached
the node and broadcast the tx with no hash returned. Route both sends
through `send_failed`, which adds the #1577 warning when
`send_broadcast_unknown` says the broadcast is unknown, and add a
mocked-provider test pair per site. `open_pool` already carries
`OpenUnconfirmed` for this case (#2419); its transport test now also
asserts the rendered warning.

Closes #2416

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: warn when a failed USDC approve send may have broadcast

The `approve` in `ensure_allowance` was the last hand-rolled send in the
pool flows without the #1577 classification. It now adds the same
broadcast-unknown note as `closePool` / `reclaim`, with a mocked-provider
test pair.

Review follow-ups: state the `send_failed` doc in the classifier's terms,
drop the ambiguous "warns" from the `# Errors` docs, and pin the
transport tests to `eth_sendTransaction`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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: daemon can escrow a second deposit after an openPool receipt failure

2 participants