peer stats fixes (#511)
Gossipsub fix, required by nimbus, merging into master as low impact
This commit is contained in:
parent
fb493d1a4a
commit
5aebf0990e
|
@ -340,8 +340,10 @@ method init*(g: GossipSub) =
|
|||
g.codecs &= GossipSubCodec
|
||||
g.codecs &= GossipSubCodec_10
|
||||
|
||||
proc initPeerStats(g: GossipSub, peer: PubSubPeer) =
|
||||
g.peerStats[peer.peerId] = PeerStats()
|
||||
proc initPeerStats(g: GossipSub, peer: PubSubPeer, stats: PeerStats = PeerStats()) =
|
||||
var initialStats = stats
|
||||
initialStats.expire = Moment.now() + g.parameters.retainScore
|
||||
g.peerStats[peer.peerId] = initialStats
|
||||
peer.iWantBudget = IWantPeerBudget
|
||||
peer.iHaveBudget = IHavePeerBudget
|
||||
|
||||
|
@ -793,7 +795,7 @@ proc updateScores(g: GossipSub) = # avoid async
|
|||
if isNil(peer) or not(peer.connected):
|
||||
if now > stats.expire:
|
||||
evicting.add(peerId)
|
||||
trace "evicted peer from memory", peer
|
||||
trace "evicted peer from memory", peer = peerId
|
||||
continue
|
||||
|
||||
trace "updating peer score", peer
|
||||
|
@ -933,6 +935,7 @@ proc updateScores(g: GossipSub) = # avoid async
|
|||
stats.score = peer.score
|
||||
stats.appScore = peer.appScore
|
||||
stats.behaviourPenalty = peer.behaviourPenalty
|
||||
stats.expire = Moment.now() + g.parameters.retainScore # refresh expiration
|
||||
assert(g.peerStats[peer.peerId].score == peer.score) # nim sanity check
|
||||
trace "updated peer's score", peer, score = peer.score, n_topics, is_grafted
|
||||
|
||||
|
@ -1123,8 +1126,7 @@ proc punishInvalidMessage(g: GossipSub, peer: PubSubPeer, topics: seq[string]) =
|
|||
do: # if we have no stats populate!
|
||||
stats[].topicInfos[t] = TopicInfo(invalidMessageDeliveries: 1)
|
||||
do: # if we have no stats populate!
|
||||
g.peerStats[peer.peerId] =
|
||||
block:
|
||||
g.initPeerStats(peer) do:
|
||||
var stats = PeerStats()
|
||||
stats.topicInfos[t] = TopicInfo(invalidMessageDeliveries: 1)
|
||||
stats
|
||||
|
@ -1314,8 +1316,7 @@ method rpcHandler*(g: GossipSub,
|
|||
do: # make sure we don't loose this information
|
||||
pstats[].topicInfos[t] = TopicInfo(meshMessageDeliveries: 1)
|
||||
do: # make sure we don't loose this information
|
||||
g.peerStats[peer.peerId] =
|
||||
block:
|
||||
g.initPeerStats(peer) do:
|
||||
var stats = PeerStats()
|
||||
stats.topicInfos[t] = TopicInfo(meshMessageDeliveries: 1)
|
||||
stats
|
||||
|
@ -1384,8 +1385,7 @@ method rpcHandler*(g: GossipSub,
|
|||
do: # make sure we don't loose this information
|
||||
pstats[].topicInfos[t] = TopicInfo(firstMessageDeliveries: 1, meshMessageDeliveries: 1)
|
||||
do: # make sure we don't loose this information
|
||||
g.peerStats[peer.peerId] =
|
||||
block:
|
||||
g.initPeerStats(peer) do:
|
||||
var stats = PeerStats()
|
||||
stats.topicInfos[t] = TopicInfo(firstMessageDeliveries: 1, meshMessageDeliveries: 1)
|
||||
stats
|
||||
|
|
Loading…
Reference in New Issue