From 6f779c47c83f8be9d98958a08c4b49508fb05767 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Sun, 14 Nov 2021 09:08:05 +0100 Subject: [PATCH] Gossipsub: don't send to peers seen during validation (#648) * Gossipsub: don't send to peers seen during validation * Less error prone code * add metric * Fix metric * remove dangling code test * address comments * don't allocate memory --- libp2p/protocols/pubsub/gossipsub.nim | 23 +++++- libp2p/protocols/pubsub/gossipsub/types.nim | 2 + tests/pubsub/testgossipsub.nim | 84 +++++++++++++++++++++ 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index 3b79a5b50..64181bff4 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -37,6 +37,7 @@ logScope: declareCounter(libp2p_gossipsub_failed_publish, "number of failed publish") declareCounter(libp2p_gossipsub_invalid_topic_subscription, "number of invalid topic subscriptions that happened") +declareCounter(libp2p_gossipsub_duplicate_during_validation, "number of duplicates received during message validation") proc init*(_: type[GossipSubParams]): GossipSubParams = GossipSubParams( @@ -295,7 +296,9 @@ method rpcHandler*(g: GossipSub, for i in 0.. 0 except: false) + result = ValidationResult.Accept + bFinished.complete() + + nodes[1].addValidator("foobar", slowValidator) + + tryPublish await nodes[0].publish("foobar", "Hello!".toBytes()), 1 + + await bFinished + + await allFuturesThrowing( + nodes[0].switch.stop(), + nodes[1].switch.stop(), + nodes[2].switch.stop() + ) + + await allFuturesThrowing( + nodes[0].stop(), + nodes[1].stop(), + nodes[2].stop() + ) + + await allFuturesThrowing(nodesFut.concat()) + asyncTest "e2e - GossipSub send over floodPublish A -> B": var passed: Future[bool] = newFuture[bool]() proc handler(topic: string, data: seq[byte]) {.async, gcsafe.} =