Skip to content

feat(cli): client-side node discovery for decdn fetch/probe (#936) - #943

Merged
alpergundogdu merged 3 commits into
mainfrom
claude/client-discovery-936
Jun 18, 2026
Merged

alpergundogdu merged 3 commits into
mainfrom
claude/client-discovery-936

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #936.

What

decdn fetch can now run without --node-id: it auto-discovers a node to fetch from. With --node-id the explicit path is unchanged.

Auto-discovery flow (no --node-id):

  1. Read the active node set from CapacityBond (the existing discovery::active_nodes foundation, PR landed earlier on this branch).
  2. Select top-K by region (K=5): same-region candidates first (case-insensitive equality on regionHint vs the client's --region/identity.region), filled to K with others. Unknown client region → skip region ordering, take first K.
  3. Probe the K concurrently over a discovery-enabled endpoint; keep those that hold the blob (has_blob), with their RTT.
  4. Rank (decision 4): prefer a node we already hold a live payment channel with (RedbBuyerChannelStore::get_by_provider) when its RTT ≤ 1.5× the best; otherwise the lowest-RTT node.
  5. Derive --provider-address from the chosen node's registry entry, then auto-open/reuse the channel and fetch (the Client-side buyer channel management: auto-open, track, reuse PaymentChannels for decdn fetch #940 flow).

Dialing is by iroh NodeId via a discovery-enabled endpoint — operator [network.discovery] resolution legs composed onto presets::Minimal, else presets::N0 — mirroring the node. NodeId-dial is QUIC-handshake-authenticated, so a bad resolved address can't MITM. The registry multiaddrs decoder remains the deferred self-contained fallback (#936 § fallback). probe gains the same NodeId-dial endpoint.

Changes

  • common resolve_discovery(&FileConfig) — exposes the existing section resolver so the one-shot client commands can resolve [network.discovery] without the full node resolve_config.
  • cli client_endpoint — client_endpoint/client_discovery build the shared discovery-enabled endpoint; fetch and probe both use it. The pkarr publisher leg the node wires is intentionally omitted (a client resolves, it never publishes its ephemeral key).
  • cli fetch — --node-id/--provider-address are now optional; new --capacity-bond-address and --region flags (flag > config). Keystore password load is deferred until after node selection, so a failed discovery never prompts. Concurrent probing via join_all (probe_once isn't Send, so single-task concurrency over tokio::spawn).
  • Selection + ranking are pure and unit-tested; the dial/on-chain paths are anvil-e2e territory.

Verification

cargo fmt --check, cargo clippy --workspace --all-targets -D warnings, cargo doc, cargo deny, and cargo nextest run --workspace (1864 passed) all green. #578 iroh-blobs-free invariant holds (cargo tree -p decdn-cli -e normal -i iroh-blobs empty).

Do not merge yet.

🤖 Generated with Claude Code

alpergundogdu and others added 2 commits June 17, 2026 18:19
First piece of client-side discovery: a read-only `active_nodes(rpc_url,
capacity_bond_addr)` that paginates CapacityBond.getActiveNodes and
distills each NodeInfo into a NodeCandidate (iroh node_id + eth address +
region hint), filtering inactive / undecodable entries. No signer needed
(view call). multiaddrs is intentionally dropped — dialing is by node_id
via iroh discovery (the decoder is the deferred self-contained fallback,
#936 § fallback).

Next: discovery-enabled endpoint (presets::N0), probe-and-rank selection,
channel-aware ranking (reads #940's store), and wiring into fetch/probe.

Refs #936

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When `decdn fetch` is given no `--node-id`, auto-discover a node: read the
active set from `CapacityBond` (existing `discovery::active_nodes`), take the
region-nearest top-K (K=5), probe them concurrently over a discovery-enabled
endpoint, keep the blob-holders, and rank them — preferring a node we already
hold a live payment channel with when its RTT is within 1.5x the best, else the
nearest. The chosen node's `--provider-address` is derived from its registry
entry; the channel is auto-opened/reused as before. With `--node-id` the
explicit path is unchanged.

Dialing is by iroh `NodeId` via a discovery-enabled endpoint (operator
`[network.discovery]` resolution legs composed onto `presets::Minimal`, else
`presets::N0`), mirroring the node — the registry `multiaddrs` decoder remains
the deferred fallback. `probe` gains the same NodeId-dial endpoint.

- common: `resolve_discovery(&FileConfig)` exposes the section resolver for the
  one-shot client commands.
- cli client_endpoint: `client_endpoint`/`client_discovery` build the
  discovery-enabled endpoint (publisher leg omitted — clients resolve, never
  publish); `fetch`/`probe` share it.
- cli fetch: `--node-id`/`--provider-address` now optional; new
  `--capacity-bond-address`/`--region`; signer load deferred until after
  selection. Concurrent probing via `join_all` (probe_once isn't `Send`).
- Pure selection/ranking unit-tested; dial/on-chain paths are e2e territory.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings June 18, 2026 10:11

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements client-side node auto-discovery for the decdn fetch and probe commands, allowing clients to query active nodes from the CapacityBond registry, filter them by region, and rank them based on latency and existing payment channels. Feedback on these changes includes preventing credential leakage by omitting raw RPC URLs from error messages, trimming on-chain region hints before comparison, and enforcing CLI constraints to reject --addr or --provider-address when --node-id is omitted.

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.

Comment thread crates/cli/src/commands/discovery.rs Resolved
Comment thread crates/cli/src/commands/discovery.rs Resolved
Comment thread crates/cli/src/commands/fetch.rs Resolved
Comment thread crates/common/src/cli/fetch.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables client-side node discovery for one-shot CLI commands (decdn fetch and decdn probe) so they can dial providers by iroh NodeId via a discovery-enabled endpoint, and (for fetch) select/rank candidate providers from the on-chain active-node registry (CapacityBond.getActiveNodes).

Changes:

  • Expose a common helper to resolve [network.discovery] without running the full node resolve_config.
  • Add CLI auto-discovery in fetch: read active nodes from CapacityBond, select top-K by region, probe concurrently, and rank by RTT with channel-aware preference.
  • Build and reuse a shared discovery-enabled client Endpoint for fetch and probe.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
crates/common/src/config/mod.rs Adds resolve_discovery(&FileConfig) to reuse node-grade shape validation for [network.discovery] in one-shot clients.
crates/common/src/cli/fetch.rs Makes --node-id/--provider-address optional and introduces --capacity-bond-address and --region flags for auto-discovery.
crates/cli/src/commands/client_endpoint.rs Adds config-driven discovery resolution and builds a discovery-enabled iroh Endpoint shared by client commands.
crates/cli/src/commands/discovery.rs New module implementing CapacityBond.getActiveNodes read + select/rank logic with unit tests.
crates/cli/src/commands/fetch.rs Implements fetch auto-discovery flow (select/probe/rank), defers keystore password prompt until after node selection, and reuses the shared endpoint.
crates/cli/src/commands/probe.rs Switches to the shared discovery-enabled client endpoint and updates reachability checks/messages accordingly.
crates/cli/src/commands/mod.rs Exposes the new discovery module.
crates/cli/Cargo.toml Adds futures-util for join_all-based concurrent probing.
Cargo.lock Locks the new dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/cli/src/commands/fetch.rs Resolved
Comment thread crates/cli/src/commands/discovery.rs Resolved
Comment thread crates/common/src/cli/fetch.rs Resolved
@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 84.70% (was 84.99%, ▼ 0.29%) — 38306/45228 lines

File Coverage Lines Δ
crates/cli/src/commands/client_endpoint.rs 50.35% 71/141 ▼ 49.65%
crates/cli/src/commands/discovery.rs 79.86% 111/139 new
crates/cli/src/commands/fetch.rs 38.34% 166/433 ▼ 7.65%
crates/cli/src/commands/probe.rs 75.14% 139/185 ▲ +5.64%
crates/common/src/config/mod.rs 96.76% 6083/6287 ▼ 0.06%
History
Commit Total Δ vs base
76c827f 84.70% ▼ 0.29%
8429852 (HEAD) 84.70% ▼ 0.29%

- client_endpoint: mirror the node's relay leg. A configured relay list →
  RelayMode::Custom; with no custom relays keep presets::N0's default relays and
  restore RelayMode::Default on presets::Minimal — dropping the n0 discovery leg
  must not also disable relays, or a NodeId-only dial of a NAT'd node can't
  connect. (Copilot)
- fetch/probe: drop the now-obsolete reachability pre-check; the discovery-
  enabled endpoint resolves a node-id via [network.discovery]/N0 (+default
  relays) without --addr or configured relays. (Copilot)
- common cli/fetch: enforce flag pairing at the clap layer — --addr and
  --provider-address require --node-id, and --node-id requires
  --provider-address; reject the silently-ignored combos in discovery mode.
  (gemini G3/G4)
- discovery: redact userinfo in the rpc_url parse error (RPC URLs can embed API
  keys); trim on-chain region_hint before the case-insensitive match. (gemini)
- docs/tests: region_hint is always a string (ADR 030 self-attested, ISO alpha-2),
  not Optional; --region help clarified; test fixtures use ISO codes (US/DE) and
  exercise the trim path. (Copilot)
- client_endpoint: reword the `ponytail:` doc label to `Note:`. (Copilot)

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alpergundogdu
alpergundogdu merged commit 6e2819f into main Jun 18, 2026
22 checks passed
@alpergundogdu
alpergundogdu deleted the claude/client-discovery-936 branch June 18, 2026 11:08
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.

Client-side node discovery: a client has no way to find a node to fetch from

2 participants