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

@ -1126,7 +1126,7 @@ method rpcHandler*(g: GossipSub,
let msgId = g.msgIdProvider(msg) let msgId = g.msgIdProvider(msg)
if g.seen.put(msgId): 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 # make sure to update score tho before continuing
for t in msg.topicIDs: # for every topic in the message 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(): if (msg.signature.len > 0 or g.verifySignature) and not msg.verify():
# always validate if signature is present or required # 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) g.punishPeer(peer, msg.topicIDs)
continue continue
if msg.seqno.len > 0 and msg.seqno.len != 8: if msg.seqno.len > 0 and msg.seqno.len != 8:
# if we have seqno should be 8 bytes long # 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) g.punishPeer(peer, msg.topicIDs)
continue continue
@ -1170,11 +1172,13 @@ method rpcHandler*(g: GossipSub,
let validation = await g.validate(msg) let validation = await g.validate(msg)
case validation case validation
of ValidationResult.Reject: 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) g.punishPeer(peer, msg.topicIDs)
continue continue
of ValidationResult.Ignore: of ValidationResult.Ignore:
debug "Dropping message after validation, reason: ignore", msgId, peer debug "Dropping message after validation, reason: ignore",
msgId = shortLog(msgId), peer
continue continue
of ValidationResult.Accept: of ValidationResult.Accept:
discard discard
@ -1215,7 +1219,8 @@ method rpcHandler*(g: GossipSub,
# In theory, if topics are the same in all messages, we could batch - we'd # 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 # also have to be careful to only include validated messages
g.broadcast(toSeq(toSendPeers), RPCMsg(messages: @[msg])) 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() libp2p_pubsub_messages_rebroadcasted.inc()
if rpcMsg.control.isSome: if rpcMsg.control.isSome:
@ -1339,7 +1344,7 @@ method publish*(g: GossipSub,
Message.init(some(g.peerInfo), data, topic, some(g.msgSeqno), g.sign) Message.init(some(g.peerInfo), data, topic, some(g.msgSeqno), g.sign)
msgId = g.msgIdProvider(msg) msgId = g.msgIdProvider(msg)
logScope: msgId logScope: msgId = shortLog(msgId)
trace "Created new message", msg = shortLog(msg), peers = peers.len trace "Created new message", msg = shortLog(msg), peers = peers.len