Skip to content

fix(client): replace a stored pool the chain has no record of in a funding recovery step - #2668

Merged
thiras merged 2 commits into
mainfrom
fix/zero-owner-pool-recovery
Oct 28, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/zero-owner-pool-recovery

Conversation

@thiras

@thiras thiras commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

What

PoolFunder::chain_remaining reads getPool. A pool id the chain does not know returns a zeroed struct: a zero owner, and the status Open, because Open is enum value 0 in PaymentPool.sol. The recovery step read that as another owner's pool:

  • Top-up path: it tried topUp, which reverts NotPoolOwner (the contract checks status before owner), not PoolNotOpen. The step skipped the replacement path, so the fetch ended "funding needed" behind an opaque revert.
  • Settle path (full pool): pool_accepts_funds saw the estimate revert, fell back to getPool, read Open, and the step settled on a pool that does not exist.

Changes:

  • A shared classifier, PoolStanding { Open, NotAccepting, Unknown, Foreign }, reads a getPool answer for both the lane-build reuse check (still_open) and the recovery step.
  • The recovery step treats Unknown as gone and opens a replacement, as for a closed pool. The exception is a pool that a run of the same command saw live: it opened the pool, or read it on chain as this wallet's. UnconfirmedEscrows is the command-wide handle that already outlives each pass, and it now records those pools (note_live / saw_live). Such a pool reads as unknown only on a lagging RPC, and replacing it would escrow a second deposit, so the step keeps today's run-view fallback with a specific warning.
  • still_open still keeps an unknown pool: a lagging RPC can miss a pool opened moments ago. a_tracked_pool_is_reused_only_while_the_chain_shows_it_open is unchanged and still passes. It now also pins which reads mark a pool live.
  • PoolFunder::replace folds the three replacement call sites into one.

ADR 003 § Funding recovery states the rule.

Closes #2665

Reviewer notes

  • Read first: chain_remaining / funds_on_chain and recover in crates/client/src/funding.rs, PoolStanding next to still_open, and note_live in crates/client/src/buyer_pool.rs.
  • Provenance is per command, not per pass. A replacement opened by an earlier recovery pass is read by the next pass's lane build as a stored row. A per-pass flag would mark it "reused" and let a lagging read replace it a second time. The command-wide handle remembers it was opened.
  • Reachability is narrow. A node answers a pool it has no on-chain record of with NotFound (PoolUnconfirmed), never Unfunded (ADR 003 § Funding recovery). So this step runs on an unknown pool only when some node still refuses Unfunded or PoolExhausted (e.g. from its cached admission) while the client's chain read shows no record. A stale row that every node answers with NotFound ends the fetch before any recovery step, and this PR does not touch that dead end. It is worth a follow-up issue if it shows up in practice.
  • Residual risk: a pool opened by an earlier command moments ago, then read through a lagging RPC by this one, is replaced. That window is the RPC lag between two commands.

Verification

  • New tests in funding/adoption_tests.rs:
    • a_stored_pool_the_chain_does_not_know_is_replaced (top-up path)
    • a_full_stored_pool_the_chain_does_not_know_is_replaced (settle path)
    • a_pool_the_command_saw_live_is_not_replaced_on_a_lagging_read
  • Live-marking assertions added to a_tracked_pool_is_reused_only_while_the_chain_shows_it_open, a_lost_row_adopts_the_live_pool_and_resumes_from_the_chain_watermark and an_open_after_an_unrecorded_open_is_refused.
  • Mutation-checked one at a time. Each mutation fails at least one test:
    • never Gone
    • always Gone
    • no note_live in still_open
    • no note_live on adoption
    • no note_live on a mined open
    • an Unknown read marked live
  • pre-commit run on the change. cargo deny reports only the existing warn-only advisories.
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features
  • cargo nextest run -p decdn-client -p decdn-incentive: 1538 passed
  • CARGO_BUILD_WARNINGS=deny cargo doc -p decdn-client --no-deps --document-private-items
  • PR title type fix, lowercase subject
  • Public API: only pub(crate) items changed. decdn-client snapshot not regenerated.
  • adr/: make -C adr check-refs. architecture.md has no recovery-step summary to update.
  • CHANGELOG: one Fixed entry

🤖 Generated with Claude Code

…nding recovery step

`getPool` on an unknown pool id returns a zeroed struct: a zero owner and
the status `Open` (enum value 0). The recovery step read that as another
owner's pool and tried a `topUp`, which reverts `NotPoolOwner`, so the fetch
ended "funding needed" behind an opaque revert. On a full pool the step
settled on a pool that does not exist.

A shared classifier (`PoolStanding`) now reads a `getPool` answer for both
the lane-build reuse check and the recovery step. The recovery step treats
an unknown pool as gone and opens a replacement, unless a run of the same
command opened the pool or read it on chain as this wallet's
(`UnconfirmedEscrows::note_live`). Such a pool reads as unknown only on a
lagging RPC, and a replacement would escrow a second deposit. The lane-build
reuse check keeps an unknown pool, as before.

Closes #2665

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-code-quality

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

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 0273aad fix/zero-owner-pool-... b6dfa07 +/-
77% 77% 0%
View coverage of the 3 most impacted files.
File main 0273aad fix/zero-owner-pool-... b6dfa07 +/-
crates/client/s...c/buyer_pool.rs 98% 98% 0%
crates/client/src/funding.rs 84% 85% +1%
crates/node/src/dht/publish.rs 78% 80% +2%

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


Updated October 28, 2026 04:37 UTC

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

Recovery after an inconclusive pool read can open a replacement despite a mined or pending refill, risking duplicate escrow due to incomplete live-state tracking and top-up synchronization.

2 open issues

Review effort: Balanced

Comment thread crates/client/src/funding.rs Resolved
Comment thread crates/client/src/funding.rs Resolved
…Up lock

A mined topUp shows its pool live, as an open or an owned read does, so a
later lagging read that shows no record keeps the pool. The replacement of
an unknown pool takes the run's topUp lock first, refuses while a topUp of
the command is unconfirmed, and keeps a pool a sibling's topUp showed live
while the step waited: each could otherwise escrow a second deposit beside
a pool the chain knows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 078606a into main Oct 28, 2026
37 checks passed
@thiras
thiras deleted the fix/zero-owner-pool-recovery branch October 28, 2026 04:38
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.

client: treat a buyer pool the chain reads with a zero owner as gone during a funding recovery step

2 participants