Skip to content

Commit

Permalink
chore: waku_discv5, peer_manager - add more logs help debug discovery…
Browse files Browse the repository at this point in the history
… issues (#2705)
  • Loading branch information
Ivansete-status authored May 16, 2024
1 parent 78132dc commit 401630e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
22 changes: 20 additions & 2 deletions waku/discovery/waku_discv5.nim
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,26 @@ proc searchLoop(wd: WakuDiscoveryV5) {.async.} =
while wd.listening:
trace "running discv5 discovery loop"
let discoveredRecords = await wd.findRandomPeers()
let discoveredPeers =
discoveredRecords.mapIt(it.toRemotePeerInfo()).filterIt(it.isOk()).mapIt(it.value)

var discoveredPeers: seq[RemotePeerInfo]
var wrongRecordsReasons: seq[tuple[record: string, errorDescription: string]]
## this is to store the reasons why certain records could not be converted to RemotePeerInfo

for record in discoveredRecords:
let peerInfo = record.toRemotePeerInfo().valueOr:
## in case of error, we keep track of it for debugging purposes
wrongRecordsReasons.add(($record, $error))
continue

discoveredPeers.add(peerInfo)

trace "discv5 discovered peers",
num_discovered_peers = discoveredPeers.len,
peers = toSeq(discoveredPeers.mapIt(shortLog(it.peerId)))

trace "discv5 discarded wrong records",
wrong_records =
wrongRecordsReasons.mapIt("(" & it.record & "," & it.errorDescription & ")")

for peer in discoveredPeers:
# Peers added are filtered by the peer manager
Expand Down
5 changes: 3 additions & 2 deletions waku/node/peer_manager/peer_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ proc addPeer*(pm: PeerManager, remotePeerInfo: RemotePeerInfo, origin = UnknownO
## Adds peer to manager for the specified protocol

if remotePeerInfo.peerId == pm.switch.peerInfo.peerId:
# Do not attempt to manage our unmanageable self
trace "skipping to manage our unmanageable self"
return

if pm.peerStore[AddressBook][remotePeerInfo.peerId] == remotePeerInfo.addrs and
pm.peerStore[KeyBook][remotePeerInfo.peerId] == remotePeerInfo.publicKey and
pm.peerStore[ENRBook][remotePeerInfo.peerId].raw.len > 0:
# Peer already managed and ENR info is already saved
trace "peer already managed and ENR info is already saved",
remote_peer_id = $remotePeerInfo.peerId
return

trace "Adding peer to manager",
Expand Down

0 comments on commit 401630e

Please sign in to comment.