Skip to content

fix(client,cli)!: sign each data dir's owned lanes with a derived key - #2482

Merged
thiras merged 2 commits into
mainfrom
fix/client-lane-signer-per-data-dir
Oct 16, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/client-lane-signer-per-data-dir

Conversation

@thiras

@thiras thiras commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

What

decdn get signed vouchers with the wallet key, and a fresh --data-dir adopts the wallet's live pool. So two data dirs on one wallet signed the same (pool, signer, provider) lanes from separate watermarks. Providers rejected the lagging run as UnderFold, and the runs burned their resume budget re-fetching elsewhere (~36% wasted traffic in the testnet repro). The AlreadyOpen message recommended exactly this setup.

Each client data dir now signs its owned lanes with a lane key derived from the wallet key and a random salt kept in its buyer-pools.redb. The derivation is keccak256("decdn/client-lane-signer/v1" ‖ owner_sk ‖ salt), the salt lives in the new buyer_lane_salt_v1 table, and the lane key is never stored. This uses the capability delegation ADR 003 already specifies: no wire, ABI or contract change.

Key Does
owner (keystore) owns the pool, sends openPool/topUp/approve, keys the buyer-store row, signs the capability for the lane key
lane (derived) signs vouchers and the client identity binding (the node keys the lane on the binding's signer)

Data dirs share the pool but never a lane, so the AlreadyOpen advice is safe on the wallet's own pool.

Closes #2468

Reviewer notes

  • Start with crates/incentive/src/lane_signer.rs, then OwnedPayer in crates/client/src/buyer_pool.rs, then open_or_reuse_pool / build_pool_ctx / attach_client_binding in crates/client/src/funding.rs.

  • Unchanged on purpose:

    • The node's upstream buyer still signs with the node key (OwnedPayer::sole, pinned by pin_ctx_signs_with_the_node_key).
    • Delegated --capability runs still sign with the delegate key, so two data dirs on one delegate key still share its lanes. The docs and CHANGELOG say so.
    • The gateway is keyless and unaffected.
  • Binding: attach_client_binding now signs with the context's own client_signer, so the binding key equals the voucher key by construction.

  • Existing data dirs: a store draws a salt on first use. Its wallet-signed lanes stay in the row and count as pool spend; new vouchers sign on fresh lanes. Nothing is stranded or paid twice.

  • SDK break (decdn-client):

    • new OwnedPayer;
    • open_pool / opened_from_receipt take no signer, and OpenedPool drops ctx and capability;
    • self_owned_lane_ctx and issue_self_capability take &OwnedPayer;
    • Funding::SelfOwned { owner };
    • BuyerPoolStore::lane_salt is a new required method.

    The public-API snapshot is regenerated.

  • A salt read/record failure carries LocalPullFault and a repair hint, so it never retries or falls back to another key.

  • Follow-up, not fixed here: the node's admin lanes() fills counterparty with the lane signer, although its DTO doc says pool owner (crates/node/src/admin.rs:1001). It was already wrong for delegated clients and now affects every CLI client. The two multi-source e2e tests now match on voucher_signer.

  • Not done: the testnet re-run of the issue's three-pull repro.

Verification

  • cargo fmt -- --check
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features (ran as cargo clippy --workspace --all-features --all-targets -- -D warnings)
  • cargo nextest run --workspace --all-features: 5068 passed
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items
  • anvil e2e: cargo nextest run -p decdn-e2e -p decdn-node --features anvil-e2e -E 'binary_id(decdn-e2e::*) | binary(anvil_settlement_e2e)': 80 passed
  • New cli_fetch_two_data_dirs e2e:
    • Data dir A opens the pool, B adopts it, then both fetch concurrently.
    • Each store records exactly its own wire bytes, and neither store records a lane under the wallet key.
    • Mutation-checked: it fails when for_store signs with the wallet key.
  • Known-answer test for the derivation, cross-checked with cast keccak + cast wallet address
  • contracts/ changed: n/a
  • User-visible change: CHANGELOG.md entries (Fixed + Changed (BREAKING))
  • Design change: ADR 012 (Ethereum Key, key compromise, store) and ADR 003 (sizing, signer role) updated
  • PR title uses an allowed type with a lowercase subject

🤖 Generated with Claude Code

…#2468)

`decdn get` signed vouchers with the wallet key, and a fresh `--data-dir`
adopts the wallet's live pool. Two data dirs on one wallet therefore signed
the same `(pool, signer, provider)` lanes from separate watermarks. Providers
rejected the run that fell behind as `UnderFold`, and the runs spent their
resume budget re-fetching bytes elsewhere: about 36% of traffic was wasted
on testnet.

Each client data dir now signs with a lane key derived from the wallet key
and a random salt kept in `buyer-pools.redb` (new `buyer_lane_salt_v1`
table, `BuyerPoolStore::lane_salt`). The derived key is never stored. The
wallet key still owns the pool, sends its transactions, keys the store row,
and signs the capability that authorizes the lane key. The lane key signs
the vouchers and the client identity binding, which the node keys the lane
on. Data dirs share the pool but never a lane, so the `AlreadyOpen` advice
to run concurrent pulls from separate data dirs is safe on the wallet's own
pool. The node keeps signing its upstream lanes with the node key
(`OwnedPayer::sole`); delegated runs are unchanged.

BREAKING CHANGE: decdn-client SDK. An owned pool pays through
`buyer_pool::OwnedPayer` (`for_store` / `sole`); `self_owned_lane_ctx` and
`issue_self_capability` take it, and `lanes::LanePayer::Owned` holds it.
`open_pool` and `opened_from_receipt` take no signer, and `OpenedPool` drops
`ctx` and `capability`. `bundle::Funding::SelfOwned` names its key `owner`.
`BuyerPoolStore` gains the required `lane_salt` method.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 15:04
@thiras thiras self-assigned this Oct 16, 2026

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.

🟡 Changes recommended

Shared-pool spending can remain invisible to funding recovery, preventing funded clients from resuming.

2 open findings
What changed in this PR

Separates client data directories’ voucher signers to prevent shared-wallet lane collisions while retaining one shared payment pool.

Changes:

  • Derives lane keys from the wallet key and a durable per-store salt.
  • Separates pool ownership from voucher signing across client and CLI paths.
  • Updates SDK APIs, documentation, and regression coverage.
File Description
crates/​node/​tests/​anvil_settlement_e2e.rs Adapts capability setup.
crates/​node/​src/​pool_store.rs Delegates salt storage.
crates/​node/​src/​buyer_pool/​tests.rs Preserves node-key signing coverage.
crates/​node/​src/​buyer_pool.rs Uses sole-key payer.
crates/​incentive/​src/​store.rs Clarifies concurrent-store documentation.
crates/​incentive/​src/​lib.rs Exports lane-key module.
crates/​incentive/​src/​lane_signer/​tests.rs Tests deterministic derivation.
crates/​incentive/​src/​lane_signer.rs Implements salted lane-key derivation.
crates/​incentive/​src/​buyer_pool.rs Adds store salt interface.
crates/​incentive/​src/​buyer_pool_table/​tests.rs Tests salt persistence.
crates/​incentive/​src/​buyer_pool_table.rs Persists salt durably.
crates/​incentive/​src/​buyer_pool_redb/​tests.rs Tests store-level salt isolation.
crates/​incentive/​src/​buyer_pool_redb.rs Exposes persisted salt.
crates/​e2e/​tests/​pool_floor_ceiling_aggregate.rs Adapts pool-opening call.
crates/​e2e/​tests/​cli_fetch_two_data_dirs.rs Tests concurrent isolated lanes.
crates/​e2e/​tests/​cli_fetch_topup.rs Tracks derived lanes.
crates/​e2e/​tests/​cli_fetch_multi_source.rs Matches voucher signers.
crates/​e2e/​tests/​cli_bundle_pull_pool_id.rs Checks derived-lane accounting.
crates/​e2e/​tests/​cli_bundle_pull_multi_source.rs Matches voucher signers.
crates/​e2e/​src/​client.rs Adapts fixture payer construction.
crates/​common/​src/​cli/​fetch.rs Explains keystore signing roles.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Records SDK API changes.
crates/​client/​src/​lib.rs Updates signing documentation.
crates/​client/​src/​lanes/​tests.rs Adjusts test imports.
crates/​client/​src/​lanes.rs Builds lanes with separated keys.
crates/​client/​src/​lane_sources/​tests.rs Tests owner-row routing.
crates/​client/​src/​lane_sources.rs Routes funding through owner.
crates/​client/​src/​funding/​tests.rs Tests bindings and salt failures.
crates/​client/​src/​funding/​adoption_tests.rs Tests disjoint adopted lanes.
crates/​client/​src/​funding.rs Separates funding and lane signers.
crates/​client/​src/​buyer_pool/​tests.rs Tests payer signing roles.
crates/​client/​src/​buyer_pool.rs Introduces OwnedPayer.
crates/​client/​src/​bundle/​engine/​tests.rs Adjusts test imports.
crates/​client/​src/​bundle/​engine.rs Carries bundle payer roles.
crates/​client/​src/​bundle.rs Derives owned bundle signers.
crates/​client/​examples/​common/​mod.rs Demonstrates derived-key usage.
crates/​cli/​src/​commands/​pool/​tests.rs Adapts store test double.
crates/​cli/​src/​commands/​pool.rs Adapts pool-opening call.
crates/​cli/​src/​commands/​fetch.rs Initializes derived fetch signers.
crates/​cli/​src/​commands/​buyer_store.rs Clarifies shared-deposit warning.
crates/​cli/​src/​commands/​bundle_pull.rs Supplies pool owner key.
CHANGELOG.md Documents fix and SDK breaks.
adr/​012-client.md Describes lane keys and exposure.
adr/​003-payments.md Updates signer-role guidance.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread adr/012-client.md Resolved
Comment thread crates/client/src/funding.rs Resolved
@github-code-quality

github-code-quality Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main b1bb14a fix/client-lane-sign... 486355c +/-
75% 75% 0%
View coverage of the 10 most impacted files.
File main b1bb14a fix/client-lane-sign... 486355c +/-
crates/incentiv...r_pool_table.rs 98% 97% -1%
crates/cli/src/...mmands/fetch.rs 51% 50% -1%
crates/node/src...s/client/mod.rs 90% 89% -1%
crates/client/s...c/buyer_pool.rs 84% 83% -1%
crates/client/src/lib.rs 89% 89% 0%
crates/client/src/funding.rs 76% 76% 0%
crates/node/src/pool_store.rs 81% 81% 0%
crates/cli/src/...ommands/pool.rs 68% 69% +1%
crates/client/s...lane_sources.rs 38% 40% +2%
crates/incentiv.../lane_signer.rs 0% 100% +100%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 16, 2026 15:48 UTC

#2468)

A data dir tracks only its own lanes. With one lane key per data dir, a
pool another data dir on the wallet drained read full to this one: the
low-water refill did not fire, and a funding recovery step only settled,
so the run ended "funding needed" with a funded wallet.

`BuyerPoolState::reconcile_with_chain` raises a row to the pool's on-chain
deposit and counts at least `totalRedeemed` as spent, less the row's own
lanes so they count once. The run's first lane build applies it to the
reused row (`still_open`, which already reads `getPool`), and each funding
recovery step caps the run's remaining deposit at what the chain shows.

ADR 012 now describes a leaked lane key as its own exposure: the lane key
sits in process memory beside the owner key and can leak alone. The
capability is uncapped and never expires, so the response is to close the
affected pools and draw a new salt, not to wait.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 45fb2eb into main Oct 16, 2026
31 checks passed
@thiras
thiras deleted the fix/client-lane-signer-per-data-dir branch October 16, 2026 15:49
thiras added a commit that referenced this pull request Oct 16, 2026
#2488)

* fix(node,cli)!: report the pool owner as a lane's counterparty (#2484)

admin_v1_lanes filled LaneSnapshot.counterparty with the lane signer. Since
#2482 every `decdn get` lane signs with a key derived for its data dir, so
`decdn node lanes` showed that key, not the wallet that funds the pool, and
an operator looking a client up by its funding wallet found nothing.

The node now reads the owner (getPool.owner) from the event-fed pool view
the serve gates already use, with no chain call. counterparty becomes
Option<String>: None when the view holds no entry for the pool, never the
signer. `decdn node lanes` prints `unknown` there, `--json` prints null.

Tests seed an owner distinct from the signer at every layer, and the two
multi-source CLI e2e journeys now assert that a derived-key lane reports
its funding wallet as the counterparty.

Closes #2484

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

* fix(node): name the owner of a lane carried across a restart

The pool projection lives in memory and the settlement watcher resumes at
its checkpoint, so after any restart every carried-over lane read `None`
until its pool saw a new request. That covered most lanes an operator
checks, including settlement-eligible ones.

admin_v1_lanes now resolves owners through PoolOwners: the projection,
then an owner cache, then one bounded getPool per pool in neither, eight
at a time. A pool's owner never changes, so the cache keeps every owner
it reads. The read uses its own binding, not ResolvingPoolView, so a
failed read never negative-caches a pool the serve path reads. A failed
read reports None, logs one warning per call, and is retried next call.

Review follow-ups: the e2e topup and coalesce helpers find the lane by
signer and then assert the owner; the JSON test requires the key; the
pool_view backfill docs describe the restart case and the real resolver.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

client: separate --data-dir runs adopt the same on-chain pool and collide on lane watermarks (UnderFold)

2 participants