Skip to content

Commit

Permalink
eth: send big transactions by announce/retrieve only (#27618)
Browse files Browse the repository at this point in the history
* eth: send big transactions by announce/retrieve only

* Update eth/handler.go

Co-authored-by: Martin Holst Swende <[email protected]>

* eth: remove superfluous bracket

* eth: add whitespace

---------

Co-authored-by: Martin Holst Swende <[email protected]>
  • Loading branch information
MariusVanDerWijden and holiman authored Jun 28, 2023
1 parent eed7983 commit f5d3d48
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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())
}
Expand Down

0 comments on commit f5d3d48

Please sign in to comment.