mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
p2p/simulations: track all connections in on snapshot loading
This commit is contained in:
parent
49ca919900
commit
cad2a699ea
1 changed files with 11 additions and 6 deletions
|
|
@ -736,8 +736,9 @@ func (net *Network) Load(snap *Snapshot) error {
|
||||||
|
|
||||||
// Expected number of connections.
|
// Expected number of connections.
|
||||||
total := len(snap.Conns)
|
total := len(snap.Conns)
|
||||||
// counter tracks the current number of connections.
|
// Set of all established connections from the snapshot, not other connections.
|
||||||
var counter int
|
// Key array element 0 is the connection One field value, and element 1 connection Other field.
|
||||||
|
connections := make(map[[2]enode.ID]struct{}, total)
|
||||||
|
|
||||||
// once is a closed channel that is read in the event loop below
|
// once is a closed channel that is read in the event loop below
|
||||||
// only once.
|
// only once.
|
||||||
|
|
@ -755,16 +756,20 @@ func (net *Network) Load(snap *Snapshot) error {
|
||||||
if e.Type != EventTypeConn {
|
if e.Type != EventTypeConn {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Detect only "connect" events of all connection events.
|
connection := [2]enode.ID{e.Conn.One, e.Conn.Other}
|
||||||
|
// Nodes are still not connected or have been disconnected.
|
||||||
if !e.Conn.Up {
|
if !e.Conn.Up {
|
||||||
|
// Delete the connection from the set of established connections.
|
||||||
|
// This will prevent false positive in case disconnections happen.
|
||||||
|
delete(connections, connection)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Check that the connection is from the snapshot.
|
// Check that the connection is from the snapshot.
|
||||||
for _, conn := range snap.Conns {
|
for _, conn := range snap.Conns {
|
||||||
if conn.One == e.Conn.One && conn.Other == e.Conn.Other {
|
if conn.One == e.Conn.One && conn.Other == e.Conn.Other {
|
||||||
counter++
|
// Add the connection to the set of established connections.
|
||||||
|
connections[connection] = struct{}{}
|
||||||
if counter == total {
|
if len(connections) == total {
|
||||||
// Signal that all nodes are connected.
|
// Signal that all nodes are connected.
|
||||||
close(allConnected)
|
close(allConnected)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue