Skip to content

fix(cli,client): fund the buyer pool from its pool-wide spend - #2291

Merged
thiras merged 2 commits into
mainfrom
fix/pool-wide-refill-2288-2289
Oct 2, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/pool-wide-refill-2288-2289

Conversation

@thiras

@thiras thiras commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

What

The CLI's proactive low-water refill compared the deposit with one lane's spend, so a pool spent across many providers never refilled (#2288). When a proactive topUp did fail, for example on a wallet with no USDC, the lane was dropped even though the pool could still pay, and the failure appeared only at DEBUG (#2289).

  • Pool-wide spend. pool_spend sums every tracked lane (BuyerPoolState::committed_amount, now shared with the node), adds the chain watermark of a lane the row has no record of, and takes the larger of that and an adopted pool's totalRedeemed.
  • Reactive gate sees the same spend. New defaulted Funder::pool_spent. The scheduler takes the larger of it and its own lanes' committed amounts. The CLI's run-scoped RunFunding keeps a baseline for lanes the run does not drive, plus every built lane's ledger. The pacer and the SpendingCapExhausted "is the node lying?" check therefore see spend on other providers, on the file, stdout and bundle paths.
  • Short wallet. After a failed refill, the CLI reads the wallet's USDC balance.
    • Below the top-up amount: the lane builds on the remaining deposit. The run records the shortfall once: one WARN, plus one closing warning: line on stderr, which shows without -v. Later refill attempts in the run are skipped.
    • Below the top-up with nothing left in the pool: the command ends with NoAffordableSource.
    • Any other refill failure fails the lane build, which retries with backoff.
  • Escrow safety. top_up names its tx when the receipt read fails (TopUpUnconfirmed). The receipt wait stays unbounded, so the node keeps its top-up slot. escrowed_but_untracked now returns a typed EscrowUntracked. Both are fatal to the command, including from a lane build: such a build used to be retried every 1–30 s, and each retry could escrow again.
  • Reactive failures. A failed Funder::top_up carries TopUpFailed and is classed as transient: the serving node keeps its health and the loop retries. A funder-reported WalletShortfall makes it unaffordable.

Closes #2288
Closes #2289

Reviewer notes

  • Start with refill_if_low, RunFunding and pool_spend in crates/cli/src/commands/fetch.rs, then classify in crates/client/src/fault.rs.
  • classify rule for LaneBuildFault. A build fault is still transient, but it now takes its cause's class when that cause is fatal: an untracked escrow, NoAffordableSource, or a full disk. The scheduler and first_open act on that Fatal instead of only logging at DEBUG.
  • RunFunding baseline rule. The first lane to join sets the baseline from the pool's spend on every other lane. A later lane moves its prior out of the baseline when the row recorded it, or when the baseline came from totalRedeemed (adopted pool). Each lane counts the largest of its ledgers, because a lane rebuilt after a fault gets a fresh ledger.
  • Node behaviour. Unchanged in practice: NodeFunder wraps every top-up error in LocalPullFault, which is still fatal, and its pool_spent defaults to None.
  • Public API. New decdn-client public items: EscrowUntracked, TopUpUnconfirmed, WalletShortfall, driver::TopUpFailed, Funder::pool_spent. The snapshot is regenerated.
  • Known gap, not fixed here. A pool adopted from chain loses its totalRedeemed context in later runs, because the recorded row has no lanes for the other providers. Filed as cli: an adopted buyer row forgets the pool's redeemed spend after the adopting run #2292.

Verification

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p decdn-cli -p decdn-client -p decdn-node -p decdn-incentive: 3234 passed
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items
  • cargo nextest run -p decdn-client --features public-api-test --test public_api (snapshot regenerated)
  • anvil e2e (--all-features): cli_fetch_topup, cli_fetch_{multi_source,delegated,resume,stdout,recovers_one_holder}, cli_bundle_pull_{multi_source,pool_id,range_dedup}, pool_floor_ceiling_aggregate, node_pull_topup, node_pull_pool_adopt: 23 passed
  • The new regression tests fail when their fix is reverted: single-lane spend, the funding-failure fallback, the scheduler's outside-spend and fatal-build paths, the adopted-pool baseline, and NoAffordableSource on a drained pool.
  • contracts/ unchanged
  • User-visible change: CHANGELOG.md entry added
  • Design change: none (no ADR; the refill policy in ADR 003 is unchanged)
  • PR title uses an allowed type and a lowercase subject

🤖 Generated with Claude Code

The proactive low-water refill compared the deposit with one lane's spend,
so a pool spent across several providers never refilled (#2288). A failed
proactive top-up then dropped the lane even when the pool could still pay,
logged only at DEBUG (#2289).

- Pool-wide spend. `pool_spend` sums every tracked lane
  (`BuyerPoolState::committed_amount`, now shared with the node), adds an
  untracked lane's chain watermark, and takes the larger of that and an
  adopted pool's `totalRedeemed`.
- Reactive gate. `Funder::pool_spent` gives the acquire loop the funder's
  view of the whole pool; the scheduler takes the larger of it and its own
  lanes. The CLI's run-scoped `RunFunding` keeps a baseline for lanes the
  run does not drive plus every built lane's ledger, so the pacer and the
  `SpendingCapExhausted` check see spend on other providers.
- Short wallet. A refill that fails reads the wallet's USDC balance. Below
  the top-up, the lane keeps building on the remaining deposit, the run
  records the shortfall (one WARN, one closing `warning:` line on stderr)
  and skips further refills; with nothing left it ends as
  `NoAffordableSource`. Any other refill failure fails the lane build,
  which retries.
- Escrow safety. `top_up` names its tx when the receipt read fails
  (`TopUpUnconfirmed`); `escrowed_but_untracked` returns a typed
  `EscrowUntracked`. Both are fatal to the command, including from a lane
  build, which `classify` now rules by its cause when that cause is fatal.
- Reactive failures. A failed `Funder::top_up` carries `TopUpFailed` and is
  transient, so the serving node keeps its health; a `WalletShortfall`
  marks it unaffordable.

Closes #2288
Closes #2289

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

🟡 Changes recommended

Some untracked escrow outcomes remain retryable, and warning behavior is incomplete or duplicated.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Fixes buyer-pool refilling to account for pool-wide spend and handle wallet shortfalls safely.

Changes:

  • Aggregates spend across all payment lanes.
  • Adds typed top-up failures and fatal escrow handling.
  • Preserves usable lanes after wallet shortfalls and reports warnings.
File Description
CHANGELOG.md Documents funding behavior changes.
crates/​cli/​src/​commands/​bundle_pull.rs Shares run funding across bundle entries.
crates/​cli/​src/​commands/​cli_sources.rs Passes funding state into CLI funders.
crates/​cli/​src/​commands/​fetch.rs Implements pool-wide accounting and short-wallet fallback.
crates/​client/​src/​buyer_pool.rs Adds typed escrow and wallet errors.
crates/​client/​src/​driver.rs Marks reactive top-up failures.
crates/​client/​src/​fault.rs Classifies new funding failures.
crates/​client/​src/​first_open.rs Propagates fatal lane-build failures.
crates/​client/​src/​scheduler.rs Uses funder-reported spend and stops fatal builds.
crates/​client/​src/​source.rs Extends the Funder API with pool spend.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Updates the public API snapshot.
crates/​incentive/​src/​buyer_pool.rs Adds aggregate committed-amount calculation.
crates/​node/​src/​buyer_channel.rs Reuses shared committed-amount logic.

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

Comment thread crates/client/src/driver.rs Resolved
Comment thread crates/cli/src/commands/bundle_pull.rs Resolved
Comment thread crates/cli/src/commands/fetch.rs Resolved
@github-code-quality

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

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit ee25a16 in the fix/pool-wide-refill... branch remains at 87%, unchanged from commit 9f243c9 in the main branch.

Show a line coverage summary of the most impacted files.
File main 9f243c9 fix/pool-wide-refill... ee25a16 +/-
crates/client/s...c/first_open.rs 98% 97% -1%
crates/client/s...c/buyer_pool.rs 74% 73% -1%
crates/client/src/source.rs 93% 92% -1%
crates/cli/src/.../bundle_pull.rs 81% 81% 0%
crates/client/src/lib.rs 92% 92% 0%
crates/node/src...uyer_channel.rs 74% 74% 0%
crates/node/src...s/client/mod.rs 95% 95% 0%
crates/client/src/driver.rs 98% 98% 0%
crates/client/src/fault.rs 96% 98% +2%
crates/cli/src/...mmands/fetch.rs 73% 77% +4%

Updated October 02, 2026 05:57 UTC

…all reporting

- The driver types a funder's `UnknownPool`/`PoolMismatch` outcome as
  `EscrowUntracked`, so a third-party `Funder` that returns one ends the
  command instead of cooling the source and retrying into a second escrow.
- Bundle pull prints the wallet-shortfall warning on every return after the
  paid `--hash` manifest fetch: a failed fetch, an empty filter, and an
  empty `--select`.
- The build that records a shortfall logs it once at WARN; the
  continuation line is INFO.

Refs #2289

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 8acfcc2 into main Oct 2, 2026
30 checks passed
@thiras
thiras deleted the fix/pool-wide-refill-2288-2289 branch October 2, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants