Repository navigation
fix(cli,client): fund the buyer pool from its pool-wide spend - #2291
Merged
Merged
Conversation
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]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Some untracked escrow outcomes remain retryable, and warning behavior is incomplete or duplicated.
Review effort: Balanced
Findings: 1
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.
Code Coverage OverviewLanguages: Rust Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit ee25a16 in the Show a line coverage summary of the most impacted files.
Updated |
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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
topUpdid 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_spendsums 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'stotalRedeemed.Funder::pool_spent. The scheduler takes the larger of it and its own lanes' committed amounts. The CLI's run-scopedRunFundingkeeps a baseline for lanes the run does not drive, plus every built lane's ledger. The pacer and theSpendingCapExhausted"is the node lying?" check therefore see spend on other providers, on the file, stdout and bundle paths.warning:line on stderr, which shows without-v. Later refill attempts in the run are skipped.NoAffordableSource.top_upnames its tx when the receipt read fails (TopUpUnconfirmed). The receipt wait stays unbounded, so the node keeps its top-up slot.escrowed_but_untrackednow returns a typedEscrowUntracked. 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.Funder::top_upcarriesTopUpFailedand is classed as transient: the serving node keeps its health and the loop retries. A funder-reportedWalletShortfallmakes it unaffordable.Closes #2288
Closes #2289
Reviewer notes
refill_if_low,RunFundingandpool_spendincrates/cli/src/commands/fetch.rs, thenclassifyincrates/client/src/fault.rs.classifyrule forLaneBuildFault. 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 andfirst_openact on thatFatalinstead of only logging at DEBUG.RunFundingbaseline 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 fromtotalRedeemed(adopted pool). Each lane counts the largest of its ledgers, because a lane rebuilt after a fault gets a fresh ledger.NodeFunderwraps every top-up error inLocalPullFault, which is still fatal, and itspool_spentdefaults toNone.decdn-clientpublic items:EscrowUntracked,TopUpUnconfirmed,WalletShortfall,driver::TopUpFailed,Funder::pool_spent. The snapshot is regenerated.totalRedeemedcontext 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 -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo nextest run -p decdn-cli -p decdn-client -p decdn-node -p decdn-incentive: 3234 passedRUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-itemscargo nextest run -p decdn-client --features public-api-test --test public_api(snapshot regenerated)--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 passedNoAffordableSourceon a drained pool.contracts/unchangedCHANGELOG.mdentry added🤖 Generated with Claude Code