don't delete while iterating in score update

This commit is contained in:
Giovanni Petrantoni 2020-07-21 13:37:06 +09:00
parent f74e693ea8
commit aded78f259
1 changed files with 5 additions and 1 deletions

View File

@ -468,13 +468,14 @@ proc updateScores(g: GossipSub) = # avoid async
debug "updating scores", peers = g.peers.len
let now = Moment.now()
var evicting: seq[PubSubPeer]
for peer, stats in g.peerStats.mpairs:
debug "updating peer score", peer, gossipTopics = peer.topics.len
if not peer.connected:
if now > stats.expire:
g.peerStats.del(peer)
evicting.add(peer)
debug "evicted peer from memory", peer
continue
@ -540,6 +541,9 @@ proc updateScores(g: GossipSub) = # avoid async
stats.topicInfos[topic] = info
debug "updated peer's score", peer, score = peer.score
for peer in evicting:
g.peerStats.del(peer)
proc heartbeat(g: GossipSub) {.async.} =
while g.heartbeatRunning: