Skip to content

feat: add flags to disable broadcast and receiving of tx gossip #1194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ var (
utils.CircuitCapacityCheckWorkersFlag,
utils.RollupVerifyEnabledFlag,
utils.ShadowforkPeersFlag,
utils.TxGossipBroadcastDisabledFlag,
utils.TxGossipReceivingDisabledFlag,
utils.DASyncEnabledFlag,
utils.DABlockNativeAPIEndpointFlag,
utils.DABlobScanAPIEndpointFlag,
Expand Down
2 changes: 2 additions & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.DARecoveryProduceBlocksFlag,
utils.CircuitCapacityCheckEnabledFlag,
utils.CircuitCapacityCheckWorkersFlag,
utils.TxGossipBroadcastDisabledFlag,
utils.TxGossipReceivingDisabledFlag,
},
},
{
Expand Down
18 changes: 18 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand Down
22 changes: 12 additions & 10 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
39 changes: 24 additions & 15 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions eth/handler_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading