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
|
||||||
g.codecs &= GossipSubCodec_10
|
g.codecs &= GossipSubCodec_10
|
||||||
|
|
||||||
proc initPeerStats(g: GossipSub, peer: PubSubPeer) =
|
proc initPeerStats(g: GossipSub, peer: PubSubPeer, stats: PeerStats = PeerStats()) =
|
||||||
g.peerStats[peer.peerId] = PeerStats()
|
var initialStats = stats
|
||||||
|
initialStats.expire = Moment.now() + g.parameters.retainScore
|
||||||
|
g.peerStats[peer.peerId] = initialStats
|
||||||
peer.iWantBudget = IWantPeerBudget
|
peer.iWantBudget = IWantPeerBudget
|
||||||
peer.iHaveBudget = IHavePeerBudget
|
peer.iHaveBudget = IHavePeerBudget
|
||||||
|
|
||||||
|
@ -793,7 +795,7 @@ proc updateScores(g: GossipSub) = # avoid async
|
||||||
if isNil(peer) or not(peer.connected):
|
if isNil(peer) or not(peer.connected):
|
||||||
if now > stats.expire:
|
if now > stats.expire:
|
||||||
evicting.add(peerId)
|
evicting.add(peerId)
|
||||||
trace "evicted peer from memory", peer
|
trace "evicted peer from memory", peer = peerId
|
||||||
continue
|
continue
|
||||||
|
|
||||||
trace "updating peer score", peer
|
trace "updating peer score", peer
|
||||||
|
@ -933,6 +935,7 @@ proc updateScores(g: GossipSub) = # avoid async
|
||||||
stats.score = peer.score
|
stats.score = peer.score
|
||||||
stats.appScore = peer.appScore
|
stats.appScore = peer.appScore
|
||||||
stats.behaviourPenalty = peer.behaviourPenalty
|
stats.behaviourPenalty = peer.behaviourPenalty
|
||||||
|
stats.expire = Moment.now() + g.parameters.retainScore # refresh expiration
|
||||||
assert(g.peerStats[peer.peerId].score == peer.score) # nim sanity check
|
assert(g.peerStats[peer.peerId].score == peer.score) # nim sanity check
|
||||||
trace "updated peer's score", peer, score = peer.score, n_topics, is_grafted
|
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!
|
do: # if we have no stats populate!
|
||||||
stats[].topicInfos[t] = TopicInfo(invalidMessageDeliveries: 1)
|
stats[].topicInfos[t] = TopicInfo(invalidMessageDeliveries: 1)
|
||||||
do: # if we have no stats populate!
|
do: # if we have no stats populate!
|
||||||
g.peerStats[peer.peerId] =
|
g.initPeerStats(peer) do:
|
||||||
block:
|
|
||||||
var stats = PeerStats()
|
var stats = PeerStats()
|
||||||
stats.topicInfos[t] = TopicInfo(invalidMessageDeliveries: 1)
|
stats.topicInfos[t] = TopicInfo(invalidMessageDeliveries: 1)
|
||||||
stats
|
stats
|
||||||
|
@ -1314,8 +1316,7 @@ method rpcHandler*(g: GossipSub,
|
||||||
do: # make sure we don't loose this information
|
do: # make sure we don't loose this information
|
||||||
pstats[].topicInfos[t] = TopicInfo(meshMessageDeliveries: 1)
|
pstats[].topicInfos[t] = TopicInfo(meshMessageDeliveries: 1)
|
||||||
do: # make sure we don't loose this information
|
do: # make sure we don't loose this information
|
||||||
g.peerStats[peer.peerId] =
|
g.initPeerStats(peer) do:
|
||||||
block:
|
|
||||||
var stats = PeerStats()
|
var stats = PeerStats()
|
||||||
stats.topicInfos[t] = TopicInfo(meshMessageDeliveries: 1)
|
stats.topicInfos[t] = TopicInfo(meshMessageDeliveries: 1)
|
||||||
stats
|
stats
|
||||||
|
@ -1384,8 +1385,7 @@ method rpcHandler*(g: GossipSub,
|
||||||
do: # make sure we don't loose this information
|
do: # make sure we don't loose this information
|
||||||
pstats[].topicInfos[t] = TopicInfo(firstMessageDeliveries: 1, meshMessageDeliveries: 1)
|
pstats[].topicInfos[t] = TopicInfo(firstMessageDeliveries: 1, meshMessageDeliveries: 1)
|
||||||
do: # make sure we don't loose this information
|
do: # make sure we don't loose this information
|
||||||
g.peerStats[peer.peerId] =
|
g.initPeerStats(peer) do:
|
||||||
block:
|
|
||||||
var stats = PeerStats()
|
var stats = PeerStats()
|
||||||
stats.topicInfos[t] = TopicInfo(firstMessageDeliveries: 1, meshMessageDeliveries: 1)
|
stats.topicInfos[t] = TopicInfo(firstMessageDeliveries: 1, meshMessageDeliveries: 1)
|
||||||
stats
|
stats
|
||||||
|
|
Loading…
Reference in New Issue