fix: avoid segfault by setting a default num peers requested in PX (#3122)

This commit is contained in:
gabrielmer 2024-10-16 17:04:27 +03:00 committed by GitHub
parent 3321fd05e7
commit 82fd5dde61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -414,7 +414,9 @@ proc startNode*(
# retrieve px peers and add the to the peer store
if conf.peerExchangeNode != "":
let desiredOutDegree = node.wakuRelay.parameters.d.uint64()
var desiredOutDegree = DefaultPXNumPeersReq
if not node.wakuRelay.isNil() and node.wakuRelay.parameters.d.uint64() > 0:
desiredOutDegree = node.wakuRelay.parameters.d.uint64()
(await node.fetchPeerExchangePeers(desiredOutDegree)).isOkOr:
error "error while fetching peers from peer exchange", error = error
quit(QuitFailure)

View File

@ -35,6 +35,7 @@ const
# TODO what is the expected size of a PX message? As currently specified, it can contain an arbitary number of ENRs...
MaxPeersCacheSize = 60
CacheRefreshInterval = 10.minutes
DefaultPXNumPeersReq* = 5.uint64()
WakuPeerExchangeCodec* = "/vac/waku/peer-exchange/2.0.0-alpha1"
@ -57,7 +58,7 @@ type
requestRateLimiter*: RequestRateLimiter
proc request*(
wpx: WakuPeerExchange, numPeers: uint64, conn: Connection
wpx: WakuPeerExchange, numPeers = DefaultPXNumPeersReq, conn: Connection
): Future[WakuPeerExchangeResult[PeerExchangeResponse]] {.async: (raises: []).} =
let rpc = PeerExchangeRpc.makeRequest(numPeers)
@ -99,7 +100,7 @@ proc request*(
return ok(decodedBuff.get().response)
proc request*(
wpx: WakuPeerExchange, numPeers: uint64, peer: RemotePeerInfo
wpx: WakuPeerExchange, numPeers = DefaultPXNumPeersReq, peer: RemotePeerInfo
): Future[WakuPeerExchangeResult[PeerExchangeResponse]] {.async: (raises: []).} =
try:
let connOpt = await wpx.peerManager.dialPeer(peer, WakuPeerExchangeCodec)
@ -120,7 +121,7 @@ proc request*(
)
proc request*(
wpx: WakuPeerExchange, numPeers: uint64
wpx: WakuPeerExchange, numPeers = DefaultPXNumPeersReq
): Future[WakuPeerExchangeResult[PeerExchangeResponse]] {.async: (raises: []).} =
let peerOpt = wpx.peerManager.selectPeer(WakuPeerExchangeCodec)
if peerOpt.isNone():