diff options
author | ledgerwatch <akhounov@gmail.com> | 2018-09-30 04:17:06 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2018-09-30 04:17:06 +0800 |
commit | 3d782bc727fb58630b1d811b9ab95d626c68e40f (patch) | |
tree | 0a3ff6ca73bb9e408c0f48d06614dc5488e67f9a /eth/handler.go | |
parent | 01d9f2980531814acc5c87e978966c26ac1bc4c2 (diff) | |
download | go-tangerine-3d782bc727fb58630b1d811b9ab95d626c68e40f.tar go-tangerine-3d782bc727fb58630b1d811b9ab95d626c68e40f.tar.gz go-tangerine-3d782bc727fb58630b1d811b9ab95d626c68e40f.tar.bz2 go-tangerine-3d782bc727fb58630b1d811b9ab95d626c68e40f.tar.lz go-tangerine-3d782bc727fb58630b1d811b9ab95d626c68e40f.tar.xz go-tangerine-3d782bc727fb58630b1d811b9ab95d626c68e40f.tar.zst go-tangerine-3d782bc727fb58630b1d811b9ab95d626c68e40f.zip |
eth: broadcast blocks to at least 4 peers (#17725)
Diffstat (limited to 'eth/handler.go')
-rw-r--r-- | eth/handler.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/eth/handler.go b/eth/handler.go index 551781ef0..1f62d820e 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -49,6 +49,9 @@ const ( // txChanSize is the size of channel listening to NewTxsEvent. // The number is referenced from the size of tx pool. txChanSize = 4096 + + // minimim number of peers to broadcast new blocks to + minBroadcastPeers = 4 ) var ( @@ -705,7 +708,14 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool) { return } // Send the block to a subset of our peers - transfer := peers[:int(math.Sqrt(float64(len(peers))))] + transferLen := int(math.Sqrt(float64(len(peers)))) + if transferLen < minBroadcastPeers { + transferLen = minBroadcastPeers + } + if transferLen > len(peers) { + transferLen = len(peers) + } + transfer := peers[:transferLen] for _, peer := range transfer { peer.AsyncSendNewBlock(block, td) } |