Skip to content

Commit

Permalink
Add bad peer count (prysmaticlabs#4537)
Browse files Browse the repository at this point in the history
* Add bad peer count
* Merge branch 'master' into badpeercount
* Merge branch 'master' into badpeercount
* Merge branch 'master' into badpeercount
* Merge branch 'master' into badpeercount
  • Loading branch information
mcdee authored and cryptomental committed Feb 24, 2020
1 parent 2a3b3ea commit 841e122
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions beacon-chain/p2p/monitoring.go
Expand Up @@ -27,4 +27,5 @@ func (s *Service) updateMetrics() {
p2pPeerCount.WithLabelValues("Disconnected").Set(float64(len(s.peers.Disconnected())))
p2pPeerCount.WithLabelValues("Connecting").Set(float64(len(s.peers.Connecting())))
p2pPeerCount.WithLabelValues("Disconnecting").Set(float64(len(s.peers.Disconnecting())))
p2pPeerCount.WithLabelValues("Bad").Set(float64(len(s.peers.Bad())))
}
13 changes: 13 additions & 0 deletions beacon-chain/p2p/peers/status.go
Expand Up @@ -294,6 +294,19 @@ func (p *Status) Inactive() []peer.ID {
return peers
}

// Bad returns the peers that are bad.
func (p *Status) Bad() []peer.ID {
p.lock.RLock()
defer p.lock.RUnlock()
peers := make([]peer.ID, 0)
for pid, status := range p.status {
if status.badResponses >= p.maxBadResponses {
peers = append(peers, pid)
}
}
return peers
}

// All returns all the peers regardless of state.
func (p *Status) All() []peer.ID {
p.lock.RLock()
Expand Down

0 comments on commit 841e122

Please sign in to comment.