Repository navigation
fix(node,incentive): adopt the payment pool a node already owns - #2075
Conversation
…al cause A failed `openPool` tx moved `node_pull_pool_open_failures_total` twice — once in `run_open`'s `inspect_err`, once in the `node_origin` classifier's residual arm — because that leg attached neither `OpenReported` nor `LocalPullFault`. The same fall-through also counted a chain revert as a local fault and told the operator to suspect the node's store or lock state. On the live fleet that read as 46 pool-open failures against 23 pull attempts. `run_open` now meters the total and its by-reason sibling where the failure is raised, marks the error `OpenReported`, and adds `LocalPullFault` for an insufficient deposit — a wallet that cannot fund a deposit can pay no provider, which is what that marker means. The classifier's ladder reads the markers through a pure `classify_pool_open_arm`, so the metering invariant is unit tested without a `NodeOriginDeps`. `PoolOpenFailureReason` also classifies `Error(string)` reverts. The deployed Sepolia USDC reverts `ERC20: transfer amount exceeds balance` rather than the OpenZeppelin v5 custom error, so an under-funded wallet was reported as an opaque `contract_revert` naming no remedy. Refs #2072 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… opening a second The buyer store was the only record that a node owns a PaymentPool deposit, so a reset `identity.data_dir` lost it. The node then opened a second deposit beside the first, forgot that one too, and once the wallet was drained every cache-miss pull failed `ERC20: transfer amount exceeds balance` with its own escrow idle on-chain. ADR 003 §node→node says a pool is opened once and reused and that owner funds are never stranded; this restores both. `BuyerPoolService::bootstrap` reconciles against `PaymentPool.getPools` and adopts the newest `Open` pool the owner holds. Adoption is soft: an RPC blip leaves the store untouched and the first miss opens one the old way, rather than disabling buying for the process the way a failed approval does. A lane with no local progress reseeds from the contract's `watermark(pool, signer, provider)`. `PoolLedger` signs `prior + accrued`, so resuming a paid lane from zero signs cumulatives at or below the contract's watermark, which `_applyVoucher` treats as transient-empty — the node would stream real bytes and buy none of them. `decdn_buyer_wallet_usdc` reports the wallet the buyer leg spends from; nothing did. `decdn_pool_deposit_usdc` is wired to the redeemer tick, which can see the pools, instead of the lane snapshot that could only pass it zero. Also corrects appendix-observability's health section: the body it documented has no relation to `HealthResponse`, and health is an admin JSON-RPC method, not an HTTP route beside `/metrics`. Refs #2072 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Drives the whole recovery: a SERVER opens a pool and pays a seeder on it, its `buyer.redb` is deleted, and it restarts. The journey asserts the owner's on-chain pool count is unchanged — the bug's only observable symptom was a second escrowed deposit — and that a further fetch completes and advances the lane's on-chain watermark, which it can only do if the lane resumed above what the contract had already paid. The reseed reads the existing `getWatermark` binding rather than the raw `watermark` mapping getter added alongside it, which was a redundant second accessor for the same lane. Also scopes the "Peers known" panel to nodes with pull-through on: the bindings projection is not built otherwise, so a cache-only node's permanent 0 read as a collapsed directory. Refs #2072 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…let alert Review findings on the adoption work, all of them paths that cost USDC quietly. A failed `getWatermark` resumed the lane from zero, which the doc called a per-pull cost. It is permanent: the pull persists its own progress on every exit path, so a zero-resumed lane gains a local row and the reseed never runs for that provider again. One RPC blip stranded the lane below the watermark until it climbed back one rejected voucher at a time. The read now refuses the pull, and a store re-read that faults pins the seed from memory rather than falling back to the unseeded snapshot — which pinned zero priors against a committed watermark and then filed the resulting regression as benign race noise. `openPool` names no provider, so neither an unfunded wallet nor an unusable chain lane varies per candidate. `RpcError` joins `InsufficientDeposit` as a refusal instead of walking the candidate list and reporting the blob absent. The join-error leg meters, which makes "meters iff marks `OpenReported`" true rather than merely asserted. `DecdnBuyerWalletUnfunded` scoped on `decdn_node_pull_attempts_total >= 0`, which matches every node: metrics register unconditionally, so a cache-only node exports the series at 0. Verified against the fleet — it would have fired on the pull-through-off node forever. Scoped on `> 0` now. Adoption skips a fully-redeemed pool, which is still `Open` on chain and would wedge buying against a deposit that funds no voucher, and names the pools it passes over so their deposits are recoverable. Failure legs count into `decdn_buyer_pool_adoption_failures_total`. `decdn_pool_deposit_usdc` no longer publishes zero when nothing is pending redemption — the healthy steady state. The e2e now fails when the fix is reverted: `second` is sized below `first` so a from-zero resume regresses below the watermark, the paid delta is asserted exactly, and the pool count is re-read after the fetch that would open a second one. Verified by mutation. Four unit tests that passed with their guard deleted now stock the mock so the guard is observable. Also: the doc block for `record_pool_open_failure` was re-parented onto `PoolOpenArm` by the earlier extraction; `decdn pool list --all` does not exist; `admin_v1_health`'s caller is `decdn node health`, not `node status`. Refs #2072 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It makes significant changes to the node’s on-chain payment/pool adoption and lane resumption behavior, which warrants careful human validation despite strong test additions.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
This PR fixes node-to-node cache-miss buying reliability by making the node recover and reuse an on-chain PaymentPool it already owns (even if the local buyer store is lost), reseeding missing lane progress from the on-chain watermark, and tightening pool-open failure classification/metering so operational signals match reality.
Changes:
- Adopt an existing on-chain buyer pool at node bootstrap (via paged
getPools) and reseed missing lane progress fromgetWatermark, refusing pulls when the watermark cannot be established. - Fix pool-open failure metering/classification (including string-revert ERC-20 shortfall detection) and publish new buyer-leg metrics plus alerts/runbook guidance.
- Add an anvil-backed e2e regression test for pool adoption + lane reseeding; deduplicate
enumerate_owned_poolsintodecdn_incentive.
| File | Description |
|---|---|
| monitoring/prometheus-alerts.yml | Adds alerts for unfunded buyer wallet and node-pull legs that never succeed. |
| monitoring/dashboard-node.json | Scopes “Peers known” stat to nodes that have attempted pulls to avoid misleading zeros. |
| docs/runbook.md | Adds operator runbook section for diagnosing node-pull failures (wallet vs forgotten pool). |
| crates/node/src/payment_settlement.rs | Publishes decdn_pool_deposit_usdc from redeemer sweep as recoverable remaining value. |
| crates/node/src/node_origin/mod.rs | Refactors/locks in pool-open failure arm classification and metering invariants with tests. |
| crates/node/src/metrics.rs | Adds buyer-leg metrics (wallet gauge + seed/adoption failure counters) and separates lane-count publishing from pool-deposit publishing. |
| crates/node/src/handlers/client/mod.rs | Switches seller-side lane gauge publishing to set_lanes_open (deposit published elsewhere). |
| crates/node/src/buyer_channel.rs | Implements pool adoption at bootstrap, lane watermark reseeding, buyer wallet balance publishing, and tighter open failure typing. |
| crates/incentive/src/pool_open_error.rs | Classifies string-based ERC-20 reverts as InsufficientDeposit; improves allowance-shortfall detection accordingly. |
| crates/incentive/src/payment_pool.rs | Moves paged enumerate_owned_pools into incentive crate for reuse. |
| crates/e2e/tests/node_pull_pool_adopt.rs | New anvil e2e covering pool adoption + reseeded lane continuing to pay and avoiding a second pool. |
| crates/common/src/cli/run.rs | Updates CLI help text to reflect /metrics (health is not on the metrics HTTP port). |
| crates/cli/src/commands/pool.rs | Removes duplicated local enumerate_owned_pools in favor of incentive crate implementation. |
| CHANGELOG.md | Documents the fixes and new metrics/alerts added in this PR. |
| adr/appendix-operator-key-rotation.md | Updates health verification steps to use admin_v1_health semantics. |
| adr/appendix-observability.md | Updates health documentation and adds/clarifies buyer-leg and pool-deposit metric definitions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
`buyer_wallet_usdc` carried a severed "Read once per" from an earlier edit, immediately above the sentence that replaced it. `record_pool_open_failure` and its ladder still spoke of a buyer *channel* throughout, including the four operator-facing log lines. The surface is a payment pool, and the metric docs already say so, so an operator grepping logs against them found mismatched nouns. Scoped to that function, whose doc and body this branch rewrote; the struct-field docs elsewhere in the file and the `buyer_channel` module name are a separate mechanical rename. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Coverage reportTotal: 83.16% (was 83.16%, ● 0.00%) — 82396/99080 lines
History
|
… beside it (#2081) * fix(cli,node): read the node's buyer pools from the node, not a store beside it (#2078) Every `decdn pool` subcommand opened `<data_dir>/buyer-pools.redb`, the client's store. A daemon keeps its buyer state in `<data_dir>/buyer.redb`, so on a node host the CLI read and wrote a different file than the node it was pointed at — and `Database::create` manufactured that file where none existed. `pool list` printed `pools=0` on a node that had just logged a successful pool adoption. redb holds a process-exclusive lock on `buyer.redb` for the daemon's lifetime, and even `ReadOnlyDatabase` cannot open it concurrently, so the CLI can never read that file from disk on a live node. The read has to come from the daemon. - `admin_v1_pools` + `decdn node pools`: the buyer-side counterpart of `admin_v1_lanes`. A node with no buyer leg answers `BUYER_POOL_UNAVAILABLE_CODE` rather than an empty list — "never pays for pulls" and "owns no pools" call for opposite operator responses. - `pool list` routes to the daemon on a node data dir and always prints `store=<path>`, so `pools=0` names the file that produced it. - `pool open` / `top-up` refuse there: they escrow USDC into a store the node never reads, manufacturing the stranded deposit #2075 prevents. - `close --all` / `reclaim --all` refuse: they enumerate from chain by keystore address, so they would close the pool the daemon is paying from. - `close --pool` / `reclaim --pool` still run their on-chain leg, but no longer grade a no-op `forget` as a clean close. Also fixes the blind spot that hid the original stranded pool: `reconcile_owned_pool` returned on `AlreadyTracked` before enumerating, so `report_stranded_pools` was reachable only after an adoption. It now runs every bootstrap, measured against the pool the store names, and skips fully-redeemed pools that would refund nothing. `decdn_buyer_pool_adoption_failures_total` is deliberately not widened. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(node,cli): drop a buyer-pool row the chain has closed; widen the node-dir marker Review follow-ups on #2078. `reuse_or_report` reads the tracked buyer row with no status check, and bootstrap answered `AlreadyTracked` for any row at all. A pool closed or reclaimed out of band — which is what `decdn pool close --pool` from a node host leaves behind, since it cannot write the daemon's store — pinned every later pull to a pool `redeemMany` rejects every voucher against, and restarting did not heal it. Bootstrap now checks the tracked pool against the chain's open set, drops a stale row, and adopts or opens a replacement. A chain that cannot be read leaves the row alone. The CLI's node-data-dir classifier keyed on `buyer.redb` alone — the one file an operator loses in exactly the reset this change is about, and the one the `node_pull_pool_adopt` e2e deletes. It now keys on the whole daemon store set and names the marker it found. The filename constants were duplicated across `buyer_pool_table.rs` and `channel_store.rs`, which is what made a partial set easy to write; they move to one home in `decdn_common::data_dir`, which node, cli and incentive all already depend on. Also: `pool list` no longer tells an operator to start a daemon that answered and refused, the runbook qualifies "no stranded warning" on a completed sweep, and the CHANGELOG scopes the defect to store-backed subcommands (`assign` touches no store). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(node): never drop a buyer-pool row on a status read that failed Review follow-ups on #2078. The stale-row drop judged a tracked pool by its absence from the set of pools read as `Open`, and a `getPool` call that faulted produced that same absence. One transient RPC error at bootstrap — that call has no retry — would delete the node's only record of a funded pool, and the next miss would escrow a second deposit: the #2072 failure, self- inflicted, and invisible, because the stranded-pool report cannot name a pool it failed to read either. `OwnedPools` now keeps "read, and not open" apart from "not known", and `TrackedStatus` makes the third state explicit. A row is dropped only on a successful read returning a non-`Open` status. An id `getPools` does not list is unknown too: that view derives ids from `ownerPoolNonce` and `closePool`/`reclaim` only change status, so it is append-only and an absent id has no on-chain producer. Corrected claims that were simply false: - `redeemMany` does not reject every voucher on a closed pool; a `Closing` pool redeems until its dispute deadline. Fixed in the drop rationale, the CHANGELOG and the runbook's urgency argument. - `BUYER_POOL_UNAVAILABLE_CODE` blamed a missing `[blockchain]` section. The runtime attaches the store unconditionally and a node without that section does not start, so the operator-facing message named a cause that cannot occur. - Three comments asserted the daemon was running from mere file presence. The row survives because `decdn pool` has no code path to `buyer.redb`, not because of a lock. - The ADR and CLI docs named only `buyer.redb` as the node marker, where the code checks the whole daemon store set. The guards now run before chain coordinates are resolved, so they refuse without demanding an `rpc_url`, and CLI subprocess tests pin them at their call sites — deleting any one of them now fails the default CI job. Daemon-path decode warnings move to stderr, matching the client path, and `decdn node pools` names the admin URL it asked. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>

Why
Every node-to-node cache-miss pull on the live fleet was failing, and
decdn_node_pull_pool_open_failures_total(46) read higher thandecdn_node_pull_attempts_total(42).The buyer-pool store (
buyer.redb) was the only record that a node owns a fundedPaymentPooldeposit. A resetidentity.data_dirloses it, so the node opened a second deposit beside the first, forgot that one too, and once the wallet drained every pull revertedERC20: transfer amount exceeds balancewith its own escrow sitting idle on-chain.Verified on Arbitrum Sepolia: fra1 holds $1.47 and owns 2 × Open pools at 10 USDC; lon1 holds $0.13 and owns another 2. ~40 USDC stranded. This contradicts ADR 003 §node→node twice — "a pool is opened once and reused" and "owner funds are therefore never stranded" — so this is a conformance fix, not a new mechanism. No ADR needed.
What
Root cause.
BuyerPoolService::bootstrapreconciles againstPaymentPool.getPoolsand adopts the newest solventOpenpool. Adoption is soft: an RPC blip leaves the store untouched and the first miss opens one the old way, rather than disabling buying for the process. A fully-redeemed pool is skipped — it is stillOpenon chain and adopting one would wedge buying against a deposit that funds no voucher. Any further open pools are named in the log so their deposits are recoverable.Lane resumption. A lane with no local record reseeds from
getWatermark.PoolLedgersignsprior + accrued, so resuming a paid lane from zero signs cumulatives_applyVouchertreats as transient-empty — the node would stream real bytes and buy none of them. On fra1's live lane that watermark isamount=191205, bytes=19.9 GB. A failed read refuses the pull rather than degrading: the pull persists its own progress on every exit path, so a zero-resumed lane gains a local row and the reseed never runs for that provider again. One RPC blip would strand it permanently.Metering. One failed
openPoolmoved the counter twice —run_open'sinspect_errand the classifier's residual arm — because that leg marked neitherOpenReportednorLocalPullFault. 23 × 2 = the 46. It now meters once where raised.openPoolnames no provider, so neither an unfunded wallet nor an unusable chain lane varies per candidate: both refuse instead of walking the candidate list and then reporting the blob absent. The ladder's arm choice is a pureclassify_pool_open_arm.Classification. The deployed Sepolia USDC reverts
Error("ERC20: transfer amount exceeds balance"), not the OZ v5 custom error, so an empty wallet reported as an opaquecontract_revertnaming no remedy. String reverts now classify asinsufficient_deposit.Observability.
decdn_pool_deposit_usdcwas hardcodedU256::ZEROat both callers since #1667 while the ADR documented itlive; it is now published from the redeemer tick, and skipped when nothing is pending so it does not sawtooth to zero in the healthy state. New:decdn_buyer_wallet_usdc,decdn_buyer_lane_seed_failures_total,decdn_buyer_pool_adoption_failures_total, two alerts, and a runbook section.Not a bug
bcl's empty address directory is
node_to_node_pull_through_enabledbeing off — the projection is never built and the gauge exports a permanent 0. The issue's premise was also partly stale: the by-reason siblings were not all 0 (fra1 had 23contract_revert) and lon1 had 3 successes.Testing
3618tests pass; clippy clean;cargo fmt --checkclean.node_pull_pool_adopt: opens a pool via a real paid pull, deletesbuyer.redb, restarts, then asserts no second pool, an exact paid delta, and an advanced on-chain watermark.cargo build --bin decdn-nodeis required first; nextest does not rebuild the spawned daemon.)getWatermarkbinding was checked against the live deployed contract.Recovery
Adoption alone restores the fleet — each orphaned pool holds ~9.8 USDC, above the 2 USDC low-water mark, so no top-up fires.
docs/runbook.mdhas the funding and reclaim steps.Found, not fixed (worth their own issues)
reconcile_onchain_watermarks' Multicall3 aggregate always fails to decode onmain(buffer overrun, 35×/e2e run). Fail-open, so redemption is correct but the reconciliation never drops already-redeemed lanes.decdn pool listreads only the local store, so it cannot show a pool the store has lost — exactly when an operator needs it.Closes #2072
🤖 Generated with Claude Code