diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 14ea24db19af..56a8e9b1d038 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -176,8 +176,10 @@ var ( utils.CircuitCapacityCheckWorkersFlag, utils.RollupVerifyEnabledFlag, utils.ShadowforkPeersFlag, - utils.TxGossipBroadcastDisabledFlag, - utils.TxGossipReceivingDisabledFlag, + utils.GossipTxBroadcastDisabledFlag, + utils.GossipTxReceivingDisabledFlag, + utils.GossipBroadcastToAllEnabledFlag, + utils.GossipBroadcastToAllCapFlag, utils.DASyncEnabledFlag, utils.DABlockNativeAPIEndpointFlag, utils.DABlobScanAPIEndpointFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index fb5b25343d1f..7b7baa29e28f 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -249,8 +249,10 @@ var AppHelpFlagGroups = []flags.FlagGroup{ utils.DARecoveryProduceBlocksFlag, utils.CircuitCapacityCheckEnabledFlag, utils.CircuitCapacityCheckWorkersFlag, - utils.TxGossipBroadcastDisabledFlag, - utils.TxGossipReceivingDisabledFlag, + utils.GossipTxBroadcastDisabledFlag, + utils.GossipTxReceivingDisabledFlag, + utils.GossipBroadcastToAllEnabledFlag, + utils.GossipBroadcastToAllCapFlag, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 25c6d568cd5b..3f7a6edc66a4 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -893,15 +893,23 @@ var ( Usage: "peer ids of shadow fork peers", } - // Tx gossip settings - TxGossipBroadcastDisabledFlag = cli.BoolFlag{ - Name: "txgossip.disablebroadcast", + // Gossip settings + GossipTxBroadcastDisabledFlag = cli.BoolFlag{ + Name: "gossip.disabletxbroadcast", Usage: "Disable gossip broadcast transactions to other peers", } - TxGossipReceivingDisabledFlag = cli.BoolFlag{ - Name: "txgossip.disablereceiving", + GossipTxReceivingDisabledFlag = cli.BoolFlag{ + Name: "gossip.disabletxreceiving", Usage: "Disable gossip receiving transactions from other peers", } + GossipBroadcastToAllEnabledFlag = cli.BoolFlag{ + Name: "gossip.enablebroadcasttoall", + Usage: "Enable gossip broadcast blocks and transactions to all peers", + } + GossipBroadcastToAllCapFlag = cli.IntFlag{ + Name: "gossip.broadcasttoallcap", + Usage: "Maximum number of peers for broadcasting blocks and transactions (effective only when gossip.enablebroadcasttoall is enabled)", + } // DA syncing settings DASyncEnabledFlag = cli.BoolFlag{ @@ -1807,14 +1815,24 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { cfg.ShadowForkPeerIDs = ctx.GlobalStringSlice(ShadowforkPeersFlag.Name) log.Info("Shadow fork peers", "ids", cfg.ShadowForkPeerIDs) } - if ctx.GlobalIsSet(TxGossipBroadcastDisabledFlag.Name) { - cfg.TxGossipBroadcastDisabled = ctx.GlobalBool(TxGossipBroadcastDisabledFlag.Name) - log.Info("Transaction gossip broadcast disabled", "disabled", cfg.TxGossipBroadcastDisabled) + if ctx.GlobalIsSet(GossipTxBroadcastDisabledFlag.Name) { + cfg.GossipTxBroadcastDisabled = ctx.GlobalBool(GossipTxBroadcastDisabledFlag.Name) + log.Info("Gossip transaction broadcast disabled", "disabled", cfg.GossipTxBroadcastDisabled) + } + if ctx.GlobalIsSet(GossipTxReceivingDisabledFlag.Name) { + cfg.GossipTxReceivingDisabled = ctx.GlobalBool(GossipTxReceivingDisabledFlag.Name) + log.Info("Gossip transaction receiving disabled", "disabled", cfg.GossipTxReceivingDisabled) + } + if ctx.GlobalIsSet(GossipBroadcastToAllEnabledFlag.Name) { + cfg.GossipBroadcastToAllEnabled = ctx.GlobalBool(GossipBroadcastToAllEnabledFlag.Name) + log.Info("Gossip broadcast to all enabled", "enabled", cfg.GossipBroadcastToAllEnabled) } - if ctx.GlobalIsSet(TxGossipReceivingDisabledFlag.Name) { - cfg.TxGossipReceivingDisabled = ctx.GlobalBool(TxGossipReceivingDisabledFlag.Name) - log.Info("Transaction gossip receiving disabled", "disabled", cfg.TxGossipReceivingDisabled) + // Only configure the gossip broadcast-to-all flag if --gossip.enablebroadcasttoall is set to true. + if ctx.GlobalIsSet(GossipBroadcastToAllCapFlag.Name) && cfg.GossipBroadcastToAllEnabled { + cfg.GossipBroadcastToAllCap = ctx.GlobalInt(GossipBroadcastToAllCapFlag.Name) + log.Info("Maximum number of peers for broadcasting blocks and transactions is set", "cap", cfg.GossipBroadcastToAllCap) } + // Cap the cache allowance and tune the garbage collector mem, err := gopsutil.VirtualMemory() diff --git a/eth/backend.go b/eth/backend.go index 0050d3853b65..46368b88a318 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -273,18 +273,20 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client l1.Client) (*Ether checkpoint = params.TrustedCheckpoints[genesisHash] } if eth.handler, err = newHandler(&handlerConfig{ - Database: chainDb, - Chain: eth.blockchain, - TxPool: eth.txPool, - Network: config.NetworkId, - Sync: config.SyncMode, - BloomCache: uint64(cacheLimit), - EventMux: eth.eventMux, - Checkpoint: checkpoint, - Whitelist: config.Whitelist, - ShadowForkPeerIDs: config.ShadowForkPeerIDs, - DisableTxBroadcast: config.TxGossipBroadcastDisabled, - DisableTxReceiving: config.TxGossipReceivingDisabled, + Database: chainDb, + Chain: eth.blockchain, + TxPool: eth.txPool, + Network: config.NetworkId, + Sync: config.SyncMode, + BloomCache: uint64(cacheLimit), + EventMux: eth.eventMux, + Checkpoint: checkpoint, + Whitelist: config.Whitelist, + ShadowForkPeerIDs: config.ShadowForkPeerIDs, + DisableTxBroadcast: config.GossipTxBroadcastDisabled, + DisableTxReceiving: config.GossipTxReceivingDisabled, + EnableBroadcastToAll: config.GossipBroadcastToAllEnabled, + BroadcastToAllCap: config.GossipBroadcastToAllCap, }); err != nil { return nil, err } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 0f70eb2ed6c9..814731d7e04d 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -231,8 +231,10 @@ type Config struct { // DA syncer options DA da_syncer.Config - TxGossipBroadcastDisabled bool - TxGossipReceivingDisabled bool + GossipTxBroadcastDisabled bool + GossipTxReceivingDisabled bool + GossipBroadcastToAllEnabled bool + GossipBroadcastToAllCap int } // CreateConsensusEngine creates a consensus engine for the given chain configuration. diff --git a/eth/handler.go b/eth/handler.go index 520723f18af2..f9b10c09d258 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -94,8 +94,11 @@ type handlerConfig struct { Whitelist map[uint64]common.Hash // Hard coded whitelist for sync challenged ShadowForkPeerIDs []string // List of peer ids that take part in the shadow-fork - DisableTxBroadcast bool - DisableTxReceiving bool + // Gossip configs + DisableTxBroadcast bool + DisableTxReceiving bool + EnableBroadcastToAll bool + BroadcastToAllCap int } type handler struct { @@ -134,9 +137,11 @@ type handler struct { wg sync.WaitGroup peerWG sync.WaitGroup - shadowForkPeerIDs []string - disableTxBroadcast bool - disableTxReceiving bool + shadowForkPeerIDs []string + disableTxBroadcast bool + disableTxReceiving bool + enableBroadcastToAll bool + broadcastToAllCap int } // newHandler returns a handler for all Ethereum chain management protocol. @@ -146,18 +151,24 @@ func newHandler(config *handlerConfig) (*handler, error) { config.EventMux = new(event.TypeMux) // Nicety initialization for tests } h := &handler{ - networkID: config.Network, - forkFilter: forkid.NewFilter(config.Chain), - eventMux: config.EventMux, - database: config.Database, - txpool: config.TxPool, - chain: config.Chain, - peers: newPeerSet(), - whitelist: config.Whitelist, - quitSync: make(chan struct{}), - shadowForkPeerIDs: config.ShadowForkPeerIDs, - disableTxBroadcast: config.DisableTxBroadcast, - disableTxReceiving: config.DisableTxReceiving, + networkID: config.Network, + forkFilter: forkid.NewFilter(config.Chain), + eventMux: config.EventMux, + database: config.Database, + txpool: config.TxPool, + chain: config.Chain, + peers: newPeerSet(), + whitelist: config.Whitelist, + quitSync: make(chan struct{}), + shadowForkPeerIDs: config.ShadowForkPeerIDs, + disableTxBroadcast: config.DisableTxBroadcast, + disableTxReceiving: config.DisableTxReceiving, + enableBroadcastToAll: config.EnableBroadcastToAll, + } + h.broadcastToAllCap = config.BroadcastToAllCap + if config.BroadcastToAllCap == 0 && config.EnableBroadcastToAll { + // Set default broadcast cap to 30 if not specified + h.broadcastToAllCap = 30 } if config.Sync == downloader.FullSync { // The database seems empty as the current block is the genesis. Yet the fast @@ -477,7 +488,12 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) { return } // Send the block to a subset of our peers - transfer := peers[:int(math.Sqrt(float64(len(peers))))] + numDirect := int(math.Sqrt(float64(len(peers)))) + // If enableBroadcastToAll is true, broadcast blocks directly to all peers (capped at 100). + if h.enableBroadcastToAll { + numDirect = min(h.broadcastToAllCap, len(peers)) + } + transfer := peers[:numDirect] for _, peer := range transfer { peer.AsyncSendNewBlock(block, td) } @@ -518,6 +534,10 @@ func (h *handler) BroadcastTransactions(txs types.Transactions) { peers := onlyShadowForkPeers(h.shadowForkPeerIDs, h.peers.peersWithoutTransaction(tx.Hash())) // Send the tx unconditionally to a subset of our peers numDirect := int(math.Sqrt(float64(len(peers)))) + // If enableBroadcastToAll is true, broadcast transactions directly to all peers (capped at 100). + if h.enableBroadcastToAll { + numDirect = min(h.broadcastToAllCap, len(peers)) + } for _, peer := range peers[:numDirect] { txset[peer] = append(txset[peer], tx.Hash()) } diff --git a/params/version.go b/params/version.go index 523d5ca47c51..555a1e557b27 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 8 // Minor version component of the current release - VersionPatch = 65 // Patch version component of the current release + VersionPatch = 66 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string )