mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-09 13:56:23 +00:00
Use async queryRandom instead of inefficient randomNodes to discover nodes (#2211)
This commit is contained in:
parent
67cce36f06
commit
66d8f317cd
@ -14,7 +14,7 @@ type
|
|||||||
PublicKey = keys.PublicKey
|
PublicKey = keys.PublicKey
|
||||||
|
|
||||||
export
|
export
|
||||||
Eth2DiscoveryProtocol, open, start, close, closeWait, randomNodes,
|
Eth2DiscoveryProtocol, open, start, close, closeWait, queryRandom,
|
||||||
updateRecord, results
|
updateRecord, results
|
||||||
|
|
||||||
proc parseBootstrapAddress*(address: TaintedString):
|
proc parseBootstrapAddress*(address: TaintedString):
|
||||||
|
@ -875,10 +875,8 @@ proc runDiscoveryLoop*(node: Eth2Node) {.async.} =
|
|||||||
let enrField = ("eth2", SSZ.encode(node.forkId))
|
let enrField = ("eth2", SSZ.encode(node.forkId))
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
# We always request constant number of peers to avoid problem with
|
if node.peerPool.lenSpace({PeerType.Outgoing}) > 0:
|
||||||
# low amount of returned peers.
|
var discoveredNodes = await node.discovery.queryRandom(enrField)
|
||||||
let discoveredNodes = node.discovery.randomNodes(node.wantedPeers, enrField)
|
|
||||||
|
|
||||||
var newPeers = 0
|
var newPeers = 0
|
||||||
for discNode in discoveredNodes:
|
for discNode in discoveredNodes:
|
||||||
let res = discNode.toPeerAddr()
|
let res = discNode.toPeerAddr()
|
||||||
@ -902,7 +900,7 @@ proc runDiscoveryLoop*(node: Eth2Node) {.async.} =
|
|||||||
debug "Failed to decode discovery's node address",
|
debug "Failed to decode discovery's node address",
|
||||||
node = discnode, errMsg = res.error
|
node = discnode, errMsg = res.error
|
||||||
|
|
||||||
trace "Discovery tick", wanted_peers = node.wantedPeers,
|
debug "Discovery tick", wanted_peers = node.wantedPeers,
|
||||||
space = node.peerPool.shortLogSpace(),
|
space = node.peerPool.shortLogSpace(),
|
||||||
acquired = node.peerPool.shortLogAcquired(),
|
acquired = node.peerPool.shortLogAcquired(),
|
||||||
available = node.peerPool.shortLogAvailable(),
|
available = node.peerPool.shortLogAvailable(),
|
||||||
@ -914,14 +912,9 @@ proc runDiscoveryLoop*(node: Eth2Node) {.async.} =
|
|||||||
if newPeers == 0:
|
if newPeers == 0:
|
||||||
let currentPeers = node.peerPool.lenCurrent()
|
let currentPeers = node.peerPool.lenCurrent()
|
||||||
if currentPeers <= node.wantedPeers shr 2: # 25%
|
if currentPeers <= node.wantedPeers shr 2: # 25%
|
||||||
notice "Peer count low, no new peers discovered",
|
|
||||||
discovered = len(discoveredNodes), new_peers = newPeers,
|
|
||||||
current_peers = currentPeers, wanted_peers = node.wantedPeers
|
|
||||||
elif currentPeers <= node.wantedPeers shr 3: # 12.5 %
|
|
||||||
warn "Peer count low, no new peers discovered",
|
warn "Peer count low, no new peers discovered",
|
||||||
discovered = len(discoveredNodes), new_peers = newPeers,
|
discovered_nodes = len(discoveredNodes), new_peers = newPeers,
|
||||||
current_peers = currentPeers, wanted_peers = node.wantedPeers
|
current_peers = currentPeers, wanted_peers = node.wantedPeers
|
||||||
await sleepAsync(5.seconds)
|
|
||||||
else:
|
else:
|
||||||
await sleepAsync(1.seconds)
|
await sleepAsync(1.seconds)
|
||||||
|
|
||||||
|
2
vendor/nim-eth
vendored
2
vendor/nim-eth
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 8de6bd4f48ee6a0bca8dc3905cf68b4cc29a96d6
|
Subproject commit e25500c9f0597e91979a4c714989abd6e01f70d9
|
Loading…
x
Reference in New Issue
Block a user