Skip to content

fix: persist a delegated client's lane watermarks - #2441

Merged
thiras merged 1 commit into
mainfrom
fix/delegate-lane-watermarks
Oct 12, 2026
Merged

thiras merged 1 commit into
mainfrom
fix/delegate-lane-watermarks

Conversation

@thiras

@thiras thiras commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

What

A client that pays under a dcap1 capability on a pool another owner funds owns no pool row. Every lane watermark write it made went through the owner index, returned UnknownPool, and was dropped with a warning. Its lanes restarted from zero on every run (and resynced against the node's watermark bundle), and the ADR 039 § Client SDK funding signal never counted spend from earlier runs. This matters now that decdn_client::bundle is public and sponsord embeds it.

This PR stores a delegate's lanes in a new buyer_delegate_lanes_v1 table in buyer-pools.redb, keyed by chain id ‖ PaymentPool ‖ pool id ‖ signer ‖ provider (100 bytes).

  • BuyerPoolStore gains delegate_lanes, advance_delegate_progress, rebase_delegate_progress. The pool row and the delegate lanes share one advance/rebase rule (BuyerLaneProgress::{advanced, rebased}).
  • ProgressWrite::apply takes a WatermarkRow (Owned(owner) / Delegated(deployment)) and drops its separate pool id. LaneSources picks the row from its payer.
  • build_delegated_pool_ctx resumes from the delegate record (deployment-scoped); seed_spend counts the key's earlier spend from it.

Closes #2435

Reviewer notes

  • Why a new table, not a pool-row change: buyer_pool_state_v1 / buyer_pool_owner_index_v1 are untouched, so no fleet-wide lane reseed and no pool row whose owner is the publisher. The node never writes the new table.
  • Bundle double count (read seed_spend first): each bundle entry builds a fresh LaneSources and seeds from the store, which by then holds sibling entries' written spend, while LaneLedgers::signed_by already counts that spend past each lane's pre-run prior. A lane the run's registry holds now counts only its prior (LaneLedgers::prior_amount).
  • Damaged records: a delegate-lane read error fails the lane build as LocalPullFault (fatal) instead of a transient retry that never clears. A rebase overwrites unread, so it replaces a damaged record; trailing bytes decode as Corrupt.
  • API break: three required BuyerPoolStore methods and the ProgressWrite::apply signature; listed under CHANGELOG Changed (BREAKING), public-API snapshot regenerated.
  • Not done here: a point lookup per provider (one damaged lane fails every provider's build for that signer and pool), cleanup of delegate lanes from old deployments, and a delegated multi-entry bundle test.

Verification

  • cargo fmt -- --check
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features (exit 0)
  • cargo nextest run -p decdn-incentive -p decdn-client -p decdn-node --all-features: 2840 passed
  • cargo nextest run -p decdn-client --features public-api-test --test public_api (snapshot regenerated)
  • cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(cli_fetch_delegated)': 2 passed. The new store assertion fails (got []) with delegated writes routed back to the owner row.
  • Mutation checks: the double-count test fails (recorded 7, want 5) without the registry-prior rule; the fatal-classification test fails (classified Transient) without LocalPullFault.
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items, pre-commit run --all-files
  • contracts/ changed: n/a
  • User-visible change: CHANGELOG.md entry added (Fixed + Changed (BREAKING))
  • Design change: adr/012-client.md updated (no new ADR; ADR 039 already requires local records)
  • PR title uses an allowed type with a lowercase subject

🤖 Generated with Claude Code

A client that pays under a dcap1 capability on a pool another owner funds
owns no pool row, so every lane watermark write it made returned
UnknownPool and was dropped. Its lanes restarted from zero on every run,
and the ADR 039 funding signal never counted earlier spend under the key.

Store a delegate's lanes in a new buyer_delegate_lanes_v1 table, keyed by
chain id, PaymentPool address, pool id, signer and provider. The pool
tables are unchanged, so no existing row moves and no lane reseeds.

- BuyerPoolStore gains delegate_lanes, advance_delegate_progress and
  rebase_delegate_progress; the pool row and the delegate lanes share one
  advance/rebase rule (BuyerLaneProgress::{advanced, rebased}).
- ProgressWrite::apply takes a WatermarkRow (owner's row or a
  deployment's delegate lanes) and drops its separate pool id.
- A delegated lane resumes from its record, and the credential slot seeds
  the key's earlier spend from it. A lane the run's registry already holds
  counts only its prior, so a bundle entry does not count a sibling
  entry's written spend twice.
- A delegate-lane record the store cannot read fails the lane build as a
  local fault rather than retrying it as a chain-side one. A rebase
  overwrites a record unread, so it replaces a damaged one.

Closes #2435

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 16:02
@thiras thiras self-assigned this Oct 12, 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.

🟢 Approval recommended

The persistence and accounting paths are consistent and covered across memory, redb, client, and end-to-end tests.

0 open findings

What changed in this PR

Persists delegated-client lane watermarks so fetches resume correctly and funding signals include prior spend.

Changes:

  • Adds deployment-scoped delegate-lane storage and APIs.
  • Routes delegated resume, accounting, and watermark writes through the new records.
  • Adds unit, persistence, API, and end-to-end coverage.

Spec-discipline assessment:

  • MECHANISM: Off-chain delegate-lane table
  • VERDICT: keep
  • FAILS: none — it prevents lost resume and spend state for active delegated clients.
  • INSTEAD: No smaller existing record can represent delegate-owned lanes.
File Description
crates/​node/​src/​pool_store.rs Delegates new store operations.
crates/​node/​src/​buyer_pool/​tests.rs Updates test store implementations.
crates/​node/​src/​buyer_pool.rs Routes owned watermarks explicitly.
crates/​incentive/​src/​buyer_pool/​tests.rs Tests in-memory delegate lanes.
crates/​incentive/​src/​buyer_pool.rs Defines delegate-lane store APIs and rules.
crates/​incentive/​src/​buyer_pool_table/​tests.rs Tests encoding, isolation, corruption, and durability.
crates/​incentive/​src/​buyer_pool_table.rs Implements the new redb table.
crates/​incentive/​src/​buyer_pool_redb/​tests.rs Verifies redb adapter delegation.
crates/​incentive/​src/​buyer_pool_redb.rs Exposes delegate-lane persistence.
crates/​e2e/​tests/​cli_fetch_delegated.rs Verifies CLI persistence end to end.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Updates the public API snapshot.
crates/​client/​src/​lib.rs Documents delegated resume behavior.
crates/​client/​src/​ledgers.rs Exposes lane prior amounts for accounting.
crates/​client/​src/​lanes/​tests.rs Tests delegated watermark writes.
crates/​client/​src/​lanes.rs Routes writes by watermark-row kind.
crates/​client/​src/​lane_sources/​tests.rs Tests prior-spend seeding and routing.
crates/​client/​src/​lane_sources.rs Seeds spend and selects delegated records.
crates/​client/​src/​funding/​adoption_tests.rs Tests delegated resume and read failures.
crates/​client/​src/​funding.rs Resumes delegated lanes from local records.
crates/​client/​src/​buyer_pool.rs Adds WatermarkRow and dispatches writes.
crates/​client/​examples/​common/​mod.rs Migrates the example to the new API.
CHANGELOG.md Records fixes and breaking API changes.
adr/​012-client.md Documents delegate-lane persistence.

🧠 Review effort: Balanced


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

@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit 6c44335 in the fix/delegate-lane-wa... branch remains at 75%, unchanged from commit abbce74 in the main branch.

Show a line coverage summary of the most impacted files.
File main abbce74 fix/delegate-lane-wa... 6c44335 +/-
crates/node/src/pool_store.rs 84% 81% -3%
crates/client/s...c/buyer_pool.rs 82% 82% 0%
crates/incentiv...c/buyer_pool.rs 94% 95% +1%
crates/incentiv...r_pool_table.rs 97% 98% +1%
crates/incentiv...er_pool_redb.rs 93% 94% +1%
crates/node/src...nt/serve_leg.rs 91% 93% +2%
crates/client/src/funding.rs 65% 74% +9%
crates/client/s...lane_sources.rs 24% 38% +14%
crates/client/src/ledgers.rs 81% 100% +19%
crates/client/src/session.rs 0% 100% +100%

@thiras
thiras merged commit 21c06e1 into main Oct 12, 2026
32 checks passed
@thiras
thiras deleted the fix/delegate-lane-watermarks branch October 12, 2026 16:18
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: a delegated client's lane watermarks are never persisted

2 participants