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: [DEBUG] using custom nim-libp2p version with onRecvAndValidated observers #2911

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
path = vendor/nim-libp2p
url = https://github.com/vacp2p/nim-libp2p.git
ignore = dirty
branch = master
branch = enhance-logs-for-nwaku
[submodule "vendor/nim-stew"]
path = vendor/nim-stew
url = https://github.com/status-im/nim-stew.git
Expand Down
2 changes: 1 addition & 1 deletion waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ proc registerRelayDefaultHandler(node: WakuNode, topic: PubsubTopic) =
let defaultHandler = proc(
topic: PubsubTopic, msg: WakuMessage
): Future[void] {.async, gcsafe.} =
await traceHandler(topic, msg)
#await traceHandler(topic, msg)
await filterHandler(topic, msg)
await archiveHandler(topic, msg)

Expand Down
53 changes: 42 additions & 11 deletions waku/waku_relay/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,32 @@ proc initRelayMetricObserver(w: WakuRelay) =
return ok((msg_id_short, msg.topic, wakuMessage, msgSize))

proc logMessageInfo(
peer: PubSubPeer, topic: string, msg_id_short: string, msg: WakuMessage
peer: PubSubPeer,
topic: string,
msg_id_short: string,
msg: WakuMessage,
onRecv: bool,
) =
let msg_hash = computeMessageHash(topic, msg).to0xHex()

notice "sent relay message",
my_peer_id = w.switch.peerInfo.peerId,
msg_hash = msg_hash,
msg_id = msg_id_short,
to_peer_id = peer.peerId,
topic = topic,
sentTime = getNowInNanosecondTime(),
payloadSizeBytes = msg.payload.len
if onRecv:
notice "received relay message",
my_peer_id = w.switch.peerInfo.peerId,
msg_hash = msg_hash,
msg_id = msg_id_short,
from_peer_id = peer.peerId,
topic = topic,
receivedTime = getNowInNanosecondTime(),
payloadSizeBytes = msg.payload.len
else:
notice "sent relay message",
my_peer_id = w.switch.peerInfo.peerId,
msg_hash = msg_hash,
msg_id = msg_id_short,
to_peer_id = peer.peerId,
topic = topic,
sentTime = getNowInNanosecondTime(),
payloadSizeBytes = msg.payload.len

proc updateMetrics(
peer: PubSubPeer,
Expand All @@ -212,14 +226,31 @@ proc initRelayMetricObserver(w: WakuRelay) =
updateMetrics(peer, topic, wakuMessage, msgSize, onRecv = true)
discard

proc onRecvAndValidated(peer: PubSubPeer, msg: Message, msgId: MessageId) =
let msg_id_short = shortLog(msgId)
let wakuMessage = WakuMessage.decode(msg.data).valueOr:
warn "onRecvAndValidated: failed decoding to Waku Message",
my_peer_id = w.switch.peerInfo.peerId,
msg_id = msg_id_short,
from_peer_id = peer.peerId,
pubsub_topic = msg.topic,
error = $error
return

logMessageInfo(peer, msg.topic, msg_id_short, wakuMessage, onRecv = true)

proc onSend(peer: PubSubPeer, msgs: var RPCMsg) =
for msg in msgs.messages:
let (msg_id_short, topic, wakuMessage, msgSize) = decodeRpcMessageInfo(peer, msg).valueOr:
warn "onSend: failed decoding RPC info",
my_peer_id = w.switch.peerInfo.peerId, to_peer_id = peer.peerId
continue
logMessageInfo(peer, topic, msg_id_short, wakuMessage)
logMessageInfo(peer, topic, msg_id_short, wakuMessage, onRecv = false)
updateMetrics(peer, topic, wakuMessage, msgSize, onRecv = false)

let administrativeObserver = PubSubObserver(onRecv: onRecv, onSend: onSend)
let administrativeObserver = PubSubObserver(
onRecv: onRecv, onSend: onSend, onRecvAndValidated: onRecvAndValidated
)

w.addObserver(administrativeObserver)

Expand Down
Loading