Skip to content

Commit

Permalink
udpate peers lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhang Lihua committed Jul 25, 2019
1 parent b676e37 commit 7f0785b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ func (pm *ProtocolManager) sendBufferTxsLoop() {
for {
select {
case <-tick.C:

for _, p := range pm.peers.peers {
peers := pm.peers.PeersList()
for _, p := range peers {

size := p.bufferTxs.Size()
if size > 0 {
Expand Down
10 changes: 10 additions & 0 deletions eth/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,16 @@ func (ps *peerSet) PeersWithoutTx(hash common.Hash) []*peer {
return list
}

func (ps *peerSet) PeersList() []*peer {
ps.lock.RLock()
defer ps.lock.RUnlock()

list := make([]*peer, 0, len(ps.peers))
for _, p := range ps.peers {
list = append(list, p)
}
return list
}
// BestPeer retrieves the known peer with the currently highest total difficulty.
func (ps *peerSet) BestPeer() *peer {
ps.lock.RLock()
Expand Down

0 comments on commit 7f0785b

Please sign in to comment.