From 3510f0fef7d2f558b1b3a77eed47812ea2a1a6d3 Mon Sep 17 00:00:00 2001 From: Serge Radinovich <47865535+sergerad@users.noreply.github.com> Date: Thu, 23 May 2024 08:06:13 +1200 Subject: [PATCH] Fix enode URL parse failure due to enode prefix (#8339) --- crates/net/discv5/src/config.rs | 2 +- crates/net/types/src/dns_node_record.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/net/discv5/src/config.rs b/crates/net/discv5/src/config.rs index 252790b4ffae..09e2fe774c8f 100644 --- a/crates/net/discv5/src/config.rs +++ b/crates/net/discv5/src/config.rs @@ -129,7 +129,7 @@ impl ConfigBuilder { self } - /// Adds boot nodes in the form a list of [`NodeRecord`]s, parsed enodes. + /// Adds boot nodes in the form a list of [`DNSNodeRecord`]s, parsed enodes. pub fn add_unsigned_boot_nodes>( mut self, enodes: impl Iterator, diff --git a/crates/net/types/src/dns_node_record.rs b/crates/net/types/src/dns_node_record.rs index b97cfa44fd2b..94e50d06424f 100644 --- a/crates/net/types/src/dns_node_record.rs +++ b/crates/net/types/src/dns_node_record.rs @@ -78,7 +78,11 @@ impl FromStr for DNSNodeRecord { fn from_str(s: &str) -> Result { use url::Url; - let url = Url::parse(s).map_err(|e| NodeRecordParseError::InvalidUrl(e.to_string()))?; + // Parse the URL with enode prefix replaced with http. + // The enode prefix causes the parser to use parse_opaque() on + // the host str which only handles domains and ipv6, not ipv4. + let url = Url::parse(s.replace("enode://", "http://").as_str()) + .map_err(|e| NodeRecordParseError::InvalidUrl(e.to_string()))?; let host = url .host()