From f122ec9dbf9f771b1bfffc010b9d1c38cabdfd16 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Wed, 22 Jul 2020 10:19:53 +0900 Subject: [PATCH] fix grafted defect --- libp2p/protocols/pubsub/gossipsub.nim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index 2d7b84cc9..baf483f18 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -285,7 +285,7 @@ proc grafted(g: GossipSub, p: PubSubPeer, topic: string) = debug "grafted", p do: - doAssert(false, "grafted: TopicInfo key not found for " & $p) + doAssert(false, "grafted: peerStats key not found for " & $p) proc pruned(g: GossipSub, p: PubSubPeer, topic: string) = g.peerStats.withValue(p, stats) do: @@ -685,7 +685,12 @@ proc handleGraft(g: GossipSub, # If they send us a graft before they send us a subscribe, what should # we do? For now, we add them to mesh but don't add them to gossipsub. + + if peer notin g.peerStats: + g.peerStats[peer] = PeerStats() + if topic in g.topics: + discard g.gossipsub.addPeer(topic, peer) if g.mesh.peers(topic) < GossipSubDHi: # In the spec, there's no mention of DHi here, but implicitly, a # peer will be removed from the mesh on next rebalance, so we don't want