Skip to content

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

Closed

Description

@alpergundogdu

Summary

The decdn CLI (decdn fetch, #391; decdn probe) has no node discovery — it must be handed an explicit --node-id + --addr/relay and (for fetch) --provider-address. This is an implementation gap, not a missing design: client node discovery is already specified and consistent across ADRs 001/003/012/016/022.

The design already exists

  • Canonical source: CapacityBond.getActiveNodes(offset, limit) (contracts/src/CapacityBond.sol:1337) returns NodeInfo[] — nodeId, ethAddress, active, multiaddrs, lastMultiaddrUpdate, regionHint.
  • ADR 012 §Bootstrap Procedure: clients query getActiveNodes (paginated) on first start, then gossip NodeAnnounce; cache to ~/.decdn/peers.json.
  • ADR 022: the DHT (cdn/dht/v1) is the content layer ("which of those nodes holds blob H"), itself bootstrapped from getActiveNodes.

How a discovered node gets dialed — NodeId + iroh discovery (primary)

The node already dials peers by NodeId and lets iroh's discovery resolve the address: its endpoint uses presets::N0 (n0-hosted pkarr/DNS — it publishes its own NodeId→address record and resolves others'), or operator-configured [network.discovery] legs. The CLI's probe/fetch currently use presets::Minimal (no discovery), which is the only reason they need an explicit --addr today.

So the lazy first cut is to build the CLI endpoint with discovery enabled (presets::N0, or honor [network.discovery]) and dial the discovered NodeId — the exact mechanism the node uses, ~no new transport code. The registry multiaddrs field is not required for this.

Security: dialing by NodeId is authenticated by the QUIC handshake (the NodeId is the ed25519 key), so a wrong resolved address simply fails to connect — no MITM — regardless of whether the address came from iroh discovery or the registry. The choice is purely availability/infra-dependence vs self-containment, not safety.

Work (implementation only — no ADR changes)

  1. Add an alloy binding + read path for CapacityBond.getActiveNodes (uses the existing blockchain RPC config).
  2. decdn fetch/probe: when --node-id/--addr/--provider-address are omitted, read getActiveNodes, pick a node (regionHint-aware + probe-and-rank by RTT / holds-the-blob), derive --provider-address from NodeInfo.ethAddress, and dial its NodeId via a discovery-enabled endpoint.
  3. Channel-aware ranking: prefer a provider the client already has a usable open channel with (reads Client-side buyer channel management: auto-open, track, reuse PaymentChannels for decdn fetch #940's BuyerChannelStore); else open one with the best-by-locality node. Default: reuse if it holds the blob and RTT is within tolerance, else open new.

Optional fallback — registry multiaddrs decoder (drop the n0 dependency later)

Option B above depends on n0's hosted pkarr/DNS discovery. To make the client self-contained / not reliant on n0, decode NodeInfo.multiaddrs (a packed (uint16 len, bytes) array, ADR 003) into an explicit EndpointAddr — addresses the operator committed on-chain, no discovery infra needed. This is the more-decentralized path and the planned follow-up to drop the n0 dependency; it is not a prerequisite for the first cut. (Nothing decodes multiaddrs today — the node dials by NodeId+discovery — so this is the only genuinely new transport code, and it's deferred.)

Dependencies / out of scope

Order: #940 (channel mgmt) → #936 (this) → #391 (bundle pull).

Activity

  1. added
    kind:feature
    prio:medium
    area:cli
    on Jun 17, 2026
  2. alpergundogdu commented on Jun 17, 2026

    @alpergundogdu
    ContributorAuthor

    Dependency + weave note (channel management): node selection here must be channel-aware, but channel open/track/reuse is a separate layer — filed as #940 (client-side buyer channel management, extracting #744's BuyerChannelService).

    Ranking should read #940's channel store and apply the 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 (probe-and-rank). So #940 lands before the channel-aware ranking in this issue; the multiaddr decoder + getActiveNodes read here are independent of it and can proceed in parallel.

    Order: #940 (channel mgmt) → #936 (channel-aware discovery) → #391 (bundle pull).

  3. alpergundogdu commented on Jun 17, 2026

    @alpergundogdu
    ContributorAuthor

    Reframing (supersedes my earlier "multiaddr decoder is the linchpin" note): the node dials peers by NodeId + iroh discovery (presets::N0 pkarr/DNS), and the CLI only needs --addr today because probe/fetch use presets::Minimal (no discovery). So the first cut is just to enable discovery on the CLI endpoint and dial the discovered NodeId — ~no new transport code, same mechanism as the node. The multiaddrs decoder is demoted to an optional, more-decentralized fallback to drop the n0 dependency later, not a prerequisite. Body updated accordingly.

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

Metadata

Metadata

Assignees

Labels

area:clikind:featureprio:medium

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions