chore: waku_discv5, peer_manager - add more logs help debug discovery issues (#2705)

This commit is contained in:
Ivan FB 2024-05-16 22:30:51 +02:00 committed by GitHub
parent 78132dc12e
commit 401630ee24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 4 deletions

View File

@ -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

View File

@ -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",