From 3514733060f2f10e757b6d6e0fcd5646437bebee Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Sun, 5 Apr 2020 01:19:10 +0900 Subject: [PATCH] Fix table assertion, edited while iterating (the fix is not so nice.. adds plenty of allocations, but for now should be ok) --- libp2p/protocols/pubsub/gossipsub.nim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index d930dd112..0f3770cf0 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -298,10 +298,13 @@ proc rebalanceMesh(g: GossipSub, topic: string) {.async.} = proc dropFanoutPeers(g: GossipSub) {.async.} = # drop peers that we haven't published to in # GossipSubFanoutTTL seconds - for topic in g.lastFanoutPubSub.keys: - if Moment.now > g.lastFanoutPubSub[topic]: - g.lastFanoutPubSub.del(topic) + var dropping = newSeq[string]() + for topic, val in g.lastFanoutPubSub: + if Moment.now > val: + dropping.add(topic) g.fanout.del(topic) + for topic in dropping: + g.lastFanoutPubSub.del(topic) proc getGossipPeers(g: GossipSub): Table[string, ControlMessage] {.gcsafe.} = ## gossip iHave messages to peers