Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit 5325cc4

Browse files
committed
p2p/server: add DNS resolved candidates to distributed hash table
Currently, DNS resolved candidates of a eth protocol are added as candidates for dialing but not added to DHT. The DHT's seed nodes are still configured via hardcoded nodes in bootnodes flag. As we want to replace the hardcoded bootnodes entirely with DNS resolved nodes, we resolve some nodes from the DNS discovery URL and put them into DHT when setting up the p2p discovery.
1 parent 800ec03 commit 5325cc4

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

cmd/ronin/les_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func startGethWithIpc(t *testing.T, name string, args ...string) *gethrpc {
141141
// We can't know exactly how long geth will take to start, so we try 10
142142
// times over a 5 second period.
143143
var err error
144-
for i := 0; i < 10; i++ {
144+
for i := 0; i < 30; i++ {
145145
time.Sleep(500 * time.Millisecond)
146146
if g.rpc, err = rpc.Dial(ipcpath); err == nil {
147147
return g

eth/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
319319

320320
// Setup DNS discovery iterators.
321321
dnsclient := dnsdisc.NewClient(dnsdisc.Config{})
322+
log.Info("DNS url", "eth", eth.config.EthDiscoveryURLs, "snap", eth.config.SnapDiscoveryURLs)
322323
eth.ethDialCandidates, err = dnsclient.NewIterator(eth.config.EthDiscoveryURLs...)
323324
if err != nil {
324325
return nil, err

p2p/server.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ const (
6262

6363
// Maximum amount of time allowed for writing a complete message.
6464
frameWriteTimeout = 20 * time.Second
65+
66+
// The number of DHT seed nodes got from DNS resolve
67+
numSeedNodesFromDns = 5
68+
69+
// Name of eth protocol
70+
ethProtocolName = "eth"
6571
)
6672

6773
var errServerStopped = errors.New("server stopped")
@@ -539,6 +545,21 @@ func (srv *Server) setupDiscovery() error {
539545
added := make(map[string]bool)
540546
for _, proto := range srv.Protocols {
541547
if proto.DialCandidates != nil && !added[proto.Name] {
548+
// If the protocol is eth, the dial candidates are retrieved from
549+
// DNS URL. We want to use the DNS discovery for bootstrap nodes
550+
// too, so resolve some node from DNS and add to DHT.
551+
if proto.Name == ethProtocolName {
552+
for i := 0; i < numSeedNodesFromDns; i++ {
553+
if !proto.DialCandidates.Next() {
554+
break
555+
}
556+
557+
node := proto.DialCandidates.Node()
558+
srv.BootstrapNodes = append(srv.BootstrapNodes, node)
559+
srv.BootstrapNodesV5 = append(srv.BootstrapNodes, node)
560+
}
561+
}
562+
542563
srv.discmix.AddSource(proto.DialCandidates)
543564
added[proto.Name] = true
544565
}

0 commit comments

Comments
 (0)