Avoid dialing peers that will be connection limited by libp2p
This commit is contained in:
parent
3076f5c3b6
commit
adcae8d416
|
@ -19,6 +19,7 @@ import
|
||||||
libp2p/protocols/pubsub/[pubsub, gossipsub, rpc/message, rpc/messages],
|
libp2p/protocols/pubsub/[pubsub, gossipsub, rpc/message, rpc/messages],
|
||||||
libp2p/transports/tcptransport,
|
libp2p/transports/tcptransport,
|
||||||
libp2p/stream/connection,
|
libp2p/stream/connection,
|
||||||
|
libp2p/utils/semaphore,
|
||||||
eth/[keys, async_utils], eth/p2p/p2p_protocol_dsl,
|
eth/[keys, async_utils], eth/p2p/p2p_protocol_dsl,
|
||||||
eth/net/nat, eth/p2p/discoveryv5/[enr, node],
|
eth/net/nat, eth/p2p/discoveryv5/[enr, node],
|
||||||
".."/[
|
".."/[
|
||||||
|
@ -853,7 +854,11 @@ proc connectWorker(node: Eth2Node, index: int) {.async.} =
|
||||||
# This loop will never produce HIGH CPU usage because it will wait
|
# This loop will never produce HIGH CPU usage because it will wait
|
||||||
# and block until it not obtains new peer from the queue ``connQueue``.
|
# and block until it not obtains new peer from the queue ``connQueue``.
|
||||||
let remotePeerAddr = await node.connQueue.popFirst()
|
let remotePeerAddr = await node.connQueue.popFirst()
|
||||||
await node.dialPeer(remotePeerAddr, index)
|
# Previous worker dial might have hit the maximum peers.
|
||||||
|
# TODO: could clear the whole connTable and connQueue here also, best
|
||||||
|
# would be to have this event based coming from peer pool or libp2p.
|
||||||
|
if node.switch.connManager.outSema.count > 0:
|
||||||
|
await node.dialPeer(remotePeerAddr, index)
|
||||||
# Peer was added to `connTable` before adding it to `connQueue`, so we
|
# Peer was added to `connTable` before adding it to `connQueue`, so we
|
||||||
# excluding peer here after processing.
|
# excluding peer here after processing.
|
||||||
node.connTable.excl(remotePeerAddr.peerId)
|
node.connTable.excl(remotePeerAddr.peerId)
|
||||||
|
@ -868,7 +873,7 @@ proc runDiscoveryLoop*(node: Eth2Node) {.async.} =
|
||||||
let enrField = ("eth2", SSZ.encode(node.forkId))
|
let enrField = ("eth2", SSZ.encode(node.forkId))
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
if node.peerPool.lenSpace({PeerType.Outgoing}) > 0:
|
if node.switch.connManager.outSema.count > 0:
|
||||||
var discoveredNodes = await node.discovery.queryRandom(enrField)
|
var discoveredNodes = await node.discovery.queryRandom(enrField)
|
||||||
var newPeers = 0
|
var newPeers = 0
|
||||||
for discNode in discoveredNodes:
|
for discNode in discoveredNodes:
|
||||||
|
|
Loading…
Reference in New Issue