Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions waku/discovery/waku_discv5.nim
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR...but what if ENR has been updated, in that case do we update the ENR stored and peers capabilities locally?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR...but what if ENR has been updated, in that case do we update the ENR stored and peers capabilities locally?

The local peer store only gets new entries when a new connections is established

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, where is the ENR record stored for a peer? Is it part of peerStore or somewhere else?

remote_peer_id = $remotePeerInfo.peerId
return

trace "Adding peer to manager",
Expand Down
Loading