Skip to content

Commit 02b33db

Browse files
jonastheisyiweichi
andauthored
feat: add flags to disable broadcast and receiving of tx gossip (#1194)
* add flags to disable broadcast and receiving of tx gossip respectively * chore: auto version bump [bot] --------- Co-authored-by: Morty <[email protected]>
1 parent a43881d commit 02b33db

File tree

8 files changed

+65
-26
lines changed

8 files changed

+65
-26
lines changed

cmd/geth/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ var (
176176
utils.CircuitCapacityCheckWorkersFlag,
177177
utils.RollupVerifyEnabledFlag,
178178
utils.ShadowforkPeersFlag,
179+
utils.TxGossipBroadcastDisabledFlag,
180+
utils.TxGossipReceivingDisabledFlag,
179181
utils.DASyncEnabledFlag,
180182
utils.DABlockNativeAPIEndpointFlag,
181183
utils.DABlobScanAPIEndpointFlag,

cmd/geth/usage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ var AppHelpFlagGroups = []flags.FlagGroup{
248248
utils.DARecoveryProduceBlocksFlag,
249249
utils.CircuitCapacityCheckEnabledFlag,
250250
utils.CircuitCapacityCheckWorkersFlag,
251+
utils.TxGossipBroadcastDisabledFlag,
252+
utils.TxGossipReceivingDisabledFlag,
251253
},
252254
},
253255
{

cmd/utils/flags.go

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

896+
// Tx gossip settings
897+
TxGossipBroadcastDisabledFlag = cli.BoolFlag{
898+
Name: "txgossip.disablebroadcast",
899+
Usage: "Disable gossip broadcast transactions to other peers",
900+
}
901+
TxGossipReceivingDisabledFlag = cli.BoolFlag{
902+
Name: "txgossip.disablereceiving",
903+
Usage: "Disable gossip receiving transactions from other peers",
904+
}
905+
896906
// DA syncing settings
897907
DASyncEnabledFlag = cli.BoolFlag{
898908
Name: "da.sync",
@@ -1790,6 +1800,14 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17901800
cfg.ShadowForkPeerIDs = ctx.GlobalStringSlice(ShadowforkPeersFlag.Name)
17911801
log.Info("Shadow fork peers", "ids", cfg.ShadowForkPeerIDs)
17921802
}
1803+
if ctx.GlobalIsSet(TxGossipBroadcastDisabledFlag.Name) {
1804+
cfg.TxGossipBroadcastDisabled = ctx.GlobalBool(TxGossipBroadcastDisabledFlag.Name)
1805+
log.Info("Transaction gossip broadcast disabled", "disabled", cfg.TxGossipBroadcastDisabled)
1806+
}
1807+
if ctx.GlobalIsSet(TxGossipReceivingDisabledFlag.Name) {
1808+
cfg.TxGossipReceivingDisabled = ctx.GlobalBool(TxGossipReceivingDisabledFlag.Name)
1809+
log.Info("Transaction gossip receiving disabled", "disabled", cfg.TxGossipReceivingDisabled)
1810+
}
17931811

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

eth/backend.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,18 @@ 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,
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,
286288
}); err != nil {
287289
return nil, err
288290
}

eth/ethconfig/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ type Config struct {
230230

231231
// DA syncer options
232232
DA da_syncer.Config
233+
234+
TxGossipBroadcastDisabled bool
235+
TxGossipReceivingDisabled bool
233236
}
234237

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

eth/handler.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ type handlerConfig struct {
9393
Checkpoint *params.TrustedCheckpoint // Hard coded checkpoint for sync challenges
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
96+
97+
DisableTxBroadcast bool
98+
DisableTxReceiving bool
9699
}
97100

98101
type handler struct {
@@ -131,7 +134,9 @@ type handler struct {
131134
wg sync.WaitGroup
132135
peerWG sync.WaitGroup
133136

134-
shadowForkPeerIDs []string
137+
shadowForkPeerIDs []string
138+
disableTxBroadcast bool
139+
disableTxReceiving bool
135140
}
136141

137142
// newHandler returns a handler for all Ethereum chain management protocol.
@@ -141,16 +146,18 @@ func newHandler(config *handlerConfig) (*handler, error) {
141146
config.EventMux = new(event.TypeMux) // Nicety initialization for tests
142147
}
143148
h := &handler{
144-
networkID: config.Network,
145-
forkFilter: forkid.NewFilter(config.Chain),
146-
eventMux: config.EventMux,
147-
database: config.Database,
148-
txpool: config.TxPool,
149-
chain: config.Chain,
150-
peers: newPeerSet(),
151-
whitelist: config.Whitelist,
152-
quitSync: make(chan struct{}),
153-
shadowForkPeerIDs: config.ShadowForkPeerIDs,
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,
154161
}
155162
if config.Sync == downloader.FullSync {
156163
// The database seems empty as the current block is the genesis. Yet the fast
@@ -415,10 +422,12 @@ func (h *handler) Start(maxPeers int) {
415422
h.maxPeers = maxPeers
416423

417424
// broadcast transactions
418-
h.wg.Add(1)
419-
h.txsCh = make(chan core.NewTxsEvent, txChanSize)
420-
h.txsSub = h.txpool.SubscribeNewTxsEvent(h.txsCh)
421-
go h.txBroadcastLoop()
425+
if !h.disableTxBroadcast {
426+
h.wg.Add(1)
427+
h.txsCh = make(chan core.NewTxsEvent, txChanSize)
428+
h.txsSub = h.txpool.SubscribeNewTxsEvent(h.txsCh)
429+
go h.txBroadcastLoop()
430+
}
422431

423432
// broadcast mined blocks
424433
h.wg.Add(1)

eth/handler_eth.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ func (h *ethHandler) PeerInfo(id enode.ID) interface{} {
5656
// AcceptTxs retrieves whether transaction processing is enabled on the node
5757
// or if inbound transactions should simply be dropped.
5858
func (h *ethHandler) AcceptTxs() bool {
59+
if h.disableTxReceiving {
60+
return false
61+
}
5962
return atomic.LoadUint32(&h.acceptTxs) == 1
6063
}
6164

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 8 // Minor version component of the current release
27-
VersionPatch = 56 // Patch version component of the current release
27+
VersionPatch = 57 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)