BestPeer retrieves the known peer with the currently highest total difficulty.
()
| 537 | |
| 538 | // BestPeer retrieves the known peer with the currently highest total difficulty. |
| 539 | func (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. |
no test coverage detected