From 820baa91a337f411e89a61fa42e65cf41d5cb128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 20 Feb 2024 15:43:32 +0200 Subject: [PATCH] eth: avoid potential division by 0 --- eth/handler.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 1a0cd6440f..9ae24ef8b6 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -616,9 +616,13 @@ func (h *handler) BroadcastTransactions(txs types.Transactions) { annos = make(map[*ethPeer][]common.Hash) // Set peer->hash to announce ) // Broadcast transactions to a batch of peers not knowing about it + direct := big.NewInt(int64(math.Sqrt(float64(h.peers.len())))) // Approximate number of peers to broadcast to + if direct.BitLen() == 0 { + direct = big.NewInt(1) + } + total := new(big.Int).Exp(direct, big.NewInt(2), nil) // Stabilise total peer count a bit based on sqrt peers + var ( - direct = big.NewInt(int64(math.Sqrt(float64(h.peers.len())))) // Approximate number of peers to broadcst to - total = new(big.Int).Exp(direct, big.NewInt(2), nil) // Stabilise total peer count a bit based on sqrt peers signer = types.LatestSignerForChainID(h.chain.Config().ChainID) // Don't care about chain status, we ust need *a* sender hasher = sha3.NewLegacyKeccak256().(crypto.KeccakState) hash = make([]byte, 32)