Skip to content

Commit 6b61b54

Browse files
authored
p2p/discover: add config option for disabling FINDNODE liveness check (#30512)
This is for fixing Prysm integration tests.
1 parent 283be23 commit 6b61b54

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

p2p/discover/common.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ type Config struct {
5353
Unhandled chan<- ReadPacket // unhandled packets are sent on this channel
5454

5555
// Node table configuration:
56-
Bootnodes []*enode.Node // list of bootstrap nodes
57-
PingInterval time.Duration // speed of node liveness check
58-
RefreshInterval time.Duration // used in bucket refresh
56+
Bootnodes []*enode.Node // list of bootstrap nodes
57+
PingInterval time.Duration // speed of node liveness check
58+
RefreshInterval time.Duration // used in bucket refresh
59+
NoFindnodeLivenessCheck bool // turns off validation of table nodes in FINDNODE handler
5960

6061
// The options below are useful in very specific cases, like in unit tests.
6162
V5ProtocolID *[6]byte

p2p/discover/table.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ func (tab *Table) findnodeByID(target enode.ID, nresults int, preferLive bool) *
268268
return nodes
269269
}
270270

271-
// appendLiveNodes adds nodes at the given distance to the result slice.
271+
// appendBucketNodes adds nodes at the given distance to the result slice.
272272
// This is used by the FINDNODE/v5 handler.
273-
func (tab *Table) appendLiveNodes(dist uint, result []*enode.Node) []*enode.Node {
273+
func (tab *Table) appendBucketNodes(dist uint, result []*enode.Node, checkLive bool) []*enode.Node {
274274
if dist > 256 {
275275
return result
276276
}
@@ -280,7 +280,7 @@ func (tab *Table) appendLiveNodes(dist uint, result []*enode.Node) []*enode.Node
280280

281281
tab.mutex.Lock()
282282
for _, n := range tab.bucketAtDistance(int(dist)).entries {
283-
if n.isValidatedLive {
283+
if !checkLive || n.isValidatedLive {
284284
result = append(result, n.Node)
285285
}
286286
}

p2p/discover/v4_udp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,8 @@ func (t *UDPv4) handleFindnode(h *packetHandlerV4, from netip.AddrPort, fromID e
746746

747747
// Determine closest nodes.
748748
target := enode.ID(crypto.Keccak256Hash(req.Target[:]))
749-
closest := t.tab.findnodeByID(target, bucketSize, true).entries
749+
preferLive := !t.tab.cfg.NoFindnodeLivenessCheck
750+
closest := t.tab.findnodeByID(target, bucketSize, preferLive).entries
750751

751752
// Send neighbors in chunks with at most maxNeighbors per packet
752753
// to stay below the packet size limit.

p2p/discover/v5_udp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,8 @@ func (t *UDPv5) collectTableNodes(rip netip.Addr, distances []uint, limit int) [
862862
}
863863
processed[dist] = struct{}{}
864864

865-
for _, n := range t.tab.appendLiveNodes(dist, bn[:0]) {
865+
checkLive := !t.tab.cfg.NoFindnodeLivenessCheck
866+
for _, n := range t.tab.appendBucketNodes(dist, bn[:0], checkLive) {
866867
// Apply some pre-checks to avoid sending invalid nodes.
867868
// Note liveness is checked by appendLiveNodes.
868869
if netutil.CheckRelayAddr(rip, n.IPAddr()) != nil {

0 commit comments

Comments
 (0)