Skip to content

feat: publisher-pays channels — open-on-behalf + adopt-by-id + reject-bundle resume (#1481) - #1488

Merged
alpergundogdu merged 14 commits into
mainfrom
claude/issue-1481-f8e471
Jul 28, 2026
Merged

alpergundogdu merged 14 commits into
mainfrom
claude/issue-1481-f8e471

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1481. Builds on #1478 (delegated voucherSigner + voucher-less close), which is merged into main.

Lets a client fetch with no wallet, no on-chain tx, and no USDC: a publisher opens a channel on the client's behalf pinning the client's key as voucherSigner, and the client signs vouchers locally, adopts the channel by id, and self-heals its watermark on a reject.

What's in it

  1. Buyer store schema v2 (7aa78b4) — re-keys BuyerChannelState by channel_id (with a provider secondary index for the auto-open reuse path), adds funder (the on-chain client — the only address topUp accepts) and voucher_signer (the pinned EIP-712 signer), bumps BUYER_SUPPORTED_SCHEMA_VERSION 1→2 (v1 records skipped, non-fatal), and fixes the channel close branch to gate on voucher_signer instead of a watermark proxy.
  2. decdn channel open --provider-address --deposit-micro-usdc [--voucher-signer] (44dad1e) — publisher-side; pins a delegate as voucherSigner, prints {"channelId": …}.
  3. decdn node lookup [--node-id|--region] [--probe] [--json] (cff0cf7) — unpaid CapacityBond.getActiveNodes() discovery → operator address, optional RTT probe-rank.
  4. decdn fetch --channel-id <id> (a5f5d39) — adopt-by-id: getChannel → verify voucherSigner-in-keystore + Open + unexpired → hydrate the watermark from on-chain claimed totals → fetch; the fetch-time top-up is skipped when the local key isn't the funder (topUp is funder-only).
  5. Voucher-reject watermark bundle (d6a87ab, 08be6dc, 520af94) — on a StaleNonce/AmountRegression/BytesRegression/InsufficientDeposit reject, the node attaches its true watermark + the client's echoed last signature to VoucherRejected; the client re-seeds its ledger and resumes, making StaleNonce self-healing. Two signature gates: the node attaches the bundle only when the rejected voucher recovers to the pinned voucher_signer (no watermark leak to a channelId guesser); the client trusts a bundle only when its last_signature recovers to the client's own key (the bundle rides in an unsigned StreamError, so this prevents a malicious upstream from inflating the watermark and draining the deposit).

Plus 6e2cbad (a --json clap-collision fix in node lookup) and 438deb0 (ADR 003/005 sync for the new wire field and delegated-payer recovery).

No contract changes

All on-chain surface shipped in #1478. This branch is Rust + ADR docs only.

Verification

  • cargo nextest run → 2614/2614 pass, 0 skipped
  • cargo clippy --all-targets clean, cargo fmt --check clean, all pre-commit hooks pass
  • New end-to-end test drives the wallet-less self-heal over live QUIC (node_origin_pull::a_stale_nonce_rejection_with_a_bundle_self_heals_over_the_wire); three tests encode the watermark-forgery attack and assert rejection.

Reviews

Each part had a spec+quality review; a whole-branch review (opus) then caught a critical unauthenticated-reseed vector (the client ignored the bundle's last_signature), fixed in 520af94 and re-reviewed clean.

Deployment notes

  • Mixed-version wire: VoucherRejected gains a bundle field (positional postcard, append-only). One-field and two-field peers do not interoperate — this is a single coordinated pre-deployment cut, not a staged rollout.
  • Buyer store: the _v1→_v2 rename makes any pre-existing local buyer store invisible to the CLI (the node rebuilds from chain via reconcile; the CLI re-adopts via --channel-id). Local cache only; acceptable for the testnet cut.

Deferred (follow-ups, non-blocking)

  • Orphaned-row invariant unit test (schema-v2 reuse-hint semantics).
  • channel open idempotency guard; --channel-id cache-hit refill logic; --probe fan-out cap vs. plain listing UX.
  • MAX_RESUME_ATTEMPTS = 3 is currently a code constant, not ADR-anchored.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added decdn channel open for opening payment channels with optional delegated voucher signers.
    • Added decdn node lookup with node/region filters, latency probing, table output, and JSON output.
    • Added decdn fetch --channel-id to adopt an existing payment channel directly.
    • Voucher rejection handling can now automatically recover and resume transfers using authenticated payment state.
  • Bug Fixes

    • Improved delegated-channel top-up and close handling.
    • Skipped or corrupted channel records now report channel IDs for clearer recovery.

alpergundogdu and others added 9 commits July 28, 2026 11:49
…keying

Re-keys BuyerChannelState by channel_id with a provider secondary index,
adds the pinned voucher_signer, bumps BUYER_SUPPORTED_SCHEMA_VERSION 1->2
(v1 records skipped, non-fatal), and fixes the channel-close branch to gate
on voucher_signer instead of the watermark proxy (#1481).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…wallet-less resume (#1481)

A wallet-less client has no way to reconstruct its true payment-channel
watermark from chain (the claim watermark stays 0 until settlement), so a
StaleNonce/AmountRegression/BytesRegression/InsufficientDeposit rejection was
previously a dead end for it.

StreamError::VoucherRejected now carries an optional WatermarkBundle (node's
last-accepted amount/nonce/bytes_delivered plus the client's own last-accepted
signature). The node attaches it only for those four gated regression/
exhaustion reasons, and only after confirming the rejected voucher's own
signature recovers to the channel's pinned voucher_signer — otherwise anyone
who guessed the chain-derivable channel_id could probe the watermark with a
garbage voucher. Handler-direct reasons (Expired, RetryLater,
CooperativeCloseSigned, RateFloorRaised, WrongChannel, BadSignature,
WrongSigner, WrongToken) never carry a bundle.

client-pull gains Cumulative::from(&WatermarkBundle) and
ChannelLedger::reseed so a caller that receives a bundle can overwrite its
local watermark and resume issuing from bundle.nonce + 1 instead of treating
the rejection as terminal.

Call sites that construct VoucherRejected/UpstreamVoucherRejected (cli
bundle_pull, node node_origin(_pull) tests) pick up the new field as fallout
of the wire-type change; no behavior change there beyond compiling against
the new shape.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…nto the real pull path (#1481)

Task 5's node-side gate was correct but nothing consumed the bundle it
sent: a wallet-less client hitting a gated StaleNonce/AmountRegression/
BytesRegression/InsufficientDeposit rejection still saw its pull
abandoned, identically to before the feature existed.

- crates/client-pull/src/lib.rs: fetch_inner (the buffered pull every
  production entrypoint funnels through, including stream_fetch_shared —
  the daemon's own node-to-node cache-miss buyer leg) now retries, bounded
  by MAX_RESUME_ATTEMPTS, when a mid-stream rejection carries a
  signer-verified WatermarkBundle for a gated reason: it reseeds the
  channel's ChannelLedger and reopens a fresh stream. Deliberately does
  NOT jump byte_offset to bundle.bytes_delivered — that field is the
  CHANNEL's cumulative payment counter (used to reconstruct each
  voucher's EIP-712 bytesDelivered), not a position within the blob being
  fetched. Every current caller requests byte_offset == 0, so jumping the
  wire offset ahead would silently return a truncated tail instead of the
  full blob the caller relies on getting back; retrying at the caller's
  original offset is always safe and is all the reseed actually needs.
  Added Cumulative::from(&WatermarkBundle) reuse via ledger.reseed(),
  WatermarkBundle::validate() (protocol crate) consulted before a bundle
  is trusted, and VoucherRejectReason::is_watermark_gated() promoted to
  the protocol crate as the single source of truth the node's gate and
  the client's retry both call, replacing node's local duplicate.
- crates/node/src/node_origin.rs: voucher_verdict/pull_verdict needed no
  behavior change — the retry resolves entirely inside client-pull before
  an error can reach this classifier — but now says so explicitly, so a
  reader doesn't have to rediscover that by reading another crate.
- crates/node/tests/node_origin_pull.rs: new end-to-end test
  (a_stale_nonce_rejection_with_a_bundle_self_heals_over_the_wire) drives
  two real ChannelLedgers against a real ClientHandler + real
  MemoryChannelStateStore over live QUIC, forcing a genuine StaleNonce
  and asserting the resumed pull returns the correct full blob with no
  special handling by the caller.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
LookupArgs flattened ChainArgs (which already exposes --json via
CommonChainArgs) while also declaring its own --json, which trips clap's
unique-argument-name assertion and fails cli_command_tree_is_clap_valid.
Drop the duplicate field and read the flattened chain.common.json.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…1481)

CRITICAL: the client-side resume wired in the previous commit trusted
WatermarkBundle.amount/nonce/bytes_delivered after only a length check
(WatermarkBundle::validate). The bundle rides inside a mid-stream
StreamError, which carries no signature of its own, so those fields were
fully attacker-controllable by the upstream node. reseed()ing the ledger
to them and retrying would sign a fresh voucher for the (possibly
inflated) bundle.amount + delta — a voucher this client genuinely holds
the key to sign, redeemable on-chain up to the deposit. A
malicious/buggy upstream could drain a channel this way, on any paid
pull through fetch_inner (stream_fetch_shared included), not only
wallet-less ones.

resumable_watermark now additionally reconstructs a decdn_incentive
SignedVoucher from ctx.channel_id/ctx.token and the bundle's
amount/nonce/bytes_delivered + last_signature, recovers its signer under
ctx.voucher_domain, and requires it to equal ctx.client_signer.address()
— the client-side half of exactly the check the node's own gate performs
before it ever attaches a bundle. A bundle that fails this (wrong key,
or the right key over a tampered field) is never reseeded from; the
rejection stays terminal, unchanged from pre-#1481 behavior.

Also folds in two doc fixes flagged by the same review pass: the
VoucherRejected::bundle field doc no longer reads as a wire byte-offset
instruction (bytes_delivered is the channel's cumulative payment
counter, not a blob offset — matches fetch_inner's own doc), and three
stale buyer_channel_state_v1 comments (channel_store.rs, runtime/mod.rs
x2) now say _v2, matching the real redb table name.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-payer recovery

ADR 005 gains the WatermarkBundle wire shape and its two signature gates
(node attaches only on recovery to voucherSigner; client trusts only when
last_signature recovers to its own key), corrects the now-false claim that
the VoucherRejected frame ends at the reason byte, and updates the
StaleNonce/InsufficientDeposit recovery rows for the delegated (publisher-pays)
client. ADR 003 notes a delegated payer cannot topUp or self-refresh from chain.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@alpergundogdu, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 7 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 3d080a7f-7129-4fae-a90b-b817b6b8b70b

📥 Commits

Reviewing files that changed from the base of the PR and between 438deb0 and 258ced5.

⛔ Files ignored due to path filters (1)
  • crates/protocol/tests/snapshots/public_api__public_api.snap is excluded by !**/*.snap, !**/*.snap
📒 Files selected for processing (12)
  • adr/003-payments.md
  • adr/005-protocol.md
  • crates/client-pull/src/ledger.rs
  • crates/client-pull/src/lib.rs
  • crates/e2e/tests/cli_fetch_topup.rs
  • crates/node/src/handlers/client/mod.rs
  • crates/node/src/handlers/client/voucher.rs
  • crates/node/src/node_origin.rs
  • crates/node/src/runtime/mod.rs
  • crates/node/tests/client_loopback.rs
  • crates/node/tests/node_origin_pull.rs
  • crates/protocol/src/client.rs

Walkthrough

Changes

The PR adds authenticated watermark bundles to voucher rejections and client-side self-healing, rekeys buyer-channel storage by channel_id, supports delegated channel opening and adoption, adds delegated close/top-up policies, and introduces decdn node lookup with filtering and optional RTT probing.

Payment recovery

Layer / File(s) Summary
Voucher rejection wire contract and emission
adr/..., crates/protocol/..., crates/node/src/handlers/client/...
VoucherRejected carries an optional validated WatermarkBundle; nodes attach it only for authenticated watermark-gated rejection reasons.
Client reseed and resume
crates/client-pull/src/ledger.rs, crates/client-pull/src/lib.rs, crates/node/tests/node_origin_pull.rs
The client verifies bundled signatures, reseeds its ledger, and retries the original fetch offset within bounded attempts.

Buyer-channel storage and CLI

Layer / File(s) Summary
Channel-ID persistence
crates/incentive/src/buyer_channel*.rs, crates/node/src/channel_store.rs
Buyer records use channel_id as the primary key, provider as a secondary index, and persist funder and voucher-signer fields.
Delegated channel flows
crates/common/src/cli/*, crates/cli/src/commands/channel.rs, crates/cli/src/commands/fetch.rs
CLI commands support voucher-signer selection, channel opening, channel-id adoption, delegated close routing, and funder-gated top-ups.
Node discovery
crates/common/src/cli/node.rs, crates/cli/src/commands/node.rs, crates/client-pull/src/discovery.rs
node lookup discovers active nodes, filters candidates, optionally probes RTT, ranks results, and renders table or JSON output.

Estimated code review effort: 5 (Critical) | ~120 minutes


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

alpergundogdu and others added 4 commits July 28, 2026 17:13
# Conflicts:
#	crates/client-pull/src/ledger.rs
#	crates/client-pull/src/lib.rs
# Conflicts:
#	crates/node/src/handlers/client/voucher.rs
# Conflicts:
#	crates/node/src/handlers/client/voucher.rs
Adds StreamError::VoucherRejected::bundle, VoucherRejectReason::is_watermark_gated,
and the WatermarkBundle struct + validate() to the public-api snapshot (#1481).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.91% (was 81.29%, ▼ 0.38%) — 53922/66647 lines

File Coverage Lines Δ
crates/cli/src/commands/bundle_pull.rs 56.59% 554/979 ▲ +0.04%
crates/cli/src/commands/channel.rs 54.58% 471/863 ▼ 1.40%
crates/cli/src/commands/fetch.rs 35.02% 387/1105 ▼ 0.21%
crates/cli/src/commands/node.rs 76.40% 1117/1462 ▼ 7.85%
crates/client-pull/src/buyer_channel.rs 45.53% 107/235 ▼ 1.07%
crates/client-pull/src/discovery.rs 96.38% 718/745 ● 0.00%
crates/client-pull/src/ledger.rs 99.77% 426/427 ▼ 0.23%
crates/client-pull/src/lib.rs 89.27% 1264/1416 ▲ +0.91%
crates/common/src/cli/fetch.rs 100.00% 122/122 ● 0.00%
crates/common/src/cli/mod.rs 100.00% 3/3 ● 0.00%
crates/common/src/cli/node.rs 100.00% 5/5 ● 0.00%
crates/incentive/src/buyer_channel.rs 90.05% 380/422 ▼ 2.54%
crates/incentive/src/buyer_channel_redb.rs 93.44% 171/183 ▼ 3.13%
crates/incentive/src/buyer_channel_table.rs 90.67% 787/868 ▼ 1.48%
crates/node/src/buyer_channel.rs 57.33% 1154/2013 ▼ 0.10%
crates/node/src/channel_store.rs 89.23% 1325/1485 ▼ 0.35%
crates/node/src/handlers/client/mod.rs 89.71% 680/758 ▲ +0.13%
crates/node/src/handlers/client/voucher.rs 83.22% 253/304 ▲ +0.07%
crates/node/src/handlers/client/wire.rs 95.20% 119/125 ▲ +0.04%
crates/node/src/node_origin.rs 91.23% 926/1015 ▲ +0.03%
crates/node/src/runtime/mod.rs 46.95% 1085/2311 ● 0.00%
crates/protocol/src/client.rs 97.53% 751/770 ▲ +0.18%
History
Commit Total Δ vs base
eb83760 80.90% ▼ 0.39%
258ced5 (HEAD) 80.91% ▼ 0.38%

Task 2 added the voucher_signer arg to open_channel; this anvil-e2e-gated
test (not compiled by the default-feature suite) still called it with 7 args.
Pass Address::ZERO (self-signing — the buyer funds and signs with one key). (#1481)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu merged commit f800783 into main Jul 28, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-1481-f8e471 branch July 28, 2026 17:47
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.

Publisher-pays channels: open-on-behalf + adopt-by-id + reject-bundle resume

1 participant