From b99f2d44fdee3f51d35c56b49044a050297dd450 Mon Sep 17 00:00:00 2001 From: blacktemplar Date: Wed, 25 Nov 2020 10:07:27 +0100 Subject: [PATCH] only respond to IWANT if message got already validated --- protocols/gossipsub/src/mcache.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/protocols/gossipsub/src/mcache.rs b/protocols/gossipsub/src/mcache.rs index 6db0c8eda69..cd8bebc190a 100644 --- a/protocols/gossipsub/src/mcache.rs +++ b/protocols/gossipsub/src/mcache.rs @@ -96,16 +96,20 @@ impl MessageCache { peer: &PeerId, ) -> Option<(&GossipsubMessageWithId, u32)> { let iwant_counts = &mut self.iwant_counts; - self.msgs.get(message_id).map(|message| { - (message, { - let count = iwant_counts - .entry(message_id.clone()) - .or_default() - .entry(peer.clone()) - .or_default(); - *count += 1; - *count - }) + self.msgs.get(message_id).and_then(|message| { + if !message.validated { + None + } else { + Some((message, { + let count = iwant_counts + .entry(message_id.clone()) + .or_default() + .entry(peer.clone()) + .or_default(); + *count += 1; + *count + })) + } }) }