Skip to content

feat(node): multi-relay config + reachability-gated endpoint bring-up (#795) - #817

Merged
thiras merged 4 commits into
mainfrom
feat/multi-relay-795
Jun 6, 2026
Merged

thiras merged 4 commits into
mainfrom
feat/multi-relay-795

Conversation

@thiras

@thiras thiras commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements scope 1 of #795 — multi-relay support for the node's iroh endpoint, so isolated/production deployments get relay redundancy/failover instead of a single point of failure.

Important context: PR #794 (which the issue assumed had landed single-relay wiring) was closed unmerged. On main, the network.relay_url field existed end-to-end but was dead config — build_endpoint ignored it and always used presets::N0. This PR makes it take effect and goes straight to multi-relay.

Config surface

  • NetworkConfig gains relay_urls: Vec<String>; relay_url kept as a deprecated singular alias folded into the list.
  • ResolvedNetwork.relay_url → relay_urls: Vec<String> (empty ⇒ n0 defaults). resolve_network precedence: CLI --relay-url > file relay_urls > file relay_url alias > empty.
  • expand_env expands ${VAR} per entry; config validate prints one line per relay; DEFAULT_CONFIG documents both keys.

Endpoint wiring (crates/node/src/runtime/mod.rs)

  • build_endpoint swaps only the relay leg via RelayMode::Custom(RelayMap::from_iter(..)) when the list is non-empty, leaving the presets::N0 DNS address-lookup leg intact. Gossip shares this endpoint (build_gossip(ep.clone())), so it inherits relays for free.
  • Reachability gate: a short TCP probe hard-fails bring-up only when ≥1 relay was actually probed and none were reachable. Relays with no derivable host/port (unprobeable — iroh may still route them) are excluded from the gate rather than counted as failures, so an all-unprobeable set proceeds on trust. A partially-reachable set proceeds (warning on the down relays). Probe logs host:port only, never the full URL (no userinfo leak).

Out of scope (follow-up)

This PR intentionally does not auto-close #795 — scope 2 remains, tracked in #818.

Test plan

  • cargo fmt --check ✅ · cargo clippy --workspace --all-targets ✅ · cargo nextest run (common+node+cli) 934 passed ✅
  • New tests: precedence ladder (list / alias-fold / CLI-override / empty-fallback), per-element ${VAR} expansion + error-context, probe outcomes (reachable/unreachable/unprobeable/IPv6), probe_relays tally, and build_endpoint gate (one-reachable binds, all-unreachable hard-fails, all-unprobeable proceeds).

This PR was reviewed by the pr-review-toolkit agents (code/tests/comments/silent-failure); their findings on the reachability gate and env-expansion coverage are addressed in the commit.

🤖 Generated with Claude Code

…#795)

Wire the node's iroh endpoint to honor multiple self-hosted relays for
isolated/production deployments (scope 1 of #795). Until now the
`network.relay_url` config field existed end-to-end but was dead config —
`build_endpoint` ignored it and always used `presets::N0`. This makes it
take effect and widens it to a list.

Config surface:
- `NetworkConfig` gains `relay_urls: Vec<String>`; `relay_url` kept as a
  deprecated singular alias folded into the list.
- `ResolvedNetwork.relay_url` -> `relay_urls: Vec<String>` (empty => n0
  defaults). `resolve_network` precedence: CLI `--relay-url` > file
  `relay_urls` > file `relay_url` alias > empty.
- `expand_env` expands `${VAR}` in each list entry; `config validate`
  prints one line per relay; DEFAULT_CONFIG documents both keys.

Endpoint wiring (crates/node/src/runtime/mod.rs):
- `build_endpoint` parses the list and, when non-empty, swaps only the
  relay leg via `RelayMode::Custom(RelayMap::from_iter(..))`, leaving the
  presets::N0 DNS address-lookup leg intact (full self-hosted discovery is
  out of scope here). Gossip shares this endpoint, so it inherits relays.
- TCP reachability probe gates bring-up: hard-fail only when >=1 relay was
  actually probed and none were reachable. Relays with no derivable
  host/port (unprobeable) are excluded from the gate rather than counted
  as failures, so an all-unprobeable set proceeds on trust. Probe reports
  host:port only, never the full URL, to avoid userinfo leaking into logs.

Tests cover the precedence ladder, per-element env expansion, the probe
outcomes (reachable/unreachable/unprobeable/IPv6), and the bring-up gate.

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

@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 transitions the network configuration from a single relay_url to a list of relay_urls to support multiple relays for redundancy and failover, while maintaining backward compatibility with the deprecated singular alias. It also introduces a reachability probe at node startup to ensure at least one configured relay is reachable. The reviewer suggested optimizing the reachability check by probing the relays in parallel rather than sequentially to prevent significant startup delays when multiple relays are unreachable.

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/node/src/runtime/mod.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

This PR implements scope 1 of #795 by making the node honor configured relay URLs and supporting a multi-relay configuration, including a reachability-gated endpoint bring-up when custom relays are provided.

Changes:

  • Add network.relay_urls (with deprecated network.relay_url alias) and implement precedence/merge logic in config resolution.
  • Wire relay configuration into node endpoint construction with per-relay TCP probing and a “≥1 reachable (among probeable relays)” bring-up gate.
  • Update CLI config validate output and add unit tests covering precedence, env expansion, probing outcomes, and endpoint gating.

Reviewed changes

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

Show a summary per file
File Description
crates/common/src/config/types.rs Adds relay_urls config field and documents deprecated relay_url alias.
crates/common/src/config/resolved.rs Switches resolved network relay config to a (possibly empty) list.
crates/common/src/config/mod.rs Implements relay precedence/alias-folding and per-entry ${VAR} expansion, with tests.
crates/node/src/runtime/mod.rs Wires relay_urls into endpoint building, adds parsing + probe/gate logic, and tests.
crates/node/src/runtime/reload.rs Updates resolved defaults and “ignored on reload” messaging for new fields.
crates/node/tests/sighup_signal.rs Updates test seed config to the new resolved relay list field.
crates/cli/src/commands/config.rs Prints one validate-summary line per relay and updates default config template text.
crates/cli/tests/config_validate.rs Adjusts/extends validate-summary tests for relay list behavior.

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

Comment thread crates/node/src/runtime/mod.rs Resolved
Comment thread crates/common/src/config/types.rs Resolved
Comment thread crates/common/src/config/resolved.rs Resolved
Comment thread crates/cli/src/commands/config.rs Resolved
@github-actions

github-actions Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 87.33% (was 87.18%, ▲ +0.14%) — 29167/33400 lines

File Coverage Lines Δ
crates/cli/src/commands/config.rs 61.42% 78/127 ▼ 0.30%
crates/common/src/config/mod.rs 96.42% 5035/5222 ▲ +0.05%
crates/common/src/config/resolved.rs 100.00% 19/19 ● 0.00%
crates/node/src/runtime/mod.rs 54.09% 813/1503 ▲ +9.56%
crates/node/src/runtime/reload.rs 95.09% 1413/1486 ● 0.00%
History
Commit Total Δ vs base
7e6593d 87.30% ▲ +0.14%
acc2899 87.30% ▲ +0.15%
e145134 87.31% ▲ +0.15%
e6359b9 (HEAD) 87.33% ▲ +0.14%

thiras and others added 2 commits June 5, 2026 04:52
…oc fixes

Address PR #817 review feedback (gemini-code-assist, copilot):

- Probe configured relays concurrently via JoinSet instead of serially.
  A serial loop added ~8s per unreachable relay to bring-up; a few down
  relays could stall startup for tens of seconds. Concurrency bounds the
  wait to ~one relay's probe time. A failed join is treated as
  "unprobeable" (excluded from the gate) so an internal error can't
  hard-fail bring-up.
- Redact `user:pass@` userinfo from the `parse_relay_urls` error message.
  A malformed relay URL can still carry credentials, and this node never
  lets relay userinfo reach logs (same invariant the probe upholds).
  Non-credential values still appear verbatim so the offending entry is
  identifiable.
- Correct three doc strings (NetworkConfig.relay_urls, ResolvedNetwork.
  relay_urls, DEFAULT_CONFIG) that still said "requires >=1 reachable":
  the gate fails only when every *probeable* relay is unreachable; an
  all-unprobeable set proceeds.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A second review pass found that the userinfo redaction added for parse
errors could still leak credentials in two reachable cases — both reach
the redaction path because they fail URL parse:

- A password containing a literal `@` (`user:p@ss@host`) was split on the
  first `@`, leaking the tail of the password.
- A credentialed entry with no `://` scheme separator was returned
  verbatim, leaking the whole userinfo.

Rework `redact_userinfo` to anchor the authority after the first `://`
(or at the start when absent) and redact to the *last* `@` before the
host delimiter. Verified against well-formed, no-scheme, empty-userinfo,
IPv6-host, password-with-`@`, and path-`@` shapes; non-credential values
still pass through borrowed (no copy).

Also: extend the redaction tests to cover the leak shapes, and correct
the now-stale `RelayProbeTally.unprobeable` doc (it also covers a probe
task that fails to join).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alpergundogdu

This comment was marked as duplicate.

@alpergundogdu alpergundogdu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review — multi-relay config + reachability-gated bring-up

The config surface is well-built: precedence (CLI --relay-url > file relay_urls > deprecated relay_url alias > empty⇒n0), per-element ${VAR} expansion, empty-list-as-unset, and only swapping the relay leg (RelayMode::Custom) while leaving the n0 DNS leg intact are all the right calls, and the precedence ladder is thoroughly tested. redact_userinfo handling last-@ so an @ in the password is fully redacted is a nice security detail. My main concern is a design one on the gate itself:

1. (Discussion) Hard-failing bring-up when all probeable relays are down turns a transient relay outage into a node outage. The gate's premise is "0 reachable ⇒ almost certainly misconfiguration, fail loud." But it can't distinguish misconfiguration from a transient outage of correctly-configured relays — and for the latter the code's own comment notes iroh "keeps retrying them in the background." So a brief relay blip during a deploy/restart now prevents the node from starting at all, whereas a node that was already up would ride it out. For a system aiming at production shape with tens of nodes, a correlated relay outage during a rolling restart could wedge the fleet. Two softer options worth considering: (a) warn-and-proceed even on all-unreachable (trust iroh's background retry, matching the all-unprobeable path), or (b) gate it behind a config knob (relay_require_reachable_at_startup, default false). At minimum, the failure message could suggest clearing the relay config to fall back to n0. I'd lean toward (a)/(b) — keep the loud warn!, drop the hard bail! — but flagging rather than blocking since it's a deliberate choice.

2. (Minor) TCP-connect liveness ≠ relay-protocol health. relay_connect_once proves the host:port accepts a TCP connection, which a fronting LB / reverse proxy will happily do even if the relay behind it is unhealthy. So the gate can pass on a relay that won't actually relay, and (per #1) hard-fail on a healthy relay that briefly refuses TCP. That's an inherent limit of a cheap probe — fine to keep, but it slightly undercuts the "fail loud on misconfig" justification for making the gate fatal. Worth a one-line caveat in the comment.

3. (Nit) redact_userinfo drops leading non-scheme text. For an entry with no :// like "relay user:s3cret@host", everything before the last authority @ becomes ***, yielding "***@host" (the literal relay is gone). Over-redaction is safe, but it means the error no longer shows the malformed prefix that might help diagnose the typo. Minor; the current behavior is defensible.

Tests are comprehensive (reachable/unreachable/unprobeable/IPv6, tally, and the three build_endpoint gate outcomes). Nice work. CI status currently shows no completed checks — worth confirming the Solidity/clippy jobs are green before merge.


Generated by Claude Code

A configured network.relay_urls set that is entirely unreachable at
bring-up no longer hard-fails the node. The startup probe couldn't tell
misconfiguration from a transient relay outage, so a correlated relay
blip during a rolling restart could wedge the fleet — whereas an
already-up node rides it out via iroh's background retry. The probe is
now advisory: an all-probeable-unreachable set logs a loud warn! (and
points the operator at clearing network.relay_urls to fall back to n0),
then proceeds. Malformed-URL parse failures stay fatal.

Also notes in the build_endpoint comment that the bare TCP probe proves
host:port liveness, not relay-protocol health (a fronting LB accepts
even when the relay behind it is down), and realigns the relay_urls
docstrings + DEFAULT_CONFIG template, which still claimed bring-up
fails. Renames the all-unreachable test to assert it binds.

Addresses review feedback on #817.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.

iroh: support multiple relays + self-hosted discovery for isolated deployments

3 participants