nice msgid log formatting (#491)

This commit is contained in:
Jacek Sieka 2020-12-18 16:14:07 +01:00 committed by GitHub
parent 52628d1a2e
commit a1a5f9abac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 10 deletions

View File

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