Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bad peer count #4537

Merged
merged 5 commits into from Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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