Skip to content

Commit

Permalink
fix(p2p): fix possible connectivity issue (#1996)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrevuelta committed Sep 8, 2023
1 parent fc6194b commit 7d9d8a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions waku/node/peer_manager/peer_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const
ConnectivityLoopInterval = chronos.seconds(15)

# How often the peer store is pruned
PrunePeerStoreInterval = chronos.minutes(5)
PrunePeerStoreInterval = chronos.minutes(10)

# How often metrics and logs are shown/updated
LogAndMetricsInterval = chronos.minutes(3)
Expand Down Expand Up @@ -583,15 +583,16 @@ proc connectToRelayPeers*(pm: PeerManager) {.async.} =
let totalRelayPeers = inRelayPeers.len + outRelayPeers.len
let inPeersTarget = maxConnections - pm.outRelayPeersTarget

if inRelayPeers.len > pm.inRelayPeersTarget:
await pm.pruneInRelayConns(inRelayPeers.len - pm.inRelayPeersTarget)
# TODO: Temporally disabled. Might be causing connection issues
#if inRelayPeers.len > pm.inRelayPeersTarget:
# await pm.pruneInRelayConns(inRelayPeers.len - pm.inRelayPeersTarget)

if outRelayPeers.len >= pm.outRelayPeersTarget:
return

let notConnectedPeers = pm.peerStore.getNotConnectedPeers().mapIt(RemotePeerInfo.init(it.peerId, it.addrs))
let outsideBackoffPeers = notConnectedPeers.filterIt(pm.canBeConnected(it.peerId))
let numPeersToConnect = min(min(maxConnections - totalRelayPeers, outsideBackoffPeers.len), MaxParalelDials)
let numPeersToConnect = min(outsideBackoffPeers.len, MaxParalelDials)

await pm.connectToNodes(outsideBackoffPeers[0..<numPeersToConnect])

Expand Down
2 changes: 1 addition & 1 deletion waku/node/waku_switch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ proc newWakuSwitch*(
if peerStoreCapacity.isSome():
b = b.withPeerStore(peerStoreCapacity.get())
else:
let defaultPeerStoreCapacity = int(round(float64(maxConnections)*1.25))
let defaultPeerStoreCapacity = int(maxConnections)*5
b = b.withPeerStore(defaultPeerStoreCapacity)
if agentString.isSome():
b = b.withAgentVersion(agentString.get())
Expand Down

0 comments on commit 7d9d8a3

Please sign in to comment.