Files
Greg ShuflinandClaude Opus 5.5 7a5a4024c7
Build Debug APK / build (push) Successful in 7m0s
docs: the bootstrap key is per epoch; drop the revoked-node TODO
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 03:29:51 -08:00

7.6 KiB

Node Discovery & Bootstrap

This document describes how nodes in an ensemble discover each other.

Problem

The original design published all node IDs to a pkarr registry under the ensemble public key, signed with the ensemble key, once, at setup. A DHT record has to be refreshed or it expires, and no node kept the key to refresh it with, so the registry expired and nodes lost the ability to find each other. Nodes may go offline for days or weeks, so this was not an edge case.

Design: Gossip + Minimal DHT Bootstrap

The new approach separates bootstrap (how a node finds its first peer) from steady-state discovery (how nodes learn about all peers). Bootstrap uses a lightweight DHT entry; steady-state uses iroh-gossip.

Gossip Layer

Each ensemble has a gossip topic derived deterministically from the ensemble public key:

topic = HKDF-SHA256(ikm = ensemble_pubkey, salt = "", info = "syn/gossip/topic/v1")

Using a derived topic rather than the raw public key provides privacy: an observer who sees gossip traffic cannot correlate it to a known ensemble public key without already knowing the key.

Nodes join this topic and broadcast announcements containing:

  • Their NodeId (iroh public key)
  • Their DelegationCert (proves ensemble membership)
  • Their current relay URL / direct addresses

Recipients verify the delegation certificate before accepting announcements. Messages from non-members are silently dropped.

DHT Bootstrap

For a node to join the gossip topic, it needs to know at least one existing peer. This is where the DHT comes in — but only as a bootstrap mechanism, not as the authoritative registry.

The code is ensemble::registry (the record) and p2p::registry_keeper (the running node's side of it).

Bootstrap keypair (HKDF-derived)

The ensemble private key exists only transiently during init. Nodes cannot sign DHT records with it after that point. Instead, a separate bootstrap keypair is derived from the ensemble secret key via HKDF with a distinct context string, the same way the vault key is, and the membership epoch (docs/NODE_REVOCATION.md §3b):

bootstrap_secret = HKDF-SHA256(ikm = ensemble_secret_key, salt = "",
                               info = "syn/dht-bootstrap/v1" || epoch (4 bytes, big-endian))

This provides domain separation: the bootstrap keypair is independent of the ensemble signing keypair and the node keypair. Compromising the bootstrap key does not allow forging delegation certificates.

Every node derives it in the same transaction that stores its cert: at setup, beside its membership and vault key, and again whenever it is re-certified at a new epoch. It keeps it (SettingsStore::save_bootstrap_key). The registry lives at the bootstrap public key, not the ensemble public key, so knowing the ensemble public key (which syn ensemble info prints) no longer locates the list of node ids. Since BEP44 mutable records require a valid Ed25519 signature, only nodes holding the bootstrap private key can publish. An outsider who learns the bootstrap public key cannot write to the record.

Why the epoch is in it. Revocation doesn't take a key back. A revoked node still holding the bootstrap key could publish a record that leaves out every honest member, or put an old one back, and so strand a node cold-starting with no persisted peers. Honest nodes write themselves back in when they find themselves missing, but a revoked node that keeps rewriting can win that race.

With the epoch in the derivation, each epoch's registry has its own address. An epoch bump needs the keyphrase, and so does re-certifying at the new epoch, which is when a node derives the new key. A revoked node can do neither, so the record it can still sign is one no current member reads. A running node picks the new key up on its next read (registry_keeper loads it from the store each cycle), so it follows the registry without a restart.

A revocation without a bump leaves the key where it was. That is the case of a device the user still controls retiring its credential; a device they don't control is what a bump is for (docs/NODE_REVOCATION.md, "When the epoch moves").

What gets published

The record is a list of entries, each a node id and when that node was last seen up. It fits 13 of them (REGISTRY_CAPACITY). No relay addresses: iroh already publishes each node's address under the node's own key, and adding one per entry would halve the capacity. No names either, since the record is world-readable (ADR 0044).

A publish carries over every entry it read. It marks the publisher and its gossip neighbors seen now, drops nodes with a revoked cert (except neighbors, which got past admission with the cert they hold now), and when there are more than fit, drops the ones seen longest ago. The publisher always stays.

This is a best-effort bootstrap aid, not the source of truth for ensemble membership.

Who publishes (leader election)

Setup publishes nothing. A running node reads the record on joining and then every minute (registry_keeper::run), and after each read decides whether to write (registry::publish_reason):

  • Missing: nothing is published. Any node writes it.
  • Unlisted: the record doesn't list this node and has room for it. Any node writes itself in. This is how a new node gets listed, and a node that was set up offline or in autistic mode. It only applies while the record has room: in a full record, a node pushing itself in would evict another, which would then do the same.
  • Refresh: the record is over an hour old (REFRESH_AFTER) and this node has the lowest id among itself and its gossip neighbors. Election is local, so two halves of a partitioned ensemble may both refresh, which costs one extra write.

A retiring node, or one whose cert is revoked, doesn't write.

BEP44 sequence numbers (a packet's timestamp) keep a slower writer's older packet from overwriting a newer one. They do not stop two nodes that read the record at the same moment from each publishing a version that lacks the other: pkarr no longer exposes a compare-and-swap on publish, so the later write wins. The node left out finds itself unlisted on its next read and writes itself back.

Node Lifecycle

  1. First boot / registration: Node derives and persists the bootstrap keypair from the ensemble key and its cert's epoch. It touches no network: it publishes itself the first time it runs with the network on.
  2. Subsequent boots: Node tries direct connections to locally-persisted peer addresses first. If none succeed, queries the DHT for bootstrap peers.
  3. Joining gossip: Once connected to at least one peer, joins the gossip topic and announces itself.
  4. Steady state: Learns about new/returning nodes via gossip. Persists peer addresses locally for next boot.
  5. Cold start after total outage: First node back online finds no DHT record, publishes its own, and waits. Second node finds the first via DHT, both join gossip, and discovery resumes normally. p2p::cold_start_tests runs this with real nodes and a fake DHT (just integration-tests-cold-start).

Persistence

Each node persists the last-known addresses of all peers locally (via iroh's address book). On boot, a node attempts direct connections to known peers before hitting the DHT — the DHT is a fallback, not the first step.

Future Work

  • Revocation: Gossip announcements include delegation certs, so if key revocation is implemented later, nodes can reject announcements from revoked node keys.
  • mDNS: Local-network discovery as an additional bootstrap path that requires no infrastructure at all.