@@ -94,8 +94,9 @@ type handlerConfig struct {
9494 Whitelist map [uint64 ]common.Hash // Hard coded whitelist for sync challenged
9595 ShadowForkPeerIDs []string // List of peer ids that take part in the shadow-fork
9696
97- DisableTxBroadcast bool
98- DisableTxReceiving bool
97+ DisableTxBroadcast bool
98+ DisableTxReceiving bool
99+ EnableBroadcastToAll bool
99100}
100101
101102type handler struct {
@@ -134,9 +135,10 @@ type handler struct {
134135 wg sync.WaitGroup
135136 peerWG sync.WaitGroup
136137
137- shadowForkPeerIDs []string
138- disableTxBroadcast bool
139- disableTxReceiving bool
138+ shadowForkPeerIDs []string
139+ disableTxBroadcast bool
140+ disableTxReceiving bool
141+ enableBroadcastToAll bool
140142}
141143
142144// newHandler returns a handler for all Ethereum chain management protocol.
@@ -146,18 +148,19 @@ func newHandler(config *handlerConfig) (*handler, error) {
146148 config .EventMux = new (event.TypeMux ) // Nicety initialization for tests
147149 }
148150 h := & handler {
149- networkID : config .Network ,
150- forkFilter : forkid .NewFilter (config .Chain ),
151- eventMux : config .EventMux ,
152- database : config .Database ,
153- txpool : config .TxPool ,
154- chain : config .Chain ,
155- peers : newPeerSet (),
156- whitelist : config .Whitelist ,
157- quitSync : make (chan struct {}),
158- shadowForkPeerIDs : config .ShadowForkPeerIDs ,
159- disableTxBroadcast : config .DisableTxBroadcast ,
160- disableTxReceiving : config .DisableTxReceiving ,
151+ networkID : config .Network ,
152+ forkFilter : forkid .NewFilter (config .Chain ),
153+ eventMux : config .EventMux ,
154+ database : config .Database ,
155+ txpool : config .TxPool ,
156+ chain : config .Chain ,
157+ peers : newPeerSet (),
158+ whitelist : config .Whitelist ,
159+ quitSync : make (chan struct {}),
160+ shadowForkPeerIDs : config .ShadowForkPeerIDs ,
161+ disableTxBroadcast : config .DisableTxBroadcast ,
162+ disableTxReceiving : config .DisableTxReceiving ,
163+ enableBroadcastToAll : config .EnableBroadcastToAll ,
161164 }
162165 if config .Sync == downloader .FullSync {
163166 // The database seems empty as the current block is the genesis. Yet the fast
@@ -477,7 +480,12 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) {
477480 return
478481 }
479482 // Send the block to a subset of our peers
480- transfer := peers [:int (math .Sqrt (float64 (len (peers ))))]
483+ numDirect := int (math .Sqrt (float64 (len (peers ))))
484+ // If enableBroadcastToAll is true, broadcast blocks directly to all peers (capped at 100).
485+ if h .enableBroadcastToAll {
486+ numDirect = min (100 , len (peers ))
487+ }
488+ transfer := peers [:numDirect ]
481489 for _ , peer := range transfer {
482490 peer .AsyncSendNewBlock (block , td )
483491 }
@@ -518,6 +526,10 @@ func (h *handler) BroadcastTransactions(txs types.Transactions) {
518526 peers := onlyShadowForkPeers (h .shadowForkPeerIDs , h .peers .peersWithoutTransaction (tx .Hash ()))
519527 // Send the tx unconditionally to a subset of our peers
520528 numDirect := int (math .Sqrt (float64 (len (peers ))))
529+ // If enableBroadcastToAll is true, broadcast transactions directly to all peers (capped at 100).
530+ if h .enableBroadcastToAll {
531+ numDirect = min (100 , len (peers ))
532+ }
521533 for _ , peer := range peers [:numDirect ] {
522534 txset [peer ] = append (txset [peer ], tx .Hash ())
523535 }
0 commit comments