MCPcopy Create free account
hub / github.com/CPChain/chain / BestPeer

Method BestPeer

protocols/cpc/peer.go:539–553  ·  view source on GitHub ↗

BestPeer retrieves the known peer with the currently highest total difficulty.

()

Source from the content-addressed store, hash-verified

537
538// BestPeer retrieves the known peer with the currently highest total difficulty.
539func (ps *peerSet) BestPeer() *peer {
540 ps.lock.RLock()
541 defer ps.lock.RUnlock()
542
543 var (
544 bestPeer *peer
545 bestHt *big.Int
546 )
547 for _, p := range ps.peers {
548 if _, ht := p.Head(); bestPeer == nil || ht.Cmp(bestHt) > 0 {
549 bestPeer, bestHt = p, ht
550 }
551 }
552 return bestPeer
553}
554
555// Close disconnects all peers.
556// No new peers can be registered after Close has returned.

Callers 2

syncerLoopMethod · 0.80
SyncFromBestPeerMethod · 0.80

Calls 2

CmpMethod · 0.80
HeadMethod · 0.65

Tested by

no test coverage detected