eth: broadcast blocks to at least 4 peers (#17725)

This commit is contained in:
ledgerwatch
2018-09-29 21:17:06 +01:00
committed by Felix Lange
parent 01d9f29805
commit 3d782bc727
2 changed files with 109 additions and 8 deletions

View File

@ -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)
}