diff --git a/pkg/network/server.go b/pkg/network/server.go index 28e1c71a9..2b5ec376f 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -253,7 +253,7 @@ func (s *Server) tryStartConsensus() { return } - if s.PeerCount() >= s.MinPeers { + if s.HandshakedPeersCount() >= s.MinPeers { log.Info("minimum amount of peers were connected to") if s.connected.CAS(false, true) { s.consensus.Start() @@ -282,6 +282,23 @@ func (s *Server) PeerCount() int { return len(s.peers) } +// HandshakedPeersCount returns the number of connected peers +// which have already performed handshake. +func (s *Server) HandshakedPeersCount() int { + s.lock.RLock() + defer s.lock.RUnlock() + + var count int + + for p := range s.peers { + if p.Handshaked() { + count++ + } + } + + return count +} + // startProtocol starts a long running background loop that interacts // every ProtoTickInterval with the peer. func (s *Server) startProtocol(p Peer) {