chore: print the full peerId in the logs

This commit is contained in:
Richard Ramos 2023-11-30 09:03:19 -04:00
parent 72a1f8c724
commit f664229bb4
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
8 changed files with 53 additions and 53 deletions

View File

@ -125,7 +125,7 @@ proc addPeer*(pm: PeerManager, remotePeerInfo: RemotePeerInfo, origin = UnknownO
# Peer already managed and ENR info is already saved
return
trace "Adding peer to manager", peerId = remotePeerInfo.peerId, addresses = remotePeerInfo.addrs
trace "Adding peer to manager", peerId = $remotePeerInfo.peerId, addresses = remotePeerInfo.addrs
pm.peerStore[AddressBook][remotePeerInfo.peerId] = remotePeerInfo.addrs
pm.peerStore[KeyBook][remotePeerInfo.peerId] = publicKey
@ -158,7 +158,7 @@ proc connectRelay*(pm: PeerManager,
pm.addPeer(peer)
let failedAttempts = pm.peerStore[NumberFailedConnBook][peerId]
debug "Connecting to relay peer", wireAddr=peer.addrs, peerId=peerId, failedAttempts=failedAttempts
debug "Connecting to relay peer", wireAddr=peer.addrs, peerId= $peerId, failedAttempts=failedAttempts
var deadline = sleepAsync(dialTimeout)
var workfut = pm.switch.connect(peerId, peer.addrs)
@ -210,7 +210,7 @@ proc dialPeer(pm: PeerManager,
error "dial shall not be used to connect to relays"
return none(Connection)
debug "Dialing peer", wireAddr=addrs, peerId=peerId, proto=proto
debug "Dialing peer", wireAddr=addrs, peerId= $peerId, proto=proto
# Dial Peer
let dialFut = pm.switch.dial(peerId, addrs, proto)
@ -224,20 +224,20 @@ proc dialPeer(pm: PeerManager,
except CatchableError as exc:
reasonFailed = "failed"
debug "Dialing peer failed", peerId=peerId, reason=reasonFailed, proto=proto
debug "Dialing peer failed", peerId= $peerId, reason=reasonFailed, proto=proto
return none(Connection)
proc loadFromStorage(pm: PeerManager) =
## Load peers from storage, if available
debug "loading peers from storage"
var amount = 0
proc onData(remotePeerInfo: RemotePeerInfo) =
let peerId = remotePeerInfo.peerId
if pm.switch.peerInfo.peerId == peerId:
# Do not manage self
return
@ -260,7 +260,7 @@ proc loadFromStorage(pm: PeerManager) =
pm.peerStore[ConnectionBook][peerId] = NotConnected # Reset connectedness state
pm.peerStore[DisconnectBook][peerId] = remotePeerInfo.disconnectTime
pm.peerStore[SourceBook][peerId] = remotePeerInfo.origin
if remotePeerInfo.enr.isSome():
pm.peerStore[ENRBook][peerId] = remotePeerInfo.enr.get()
@ -363,7 +363,7 @@ proc onPeerEvent(pm: PeerManager, peerId: PeerId, event: PeerEvent) {.async.} =
clusterOk = true
if not pm.wakuMetadata.isNil() and pm.wakuMetadata.clusterId != 0 and not clusterOk:
info "disconnecting from peer", peerId=peerId, reason=reason
info "disconnecting from peer", peerId= $peerId, reason=reason
asyncSpawn(pm.switch.disconnect(peerId))
pm.peerStore.delete(peerId)
@ -377,7 +377,7 @@ proc onPeerEvent(pm: PeerManager, peerId: PeerId, event: PeerEvent) {.async.} =
if peersBehindIp.len > pm.colocationLimit:
# in theory this should always be one, but just in case
for peerId in peersBehindIp[0..<(peersBehindIp.len - pm.colocationLimit)]:
debug "Pruning connection due to ip colocation", peerId = peerId, ip = ip
debug "Pruning connection due to ip colocation", peerId = $peerId, ip = ip
asyncSpawn(pm.switch.disconnect(peerId))
pm.peerStore.delete(peerId)
@ -498,7 +498,7 @@ proc addServicePeer*(pm: PeerManager, remotePeerInfo: RemotePeerInfo, proto: str
warn "Can't add relay peer to service peers slots"
return
info "Adding peer to service slots", peerId = remotePeerInfo.peerId, addr = remotePeerInfo.addrs[0], service = proto
info "Adding peer to service slots", peerId = $remotePeerInfo.peerId, addr = remotePeerInfo.addrs[0], service = proto
waku_service_peers.set(1, labelValues = [$proto, $remotePeerInfo.addrs[0]])
# Set peer for service slot
@ -518,7 +518,7 @@ proc reconnectPeers*(pm: PeerManager,
for peerInfo in pm.peerStore.peers(protocolMatcher(proto)):
# Check that the peer can be connected
if peerInfo.connectedness == CannotConnect:
debug "Not reconnecting to unreachable or non-existing peer", peerId=peerInfo.peerId
debug "Not reconnecting to unreachable or non-existing peer", peerId= $peerInfo.peerId
continue
# Respect optional backoff period where applicable.
@ -532,7 +532,7 @@ proc reconnectPeers*(pm: PeerManager,
# TODO: This blocks the whole function. Try to connect to another peer in the meantime.
if backoffTime > ZeroDuration:
debug "Backing off before reconnect...", peerId=peerInfo.peerId, backoffTime=backoffTime
debug "Backing off before reconnect...", peerId= $peerInfo.peerId, backoffTime=backoffTime
# We disconnected recently and still need to wait for a backoff period before connecting
await sleepAsync(backoffTime)
@ -705,19 +705,19 @@ proc selectPeer*(pm: PeerManager, proto: string, shard: Option[PubsubTopic] = no
if proto == WakuRelayCodec:
# TODO: proper heuristic here that compares peer scores and selects "best" one. For now the first peer for the given protocol is returned
if peers.len > 0:
debug "Got peer from peerstore", peerId=peers[0].peerId, multi=peers[0].addrs[0], protocol=proto
debug "Got peer from peerstore", peerId= $peers[0].peerId, multi=peers[0].addrs[0], protocol=proto
return some(peers[0])
debug "No peer found for protocol", protocol=proto
return none(RemotePeerInfo)
# For other protocols, we select the peer that is slotted for the given protocol
pm.serviceSlots.withValue(proto, serviceSlot):
debug "Got peer from service slots", peerId=serviceSlot[].peerId, multi=serviceSlot[].addrs[0], protocol=proto
debug "Got peer from service slots", peerId= $serviceSlot[].peerId, multi=serviceSlot[].addrs[0], protocol=proto
return some(serviceSlot[])
# If not slotted, we select a random peer for the given protocol
if peers.len > 0:
debug "Got peer from peerstore", peerId=peers[0].peerId, multi=peers[0].addrs[0], protocol=proto
debug "Got peer from peerstore", peerId= $peers[0].peerId, multi=peers[0].addrs[0], protocol=proto
return some(peers[0])
debug "No peer found for protocol", protocol=proto
return none(RemotePeerInfo)

View File

@ -188,7 +188,7 @@ proc connectToNodes*(node: WakuNode, nodes: seq[RemotePeerInfo] | seq[string], s
proc mountMetadata*(node: WakuNode, clusterId: uint32): Result[void, string] =
if not node.wakuMetadata.isNil():
return err("Waku metadata already mounted, skipping")
let metadata = WakuMetadata.new(clusterId, node.enr, node.topicSubscriptionQueue)
node.wakuMetadata = metadata
@ -544,7 +544,7 @@ proc filterSubscribe*(node: WakuNode,
let remotePeer = remotePeerRes.value
if pubsubTopic.isSome():
info "registering filter subscription to content", pubsubTopic=pubsubTopic.get(), contentTopics=contentTopics, peer=remotePeer.peerId
info "registering filter subscription to content", pubsubTopic=pubsubTopic.get(), contentTopics=contentTopics, peer= $remotePeer.peerId
let subRes = await node.wakuFilterClient.subscribe(remotePeer, pubsubTopic.get(), contentTopics)
if subRes.isOk():
@ -565,7 +565,7 @@ proc filterSubscribe*(node: WakuNode,
var futures = collect(newSeq):
for pubsub, topics in topicMap.pairs:
info "registering filter subscription to content", pubsubTopic=pubsub, contentTopics=topics, peer=remotePeer.peerId
info "registering filter subscription to content", pubsubTopic=pubsub, contentTopics=topics, peer= $remotePeer.peerId
let content = topics.mapIt($it)
node.wakuFilterClient.subscribe(remotePeer, $pubsub, content)
@ -604,7 +604,7 @@ proc legacyFilterUnsubscribe*(node: WakuNode,
let remotePeer = remotePeerRes.value
if pubsubTopic.isSome():
info "deregistering legacy filter subscription to content", pubsubTopic=pubsubTopic.get(), contentTopics=contentTopics, peer=remotePeer.peerId
info "deregistering legacy filter subscription to content", pubsubTopic=pubsubTopic.get(), contentTopics=contentTopics, peer= $remotePeer.peerId
let res = await node.wakuFilterClientLegacy.unsubscribe(pubsubTopic.get(), contentTopics, peer=remotePeer)
@ -624,7 +624,7 @@ proc legacyFilterUnsubscribe*(node: WakuNode,
var futures = collect(newSeq):
for pubsub, topics in topicMap.pairs:
info "deregistering filter subscription to content", pubsubTopic=pubsub, contentTopics=topics, peer=remotePeer.peerId
info "deregistering filter subscription to content", pubsubTopic=pubsub, contentTopics=topics, peer= $remotePeer.peerId
let content = topics.mapIt($it)
node.wakuFilterClientLegacy.unsubscribe($pubsub, content, peer=remotePeer)
@ -662,7 +662,7 @@ proc filterUnsubscribe*(node: WakuNode,
let remotePeer = remotePeerRes.value
if pubsubTopic.isSome():
info "deregistering filter subscription to content", pubsubTopic=pubsubTopic.get(), contentTopics=contentTopics, peer=remotePeer.peerId
info "deregistering filter subscription to content", pubsubTopic=pubsubTopic.get(), contentTopics=contentTopics, peer= $remotePeer.peerId
let unsubRes = await node.wakuFilterClient.unsubscribe(remotePeer, pubsubTopic.get(), contentTopics)
if unsubRes.isOk():
@ -684,7 +684,7 @@ proc filterUnsubscribe*(node: WakuNode,
var futures = collect(newSeq):
for pubsub, topics in topicMap.pairs:
info "deregistering filter subscription to content", pubsubTopic=pubsub, contentTopics=topics, peer=remotePeer.peerId
info "deregistering filter subscription to content", pubsubTopic=pubsub, contentTopics=topics, peer= $remotePeer.peerId
let content = topics.mapIt($it)
node.wakuFilterClient.unsubscribe(remotePeer, $pubsub, content)
@ -724,11 +724,11 @@ proc filterUnsubscribeAll*(node: WakuNode,
let remotePeer = remotePeerRes.value
info "deregistering all filter subscription to content", peer=remotePeer.peerId
info "deregistering all filter subscription to content", peer= $remotePeer.peerId
let unsubRes = await node.wakuFilterClient.unsubscribeAll(remotePeer)
if unsubRes.isOk():
info "unsubscribed from all content-topic", peerId=remotePeer.peerId
info "unsubscribed from all content-topic", peerId= $remotePeer.peerId
else:
error "failed filter unsubscription from all content-topic", error=unsubRes.error
waku_node_errors.inc(labelValues = ["unsubscribe_filter_failure"])
@ -930,7 +930,7 @@ proc lightpushPublish*(node: WakuNode, pubsubTopic: Option[PubsubTopic], message
return err("waku lightpush client is nil")
if pubsubTopic.isSome():
debug "publishing message with lightpush", pubsubTopic=pubsubTopic.get(), contentTopic=message.contentTopic, peer=peer.peerId
debug "publishing message with lightpush", pubsubTopic=pubsubTopic.get(), contentTopic=message.contentTopic, peer= $peer.peerId
return await node.wakuLightpushClient.publish(pubsubTopic.get(), message, peer)
let topicMapRes = parseSharding(pubsubTopic, message.contentTopic)
@ -941,7 +941,7 @@ proc lightpushPublish*(node: WakuNode, pubsubTopic: Option[PubsubTopic], message
else: topicMapRes.get()
for pubsub, _ in topicMap.pairs: # There's only one pair anyway
debug "publishing message with lightpush", pubsubTopic=pubsub, contentTopic=message.contentTopic, peer=peer.peerId
debug "publishing message with lightpush", pubsubTopic=pubsub, contentTopic=message.contentTopic, peer= $peer.peerId
return await node.wakuLightpushClient.publish($pubsub, message, peer)
# TODO: Move to application module (e.g., wakunode2.nim)
@ -1106,7 +1106,7 @@ proc printNodeNetworkInfo*(node: WakuNode): void =
except Exception as e:
warn "Could not retrieve localIp", msg=e.msg
info "PeerInfo", peerId = peerInfo.peerId, addrs = peerInfo.addrs
info "PeerInfo", peerId = $peerInfo.peerId, addrs = peerInfo.addrs
for address in node.announcedAddresses:
var fulladdr = "[" & $address & "/p2p/" & $peerInfo.peerId & "]"

View File

@ -66,7 +66,7 @@ proc initProtocolHandler(wf: WakuFilterClientLegacy) =
requestId = rpc.requestId
push = rpc.push.get()
info "received filter message push", peerId=conn.peerId, requestId=requestId
info "received filter message push", peerId= $conn.peerId, requestId=requestId
wf.handleMessagePush(peerId, requestId, push)
wf.handler = handle

View File

@ -75,10 +75,10 @@ proc handleFilterRequest(wf: WakuFilterLegacy, peerId: PeerId, rpc: FilterRPC) =
contentTopics = rpc.request.get().contentFilters.mapIt(it.contentTopic)
if subscribe:
info "added filter subscritpiton", peerId=peerId, pubsubTopic=pubsubTopic, contentTopics=contentTopics
info "added filter subscription", peerId= $peerId, pubsubTopic=pubsubTopic, contentTopics=contentTopics
wf.subscriptions.addSubscription(peerId, requestId, pubsubTopic, contentTopics)
else:
info "removed filter subscritpiton", peerId=peerId, contentTopics=contentTopics
info "removed filter subscription", peerId= $peerId, contentTopics=contentTopics
wf.subscriptions.removeSubscription(peerId, contentTopics)
waku_legacy_filter_subscribers.set(wf.subscriptions.len.int64)

View File

@ -37,7 +37,7 @@ proc sendSubscribeRequest(wfc: WakuFilterClient, servicePeer: RemotePeerInfo,
filterSubscribeRequest: FilterSubscribeRequest):
Future[FilterSubscribeResult]
{.async.} =
trace "Sending filter subscribe request", peerId=servicePeer.peerId, filterSubscribeRequest
trace "Sending filter subscribe request", peerId= $servicePeer.peerId, filterSubscribeRequest
let connOpt = await wfc.peerManager.dialPeer(servicePeer, WakuFilterSubscribeCodec)
if connOpt.isNone():
@ -132,12 +132,12 @@ proc initProtocolHandler(wfc: WakuFilterClient) =
let decodeRes = MessagePush.decode(buf)
if decodeRes.isErr():
error "Failed to decode message push", peerId=conn.peerId
error "Failed to decode message push", peerId= $conn.peerId
waku_filter_errors.inc(labelValues = [decodeRpcFailure])
return
let messagePush = decodeRes.value #TODO: toAPI() split here
trace "Received message push", peerId=conn.peerId, messagePush
trace "Received message push", peerId= $conn.peerId, messagePush
for handler in wfc.pushHandlers:
asyncSpawn handler(messagePush.pubsubTopic,

View File

@ -34,10 +34,10 @@ type
maintenanceTask: TimerCallback
proc pingSubscriber(wf: WakuFilter, peerId: PeerID): FilterSubscribeResult =
trace "pinging subscriber", peerId=peerId
trace "pinging subscriber", peerId= $peerId
if peerId notin wf.subscriptions:
debug "pinging peer has no subscriptions", peerId=peerId
debug "pinging peer has no subscriptions", peerId= $peerId
return err(FilterSubscribeError.notFound())
ok()
@ -51,7 +51,7 @@ proc subscribe(wf: WakuFilter, peerId: PeerID, pubsubTopic: Option[PubsubTopic],
let filterCriteria = toHashSet(contentTopics.mapIt((pubsubTopic.get(), it)))
trace "subscribing peer to filter criteria", peerId=peerId, filterCriteria=filterCriteria
trace "subscribing peer to filter criteria", peerId= $peerId, filterCriteria=filterCriteria
if peerId in wf.subscriptions:
# We already have a subscription for this peer. Try to add the new filter criteria.
@ -65,7 +65,7 @@ proc subscribe(wf: WakuFilter, peerId: PeerID, pubsubTopic: Option[PubsubTopic],
# We don't have a subscription for this peer yet. Try to add it.
if wf.subscriptions.len() >= MaxTotalSubscriptions:
return err(FilterSubscribeError.serviceUnavailable("node has reached maximum number of subscriptions"))
debug "creating new subscription", peerId=peerId
debug "creating new subscription", peerId= $peerId
wf.subscriptions[peerId] = filterCriteria
ok()
@ -79,10 +79,10 @@ proc unsubscribe(wf: WakuFilter, peerId: PeerID, pubsubTopic: Option[PubsubTopic
let filterCriteria = toHashSet(contentTopics.mapIt((pubsubTopic.get(), it)))
trace "unsubscribing peer from filter criteria", peerId=peerId, filterCriteria=filterCriteria
trace "unsubscribing peer from filter criteria", peerId= $peerId, filterCriteria=filterCriteria
if peerId notin wf.subscriptions:
debug "unsubscribing peer has no subscriptions", peerId=peerId
debug "unsubscribing peer has no subscriptions", peerId= $peerId
return err(FilterSubscribeError.notFound())
var peerSubscription = wf.subscriptions.mgetOrPut(peerId, initHashSet[FilterCriterion]())
@ -94,7 +94,7 @@ proc unsubscribe(wf: WakuFilter, peerId: PeerID, pubsubTopic: Option[PubsubTopic
peerSubscription.excl(filterCriteria)
if peerSubscription.len() == 0:
debug "peer has no more subscriptions, removing subscription", peerId=peerId
debug "peer has no more subscriptions, removing subscription", peerId= $peerId
wf.subscriptions.del(peerId)
else:
wf.subscriptions[peerId] = peerSubscription
@ -103,16 +103,16 @@ proc unsubscribe(wf: WakuFilter, peerId: PeerID, pubsubTopic: Option[PubsubTopic
proc unsubscribeAll(wf: WakuFilter, peerId: PeerID): FilterSubscribeResult =
if peerId notin wf.subscriptions:
debug "unsubscribing peer has no subscriptions", peerId=peerId
debug "unsubscribing peer has no subscriptions", peerId= $peerId
return err(FilterSubscribeError.notFound())
debug "removing peer subscription", peerId=peerId
debug "removing peer subscription", peerId= $peerId
wf.subscriptions.del(peerId)
ok()
proc handleSubscribeRequest*(wf: WakuFilter, peerId: PeerId, request: FilterSubscribeRequest): FilterSubscribeResponse =
info "received filter subscribe request", peerId=peerId, request=request
info "received filter subscribe request", peerId= $peerId, request=request
waku_filter_requests.inc(labelValues = [$request.filterSubscribeType])
var subscribeResult: FilterSubscribeResult
@ -183,7 +183,7 @@ proc maintainSubscriptions*(wf: WakuFilter) =
## TODO: currently we only maintain by syncing with peer store. We could
## consider other metrics, such as subscription age, activity, etc.
if not wf.peerManager.peerStore.hasPeer(peerId, WakuFilterPushCodec):
debug "peer has been removed from peer store, removing subscription", peerId=peerId
debug "peer has been removed from peer store, removing subscription", peerId= $peerId
peersToRemove.add(peerId)
if peersToRemove.len() > 0:
@ -224,13 +224,13 @@ proc handleMessage*(wf: WakuFilter, pubsubTopic: PubsubTopic, message: WakuMessa
proc initProtocolHandler(wf: WakuFilter) =
proc handler(conn: Connection, proto: string) {.async.} =
trace "filter subscribe request handler triggered", peerId=conn.peerId
trace "filter subscribe request handler triggered", peerId= $conn.peerId
let buf = await conn.readLp(MaxSubscribeSize)
let decodeRes = FilterSubscribeRequest.decode(buf)
if decodeRes.isErr():
error "Failed to decode filter subscribe request", peerId=conn.peerId, err=decodeRes.error
error "Failed to decode filter subscribe request", peerId= $conn.peerId, err=decodeRes.error
waku_filter_errors.inc(labelValues = [decodeRpcFailure])
return
@ -238,7 +238,7 @@ proc initProtocolHandler(wf: WakuFilter) =
let response = wf.handleSubscribeRequest(conn.peerId, request)
debug "sending filter subscribe response", peerId=conn.peerId, response=response
debug "sending filter subscribe response", peerId= $conn.peerId, response=response
await conn.writeLp(response.encode().buffer) #TODO: toRPC() separation here
return

View File

@ -35,7 +35,7 @@ type
peerManager*: PeerManager
pushHandler*: PushMessageHandler
proc handleRequest*(wl: WakuLightPush, peerId: PeerId, buffer: seq[byte]): Future[PushRPC] {.async.} =
proc handleRequest*(wl: WakuLightPush, peerId: PeerId, buffer: seq[byte]): Future[PushRPC] {.async.} =
let reqDecodeRes = PushRPC.decode(buffer)
var
isSuccess = false
@ -57,8 +57,8 @@ proc handleRequest*(wl: WakuLightPush, peerId: PeerId, buffer: seq[byte]): Futur
pubSubTopic = request.get().pubSubTopic
message = request.get().message
waku_lightpush_messages.inc(labelValues = ["PushRequest"])
debug "push request", peerId=peerId, requestId=requestId, pubsubTopic=pubsubTopic
debug "push request", peerId= $peerId, requestId=requestId, pubsubTopic=pubsubTopic
let handleRes = await wl.pushHandler(peerId, pubsubTopic, message)
isSuccess = handleRes.isOk()
pushResponseInfo = (if isSuccess: "OK" else: handleRes.error)

View File

@ -69,7 +69,7 @@ proc initProtocolHandler(ws: WakuStore) =
requestId = reqRpc.requestId
request = reqRpc.query.get().toAPI()
info "received history query", peerId=conn.peerId, requestId=requestId, query=request
info "received history query", peerId= $conn.peerId, requestId=requestId, query=request
waku_store_queries.inc()
var responseRes: HistoryResult
@ -95,7 +95,7 @@ proc initProtocolHandler(ws: WakuStore) =
let response = responseRes.toRPC()
info "sending history response", peerId=conn.peerId, requestId=requestId, messages=response.messages.len
info "sending history response", peerId= $conn.peerId, requestId=requestId, messages=response.messages.len
let rpc = HistoryRPC(requestId: requestId, response: some(response))
await conn.writeLp(rpc.encode().buffer)