Skip to content

Client-side buyer channel management: auto-open, track, reuse PaymentChannels for decdn fetch #940

Closed

Description

@alpergundogdu

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::BuyerChannelService has open_or_reuse_channel (one-time approve → openChannel → decode ChannelOpened → persist), record_progress (advance the watermark), and top_up. open_or_reuse_channel already 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

  1. Extract BuyerChannelService (open_or_reuse_channel + record_progress + store wiring) into a shared crate, decoupled from node Metrics and the background reclaim-sweep task (a one-shot CLI doesn't need the sweep).
  2. Wire into fetch: open-or-reuse a channel with the selected provider, seed ChannelContext from the stored BuyerChannelState (prior_* from the persisted watermark), persist the returned VoucherProgress after. This removes the prior_*=0 "unused channel" assumption and makes --channel-id derived/optional.
  3. Config: reuse the existing blockchain settings (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.

Activity

  1. added
    kind:feature
    prio:medium
    area:cli
    on Jun 17, 2026
  2. added
    rust
    on Jun 17, 2026
  3. github-actions commented on Jun 17, 2026

    @github-actions

    🎯 Triage report

    decdn fetch (shipped in #938) currently requires a manually pre-opened PaymentChannel via --channel-id, making it far from turnkey. This issue tracks the client-side extraction and wiring of BuyerChannelService (already exists in crates/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

    Dimension Value Reasoning
    Type Feature New client-side capability enabling turnkey paid fetch
    Labels rust, poc-blocking added (existing: enhancement, technical, medium, cli) Rust crate refactoring; decdn fetch is unusable for real PoC workflows without payment channel lifecycle management
    Coding agent Suitable Three clearly numbered work items with specific types/files called out; success criteria are well-defined (remove prior_*=0 assumption, --channel-id becomes optional)

    🔗 Similar issues

    💡 Notes and suggestions

    Extraction boundary to watch:
    BuyerChannelService in node/src/buyer_channel.rs currently takes node::Metrics. The extraction must introduce a metrics abstraction (a no-op impl or Option<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 only open_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 in crates/incentive (where BuyerChannelState and BuyerChannelStore already live) or a thin new crates/buyer-channel shim that both node and cli depend on. Check crates/incentive's existing dep graph before adding a new crate.

    Config reuse:
    The blockchain config 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:

    • Extract BuyerChannelService::open_or_reuse_channel + record_progress out of crates/node (decouple from Metrics and reclaim sweep)
    • Place extracted service in crates/incentive or new thin crate; update crates/node to import it
    • Wire into cli fetch: open-or-reuse channel before stream_fetch_tracked, seed ChannelContext.prior_* from persisted watermark, persist VoucherProgress after
    • Make --channel-id optional/derived; add error if blockchain config is absent and channel can't be opened
    • Unit test: re-entrant fetch advances watermark correctly; fresh fetch opens channel and persists state
    • Follow-up (separate issue): wire channel-aware scoring into Client-side node discovery: a client has no way to find a node to fetch from #936 node-selection once both land

    Generated by Agentic Triage for issue #940 · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. assigned and unassigned on Jun 19, 2026
  5. thiras commented on Jun 20, 2026

    @thiras
    Contributor

    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):

    1. Extract BuyerChannelService decoupled from node Metrics + reclaim sweep — done via a lighter approach: the open kernel (open_channel + ensure_allowance) was extracted to crates/client-pull/src/buyer_channel.rs, and the node's BuyerChannelService::open_and_persist delegates to it. This sidesteps the Metrics/sweep coupling rather than abstracting it.
    2. Wire into fetch — open_or_reuse (crates/cli/src/commands/fetch.rs) reuses a live channel (seeding prior_* via ChannelContext::for_buyer_channel) or opens+persists a new one; the watermark is persisted via store.advance_progress(...) after each fetch. --channel-id/--token were dropped (derived).
    3. Config — reuses the existing [blockchain]/[identity] schema (flag > config > default); no new config surface.

    Buyer-only persistence: RedbBuyerChannelStore behind a default-off redb feature in crates/incentive (keeps the CLI iroh-blobs-free, #578), used by both fetch and bundle pull.

    Discovery weave (#936): landed in #943 — probe_and_rank + discovery::rank prefer 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clikind:featureprio:mediumrust

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions