Skip to content

Commit 794836f

Browse files
committed
feat: add broadcast to all cap
1 parent b01ee4e commit 794836f

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ var (
179179
utils.GossipTxBroadcastDisabledFlag,
180180
utils.GossipTxReceivingDisabledFlag,
181181
utils.GossipBroadcastToAllEnabledFlag,
182+
utils.GossipBroadcastToAllCapFlag,
182183
utils.DASyncEnabledFlag,
183184
utils.DABlockNativeAPIEndpointFlag,
184185
utils.DABlobScanAPIEndpointFlag,

cmd/geth/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
252252
utils.GossipTxBroadcastDisabledFlag,
253253
utils.GossipTxReceivingDisabledFlag,
254254
utils.GossipBroadcastToAllEnabledFlag,
255+
utils.GossipBroadcastToAllCapFlag,
255256
},
256257
},
257258
{

cmd/utils/flags.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,10 @@ var (
906906
Name: "gossip.enablebroadcasttoall",
907907
Usage: "Enable gossip broadcast blocks and transactions to all peers",
908908
}
909+
GossipBroadcastToAllCapFlag = cli.IntFlag{
910+
Name: "gossip.broadcasttoallcap",
911+
Usage: "Maximum number of peers for broadcasting blocks and transactions (effective only when gossip.enablebroadcasttoall is enabled)",
912+
}
909913

910914
// DA syncing settings
911915
DASyncEnabledFlag = cli.BoolFlag{
@@ -1823,6 +1827,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18231827
cfg.GossipBroadcastToAllEnabled = ctx.GlobalBool(GossipBroadcastToAllEnabledFlag.Name)
18241828
log.Info("Gossip broadcast to all enabled", "enabled", cfg.GossipBroadcastToAllEnabled)
18251829
}
1830+
// Only configure the gossip broadcast-to-all flag if --gossip.enablebroadcasttoall is set to true.
1831+
if ctx.GlobalIsSet(GossipBroadcastToAllCapFlag.Name) && cfg.GossipBroadcastToAllEnabled {
1832+
cfg.GossipBroadcastToAllCap = ctx.GlobalInt(GossipBroadcastToAllCapFlag.Name)
1833+
log.Info("Maximum number of peers for broadcasting blocks and transactions is set", "cap", cfg.GossipBroadcastToAllCap)
1834+
}
1835+
18261836

18271837
// Cap the cache allowance and tune the garbage collector
18281838
mem, err := gopsutil.VirtualMemory()

eth/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client l1.Client) (*Ether
286286
DisableTxBroadcast: config.GossipTxBroadcastDisabled,
287287
DisableTxReceiving: config.GossipTxReceivingDisabled,
288288
EnableBroadcastToAll: config.GossipBroadcastToAllEnabled,
289+
BroadcastToAllCap: config.GossipBroadcastToAllCap,
289290
}); err != nil {
290291
return nil, err
291292
}

eth/ethconfig/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ type Config struct {
234234
GossipTxBroadcastDisabled bool
235235
GossipTxReceivingDisabled bool
236236
GossipBroadcastToAllEnabled bool
237+
GossipBroadcastToAllCap int
237238
}
238239

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

eth/handler.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +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+
// Gossip configs
9798
DisableTxBroadcast bool
9899
DisableTxReceiving bool
99100
EnableBroadcastToAll bool
101+
BroadcastToAllCap int
100102
}
101103

102104
type handler struct {
@@ -139,6 +141,7 @@ type handler struct {
139141
disableTxBroadcast bool
140142
disableTxReceiving bool
141143
enableBroadcastToAll bool
144+
broadcastToAllCap int
142145
}
143146

144147
// newHandler returns a handler for all Ethereum chain management protocol.
@@ -162,6 +165,11 @@ func newHandler(config *handlerConfig) (*handler, error) {
162165
disableTxReceiving: config.DisableTxReceiving,
163166
enableBroadcastToAll: config.EnableBroadcastToAll,
164167
}
168+
h.broadcastToAllCap = config.BroadcastToAllCap
169+
if config.BroadcastToAllCap == 0 && config.EnableBroadcastToAll {
170+
// Set default broadcast cap to 30 if not specified
171+
h.broadcastToAllCap = 30
172+
}
165173
if config.Sync == downloader.FullSync {
166174
// The database seems empty as the current block is the genesis. Yet the fast
167175
// block is ahead, so fast sync was enabled for this node at a certain point.
@@ -483,7 +491,7 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) {
483491
numDirect := int(math.Sqrt(float64(len(peers))))
484492
// If enableBroadcastToAll is true, broadcast blocks directly to all peers (capped at 100).
485493
if h.enableBroadcastToAll {
486-
numDirect = min(100, len(peers))
494+
numDirect = min(h.broadcastToAllCap, len(peers))
487495
}
488496
transfer := peers[:numDirect]
489497
for _, peer := range transfer {
@@ -528,7 +536,7 @@ func (h *handler) BroadcastTransactions(txs types.Transactions) {
528536
numDirect := int(math.Sqrt(float64(len(peers))))
529537
// If enableBroadcastToAll is true, broadcast transactions directly to all peers (capped at 100).
530538
if h.enableBroadcastToAll {
531-
numDirect = min(100, len(peers))
539+
numDirect = min(h.broadcastToAllCap, len(peers))
532540
}
533541
for _, peer := range peers[:numDirect] {
534542
txset[peer] = append(txset[peer], tx.Hash())

0 commit comments

Comments
 (0)