Repository navigation
feat: auto-open/track/reuse payment channels for decdn fetch (#940) - #941
Conversation
Extract the duplication-prone buyer-channel open logic — the openChannel tx, the authoritative ChannelOpened-from-receipt decode, and the BuyerChannelState/ChannelContext construction — plus the one-time USDC `ensure_allowance` into decdn-client-pull, so both the node service (#744) and the CLI (decdn fetch, #940) share one copy. Channel reuse and watermark recording stay thin compositions over decdn_incentive's BuyerChannelStore that each caller does directly; a one-shot CLI fetch needs neither the node service's per-provider concurrency guard nor its background reclaim/reconcile machinery, so only the kernel is shared. Additive — node still uses its own copy; delegating it to this kernel is the next step. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
BuyerChannelService::open_and_persist now calls decdn_client_pull::buyer_channel::open_channel for the openChannel tx + ChannelOpened decode + state/ctx build, and bootstrap calls the kernel's ensure_allowance — dropping node's duplicate copies (and the now-dead approval_floor + Erc20 import). The escrowed-but-untracked error posture on a local persist failure stays node-side. Behavior-identical: the buyer/loopback/reconcile/origin suites pass unchanged. Refs #940 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ature (#940) A client (decdn fetch) needs a PERSISTENT buyer-channel store to reuse channels across one-shot invocations (resuming the voucher watermark rather than opening a fresh channel every run). The node's redb store is deliberately a combined seller+buyer file, so this is a buyer-only store: one redb file, one table, the same Durability::Immediate fsync-on-commit discipline and the same versioned StoredBuyerChannelState encoding + transactional advance/deposit/CAS semantics as the node's buyer table. Gated behind a new `redb` feature (off by default) so the contracts/voucher consumers of decdn-incentive don't pull redb/postcard; verified redb stays out of the default dep tree. Tests cover reuse-across-reopen, advance regression/mismatch guards, and empty-store outcomes. Refs #940 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
#940) decdn fetch is now turnkey: it opens-or-reuses a PaymentChannel with --provider-address instead of requiring a pre-opened --channel-id. A live channel in the persistent RedbBuyerChannelStore is reused (resuming its voucher watermark via stream_fetch_tracked); otherwise one is opened on-chain (ensure_allowance + the shared open_channel kernel) and recorded. The acked watermark is persisted after the pull (even on a paid-but-failed delivery) so the next reuse resumes correctly. Chain coordinates (rpc_url, PaymentChannel/SlashJudge addresses, chain id, keystore, data dir, deposit) resolve flag > [blockchain]/[identity] config > default, reusing chain_ctx::{build_provider, parse_address} and the main config schema. So a configured client runs `decdn fetch --node-id … --addr … --provider-address … --hash … -o …` with no chain flags. Drops --channel-id and --token (both now derived). Enables decdn-incentive's redb feature for the CLI. Tests cover the flag>config>default resolution precedence; the on-chain open+fetch path is exercised by the anvil e2e (the requester itself is covered by node's loopback suite). Refs #391, #940 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces persistent buyer-channel management and auto-opening/reusing of payment channels for the decdn fetch CLI command. It extracts the core PaymentChannel opening logic into a shared buyer_channel module in crates/client-pull and implements a client-side RedbBuyerChannelStore in crates/incentive backed by redb. The decdn fetch command is updated to automatically resolve chain configuration, reuse active channels, and persist voucher progress. Feedback on the changes suggests refactoring an unidiomatic early return in fetch.rs to use a cleaner .map_err chain with the ? operator.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…review) Replace the awkward `return Err(anyhow::Error::new(e)).map_err(...)` with a direct `store.record(...).map_err(...)?` chain — same escrowed-but-untracked error context, cleaner control flow. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR makes decdn fetch turnkey by automatically opening, tracking, and reusing buyer PaymentChannels across CLI invocations, while reducing duplication by extracting the buyer-channel “open kernel” into the shared decdn-client-pull crate. It also introduces a buyer-only redb-backed store in decdn-incentive (feature-gated) so the CLI can persist and resume voucher watermarks.
Changes:
- Extract shared buyer-channel open/approval logic into
crates/client-pulland delegate node buyer-channel opening to it. - Add a feature-gated buyer-only
redbstore (buyer_channel_redb) to persist buyer channel state for CLI reuse. - Update
decdn fetchCLI args/config resolution and wire fetch to reuse-or-open + tracked watermark persistence.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/buyer_channel.rs | Removes duplicated open/approve logic and delegates channel opening to the shared kernel. |
| crates/incentive/src/lib.rs | Exposes the new buyer-only redb store behind the redb feature gate. |
| crates/incentive/src/buyer_channel_redb.rs | Implements buyer-only redb persistence for channel state + watermark resume. |
| crates/incentive/Cargo.toml | Adds redb feature and optional redb/postcard deps. |
| crates/common/src/cli/fetch.rs | Updates fetch CLI args to remove --channel-id/--token and add chain/config inputs. |
| crates/client-pull/src/lib.rs | Exposes the new shared buyer-channel kernel module. |
| crates/client-pull/src/buyer_channel.rs | Adds shared ensure_allowance + open_channel kernel for node + CLI. |
| crates/client-pull/Cargo.toml | Adds tracing dep for the new buyer-channel kernel logging. |
| crates/cli/src/commands/fetch.rs | Implements reuse-or-open flow, tracked fetch, and watermark persistence. |
| crates/cli/Cargo.toml | Enables decdn-incentive’s redb feature for CLI channel reuse. |
| Cargo.lock | Locks new deps (redb, postcard, tracing usage). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 84.99% (was 85.11%, ▼ 0.12%) — 38177/44921 lines
History
|
… zero-length guard) - fetch: handle the full AdvanceOutcome from advance_progress, not just backend errors — a non-Advanced outcome (unknown provider / channel replaced / regression) also means the watermark didn't move, so warn rather than silently risk a stale-nonce reuse. - fetch: clamp the new-channel deposit up to the on-chain PaymentChannel.minDeposit() (matches the --deposit-micro-usdc help and the node's buyer path) so openChannel can't revert for under-funding on a higher-floor network. - RedbBuyerChannelStore::open: reject a zero-length db file (redb's Database::create treats empty-but-present as 'create fresh', silently wiping the watermark) — mirrors the node store's guard. New test covers it. - client-pull: drop the stale node::buyer_channel::approval_floor doc reference (that helper moved into this kernel). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add tests for the previously-uncovered money-path store branches: load_all (multiple records), forget (remove + absent no-op), forget_if_channel (CAS: stale id does not delete, matching id does), and add_deposit (Added / ChannelMismatch / UnknownProvider). These are the transactional/CAS guards most likely to hide a funds bug. The open kernel in decdn-client-pull (open_channel/ensure_allowance) stays at unit-0%: it is async on-chain work whose meaningful coverage needs a live chain (anvil e2e), not a mock — deferred to a fetch anvil e2e rather than padded with hollow tests. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… review) stream_fetch_tracked was called with max_blob_size_bytes = 0 (unlimited), so a provider that over-claims total_bytes could drive the buffered delivery toward client OOM (bounded only by the channel deposit, which can be large at a low rate). Add --max-blob-mb (default 1024 MiB, the node's default serve ceiling) and pass it as the ceiling, mirroring the node's buyer-pull guard. Self-review finding. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
What
Makes
decdn fetchturnkey: instead of requiring a pre-opened, unused--channel-id, it auto-opens aPaymentChannelwith--provider-address, persists it, and reuses it (resuming the voucher watermark) on the next fetch. Implements #940; builds on the client-fetch foundation from #938.Prioritising already-open channels is built in: reuse is the fast path; a new channel is opened only when none is live. (The discovery side, #936, will rank candidates by this store — see that issue.)
Commits (reviewable in order)
feat(client-pull)— extract the duplication-prone buyer-channel open kernel (openChanneltx + authoritativeChannelOpened-from-receipt decode + state/ctx build) andensure_allowanceintodecdn-client-pull.refactor(node)— node'sBuyerChannelService::open_and_persistnow delegates to that kernel (drops its duplicate copy + deadapproval_floor/Erc20). Behaviour-identical: buyer/loopback/reconcile/origin suites pass unchanged.feat(incentive)— a buyer-only redbBuyerChannelStorebehind a newredbfeature (off by default; the node keeps its combined seller+buyer store). Same durable-fsync + versioned-encoding + transactional advance/deposit/CAS semantics as the node's buyer table.feat(cli)—fetchcomposes it all: reuse-or-open →stream_fetch_tracked→ persist watermark. Chain coordinates resolve flag >[blockchain]/[identity]config > default (reusingchain_ctx+ the main config schema), so a configured client needs no chain flags.--channel-id/--tokendropped (derived).Verification
cargo metadata --all-features,cargo build --workspace,clippy --workspace --all-targets -- -D warnings,fmt --check,cargo doc,cargo deny— all clean (via pre-commit on every commit).#578holds — CLI stays iroh-blobs-free (redb ≠ iroh-blobs).fetchflag>config>default resolution.Scope / deferred
fetchwarns. Natural Client-side buyer channel management: auto-open, track, reuse PaymentChannels for decdn fetch #940 follow-up.🤖 Generated with Claude Code