@@ -94,8 +94,11 @@ 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+ // Gossip configs
98+ DisableTxBroadcast bool
99+ DisableTxReceiving bool
100+ EnableBroadcastToAll bool
101+ BroadcastToAllCap int
99102}
100103
101104type handler struct {
@@ -134,9 +137,11 @@ type handler struct {
134137 wg sync.WaitGroup
135138 peerWG sync.WaitGroup
136139
137- shadowForkPeerIDs []string
138- disableTxBroadcast bool
139- disableTxReceiving bool
140+ shadowForkPeerIDs []string
141+ disableTxBroadcast bool
142+ disableTxReceiving bool
143+ enableBroadcastToAll bool
144+ broadcastToAllCap int
140145}
141146
142147// newHandler returns a handler for all Ethereum chain management protocol.
@@ -146,18 +151,20 @@ func newHandler(config *handlerConfig) (*handler, error) {
146151 config .EventMux = new (event.TypeMux ) // Nicety initialization for tests
147152 }
148153 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 ,
154+ networkID : config .Network ,
155+ forkFilter : forkid .NewFilter (config .Chain ),
156+ eventMux : config .EventMux ,
157+ database : config .Database ,
158+ txpool : config .TxPool ,
159+ chain : config .Chain ,
160+ peers : newPeerSet (),
161+ whitelist : config .Whitelist ,
162+ quitSync : make (chan struct {}),
163+ shadowForkPeerIDs : config .ShadowForkPeerIDs ,
164+ disableTxBroadcast : config .DisableTxBroadcast ,
165+ disableTxReceiving : config .DisableTxReceiving ,
166+ enableBroadcastToAll : config .EnableBroadcastToAll ,
167+ broadcastToAllCap : config .BroadcastToAllCap ,
161168 }
162169 if config .Sync == downloader .FullSync {
163170 // The database seems empty as the current block is the genesis. Yet the fast
@@ -477,7 +484,12 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) {
477484 return
478485 }
479486 // Send the block to a subset of our peers
480- transfer := peers [:int (math .Sqrt (float64 (len (peers ))))]
487+ numDirect := int (math .Sqrt (float64 (len (peers ))))
488+ // If enableBroadcastToAll is true, broadcast blocks directly to all peers (capped at broadcastToAllCap).
489+ if h .enableBroadcastToAll {
490+ numDirect = min (h .broadcastToAllCap , len (peers ))
491+ }
492+ transfer := peers [:numDirect ]
481493 for _ , peer := range transfer {
482494 peer .AsyncSendNewBlock (block , td )
483495 }
@@ -518,6 +530,10 @@ func (h *handler) BroadcastTransactions(txs types.Transactions) {
518530 peers := onlyShadowForkPeers (h .shadowForkPeerIDs , h .peers .peersWithoutTransaction (tx .Hash ()))
519531 // Send the tx unconditionally to a subset of our peers
520532 numDirect := int (math .Sqrt (float64 (len (peers ))))
533+ // If enableBroadcastToAll is true, broadcast transactions directly to all peers (capped at broadcastToAllCap).
534+ if h .enableBroadcastToAll {
535+ numDirect = min (h .broadcastToAllCap , len (peers ))
536+ }
521537 for _ , peer := range peers [:numDirect ] {
522538 txset [peer ] = append (txset [peer ], tx .Hash ())
523539 }
0 commit comments