From a1a5f9abaca41ec37ea2c4d6b34b5c4fcecf7591 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 18 Dec 2020 16:14:07 +0100 Subject: [PATCH] nice msgid log formatting (#491) --- libp2p/protocols/pubsub/gossipsub.nim | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index f806782e9..5e75505c0 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -914,14 +914,14 @@ method subscribeTopic*(g: GossipSub, peer topic - # this is a workaround for a race condition + # this is a workaround for a race condition # that can happen if we disconnect the peer very early - # in the future we might use this as a test case + # in the future we might use this as a test case # and eventually remove this workaround if subscribe and peer.peerId notin g.peers: trace "ignoring unknown peer" return - + # Skip floodsub - we don't want it to add the peer to `g.floodsub` procCall PubSub(g).subscribeTopic(topic, subscribe, peer) @@ -1126,7 +1126,7 @@ method rpcHandler*(g: GossipSub, let msgId = g.msgIdProvider(msg) if g.seen.put(msgId): - trace "Dropping already-seen message", msgId, peer + trace "Dropping already-seen message", msgId = shortLog(msgId), peer # make sure to update score tho before continuing for t in msg.topicIDs: # for every topic in the message @@ -1154,13 +1154,15 @@ method rpcHandler*(g: GossipSub, if (msg.signature.len > 0 or g.verifySignature) and not msg.verify(): # always validate if signature is present or required - debug "Dropping message due to failed signature verification", msgId, peer + debug "Dropping message due to failed signature verification", + msgId = shortLog(msgId), peer g.punishPeer(peer, msg.topicIDs) continue if msg.seqno.len > 0 and msg.seqno.len != 8: # if we have seqno should be 8 bytes long - debug "Dropping message due to invalid seqno length", msgId, peer + debug "Dropping message due to invalid seqno length", + msgId = shortLog(msgId), peer g.punishPeer(peer, msg.topicIDs) continue @@ -1170,11 +1172,13 @@ method rpcHandler*(g: GossipSub, let validation = await g.validate(msg) case validation of ValidationResult.Reject: - debug "Dropping message after validation, reason: reject", msgId, peer + debug "Dropping message after validation, reason: reject", + msgId = shortLog(msgId), peer g.punishPeer(peer, msg.topicIDs) continue of ValidationResult.Ignore: - debug "Dropping message after validation, reason: ignore", msgId, peer + debug "Dropping message after validation, reason: ignore", + msgId = shortLog(msgId), peer continue of ValidationResult.Accept: discard @@ -1215,7 +1219,8 @@ method rpcHandler*(g: GossipSub, # In theory, if topics are the same in all messages, we could batch - we'd # also have to be careful to only include validated messages g.broadcast(toSeq(toSendPeers), RPCMsg(messages: @[msg])) - trace "forwared message to peers", peers = toSendPeers.len, msgId, peer + trace "forwared message to peers", peers = toSendPeers.len, + msgId = shortLog(msgId), peer libp2p_pubsub_messages_rebroadcasted.inc() if rpcMsg.control.isSome: @@ -1339,7 +1344,7 @@ method publish*(g: GossipSub, Message.init(some(g.peerInfo), data, topic, some(g.msgSeqno), g.sign) msgId = g.msgIdProvider(msg) - logScope: msgId + logScope: msgId = shortLog(msgId) trace "Created new message", msg = shortLog(msg), peers = peers.len