From 597abddba7cf7c55ef01e4dc42d0d75c834f3592 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 30 Jun 2022 09:56:49 +0200 Subject: [PATCH] don't increase seqno when anonymizing (#734) --- libp2p/protocols/pubsub/floodsub.nim | 14 +++++--------- libp2p/protocols/pubsub/gossipsub.nim | 18 +++++++----------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/libp2p/protocols/pubsub/floodsub.nim b/libp2p/protocols/pubsub/floodsub.nim index 1a573ba28..b1b462ce8 100644 --- a/libp2p/protocols/pubsub/floodsub.nim +++ b/libp2p/protocols/pubsub/floodsub.nim @@ -187,21 +187,17 @@ method publish*(f: FloodSub, debug "No peers for topic, skipping publish", topic return 0 - inc f.msgSeqno let msg = if f.anonymize: Message.init(none(PeerInfo), data, topic, none(uint64), false) else: + inc f.msgSeqno Message.init(some(f.peerInfo), data, topic, some(f.msgSeqno), f.sign) - msgIdResult = f.msgIdProvider(msg) - - if msgIdResult.isErr: - trace "Error generating message id, skipping publish", - error = msgIdResult.error - return 0 - - let msgId = msgIdResult.get + msgId = f.msgIdProvider(msg).valueOr: + trace "Error generating message id, skipping publish", + error = error + return 0 trace "Created new message", msg = shortLog(msg), peers = peers.len, topic, msgId diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index 5f94f2f65..797572184 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -506,7 +506,7 @@ method publish*(g: GossipSub, g.rng.shuffle(fanoutPeers) if fanoutPeers.len + peers.len > g.parameters.d: fanoutPeers.setLen(g.parameters.d - peers.len) - + for fanPeer in fanoutPeers: peers.incl(fanPeer) if peers.len > g.parameters.d: break @@ -527,22 +527,18 @@ method publish*(g: GossipSub, libp2p_gossipsub_failed_publish.inc() return 0 - inc g.msgSeqno let msg = if g.anonymize: Message.init(none(PeerInfo), data, topic, none(uint64), false) else: + inc g.msgSeqno Message.init(some(g.peerInfo), data, topic, some(g.msgSeqno), g.sign) - msgIdResult = g.msgIdProvider(msg) - - if msgIdResult.isErr: - trace "Error generating message id, skipping publish", - error = msgIdResult.error - libp2p_gossipsub_failed_publish.inc() - return 0 - - let msgId = msgIdResult.get + msgId = g.msgIdProvider(msg).valueOr: + trace "Error generating message id, skipping publish", + error = error + libp2p_gossipsub_failed_publish.inc() + return 0 logScope: msgId = shortLog(msgId)