fix(relay-server): pass dummy port to lookup_host#424
Open
varex83 wants to merge 4 commits into
Open
Conversation
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).
emlautarom1
approved these changes
May 19, 2026
| // 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); |
Collaborator
There was a problem hiding this comment.
nit: Could use tokio::time::timeout to make it clearer (test should take at most 10 seconds)
iamquang95
reviewed
May 19, 2026
| if let Some(ipv4) = ipv4 { | ||
| debug!("Resolved external host {external_host} to {ipv4}"); | ||
| state.set_external_host_ip(Some(ipv4)).await; | ||
| } else { |
Collaborator
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tokio::net::lookup_hostrequires ahost:portinput, so passing a bare hostname (e.g.pluto-relay-0-p2p.ovh.dev-nethermind.xyz) failed withinvalid socket addressand the relay never resolved the configuredexternal_hostfor its ENR.0so 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
external_hostset to a hostname and verify the warningFailed to resolve external host ... invalid socket addressno longer appears/enrresponse contains the resolved IPv4 in the ENRipfieldcargo clippy --workspace --all-targets --all-features -- -D warnings