Repository navigation
fix: persist a delegated client's lane watermarks - #2441
Merged
Merged
Conversation
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]>
There was a problem hiding this comment.
🟢 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.
Code Coverage OverviewLanguages: Rust Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit 6c44335 in the Show a line coverage summary of the most impacted files.
|
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
A client that pays under a
dcap1capability on a pool another owner funds owns no pool row. Every lane watermark write it made went through the owner index, returnedUnknownPool, 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 thatdecdn_client::bundleis public and sponsord embeds it.This PR stores a delegate's lanes in a new
buyer_delegate_lanes_v1table inbuyer-pools.redb, keyed by chain id ‖PaymentPool‖ pool id ‖ signer ‖ provider (100 bytes).BuyerPoolStoregainsdelegate_lanes,advance_delegate_progress,rebase_delegate_progress. The pool row and the delegate lanes share one advance/rebase rule (BuyerLaneProgress::{advanced, rebased}).ProgressWrite::applytakes aWatermarkRow(Owned(owner)/Delegated(deployment)) and drops its separate pool id.LaneSourcespicks the row from its payer.build_delegated_pool_ctxresumes from the delegate record (deployment-scoped);seed_spendcounts the key's earlier spend from it.Closes #2435
Reviewer notes
buyer_pool_state_v1/buyer_pool_owner_index_v1are untouched, so no fleet-wide lane reseed and no pool row whose owner is the publisher. The node never writes the new table.seed_spendfirst): each bundle entry builds a freshLaneSourcesand seeds from the store, which by then holds sibling entries' written spend, whileLaneLedgers::signed_byalready 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).LocalPullFault(fatal) instead of a transient retry that never clears. A rebase overwrites unread, so it replaces a damaged record; trailing bytes decode asCorrupt.BuyerPoolStoremethods and theProgressWrite::applysignature; listed under CHANGELOG Changed (BREAKING), public-API snapshot regenerated.Verification
cargo fmt -- --checkCARGO_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 passedcargo 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.recorded 7, want 5) without the registry-prior rule; the fatal-classification test fails (classified Transient) withoutLocalPullFault.CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items,pre-commit run --all-filescontracts/changed: n/aCHANGELOG.mdentry added (Fixed + Changed (BREAKING))adr/012-client.mdupdated (no new ADR; ADR 039 already requires local records)🤖 Generated with Claude Code