Skip to content

fix(node): bind the seller store to its PaymentPool deployment - #2191

Merged
thiras merged 8 commits into
mainfrom
claude/seller-lane-state-collision-92835d
Sep 30, 2026
Merged

thiras merged 8 commits into
mainfrom
claude/seller-lane-state-collision-92835d

Conversation

@yigitdot

@yigitdot yigitdot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What

poolId = keccak256(owner, ownerPoolNonce) names neither the chain nor the contract, and a redeploy restarts every owner's nonce. So a buyer's Nth pool on a new PaymentPool has the same id as its Nth pool on the old one. #2087 fixed the buyer side. On the seller side, lane_state_v1, both pending-settle sets and watcher_checkpoint_v1 carried no deployment. A seller repointed with its data dir intact kept the old lane for the reissued pool. It rejected the buyer's first voucher as AmountRegression, so the buyer suppressed the provider. It also redeemed the old deployment's signatures against the new contract, which reverted and took the rest of each redeemMany batch with it.

PersistentPoolStateStore::open now takes the configured Deployment (chain id + PaymentPool address). lanes.redb stores it in a one-row deployment_v1 table. At boot:

Boot preflight. Because the drop is irreversible, a config typo must never trigger it. Before the store opens, the node checks the configured deployment against the live chain: eth_chainId must equal blockchain.chain_id, the address must have code, and that code must answer PaymentPool.usdc() — code presence alone would pass a sibling contract pasted from the same deploy manifest. Any mismatch aborts boot with the store untouched. The voucher EIP-712 domain is derived from the same Deployment value, so the store stamp and the signature domain cannot disagree.

ADR 003 § Off-chain voucher state persistence describes the binding; docs/runbook.md gains Repointing at a redeployed PaymentPool (drain sub-floor lanes by lowering redeem_threshold_micro_usdc, what the gauge does and does not count, how to read the drop WARNs).

Closes #2181

Reviewer notes

Verification

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p decdn-node: 1481 passed. -p decdn-cli --test pool_list: 14 passed.
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items
  • cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(node_pull_pool_redeploy)': 3 passed, including the acceptance journey a_seeder_repointed_at_a_redeploy_drops_its_stale_lane_and_serves_the_reissued_pool. It repoints SEEDER Add devcontainer for secure Claude Code sessions #1 with its data dir intact and checks that it drops its Add devcontainer for secure Claude Code sessions #1 lane (dropped_lanes=1, undecodable_lanes=0, the per-lane last-record line) and serves and redeems the reissued pool at exactly the leg-2 price. The full anvil suite (77) passed after the preflight landed.
  • Mutation check: with the lane drop disabled, the acceptance journey fails with the issue's symptom (reason=AmountRegression and the SERVER suppressing the provider).
  • cargo nextest run -p decdn-node --features anvil-e2e -E 'binary(anvil_settlement_e2e)': 4 passed.
  • Unit tests: channel_store covers same deployment kept, other address and other chain dropped, no record claimed, no file growth on a matching reopen, malformed record is Corrupt, a crashed drop repeated by the next boot, a foreign record with no lane table, a corrupt foreign row, buyer.redb surviving, and the forfeited-value math. runtime covers the preflight: match, chain-id mismatch, codeless address, non-PaymentPool contract (not retried), transient fault retried.
  • contracts/ changed: n/a
  • User-visible change: CHANGELOG.md entry added under Fixed
  • Design change: ADR 003 updated
  • PR title uses an allowed type

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings September 28, 2026 00:57

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-code-quality

github-code-quality Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit b23147a in the claude/seller-lane-s... branch remains at 86%, unchanged from commit 74e2cd4 in the main branch.

Show a line coverage summary of the most impacted files.
File main 74e2cd4 claude/seller-lane-s... b23147a +/-
crates/node/src/dht/publish.rs 92% 92% 0%
crates/client/src/lib.rs 92% 92% 0%
crates/client/src/scheduler.rs 96% 96% 0%
crates/client/src/driver.rs 97% 97% 0%
crates/node/src...gin/pull_leg.rs 89% 89% 0%
crates/node/src...nt/serve_leg.rs 91% 92% +1%
crates/node/src/runtime/mod.rs 51% 53% +2%
crates/node/src...hannel_store.rs 91% 93% +2%

Updated September 29, 2026 17:49 UTC

@yigitdot
yigitdot force-pushed the claude/seller-lane-state-collision-92835d branch from 744ec42 to 13f4cf6 Compare September 28, 2026 01:46
@yigitdot

Copy link
Copy Markdown
Contributor Author

Ran a five-agent review pass (code, tests, comments, silent failures, type design) over the diff; no critical findings. 13f4cf6 applies the follow-ups:

  • Boot preflight before the store opens: eth_chainId must match blockchain.chain_id and the PaymentPool address must have code, so a config typo aborts bring-up instead of triggering the irreversible seller-state drop. The voucher domain is now derived from the same Deployment the store is stamped with (one parse).
  • Auditable drop: the rebind logs each dropped lane's pool_id/signer/provider/unredeemed value as the last record of its claim, plus forfeited_micro_usdc on the summary WARN — mirroring the buyer-side drop_foreign_row convention.
  • Five new/extended unit tests: a crashed drop is repeated by the next boot; a foreign stamp over an absent lane table drops cleanly; buyer.redb survives the seller-side drop; the stamp survives record/flush cycles; the unstamped claim keeps every family.
  • Docs: the unstamped case is a pre-stamp store (not "new"); the config-revert crash hazard is documented on bind_deployment; ADR 003 sentences split to STE; runbook gains "Repointing at a redeployed PaymentPool"; CHANGELOG notes that a node repointed before this upgrade must clear its store by hand.
  • Out of scope, filed as buyer pool row's deployment tag carries no chain id #2198: the buyer row's deployment tag carries no chain id.

All gates re-run green after the rebase onto 8d27ddf5: fmt, clippy --all-targets --all-features, 1448 node tests, doc gate, and the three redeploy e2e journeys (full anvil e2e suite re-running now).

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

🔵 Needs a closer look

It changes irreversible seller payment-state deletion with cross-file crash-safety and on-chain redemption implications, so a human should confirm the forfeit semantics and boot-preflight before merge.

Review effort: Balanced
Findings: None

@yigitdot
yigitdot requested a balanced review from Copilot September 28, 2026 14:53

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread docs/runbook.md Outdated
Comment on lines +912 to +914
1. Let the node redeem its open lanes and finish any pending settles on the
old deployment (`decdn_unredeemed_usdc` reaches 0 / the redeemer logs go
quiet), then stop the node.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step 1 can wait forever: a lane below the per-chunk redeem floor never settles while the node runs, so decdn_unredeemed_usdc may never reach 0. Only the graceful-shutdown sweep (PaymentSettlement::shutdown, floor == 0) redeems that dust.

Suggested wording:

Suggested change
1. Let the node redeem its open lanes and finish any pending settles on the
old deployment (`decdn_unredeemed_usdc` reaches 0 / the redeemer logs go
quiet), then stop the node.
1. Stop the node gracefully while it still points at the old deployment.
Shutdown runs one final redeem sweep with no floor, so it settles every
open lane, dust included. Confirm the log has no `shutdown redeem deadline
elapsed` warning; if it does, start the node on the old config and stop it
again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that step 1 could hang. decdn_unredeemed_usdc counts every lane's owed − paid, and a chunk below the floor never redeems, so the gauge may never reach 0.

The suggested fix doesn't hold, though: graceful shutdown doesn't sweep with floor == 0. final_redeem_sweep passes self.redeem_threshold (payment_settlement.rs:445), and config requires redeem_threshold_micro_usdc > 0 (default 1 USDC). So a stop leaves sub-floor dust unredeemed, same as the self-tick. The floor == U256::ZERO forces every lane (the close/shutdown path) doc on redeem_planned_lanes (:1854) is stale. No caller passes zero.

Fixed in 2fa187c:

  1. On the old deployment, set redeem_threshold_micro_usdc = 1 and restart. The next self-tick then redeems every lane that owes anything.
  2. Wait for decdn_unredeemed_usdc to reach 0, then stop gracefully. Check for the shutdown redeem deadline elapsed warning (your check, kept).
  3. Repoint and restore the threshold.

I also dropped the "finish pending settles" wait. The pending-settle tables have no production reader or writer, so there is nothing to wait on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked against current main (after #2226) and the history. The graceful-shutdown sweep has always passed self.redeem_threshold: it does so now, in b57d55ef (chunking), and in b82100fc before chunking. The only zero-floor caller was the close-redeem path, and #1761 removed it. The floor == 0 … close/shutdown path doc outlived it. 562dcbc corrects that doc in redeem_planned_lanes, chunk_redemptions, flush_store_durable, final_redeem_sweep, the non-strict flush-failure log line and two test comments. They now say that every path, shutdown included, applies the configured floor.

yigitdot and others added 5 commits September 29, 2026 17:22
poolId = keccak256(owner, ownerPoolNonce) names neither the chain nor the
contract, so a pool id repeats across PaymentPool redeploys. The seller
lane table, both pending-settle sets and the watcher checkpoint carried no
deployment, so a seller repointed with its data dir intact kept the old
deployment's frontier for a returning buyer's reissued pool: it rejected
the buyer's first voucher as AmountRegression and redeemed the old
signatures against the new contract.

PersistentPoolStateStore::open now takes the configured Deployment
(chain id + PaymentPool) and keeps a stamp in lanes.redb. A matching
stamp is a read-only check; a missing stamp is claimed without dropping
rows; a foreign stamp drops the lanes, pending settles and checkpoints
(lanes in the same commit as the new stamp) and logs the drop at WARN.

The redeploy e2e gains the acceptance journey: SEEDER #1 repointed at
the redeploy with its data dir intact serves the reissued pool from zero.

Closes #2181.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-ups on the seller-store deployment binding (#2181):

- Boot verifies the configured deployment against the live chain before
  the lane store opens: eth_chainId must match blockchain.chain_id and
  the PaymentPool address must have code. A config typo aborts bring-up
  instead of triggering the irreversible seller-state drop.
- The voucher EIP-712 domain is derived from the same Deployment the
  store is stamped with (one parse in build_infra, threaded via Infra).
- The rebind logs each dropped lane (pool id, signer, provider,
  unredeemed value) as the last record of its claim, plus a summed
  forfeited_micro_usdc on the summary WARN.
- Deployment::from_bytes decodes without the panicking Address::from_slice.
- New unit tests: a crashed drop is repeated by the next boot, a foreign
  stamp over an absent lane table drops cleanly, buyer.redb survives the
  seller-side drop, the stamp survives record/flush cycles, and the
  unstamped claim keeps every family.
- Docs: the unstamped-store case is a pre-stamp store (not "new"), the
  config-revert crash hazard is documented, ADR 003 sentences are split
  to STE form, the e2e module doc names both watched logs and pins the
  blob-price ordering its mutation detection rests on, and the operator
  runbook gains a "Repointing at a redeployed PaymentPool" section.

Co-Authored-By: Claude Fable 5 <[email protected]>
…ntPool

Every redeem path, graceful shutdown included, submits a chunk only when
its unredeemed total clears blockchain.redeem_threshold_micro_usdc (config
enforces > 0), so sub-floor lanes never redeem and decdn_unredeemed_usdc
may never reach 0. Drop the floor to 1 µUSDC on the old deployment first,
drain, stop gracefully, then repoint. Also drop the pending-settle wait:
those tables have no production writer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The redeem path docs still described a forced close/shutdown path passing
floor == 0. The close-redeem path was the only zero-floor caller and is
gone; every caller, including the graceful-shutdown sweep, passes
blockchain.redeem_threshold_micro_usdc, which config keeps above zero, so
sub-floor dust defers on every path. Correct the redeem_planned_lanes,
chunk_redemptions, flush_store_durable and final_redeem_sweep docs, the
non-strict flush-failure log line, and two test comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…feited claim

Second review pass on the deployment-binding follow-ups:

- The deployment preflight now also calls PaymentPool.usdc(): a code-
  presence check alone passes a sibling contract pasted from the same
  deploy manifest — the likeliest wrong-address typo — and the rebind
  would still drop the lanes. A non-PaymentPool target surfaces as a
  permanent contract error and aborts at once. The preflight is generic
  over the provider and gains five mocked unit tests (match, chain-id
  mismatch, codeless address, non-PaymentPool target pinned as
  not-retried, transient fault retried). It runs on its own retry
  budget, and the misplaced doc block that had swallowed
  check_rpc_reachability's rustdoc is re-attached.

- The forfeit audit reports the lane's full claim: forfeited_value is
  owed() — the signed cumulative plus the chain-verified frontier —
  minus the paid watermark, the figure the redeemer collects;
  last_amount alone understates a lane by up to one whole chain. The
  summary WARN gains undecodable_lanes so a partial sum announces
  itself, and a table or iterator error during the walk degrades to a
  WARN instead of aborting bring-up: the walk is observational, and the
  delete that follows arbitrates real corruption. New tests pin the
  value math, the corrupt-foreign-row tolerance, the crash-state setup
  deletes, and the absent-lane-table precondition; journey 3 asserts
  undecodable_lanes=0 and the per-lane last-record line.

- Docs: the rpc_url parse error no longer echoes the URL (it can embed
  an API key); two remaining "forced close" passages in receipt_log and
  the watermark-reconcile comment now name the shutdown sweep; the
  redeem floor is described as per-chunk (dust rides alongside larger
  lanes); the runbook drain procedure waits out the gauge's initial
  zero, watches decdn_redemption_skipped_insolvent_total for held
  drained-pool lanes, and tallies from the final boot's summary line;
  the CHANGELOG tells operators to leave buyer.redb in place.

Co-Authored-By: Claude Fable 5 <[email protected]>
@yigitdot

Copy link
Copy Markdown
Contributor Author

Second review pass (four agents over the follow-up commits 49e511d9/2331bd60/562dcbcd); 285274d applies it:

  • Contract-identity probe: the preflight also calls PaymentPool.usdc() — code presence alone passed a sibling address pasted from the same deploy manifest, the likeliest typo, and the rebind would still have dropped the lanes. A non-PaymentPool target aborts at once as a permanent contract error.
  • Preflight is now unit-tested (the guard for the irreversible drop had zero direct tests): generic over the provider, five mocked tests — match, chain-id mismatch, codeless address, non-PaymentPool pinned as not retried, transient fault retried. Also re-attached check_rpc_reachability's rustdoc, which the inserted const had swallowed.
  • Forfeit audit reports the full claim: owed() (signed cumulative + chain-verified frontier) minus the paid watermark — last_amount alone understates a lane by up to one whole chain. The summary gains undecodable_lanes so a partial sum announces itself, and walk errors degrade to a WARN instead of aborting a rebind over data that is being deleted anyway. New tests pin the math, the corrupt-foreign-row tolerance, and two vacuity vectors; journey 3 asserts undecodable_lanes=0 + the per-lane last-record line.
  • Docs: rpc_url no longer echoed on parse failure; two more stale "forced close" passages fixed (receipt_log.rs, the reconcile comment); the floor described as per-chunk (dust rides alongside larger lanes); the runbook drain now waits out the gauge's initial zero, watches decdn_redemption_skipped_insolvent_total for held drained-pool lanes, and tallies from the final boot's summary; CHANGELOG says to leave buyer.redb in place.
  • Follow-ups filed: e2e: pin that the deployment preflight aborts before the lane store is touched #2234 (e2e pinning the preflight aborts before the store is touched), node: service-level test that the shutdown redeem sweep applies the configured floor #2235 (service-level shutdown-floor test).

Gates: fmt, workspace clippy (all targets+features), 1481 node tests, doc gate, and the three redeploy e2e journeys all pass.

yigitdot and others added 2 commits September 29, 2026 20:35
…ace convention

The preflight test helpers returned Result<Value, ()> so they could sit
beside Err(()) fault entries, which needed three
#[expect(clippy::unnecessary_wraps)]. Follow the Option convention the
other mixed-response mock helpers use (incentive payment_pool.rs mocked,
cli fetch.rs run): the helpers return a bare serde_json::Value, the call
sites wrap in Some, and None faults the call. The list stays JSON rather
than Bytes because eth_chainId answers with a quantity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the Option encoding in the preflight test provider with a small
local enum, MockAnswer { Ok(serde_json::Value), TransientError }, so each
queued answer names what it is. The helpers keep returning a bare
serde_json::Value and call sites wrap them. buyer_channel.rs's MockCall is
not reused: it holds Bytes, and eth_chainId answers with a JSON quantity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit e90f1e3 into main Sep 30, 2026
30 checks passed
@thiras
thiras deleted the claude/seller-lane-state-collision-92835d branch September 30, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node: seller lane state collides across PaymentPool redeploys (lane_state_v1 keyed without the contract address)

4 participants