mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-18 04:41:36 +00:00
cmd/devp2p/v5test: prefill FindnodeResults bystanders
This commit is contained in:
parent
827689c146
commit
e61598bd6f
1 changed files with 23 additions and 7 deletions
|
|
@ -263,13 +263,23 @@ that they are returned by FINDNODE.`)
|
||||||
defer nodes[i].close()
|
defer nodes[i].close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prefill each bystander with the full bystander set so background FINDNODE
|
||||||
|
// lookups see useful routing data instead of empty responses.
|
||||||
|
known := make([]*enode.Node, 0, len(nodes))
|
||||||
|
for _, bn := range nodes {
|
||||||
|
known = append(known, bn.conn.localNode.Node())
|
||||||
|
}
|
||||||
|
for _, bn := range nodes {
|
||||||
|
bn.known = append([]*enode.Node(nil), known...)
|
||||||
|
}
|
||||||
|
|
||||||
// Wait until enough bystanders have actually become live, i.e. the remote node
|
// Wait until enough bystanders have actually become live, i.e. the remote node
|
||||||
// has revalidated them by sending PING and receiving our PONG.
|
// has revalidated them by sending PING and receiving our PONG.
|
||||||
const minLiveNodes = 3
|
requiredLiveNodes := len(nodes)
|
||||||
timeout := 60 * time.Second
|
timeout := 60 * time.Second
|
||||||
timeoutCh := time.After(timeout)
|
timeoutCh := time.After(timeout)
|
||||||
liveSet := make(map[enode.ID]*enode.Node)
|
liveSet := make(map[enode.ID]*enode.Node)
|
||||||
for len(liveSet) < minLiveNodes {
|
for len(liveSet) < requiredLiveNodes {
|
||||||
select {
|
select {
|
||||||
case id := <-liveCh:
|
case id := <-liveCh:
|
||||||
for _, bn := range nodes {
|
for _, bn := range nodes {
|
||||||
|
|
@ -280,11 +290,11 @@ that they are returned by FINDNODE.`)
|
||||||
}
|
}
|
||||||
t.Logf("bystander node %v became live", id)
|
t.Logf("bystander node %v became live", id)
|
||||||
case <-timeoutCh:
|
case <-timeoutCh:
|
||||||
t.Errorf("remote revalidated %d bystander nodes in %v, need %d to continue", len(liveSet), timeout, minLiveNodes)
|
t.Errorf("remote revalidated %d bystander nodes in %v, need %d to continue", len(liveSet), timeout, requiredLiveNodes)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.Logf("continuing after %d bystander nodes became live", len(liveSet))
|
t.Logf("continuing after all %d bystander nodes became live", len(liveSet))
|
||||||
|
|
||||||
// Collect live nodes by distance.
|
// Collect live nodes by distance.
|
||||||
var dists []uint
|
var dists []uint
|
||||||
|
|
@ -332,9 +342,10 @@ that they are returned by FINDNODE.`)
|
||||||
|
|
||||||
// A bystander is a node whose only purpose is filling a spot in the remote table.
|
// A bystander is a node whose only purpose is filling a spot in the remote table.
|
||||||
type bystander struct {
|
type bystander struct {
|
||||||
dest *enode.Node
|
dest *enode.Node
|
||||||
conn *conn
|
conn *conn
|
||||||
l net.PacketConn
|
l net.PacketConn
|
||||||
|
known []*enode.Node
|
||||||
|
|
||||||
liveCh chan enode.ID
|
liveCh chan enode.ID
|
||||||
sent map[v5wire.Nonce]v5wire.Packet
|
sent map[v5wire.Nonce]v5wire.Packet
|
||||||
|
|
@ -404,6 +415,11 @@ func (bn *bystander) loop() {
|
||||||
bn.notifyLive()
|
bn.notifyLive()
|
||||||
case *v5wire.Findnode:
|
case *v5wire.Findnode:
|
||||||
resp := &v5wire.Nodes{ReqID: append([]byte(nil), p.ReqID...), RespCount: 1}
|
resp := &v5wire.Nodes{ReqID: append([]byte(nil), p.ReqID...), RespCount: 1}
|
||||||
|
for _, n := range bn.known {
|
||||||
|
if slices.Contains(p.Distances, uint(enode.LogDist(n.ID(), bn.id()))) {
|
||||||
|
resp.Nodes = append(resp.Nodes, n.Record())
|
||||||
|
}
|
||||||
|
}
|
||||||
nonce := bn.conn.writeTo(bn.l, resp, nil, from)
|
nonce := bn.conn.writeTo(bn.l, resp, nil, from)
|
||||||
bn.sent[nonce] = resp
|
bn.sent[nonce] = resp
|
||||||
case *v5wire.TalkRequest:
|
case *v5wire.TalkRequest:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue