From f5d3d486e459dce29130576ae88f2324ad586b50 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 28 Jun 2023 11:06:20 +0200 Subject: [PATCH] eth: send big transactions by announce/retrieve only (#27618) * eth: send big transactions by announce/retrieve only * Update eth/handler.go Co-authored-by: Martin Holst Swende * eth: remove superfluous bracket * eth: add whitespace --------- Co-authored-by: Martin Holst Swende --- eth/handler.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/eth/handler.go b/eth/handler.go index 46113fbc2ffc..6a8487649ed6 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -45,6 +45,11 @@ const ( // txChanSize is the size of channel listening to NewTxsEvent. // The number is referenced from the size of tx pool. txChanSize = 4096 + + // txMaxBroadcastSize is the max size of a transaction that will be broadcasted. + // All transactions with a higher size will be announced and need to be fetched + // by the peer. + txMaxBroadcastSize = 4096 ) var ( @@ -564,8 +569,12 @@ func (h *handler) BroadcastTransactions(txs types.Transactions) { // Broadcast transactions to a batch of peers not knowing about it for _, tx := range txs { peers := h.peers.peersWithoutTransaction(tx.Hash()) + + var numDirect int + if tx.Size() <= txMaxBroadcastSize { + numDirect = int(math.Sqrt(float64(len(peers)))) + } // Send the tx unconditionally to a subset of our peers - numDirect := int(math.Sqrt(float64(len(peers)))) for _, peer := range peers[:numDirect] { txset[peer] = append(txset[peer], tx.Hash()) }