Skip to content

fix(relay-server): pass dummy port to lookup_host#424

Open
varex83 wants to merge 4 commits into
mainfrom
fix/relay-external-host-resolve
Open

fix(relay-server): pass dummy port to lookup_host#424
varex83 wants to merge 4 commits into
mainfrom
fix/relay-external-host-resolve

Conversation

@varex83
Copy link
Copy Markdown
Collaborator

@varex83 varex83 commented May 19, 2026

Summary

  • tokio::net::lookup_host requires a host:port input, so passing a bare hostname (e.g. pluto-relay-0-p2p.ovh.dev-nethermind.xyz) failed with invalid socket address and the relay never resolved the configured external_host for its ENR.
  • Pass a dummy port of 0 so the bare hostname resolves, and iterate the resolved addresses to find the first IPv4 instead of silently giving up if the first record happens to be IPv6.

Test plan

  • Deploy a relay with external_host set to a hostname and verify the warning Failed to resolve external host ... invalid socket address no longer appears
  • Confirm the relay's /enr response contains the resolved IPv4 in the ENR ip field
  • cargo clippy --workspace --all-targets --all-features -- -D warnings

varex83 added 2 commits May 19, 2026 14:15
tokio::net::lookup_host requires a host:port input, so passing a bare
hostname (e.g. pluto-relay-0-p2p.ovh.dev-nethermind.xyz) failed with
"invalid socket address" and the relay never resolved the external host
for its ENR. Use a dummy port of 0 and iterate through the resolved
addresses to find the first IPv4, rather than silently giving up if the
first record happens to be IPv6.
The previous assertion required the ENR's ip to be loopback after
setting external_host = "www.google.com", which only held because
lookup_host silently failed on a bare hostname. With the resolver
fixed, the ip override now applies, so poll the ENR until a
non-loopback ip is observed (matching the Go assert.Eventually test).
Copy link
Copy Markdown
Collaborator

@emlautarom1 emlautarom1 left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread crates/cli/src/commands/relay.rs Outdated
// Resolution happens asynchronously on a tick, so poll until the
// ENR reflects a non-loopback IP (mirrors the Go test using
// `assert.Eventually`).
let deadline = time::Instant::now() + time::Duration::from_secs(10);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Could use tokio::time::timeout to make it clearer (test should take at most 10 seconds)

if let Some(ipv4) = ipv4 {
debug!("Resolved external host {external_host} to {ipv4}");
state.set_external_host_ip(Some(ipv4)).await;
} else {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we invalidate the cache here state.set_external_host_ip(None).await;? The DNS may no longer return IPv4 for the host, so a later query could fail

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.

3 participants