diff --git a/cmd/geth/main.go b/cmd/geth/main.go index c1fbb08746a..efffc9480ac 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -176,6 +176,8 @@ var ( utils.CircuitCapacityCheckWorkersFlag, utils.RollupVerifyEnabledFlag, utils.ShadowforkPeersFlag, + utils.TxGossipBroadcastDisabledFlag, + utils.TxGossipReceivingDisabledFlag, utils.DASyncEnabledFlag, utils.DABlockNativeAPIEndpointFlag, utils.DABlobScanAPIEndpointFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 1d299d339fe..60b7e5416b0 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -248,6 +248,8 @@ var AppHelpFlagGroups = []flags.FlagGroup{ utils.DARecoveryProduceBlocksFlag, utils.CircuitCapacityCheckEnabledFlag, utils.CircuitCapacityCheckWorkersFlag, + utils.TxGossipBroadcastDisabledFlag, + utils.TxGossipReceivingDisabledFlag, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 7371a377007..a2a1655502d 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -893,6 +893,16 @@ var ( Usage: "peer ids of shadow fork peers", } + // Tx gossip settings + TxGossipBroadcastDisabledFlag = cli.BoolFlag{ + Name: "txgossip.disablebroadcast", + Usage: "Disable gossip broadcast transactions to other peers", + } + TxGossipReceivingDisabledFlag = cli.BoolFlag{ + Name: "txgossip.disablereceiving", + Usage: "Disable gossip receiving transactions from other peers", + } + // DA syncing settings DASyncEnabledFlag = cli.BoolFlag{ Name: "da.sync", @@ -1790,6 +1800,14 @@ 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(TxGossipReceivingDisabledFlag.Name) { + cfg.TxGossipReceivingDisabled = ctx.GlobalBool(TxGossipReceivingDisabledFlag.Name) + log.Info("Transaction gossip receiving disabled", "disabled", cfg.TxGossipReceivingDisabled) + } // Cap the cache allowance and tune the garbage collector mem, err := gopsutil.VirtualMemory() diff --git a/eth/backend.go b/eth/backend.go index ad765b835b0..0050d3853b6 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -273,16 +273,18 @@ 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, + 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, }); err != nil { return nil, err } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 94fa46c34c3..0f70eb2ed6c 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -230,6 +230,9 @@ type Config struct { // DA syncer options DA da_syncer.Config + + TxGossipBroadcastDisabled bool + TxGossipReceivingDisabled bool } // CreateConsensusEngine creates a consensus engine for the given chain configuration. diff --git a/eth/handler.go b/eth/handler.go index 4755a0c7b70..520723f18af 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -93,6 +93,9 @@ type handlerConfig struct { Checkpoint *params.TrustedCheckpoint // Hard coded checkpoint for sync challenges 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 } type handler struct { @@ -131,7 +134,9 @@ type handler struct { wg sync.WaitGroup peerWG sync.WaitGroup - shadowForkPeerIDs []string + shadowForkPeerIDs []string + disableTxBroadcast bool + disableTxReceiving bool } // newHandler returns a handler for all Ethereum chain management protocol. @@ -141,16 +146,18 @@ 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, + 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, } if config.Sync == downloader.FullSync { // The database seems empty as the current block is the genesis. Yet the fast @@ -415,10 +422,12 @@ func (h *handler) Start(maxPeers int) { h.maxPeers = maxPeers // broadcast transactions - h.wg.Add(1) - h.txsCh = make(chan core.NewTxsEvent, txChanSize) - h.txsSub = h.txpool.SubscribeNewTxsEvent(h.txsCh) - go h.txBroadcastLoop() + if !h.disableTxBroadcast { + h.wg.Add(1) + h.txsCh = make(chan core.NewTxsEvent, txChanSize) + h.txsSub = h.txpool.SubscribeNewTxsEvent(h.txsCh) + go h.txBroadcastLoop() + } // broadcast mined blocks h.wg.Add(1) diff --git a/eth/handler_eth.go b/eth/handler_eth.go index 1a3aff8aa09..9fc494711f7 100644 --- a/eth/handler_eth.go +++ b/eth/handler_eth.go @@ -56,6 +56,9 @@ func (h *ethHandler) PeerInfo(id enode.ID) interface{} { // AcceptTxs retrieves whether transaction processing is enabled on the node // or if inbound transactions should simply be dropped. func (h *ethHandler) AcceptTxs() bool { + if h.disableTxReceiving { + return false + } return atomic.LoadUint32(&h.acceptTxs) == 1 } diff --git a/params/version.go b/params/version.go index 0a9f4e2b00b..f8f2cbeb11b 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 = 56 // Patch version component of the current release + VersionPatch = 57 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string )