From bac754e2adcccdb5741c5b7430c4d14452dc5091 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Tue, 21 Mar 2023 17:13:25 +0100 Subject: [PATCH] Various gossipsub fixes (#827) --- libp2p/protocols/pubsub/gossipsub/behavior.nim | 8 ++++++++ libp2p/protocols/pubsub/gossipsub/scoring.nim | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libp2p/protocols/pubsub/gossipsub/behavior.nim b/libp2p/protocols/pubsub/gossipsub/behavior.nim index 57ea160ee..bbdcd27e7 100644 --- a/libp2p/protocols/pubsub/gossipsub/behavior.nim +++ b/libp2p/protocols/pubsub/gossipsub/behavior.nim @@ -130,6 +130,10 @@ proc handleGraft*(g: GossipSub, continue + if g.mesh.hasPeer(topic, peer): + trace "peer already in mesh", peer, topic + continue + # Check backingOff # Ignore BackoffSlackTime here, since this only for outbound activity # and subtract a second time to avoid race conditions @@ -176,6 +180,10 @@ proc handleGraft*(g: GossipSub, topicID: topic, peers: g.peerExchangeList(topic), backoff: g.parameters.pruneBackoff.seconds.uint64)) + + let backoff = Moment.fromNow(g.parameters.pruneBackoff) + g.backingOff + .mgetOrPut(topic, initTable[PeerId, Moment]())[peer.peerId] = backoff else: trace "peer grafting topic we're not interested in", peer, topic # gossip 1.1, we do not send a control message prune anymore diff --git a/libp2p/protocols/pubsub/gossipsub/scoring.nim b/libp2p/protocols/pubsub/gossipsub/scoring.nim index b107e8f68..fdc34cc74 100644 --- a/libp2p/protocols/pubsub/gossipsub/scoring.nim +++ b/libp2p/protocols/pubsub/gossipsub/scoring.nim @@ -295,11 +295,11 @@ proc rewardDelivered*( g.withPeerStats(peer.peerId) do (stats: var PeerStats): stats.topicInfos.withValue(tt, tstats): - if tstats[].inMesh: - if first: - tstats[].firstMessageDeliveries.addCapped( - 1, topicParams.firstMessageDeliveriesCap) + if first: + tstats[].firstMessageDeliveries.addCapped( + 1, topicParams.firstMessageDeliveriesCap) + if tstats[].inMesh: tstats[].meshMessageDeliveries.addCapped( 1, topicParams.meshMessageDeliveriesCap) do: # make sure we don't loose this information