Skip to content

fix(client): retire a stored buyer pool the chain has no record of at fetch end - #3015

Open
yigitdot wants to merge 4 commits into
mainfrom
fix/2678-stale-stored-pool
Open

yigitdot wants to merge 4 commits into
mainfrom
fix/2678-stale-stored-pool

Conversation

@yigitdot

@yigitdot yigitdot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When getPool reads a stored buyer pool with a zero owner (PoolStanding::Unknown), the first lane build keeps the row. That is deliberate: a lagging RPC can miss a pool opened moments ago. But every node refuses lanes on such a pool with NotFound (PoolUnconfirmed). That refusal is Fault::Source, not an Unfunded-class one, so the candidate set never exhausts into NoAffordableSource and no funding recovery step runs. The fetch retries until GaveUp, or forever in a terminal, and every later run reuses the dead row until someone deletes it by hand.

Fix

At the end of a failed fetch, one authoritative getPool re-read decides whether to drop the row.

  • Record: still_open records on RunFunding that the stored row read with no record. Nothing else changes during the fetch.

  • Retire: RunFunding::retire_stale_pool(contract, store) acts only when all of these hold:

    • the first read showed no record;
    • no run on the escrow handle saw the pool live (saw_live);
    • no lane of the run paid for a byte;
    • no topUp of the command is unconfirmed and no escrow is untracked (the same hold-back as replace_unknown).

    It re-reads getPool once. If the owner is still zero, it calls forget_if_pool and returns StalePool::Retired. forget_if_pool is compare-and-delete, so a row another run already moved to a new pool survives. If the store fails, it returns StalePool::Kept, which names the error and asks for a rerun. If the re-read fails or shows the pool, the row is kept.

  • Call sites:

    • the end of a failed decdn get pass (cli/src/commands/fetch.rs), skipped when a pool replacement ended the pass (a Ctrl-C drops the pass before this step runs);
    • the bundle engine, after a failed manifest fetch;
    • the bundle engine, after a failed pull that paid nothing and was not rerun on a replacement pool.
  • What the user sees:

    • the note is context on the fetch error;
    • a bundle pull that no fault stopped lists it as a warning;
    • a give-up or an interrupt prints it as a note: line under the stop line (stop_message);
    • a pass that the fetch moves on from prints it as a note: line.

Why fetch end, not "every refusal was NotFound"

That signal does not exist. A discovered holder that answers NotFound is only cooled (source_set.rs record_not_found), never marked absent, so there is nothing to count. NotFound also means a miss, a load shed or a stale chain.

ADR 003

  • § Funding recovery describes the retire step, one condition per sentence.
  • § Pool solvency said a pool with no on-chain record is refused Unfunded. It is refused NotFound, like a Closed pool, and that section now says so.
  • The same paragraph now says that Unfunded goes only to a requester that proves it holds a lane on the pool.

Accepted residual

Two lagging reads in a row can retire a pool that another process has just opened, if this fetch fails with no byte paid for an unrelated reason. The lag has to span the whole failed fetch. A buyer that adopts from chain takes the pool back on its next run. A buyer that never adopts, such as one running from a node's data dir, would open a second pool.

Tests

  • funding/adoption_tests.rs:
    • the row is dropped and named, and the next run finds no row;
    • an end read that shows the pool live, faults, or shows another owner keeps the row;
    • a pool seen live, or read as open, is never retired;
    • a run that paid for bytes never retires its pool;
    • a row moved to another pool survives;
    • an unconfirmed topUp blocks the step.
  • funding/tests.rs: a store fault yields StalePool::Kept.
  • bundle/engine/tests.rs: warning-or-context folding, the end-of-pull condition, retire_allowed, and the manifest error keeping its note.
  • interrupt/tests.rs: a give-up prints the stale-pool note.
  • e2e/tests/cli_fetch_stale_pool.rs (anvil): a stale stored row makes the first decdn get give up (exit 75), print a note: naming the pool, and drop the row. The second run opens a pool and lands the blob byte-identical.

Verified

  • cargo nextest run -p decdn-client -p decdn-cli --no-fail-fast: 2453 passed.
  • cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(cli_fetch_stale_pool)': passed.
  • cargo clippy --workspace --all-targets -- -D warnings and cargo clippy -p decdn-e2e --features anvil-e2e --all-targets -- -D warnings: clean.
  • cargo fmt -- --check: clean.

Closes #2678

… fetch end

A stored buyer pool that reads with a zero owner keeps its row (a lagging
RPC can miss a fresh pool), but every node refuses lanes on it NotFound,
so no funding recovery step ever runs and each later run reuses the row.

A fetch or bundle pull that fails with no byte paid for now reads the pool
once more. When the first read showed no record, no run on the escrow
handle saw it live, and the end read still shows no record, the buyer row
is dropped via forget_if_pool and the fetch error names the pool; the next
run adopts or opens one.

ADR 003 now describes this step, and states that admission refuses a pool
with no on-chain record (or Closed) NotFound, not Unfunded.

Closes #2678
Copilot AI balanced review requested due to automatic review settings November 26, 2026 17:44

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. Try requesting a review at a lower effort level.

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 Nov 26, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust, Solidity

Rust / code-coverage/cargo-llvm-cov

main d769020 fix/2678-stale-store... 60c8dcb +/-
78% 78% 0%
View coverage of the 7 most impacted files.
File main d769020 fix/2678-stale-store... 60c8dcb +/-
crates/cli/src/...mmands/fetch.rs 48% 47% -1%
crates/client/s...undle/engine.rs 51% 51% 0%
crates/client/src/lib.rs 89% 89% 0%
crates/node/src...gin/pull_leg.rs 84% 84% 0%
crates/cli/src/...ds/interrupt.rs 89% 89% 0%
crates/client/src/funding.rs 88% 89% +1%
crates/protocol/src/framing.rs 92% 93% +1%

Solidity / code-coverage/forge

main d769020 fix/2678-stale-store... 60c8dcb +/-
93% 93% 0%

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


Updated November 27, 2026 23:37 UTC

The stale-pool note now reaches the user: a give-up or interrupt prints
it under its stop line, and a pass the fetch moves on from prints it as a
note. A store that cannot drop the row yields StalePool::Kept, which names
the fault instead of ending like a plain miss. The step also holds back
while a topUp of the command is unconfirmed or an escrow is untracked,
matching replace_unknown, and an interrupted pass reads nothing.

The bundle end condition and note folding are pure helpers with tests;
new tests cover the compare-and-delete guard, the topUp guard, the store
fault and the give-up message. ADR 003 states the Unfunded/NotFound
audience split at admission and the retire conditions one per sentence.
@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

Seed the client store with a buyer row for a pool this deployment never
opened. The first decdn get gives up (exit 75), names the stale pool on a
note: line, and drops the row. The second run opens a pool and lands the
blob byte-identical.

@alpergundogdu alpergundogdu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good overall. I traced the routes that could delete the row of a pool that exists (failed RPC read, a pool this command opened or topped up, a pending openPool, a row moved to a newer pool, Ctrl-C, a fetch that paid bytes) and each one is guarded. Two changes before merge:

1. Check the RPC's chain id before retiring. The fetch path never checks that the RPC serves the deployment's chain. An RPC pointed at another chain with a PaymentPool at the same address reads a zero owner twice, and the row of a funded pool is dropped. A data-dir buyer that never adopts then opens a second pool. Please read eth_chainId once in retire_stale_pool and skip the retire unless it equals stored.deployment's chain. The same check already exists in sweep.rs, receipt.rs and the node's deployment preflight (runtime/mod.rs), so reuse that shape.

2. Drop the dead Interrupted check (crates/cli/src/commands/fetch.rs:1702). Interrupted only comes from the outer tokio::select! (line 583), which drops fetch_on rather than returning through it, so err.downcast_ref::<Interrupted>().is_none() is always true here. Remove it, and have the doc say a Ctrl-C drops the pass before this step runs.

The cross-process residual in the description (process B opens P, process A's lagging RPC reads P unknown twice and deletes B's row) is accepted as written. No change needed there.

@alpergundogdu

Copy link
Copy Markdown
Contributor

Update to item 1 of my review: drop the chain-id check in retire_stale_pool. A mismatched rpc_url gets caught once at client startup instead, tracked in #3025, so this PR needs no chain-id read. The only remaining item is removing the dead Interrupted check at fetch.rs:1702.

…e pool

Interrupted comes only from the outer tokio::select!, which drops
fetch_on rather than returning through it, so the check never fired. A
Ctrl-C drops the pass before the retire step runs.
@yigitdot

Copy link
Copy Markdown
Contributor Author

Removed the dead Interrupted check in 60c8dcb. Interrupted is only built by the outer tokio::select! arms (fetch.rs:583, pool.rs, bundle_pull.rs), which drop the future instead of returning through fetch_on, so the check never fired. retire_on_failure now skips only a PoolReplaced pass, and its doc says a Ctrl-C drops the pass before the step runs. No chain-id read added, per your update (#3025).

This branch has not been deployed

No deployments
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: a stored buyer pool the chain has no record of dead-ends the fetch on NotFound

3 participants