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