Skip to content

Commit e6632af

Browse files
committed
p2p/enode: add back DNS hostname resolution at parsing time
- removed in ethereum/go-ethereum#30822 in favor of on-demand runtime dialling - reported to have removed bootnodes DNS resolution at ethereum/go-ethereum#31208 - possibly broke DNS resolution for other methods of adding peers
1 parent e136827 commit e6632af

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

p2p/enode/urlv4.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ import (
3131
"github.com/ethereum/go-ethereum/p2p/enr"
3232
)
3333

34-
var (
35-
incompleteNodeURL = regexp.MustCompile("(?i)^(?:enode://)?([0-9a-f]+)$")
36-
)
34+
var incompleteNodeURL = regexp.MustCompile("(?i)^(?:enode://)?([0-9a-f]+)$")
3735

3836
// MustParseV4 parses a node URL. It panics if the URL is not valid.
3937
func MustParseV4(rawurl string) *Node {
@@ -128,6 +126,23 @@ func parseComplete(rawurl string) (*Node, error) {
128126

129127
// Parse the IP and ports.
130128
ip := net.ParseIP(u.Hostname())
129+
130+
// OP-Stack diff: add back DNS hostname resolution at parsing time
131+
// - removed in https://github.com/ethereum/go-ethereum/pull/30822 in favor of on-demand runtime dialling
132+
// - reported to have removed bootnodes DNS resolution at https://github.com/ethereum/go-ethereum/issues/31208
133+
// - possibly broke DNS resolution for other methods of adding peers
134+
if ip == nil {
135+
ips, err := net.LookupIP(u.Hostname())
136+
if err != nil {
137+
return nil, err
138+
}
139+
ip = ips[0]
140+
}
141+
// Ensure the IP is 4 bytes long for IPv4 addresses.
142+
if ipv4 := ip.To4(); ipv4 != nil {
143+
ip = ipv4
144+
}
145+
131146
if tcpPort, err = strconv.ParseUint(u.Port(), 10, 16); err != nil {
132147
return nil, errors.New("invalid port")
133148
}
@@ -142,7 +157,7 @@ func parseComplete(rawurl string) (*Node, error) {
142157

143158
// Create the node.
144159
node := NewV4(id, ip, int(tcpPort), int(udpPort))
145-
if ip == nil && u.Hostname() != "" {
160+
if u.Hostname() != "" {
146161
node = node.WithHostname(u.Hostname())
147162
}
148163
return node, nil

0 commit comments

Comments
 (0)