Repository navigation
Description
Summary
decdn fetch (#391, shipped in #938) currently assumes a pre-opened, unused PaymentChannel passed via --channel-id (the requester starts vouchers at nonce 1; there is no client-side watermark store). To make client fetch turnkey, the CLI needs to auto-open a channel with the target provider, track its voucher watermark across fetches, and reuse existing channels.
This largely exists already — node-side (#744)
node/src/buyer_channel.rs::BuyerChannelServicehasopen_or_reuse_channel(one-timeapprove→openChannel→ decodeChannelOpened→ persist),record_progress(advance the watermark), andtop_up.open_or_reuse_channelalready prioritizes reuse.incentive::{BuyerChannelState, BuyerChannelStore}are the shared persistent state + redb store.- The extracted requester (
decdn-client-pull:stream_fetch_tracked+VoucherProgress) already supports resume-from-watermark and reports the new watermark.
So the wire + persistence + open/reuse logic exists; it is just trapped in crates/node, unreachable from the CLI — the same situation client_requester was in before #938 extracted it.
Work
- Extract
BuyerChannelService(open_or_reuse_channel+record_progress+ store wiring) into a shared crate, decoupled from nodeMetricsand the background reclaim-sweep task (a one-shot CLI doesn't need the sweep). - Wire into
fetch: open-or-reuse a channel with the selected provider, seedChannelContextfrom the storedBuyerChannelState(prior_*from the persisted watermark), persist the returnedVoucherProgressafter. This removes the prior_*=0 "unused channel" assumption and makes--channel-idderived/optional. - Config: reuse the existing
blockchainsettings (rpc_url,payment_channel_address, buyer deposit) the node already parses.
Weave with discovery (#936)
Channel management is a separate layer from discovery, but discovery becomes channel-aware: its node-selection ranking reads this store to prefer providers the client already has a usable open channel with. Agreed default: reuse an existing-channel provider if it holds the blob and RTT is within tolerance; otherwise open a new channel with the best-by-locality node.
Out of scope
- Background reclaim sweep for the one-shot CLI (reclaim can be a separate command or left to node-side).
- Automated top-up policy.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
github-actions commentedon Jun 17, 2026
🎯 Triage report
decdn fetch(shipped in #938) currently requires a manually pre-openedPaymentChannelvia--channel-id, making it far from turnkey. This issue tracks the client-side extraction and wiring ofBuyerChannelService(already exists incrates/node) into a shared crate so that the CLI can auto-open, track watermarks, and reuse channels—removing the "unused channel" assumption entirely. The scope is well-defined and tightly coupled to the discovery work in #936.📊 Assessment
rust,poc-blockingadded (existing:enhancement,technical,medium,cli)decdn fetchis unusable for real PoC workflows without payment channel lifecycle managementprior_*=0assumption,--channel-idbecomes optional)🔗 Similar issues
cdn/client/v1; works on the sameclient_requesterfetch path and will interact with theChannelContextseeding added here💡 Notes and suggestions
Extraction boundary to watch:
BuyerChannelServiceinnode/src/buyer_channel.rscurrently takesnode::Metrics. The extraction must introduce a metrics abstraction (a no-op impl orOption<Metrics>) so the shared crate has no dependency on the node's metrics registry. The background reclaim sweep is out of scope for the CLI, so onlyopen_or_reuse_channel+record_progress+ store wiring need to move.Crate placement:
Following the existing pattern (#938 /
decdn-client-pull), the extracted service likely belongs incrates/incentive(whereBuyerChannelStateandBuyerChannelStorealready live) or a thin newcrates/buyer-channelshim that bothnodeandclidepend on. Checkcrates/incentive's existing dep graph before adding a new crate.Config reuse:
The
blockchainconfig section (rpc_url,payment_channel_address, buyer deposit) already exists in the common config schema — no new config surface needed for the CLI.Discovery weave (post-#936):
The channel-store query in node-selection scoring is read-only (
BuyerChannelStore::get(provider_addr)), so it can be introduced without blocking on #940 landing first — just needs the store type to be accessible from the discovery layer.Suggested sub-task checklist:
BuyerChannelService::open_or_reuse_channel+record_progressout ofcrates/node(decouple fromMetricsand reclaim sweep)crates/incentiveor new thin crate; updatecrates/nodeto import itcli fetch: open-or-reuse channel beforestream_fetch_tracked, seedChannelContext.prior_*from persisted watermark, persistVoucherProgressafter--channel-idoptional/derived; add error if blockchain config is absent and channel can't be openedAdd this agentic workflows to your repo
To install this agentic workflow, run
feat(incentive): add buyer-only redb BuyerChannelStore behind redb fe…
feat(cli): auto-open, track, and reuse payment channels in decdn fetch (
fix(cli): bound fetch's accepted blob size to guard client memory (#940…
feat: auto-open/track/reuse payment channels for decdn fetch (#940) (#…
feat(cli): client-side node discovery for decdn fetch/probe (#936) (#943
thiras commentedon Jun 20, 2026
Closing — this shipped in PR #941 ("feat: auto-open/track/reuse payment channels for decdn fetch", merged, commit 351ad72). The PR referenced the issue but didn't auto-close it.
Audit vs. the issue's Work items (all verified on
main):BuyerChannelServicedecoupled from nodeMetrics+ reclaim sweep — done via a lighter approach: the open kernel (open_channel+ensure_allowance) was extracted tocrates/client-pull/src/buyer_channel.rs, and the node'sBuyerChannelService::open_and_persistdelegates to it. This sidesteps theMetrics/sweep coupling rather than abstracting it.fetch—open_or_reuse(crates/cli/src/commands/fetch.rs) reuses a live channel (seedingprior_*viaChannelContext::for_buyer_channel) or opens+persists a new one; the watermark is persisted viastore.advance_progress(...)after each fetch.--channel-id/--tokenwere dropped (derived).[blockchain]/[identity]schema (flag > config > default); no new config surface.Buyer-only persistence:
RedbBuyerChannelStorebehind a default-offredbfeature incrates/incentive(keeps the CLI iroh-blobs-free, #578), used by bothfetchandbundle pull.Discovery weave (#936): landed in #943 —
probe_and_rank+discovery::rankprefer a live-channel provider within RTT tolerance.Out of scope (correctly deferred): background reclaim sweep and automated top-up (both excluded by the issue). Client-side expired-channel reclaim is a new follow-up introduced by #941 (expired channels are replaced with a fresh open; residual-deposit reclaim is manual and node-owned) — tracking separately, not part of this issue's acceptance.
refactor(node,incentive): hoist the duplicated buyer-channel redb sto…
fix(cli): auto-reclaim replaced expired buyer channel on fetch (#1553) (