Repository navigation
fix(incentive,node): scope buyer pool rows to their PaymentPool deployment - #2087
Merged
Merged
Conversation
…yment `poolId` is `keccak256(owner, ownerPoolNonce)` — the derivation carries neither the contract address nor the chain id — and a fresh `PaymentPool` deployment restarts `ownerPoolNonce` at zero. The same owner's Nth pool therefore has the same id on every deployment, so a buyer row written against one contract names a pool the next contract will also mint. Bootstrap could not tell the two apart. `getPools` on the new contract does not list the stale id, `tracked_status` answers `Unknown` for an unlisted id, and `reconcile_tracked` keeps the row on `Unknown` — so the node pinned every pull to a pool the live contract has never heard of and never opened a replacement. Worse, once the owner's nonce walked back over that id the row would start matching a real and unrelated pool, carrying lane progress that priced bytes the live contract never saw. Carry the `PaymentPool` address in `BuyerPoolState` and make it part of the identity key. Bootstrap now drops a row whose `payment_pool` is not the configured one, before the enumeration that would otherwise re-adopt it. The on-disk record gains the address and the tables move to `_v4`; a row in the old shape is ignored, not migrated. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
drop_foreign_row currently ignores the Ok(false) outcome of forget_if_pool, so reconciliation can proceed without guaranteeing the foreign row was actually removed.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
This PR hardens buyer pool persistence against PaymentPool redeploys by recording the contract address in BuyerPoolState, updating the on-disk schema, and dropping tracked rows that belong to a different deployment before they can be reused or collide.
Changes:
- Add
payment_pool: AddresstoBuyerPoolState, persist it in redb (schema v2, table suffix_v4), and plumb it through call sites/tests. - Teach bootstrap reconciliation to detect “foreign deployment” tracked rows and attempt to drop them before enumerating/adopting on-chain pools.
- Update unit/e2e/CLI tests and golden bytes for the new record layout.
| File | Description |
|---|---|
| crates/node/src/buyer_channel.rs | Adds foreign-row detection during reconciliation and a helper to drop rows from other PaymentPool deployments. |
| crates/node/src/admin.rs | Updates admin tests to hydrate/construct BuyerPoolState with the new payment_pool field. |
| crates/incentive/src/buyer_pool.rs | Extends BuyerPoolState with payment_pool, adds is_on(), and updates docs/tests accordingly. |
| crates/incentive/src/buyer_pool_table.rs | Bumps tables to _v4, bumps schema version to v2, and adds payment_pool to postcard-encoded records + golden bytes. |
| crates/incentive/src/buyer_pool_redb.rs | Updates redb-backed store tests for the new BuyerPoolState::new signature. |
| crates/e2e/tests/pool_floor_ceiling_aggregate.rs | Updates e2e helper to construct BuyerPoolState with payment_pool. |
| crates/e2e/src/client.rs | Updates fixture state construction to pass payment_pool. |
| crates/client-pull/src/buyer_pool.rs | Ensures newly opened pools record the PaymentPool contract address in persisted state. |
| crates/cli/tests/pool_list.rs | Updates CLI tests that seed buyer pool state to include payment_pool. |
| crates/cli/tests/admin_rpc.rs | Updates RPC round-trip tests to seed buyer pool state with payment_pool. |
| crates/cli/src/commands/pool.rs | Updates CLI command tests constructing buyer pool state to include payment_pool. |
| crates/cli/src/commands/fetch.rs | Updates fetch path and tests to construct buyer pool state with the contract address. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 83.37% (was 83.35%, ▲ +0.02%) — 84357/101178 lines
History
|
…ow drop actually guarantee The store is keyed by `pool_id` alone, so calling `(payment_pool, pool_id)` the identity key overstated it: two rows for one id cannot coexist, and the tag buys detection at reconciliation, not addressability. `drop_foreign_row` likewise promised more than it delivers. `forget_if_pool` is a compare-and-delete on the owner index, and `get_by_owner` resolves only through that index, so `Ok(false)` already means nothing maps this owner to the foreign row — the property adoption needs. Say that, rather than "the row is gone". Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…reuses a pool row Writing the tag was half the job. Bootstrap was the only reader, so the guard was temporal: one failed forget at boot and the node paid against a foreign row for the life of the process, because `reuse_or_report` and the CLI's `open_or_reuse_pool` / `cached_pool_token` all read rows without it. The CLI path carried the original bug unfixed. All three now treat a row from another `PaymentPool` as no row. Name the hazard correctly while here. Resuming a foreign lane seeds the first voucher at a cumulative the live pool has never redeemed against, so the provider collects it for bytes it never delivered — an over-pay, not the under-pay the docs claimed. `reseed_lane_from_chain` returns early when a row already has lane progress, so the stale cumulative is used as-is. The failed-drop path no longer meters `buyer_pool_adoption_failures`: that counter means "about to escrow a second deposit beside one it holds", and this node escrows nothing — it is stuck on a row it already has, which is `drop_stale_row`'s reasoning for the identical shape. `AdoptionCheck::Foreign` now carries the contract the row was written against, because the warning promised an address it was not logging and the drop then destroyed the only record of it. `BUYER_SUPPORTED_SCHEMA_VERSION` is matched exactly rather than as a ceiling. The fields are positional and `payment_pool` sits third, so a v1 record decoded under a ceiling check shifts every field after `pool_id` silently; the table rename hid that rather than preventing it. Tests: the previous foreign-row test passed with `drop_foreign_row` gutted to a no-op — its enumeration returned the same colliding id, so `record` rewrote that key either way. The new one queues an empty enumeration, where the early return precedes any write and only the forget can clear the row. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Sep 21, 2026
Closed
thiras
added a commit
that referenced
this pull request
Sep 21, 2026
… opening a second (#2098) * fix(cli,incentive): adopt the pool the wallet already owns instead of 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]> * fix(cli): refuse adoption when the buy signs with a node's operator key `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]> --------- 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
Carry the
PaymentPoolcontract address inBuyerPoolState, make it part of the row's identity key, and drop a tracked row that belongs to a different deployment before anything can reuse it.Why
PaymentPool.openPoolderiveswith neither the contract address nor the chain id in it, and a fresh deployment restarts
ownerPoolNonceat zero. The same owner's Nth pool therefore has a byte-identical id on every deployment, so a persisted pool id alone cannot say which contract it belongs to.Bootstrap had no way to tell them apart, and the failure was silent in both directions:
getPoolson the new contract does not list the stale id,tracked_statusanswersUnknownfor an unlisted id, andreconcile_trackedkeeps the row onUnknown. The node pins every pull to a pool the live contract has never heard of and never opens a replacement.This is not hypothetical. It wedged the testnet fleet after the 2026-09-20 redeploy: fra1 and lon1 each tracked
keccak(owner, nonce=1)from the old contract, every node→node miss pull was refused withadmit getPool: pool absent or closed; refusing, and the buy side stayed dead across restarts. Both stale ids were low-nonce, so case 2 was one and two pool opens away respectively.How
BuyerPoolStategainspayment_pool: Addressplusis_on(); the field invariant now reads(payment_pool, pool_id).adoption_appliesgains anAdoptionCheck::Foreignarm;reconcile_owned_pooldrops the foreign row through the newdrop_foreign_rowbefore the enumeration that would otherwise re-adopt it. A failed forget refuses the adoption rather than adopting beside a row that would shadow it at the nextget_by_owner._v4. A row in the old shape is ignored, not migrated (pre-launch: no compat shims).Tests
reconcile_drops_a_row_from_another_payment_pool_deployment— seeds a foreign row whose id is one the mocked contract also mints, and asserts the surviving row's deposit comes from this contract's pool. Equality with the stale row's deposit is exactly the bug.reconcile_keeps_a_row_on_the_configured_deployment— the check keys on the contract address alone; a local row is stillAlreadyTracked.01→02plus the 20-byte address afterpool_idand nothing else displaced.Verified:
cargo nextest run --workspace3685 passed / 0 failed;cargo clippy --workspace --all-targetsexit 0 with zero warnings;cargo fmt --all; pre-commit clean. The new test was confirmed to fail whenis_onis stubbed totrue.Operational note
A node already wedged by this needs its
buyer.redbmoved aside once — this change prevents the state but does not rewrite a row that predates it.decdn pool close/reclaimcannot help: both revert on a pool the contract does not have, anddecdn poolwrites only the client store while a running daemon holdsbuyer.redbexclusively. That file holds pool tracking only; seller settlement lives inlanes.redb.🤖 Generated with Claude Code