Repository navigation
fix(cli,incentive): adopt the pool the wallet already owns instead of opening a second - #2098
Merged
Merged
Conversation
… opening a second The client decided whether it owned a pool from its local store alone, so a lost row read as "no pool" and it escrowed a fresh working deposit beside the live one. On a wallet whose USDC was already in that pool the second `openPool` reverted (`ERC20: transfer amount exceeds balance`). #2087's move of the buyer tables to `_v4` made this the common case — every client row written before it reads as absent — but any store loss reached it. The node already recovers from chain at bootstrap; the client now does the same on demand. With no usable row it asks `getPools` for the newest `Open` pool that still has deposit to spend (`newest_solvent_owned_pool`, shared in decdn-incentive), records it and reuses it, and opens a pool only when none qualifies. It fails closed where the node fails open: a read that faults aborts the fetch rather than answering "no pool", because a one-shot fetch can be rerun and "could not tell" must not become a second deposit. Three things adoption has to get right alongside it: - A lane with no local record resumes from the chain watermark, not zero. At or below it every voucher redeems nothing on chain, and an adopted pool has no local lanes at all. - The refill decision counts the adopted pool's `totalRedeemed`. The row has no lanes to account for what the pool has paid out, so a pool other lanes drained otherwise reads as a full deposit, no top-up fires, and the provider refuses the fetch. - A buy from a node's data dir never adopts. #2082 still accepts an explicit `--data-dir <node dir>`, whose keystore is the operator's, so the wallet's newest live pool is the daemon's own; adopting it would put a second voucher series on the daemon's lanes. `ChainAdoption::for_data_dir` reads the same daemon markers as the store classifier. Tests drive `open_or_reuse_pool` against a mocked `PaymentPool`. Each was checked against a mutation of the behaviour it names — skipping adoption, a zero watermark seed, an unrecorded row, a swallowed read fault, an ignored node-dir verdict, an ignored `totalRedeemed` — and fails under it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Adoption is keyed only to directory markers, so a client using a shared daemon keystore from another directory can adopt the daemon’s pool and create conflicting voucher lanes.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Adds client-side recovery of live buyer pools from chain when local state is missing.
Changes:
- Adds solvent-pool enumeration and adoption.
- Resumes lanes from on-chain watermarks and accounts for redeemed funds during refill.
- Applies adoption rules to fetch and bundle pull, with tests and changelog updates.
| File | Description |
|---|---|
crates/incentive/src/payment_pool.rs |
Adds solvent pool discovery. |
crates/cli/src/commands/fetch.rs |
Implements adoption, watermark recovery, and refill handling. |
crates/cli/src/commands/buyer_store.rs |
Adds data-directory adoption policy. |
crates/cli/src/commands/bundle_pull.rs |
Passes adoption policy to pool reuse. |
CHANGELOG.md |
Documents the fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 83.60% (was 82.86%, ▲ +0.74%) — 85482/102248 lines
History
|
`ChainAdoption` judged only the data dir, but the keystore resolves independently: `--keystore` or `blockchain.eth_keystore` can point a client dir at `/var/lib/decdn/keystore.json`. That buy classified as `Allowed` and, after a store reset, would adopt the daemon's live pool — a second voucher series on the daemon's lanes, which is the hazard the node-dir check exists to stop. The wallet decides whose pools it owns, so its key's directory is now checked against the same daemon markers as the store's. A key copied out of a node's dir, or a wallet two clients share, is still not detectable locally; the doc states the one-buyer-per-wallet assumption rather than implying the check covers it. Co-Authored-By: Claude Opus 5 (1M context) <[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 client (
decdn fetch,decdn bundle pull) now adopts the pool its wallet already owns on chain when its local store has no row, instead of opening a second one.Why
This fixes a regression from #2087 that reached a user. Moving the buyer tables to
_v4made every existing client row read as absent. Their wallet held $0 USDC, all of it escrowed in one live,Openpool on the current contract ($10.00 deposit, $1.11 redeemed). The new binary could not see that pool, so it tried to escrow a second $10 and reverted:The underlying gap: the node recovers its pool from chain, the client didn't. The node's bootstrap enumerates
getPools(owner)and adopts its live pool. The client only looked at its store, which loses rows (reset data dir, new machine, store-format change) while the pool is still live on chain.enumerate_owned_poolsalready documents this case, and thegetWatermarkbinding already describes the buyer reseeding a lost lane. The client just never used either.How
newest_solvent_owned_pool(decdn-incentive, next toenumerate_owned_pools) finds the newestOpenpool withdeposit > totalRedeemed. A faulted read returnsErr, neverNone.pool_to_reuse/adopt_owned_pool(CLI) take a tracked row on this deployment, or adopt and record one from chain. The client opens a pool only when none qualifies.Adoption also needs three things to be right:
getWatermark, not zero. At or below the watermark every voucher redeems nothing on chain, and an adopted pool has no local lanes. This also affects a tracked pool's first contact with a new provider: that's one extra read per new lane, and a fault on it now aborts.totalRedeemed. An adopted row has no lanes to account for what the pool has already paid out. Without this, a pool that other lanes drained reads as a full deposit, no top-up fires, and the provider refuses the fetch. The refill policy's own doc already definesprior_amountas spend across its lanes.--data-dir <node dir>, and there the keystore is the operator's. The wallet's newest live pool is then the daemon's own, and adopting it would put a second voucher series on the daemon's lanes.ChainAdoption::for_data_dirreads the same daemon markers as the store classifier, and matching on(tracked, adoption)is exhaustive, so dropping theRefusedarm won't compile.Tests
adoption_testsdrivesopen_or_reuse_poolagainst a mockedPaymentPool. Each test was checked against a mutation of the behaviour it names, and fails under it:a_lost_row_adopts_the_live_pool_…(+2)a_lost_row_…,a_tracked_pool_resumes_a_new_lane_…a_lost_row_…,an_adopted_pool_drained_…a_faulted_enumeration_refuses_rather_than_openinga_node_data_dir_never_adopts_the_daemons_pooltotalRedeemedignoredan_adopted_pool_drained_by_other_lanes_is_topped_upAlso added: three
newest_solvent_owned_pooltests (walk order with two solvent pools, so the positional mock can't pass it by accident; drained pools skipped; a fault isErr) andchain_adoption_is_refused_in_a_node_data_dir.Verified:
cargo nextest run --workspace3699 passed / 0 failed;cargo clippy --workspace --all-targetsexit 0, zero warnings;RUSTDOCFLAGS="-D warnings" cargo docpasses;cargo check -p decdn-e2e --features anvil-e2e --all-targetsclean.Not in this PR
🤖 Generated with Claude Code