Skip to content

Commit dd9135a

Browse files
committed
feat: add flag to enable broadcast blocks and transactions to all peers
1 parent 1043f66 commit dd9135a

File tree

6 files changed

+71
-47
lines changed

6 files changed

+71
-47
lines changed

cmd/geth/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ var (
176176
utils.CircuitCapacityCheckWorkersFlag,
177177
utils.RollupVerifyEnabledFlag,
178178
utils.ShadowforkPeersFlag,
179-
utils.TxGossipBroadcastDisabledFlag,
180-
utils.TxGossipReceivingDisabledFlag,
179+
utils.GossipTxBroadcastDisabledFlag,
180+
utils.GossipTxReceivingDisabledFlag,
181+
utils.GossipBroadcastToAllEnabledFlag,
181182
utils.DASyncEnabledFlag,
182183
utils.DABlockNativeAPIEndpointFlag,
183184
utils.DABlobScanAPIEndpointFlag,

cmd/geth/usage.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ var AppHelpFlagGroups = []flags.FlagGroup{
248248
utils.DARecoveryProduceBlocksFlag,
249249
utils.CircuitCapacityCheckEnabledFlag,
250250
utils.CircuitCapacityCheckWorkersFlag,
251-
utils.TxGossipBroadcastDisabledFlag,
252-
utils.TxGossipReceivingDisabledFlag,
251+
utils.GossipTxBroadcastDisabledFlag,
252+
utils.GossipTxReceivingDisabledFlag,
253+
utils.GossipBroadcastToAllEnabledFlag,
253254
},
254255
},
255256
{

cmd/utils/flags.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -893,15 +893,19 @@ var (
893893
Usage: "peer ids of shadow fork peers",
894894
}
895895

896-
// Tx gossip settings
897-
TxGossipBroadcastDisabledFlag = cli.BoolFlag{
898-
Name: "txgossip.disablebroadcast",
896+
// Gossip settings
897+
GossipTxBroadcastDisabledFlag = cli.BoolFlag{
898+
Name: "gossip.disabletxbroadcast",
899899
Usage: "Disable gossip broadcast transactions to other peers",
900900
}
901-
TxGossipReceivingDisabledFlag = cli.BoolFlag{
902-
Name: "txgossip.disablereceiving",
901+
GossipTxReceivingDisabledFlag = cli.BoolFlag{
902+
Name: "txgossip.disabletxreceiving",
903903
Usage: "Disable gossip receiving transactions from other peers",
904904
}
905+
GossipBroadcastToAllEnabledFlag = cli.BoolFlag{
906+
Name: "gossip.enablebroadcasttoall",
907+
Usage: "Enable gossip broadcast blocks and transactions to all peers",
908+
}
905909

906910
// DA syncing settings
907911
DASyncEnabledFlag = cli.BoolFlag{
@@ -1800,13 +1804,17 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18001804
cfg.ShadowForkPeerIDs = ctx.GlobalStringSlice(ShadowforkPeersFlag.Name)
18011805
log.Info("Shadow fork peers", "ids", cfg.ShadowForkPeerIDs)
18021806
}
1803-
if ctx.GlobalIsSet(TxGossipBroadcastDisabledFlag.Name) {
1804-
cfg.TxGossipBroadcastDisabled = ctx.GlobalBool(TxGossipBroadcastDisabledFlag.Name)
1805-
log.Info("Transaction gossip broadcast disabled", "disabled", cfg.TxGossipBroadcastDisabled)
1807+
if ctx.GlobalIsSet(GossipTxBroadcastDisabledFlag.Name) {
1808+
cfg.GossipTxBroadcastDisabled = ctx.GlobalBool(GossipTxBroadcastDisabledFlag.Name)
1809+
log.Info("Transaction gossip broadcast disabled", "disabled", cfg.GossipTxBroadcastDisabled)
1810+
}
1811+
if ctx.GlobalIsSet(GossipTxReceivingDisabledFlag.Name) {
1812+
cfg.GossipTxReceivingDisabled = ctx.GlobalBool(GossipTxReceivingDisabledFlag.Name)
1813+
log.Info("Transaction gossip receiving disabled", "disabled", cfg.GossipTxReceivingDisabled)
18061814
}
1807-
if ctx.GlobalIsSet(TxGossipReceivingDisabledFlag.Name) {
1808-
cfg.TxGossipReceivingDisabled = ctx.GlobalBool(TxGossipReceivingDisabledFlag.Name)
1809-
log.Info("Transaction gossip receiving disabled", "disabled", cfg.TxGossipReceivingDisabled)
1815+
if ctx.GlobalIsSet(GossipBroadcastToAllEnabledFlag.Name) {
1816+
cfg.GossipTxReceivingDisabled = ctx.GlobalBool(GossipBroadcastToAllEnabledFlag.Name)
1817+
log.Info("Transaction gossip receiving disabled", "disabled", cfg.GossipTxReceivingDisabled)
18101818
}
18111819

18121820
// Cap the cache allowance and tune the garbage collector

eth/backend.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,19 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client l1.Client) (*Ether
273273
checkpoint = params.TrustedCheckpoints[genesisHash]
274274
}
275275
if eth.handler, err = newHandler(&handlerConfig{
276-
Database: chainDb,
277-
Chain: eth.blockchain,
278-
TxPool: eth.txPool,
279-
Network: config.NetworkId,
280-
Sync: config.SyncMode,
281-
BloomCache: uint64(cacheLimit),
282-
EventMux: eth.eventMux,
283-
Checkpoint: checkpoint,
284-
Whitelist: config.Whitelist,
285-
ShadowForkPeerIDs: config.ShadowForkPeerIDs,
286-
DisableTxBroadcast: config.TxGossipBroadcastDisabled,
287-
DisableTxReceiving: config.TxGossipReceivingDisabled,
276+
Database: chainDb,
277+
Chain: eth.blockchain,
278+
TxPool: eth.txPool,
279+
Network: config.NetworkId,
280+
Sync: config.SyncMode,
281+
BloomCache: uint64(cacheLimit),
282+
EventMux: eth.eventMux,
283+
Checkpoint: checkpoint,
284+
Whitelist: config.Whitelist,
285+
ShadowForkPeerIDs: config.ShadowForkPeerIDs,
286+
DisableTxBroadcast: config.GossipTxBroadcastDisabled,
287+
DisableTxReceiving: config.GossipTxReceivingDisabled,
288+
EnableBroadcastToAll: config.GossipBroadcastToAllEnabled,
288289
}); err != nil {
289290
return nil, err
290291
}

eth/ethconfig/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ type Config struct {
231231
// DA syncer options
232232
DA da_syncer.Config
233233

234-
TxGossipBroadcastDisabled bool
235-
TxGossipReceivingDisabled bool
234+
GossipTxBroadcastDisabled bool
235+
GossipTxReceivingDisabled bool
236+
GossipBroadcastToAllEnabled bool
236237
}
237238

238239
// CreateConsensusEngine creates a consensus engine for the given chain configuration.

eth/handler.go

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

101102
type 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

Comments
 (0)