Skip to content

Commit

Permalink
txpool: add flag to disable tx gossip (ethereum#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly authored and protolambda committed Nov 4, 2022
1 parent 07fe0be commit 448c8eb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ var (
utils.MinerNotifyFullFlag,
utils.IgnoreLegacyReceiptsFlag,
utils.RollupSequencerHTTPFlag,
utils.RollupDisableTxPoolGossipFlag,
configFileFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags)

Expand Down
7 changes: 7 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,12 @@ var (
Category: flags.RollupCategory,
}

RollupDisableTxPoolGossipFlag = &cli.BoolFlag{
Name: "rollup.disabletxpoolgossip",
Usage: "Disable transaction pool gossip.",
Category: flags.RollupCategory,
}

// Metrics flags
MetricsEnabledFlag = &cli.BoolFlag{
Name: "metrics",
Expand Down Expand Up @@ -1916,6 +1922,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.IsSet(RollupSequencerHTTPFlag.Name) && !ctx.IsSet(MiningEnabledFlag.Name) {
cfg.RollupSequencerHTTP = ctx.String(RollupSequencerHTTPFlag.Name)
}
cfg.RollupDisableTxPoolGossip = ctx.Bool(RollupDisableTxPoolGossipFlag.Name)
// Override any default configs for hard coded networks.
switch {
case ctx.Bool(MainnetFlag.Name):
Expand Down
1 change: 1 addition & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
EventMux: eth.eventMux,
Checkpoint: checkpoint,
RequiredBlocks: config.RequiredBlocks,
NoTxGossip: config.RollupDisableTxPoolGossip,
}); err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ type Config struct {
SyncTarget *types.Block

RollupSequencerHTTP string

RollupDisableTxPoolGossip bool
}

// CreateConsensusEngine creates a consensus engine for the given chain configuration.
Expand Down
4 changes: 4 additions & 0 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type handlerConfig struct {
EventMux *event.TypeMux // Legacy event mux, deprecate for `feed`
Checkpoint *params.TrustedCheckpoint // Hard coded checkpoint for sync challenges
RequiredBlocks map[uint64]common.Hash // Hard coded map of required block hashes for sync challenges
NoTxGossip bool // Disable P2P transaction gossip
}

type handler struct {
Expand All @@ -104,6 +105,8 @@ type handler struct {
chain *core.BlockChain
maxPeers int

noTxGossip bool

downloader *downloader.Downloader
blockFetcher *fetcher.BlockFetcher
txFetcher *fetcher.TxFetcher
Expand Down Expand Up @@ -137,6 +140,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
eventMux: config.EventMux,
database: config.Database,
txpool: config.TxPool,
noTxGossip: config.NoTxGossip,
chain: config.Chain,
peers: newPeerSet(),
merger: config.Merger,
Expand Down
18 changes: 17 additions & 1 deletion eth/handler_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@ import (
type ethHandler handler

func (h *ethHandler) Chain() *core.BlockChain { return h.chain }
func (h *ethHandler) TxPool() eth.TxPool { return h.txpool }

// NilPool satisfies the TxPool interface but does not return any tx in the
// pool. It is used to disable transaction gossip.
type NilPool struct{}

// NilPool Get always returns nil
func (n NilPool) Get(hash common.Hash) *types.Transaction { return nil }

func (h *ethHandler) TxPool() eth.TxPool {
if h.noTxGossip {
return &NilPool{}
}
return h.txpool
}

// RunPeer is invoked when a peer joins on the `eth` protocol.
func (h *ethHandler) RunPeer(peer *eth.Peer, hand eth.Handler) error {
Expand All @@ -52,6 +65,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.noTxGossip {
return false
}
return atomic.LoadUint32(&h.acceptTxs) == 1
}

Expand Down

0 comments on commit 448c8eb

Please sign in to comment.