Repository navigation
feat(cli): client-side node discovery for decdn fetch/probe (#936) - #943
Conversation
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]>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
commonhelper to resolve[network.discovery]without running the full noderesolve_config. - Add CLI auto-discovery in
fetch: read active nodes fromCapacityBond, select top-K by region, probe concurrently, and rank by RTT with channel-aware preference. - Build and reuse a shared discovery-enabled client
Endpointforfetchandprobe.
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.
Coverage reportTotal: 84.70% (was 84.99%, ▼ 0.29%) — 38306/45228 lines
History
|
- 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]>
Closes #936.
What
decdn fetchcan now run without--node-id: it auto-discovers a node to fetch from. With--node-idthe explicit path is unchanged.Auto-discovery flow (no
--node-id):CapacityBond(the existingdiscovery::active_nodesfoundation, PR landed earlier on this branch).regionHintvs the client's--region/identity.region), filled to K with others. Unknown client region → skip region ordering, take first K.has_blob), with their RTT.RedbBuyerChannelStore::get_by_provider) when its RTT ≤ 1.5× the best; otherwise the lowest-RTT node.--provider-addressfrom 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
NodeIdvia a discovery-enabled endpoint — operator[network.discovery]resolution legs composed ontopresets::Minimal, elsepresets::N0— mirroring the node. NodeId-dial is QUIC-handshake-authenticated, so a bad resolved address can't MITM. The registrymultiaddrsdecoder remains the deferred self-contained fallback (#936 § fallback).probegains the same NodeId-dial endpoint.Changes
resolve_discovery(&FileConfig)— exposes the existing section resolver so the one-shot client commands can resolve[network.discovery]without the full noderesolve_config.client_endpoint—client_endpoint/client_discoverybuild the shared discovery-enabled endpoint;fetchandprobeboth use it. The pkarr publisher leg the node wires is intentionally omitted (a client resolves, it never publishes its ephemeral key).fetch—--node-id/--provider-addressare now optional; new--capacity-bond-addressand--regionflags (flag > config). Keystore password load is deferred until after node selection, so a failed discovery never prompts. Concurrent probing viajoin_all(probe_onceisn'tSend, so single-task concurrency overtokio::spawn).Verification
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo doc,cargo deny, andcargo nextest run --workspace(1864 passed) all green.#578iroh-blobs-free invariant holds (cargo tree -p decdn-cli -e normal -i iroh-blobsempty).Do not merge yet.
🤖 Generated with Claude Code