Skip to content

Commit

Permalink
txpool: remove DeprecatedTxPoolConfig (#13148)
Browse files Browse the repository at this point in the history
Noticed some code debt while working on Shutter with regards to
`DeprecatedTxPoolConfig`
This PR fully removes it in favour of `txpoolcfg.Config` to simplify the
code base.
As part of this some unused txpool cmd flags and dead code is removed.
  • Loading branch information
taratorio authored Dec 17, 2024
1 parent 881e68d commit 7c5dead
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 220 deletions.
2 changes: 1 addition & 1 deletion cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ func newSync(ctx context.Context, db kv.TemporalRwDB, miningConfig *params.Minin

cfg.Prune = pm
cfg.BatchSize = batchSize
cfg.DeprecatedTxPool.Disable = true
cfg.TxPool.Disable = true
cfg.Genesis = genesis
if miningConfig != nil {
cfg.Miner = *miningConfig
Expand Down
82 changes: 23 additions & 59 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,10 @@ var (
Usage: "Disabling p2p gossip of txs. Any txs received by p2p - will be dropped. Some networks like 'Optimism execution engine'/'Optimistic Rollup' - using it to protect against MEV attacks",
Value: txpoolcfg.DefaultConfig.NoGossip,
}
TxPoolLocalsFlag = cli.StringFlag{
Name: "txpool.locals",
Usage: "Comma separated accounts to treat as locals (no flush, priority inclusion)",
}
TxPoolNoLocalsFlag = cli.BoolFlag{
Name: "txpool.nolocals",
Usage: "Disables price exemptions for locally submitted transactions",
}
TxPoolPriceLimitFlag = cli.Uint64Flag{
Name: "txpool.pricelimit",
Usage: "Minimum gas price (fee cap) limit to enforce for acceptance into the pool",
Value: ethconfig.Defaults.DeprecatedTxPool.PriceLimit,
Value: txpoolcfg.DefaultConfig.MinFeeCap,
}
TxPoolPriceBumpFlag = cli.Uint64Flag{
Name: "txpool.pricebump",
Expand All @@ -180,7 +172,7 @@ var (
TxPoolAccountSlotsFlag = cli.Uint64Flag{
Name: "txpool.accountslots",
Usage: "Minimum number of executable transaction slots guaranteed per account",
Value: ethconfig.Defaults.DeprecatedTxPool.AccountSlots,
Value: txpoolcfg.DefaultConfig.AccountSlots,
}
TxPoolBlobSlotsFlag = cli.Uint64Flag{
Name: "txpool.blobslots",
Expand All @@ -192,30 +184,20 @@ var (
Usage: "Total limit of number of all blobs in txs within the txpool",
Value: txpoolcfg.DefaultConfig.TotalBlobPoolLimit,
}
TxPoolGlobalSlotsFlag = cli.Uint64Flag{
TxPoolGlobalSlotsFlag = cli.IntFlag{
Name: "txpool.globalslots",
Usage: "Maximum number of executable transaction slots for all accounts",
Value: ethconfig.Defaults.DeprecatedTxPool.GlobalSlots,
Value: txpoolcfg.DefaultConfig.PendingSubPoolLimit,
}
TxPoolGlobalBaseFeeSlotsFlag = cli.Uint64Flag{
TxPoolGlobalBaseFeeSlotsFlag = cli.IntFlag{
Name: "txpool.globalbasefeeslots",
Usage: "Maximum number of non-executable transactions where only not enough baseFee",
Value: ethconfig.Defaults.DeprecatedTxPool.GlobalQueue,
}
TxPoolAccountQueueFlag = cli.Uint64Flag{
Name: "txpool.accountqueue",
Usage: "Maximum number of non-executable transaction slots permitted per account",
Value: ethconfig.Defaults.DeprecatedTxPool.AccountQueue,
Value: txpoolcfg.DefaultConfig.BaseFeeSubPoolLimit,
}
TxPoolGlobalQueueFlag = cli.Uint64Flag{
TxPoolGlobalQueueFlag = cli.IntFlag{
Name: "txpool.globalqueue",
Usage: "Maximum number of non-executable transaction slots for all accounts",
Value: ethconfig.Defaults.DeprecatedTxPool.GlobalQueue,
}
TxPoolLifetimeFlag = cli.DurationFlag{
Name: "txpool.lifetime",
Usage: "Maximum amount of time non-executable transaction are queued",
Value: ethconfig.Defaults.DeprecatedTxPool.Lifetime,
Value: txpoolcfg.DefaultConfig.QueuedSubPoolLimit,
}
TxPoolTraceSendersFlag = cli.StringFlag{
Name: "txpool.trace.senders",
Expand Down Expand Up @@ -1533,56 +1515,37 @@ func setGPOCobra(f *pflag.FlagSet, cfg *gaspricecfg.Config) {
}
}

func setTxPool(ctx *cli.Context, fullCfg *ethconfig.Config) {
cfg := &fullCfg.DeprecatedTxPool
func setTxPool(ctx *cli.Context, dbDir string, fullCfg *ethconfig.Config) {
cfg := txpoolcfg.DefaultConfig
if ctx.IsSet(TxPoolDisableFlag.Name) || TxPoolDisableFlag.Value {
cfg.Disable = true
}
if ctx.IsSet(TxPoolLocalsFlag.Name) {
locals := libcommon.CliString2Array(ctx.String(TxPoolLocalsFlag.Name))
for _, account := range locals {
if !libcommon.IsHexAddress(account) {
Fatalf("Invalid account in --txpool.locals: %s", account)
} else {
cfg.Locals = append(cfg.Locals, libcommon.HexToAddress(account))
}
}
}
if ctx.IsSet(TxPoolNoLocalsFlag.Name) {
cfg.NoLocals = ctx.Bool(TxPoolNoLocalsFlag.Name)
}
if ctx.IsSet(TxPoolPriceLimitFlag.Name) {
cfg.PriceLimit = ctx.Uint64(TxPoolPriceLimitFlag.Name)
cfg.MinFeeCap = ctx.Uint64(TxPoolPriceLimitFlag.Name)
}
if ctx.IsSet(TxPoolPriceBumpFlag.Name) {
cfg.PriceBump = ctx.Uint64(TxPoolPriceBumpFlag.Name)
}
if ctx.IsSet(TxPoolBlobPriceBumpFlag.Name) {
fullCfg.TxPool.BlobPriceBump = ctx.Uint64(TxPoolBlobPriceBumpFlag.Name)
cfg.BlobPriceBump = ctx.Uint64(TxPoolBlobPriceBumpFlag.Name)
}
if ctx.IsSet(TxPoolAccountSlotsFlag.Name) {
cfg.AccountSlots = ctx.Uint64(TxPoolAccountSlotsFlag.Name)
}
if ctx.IsSet(TxPoolBlobSlotsFlag.Name) {
fullCfg.TxPool.BlobSlots = ctx.Uint64(TxPoolBlobSlotsFlag.Name)
cfg.BlobSlots = ctx.Uint64(TxPoolBlobSlotsFlag.Name)
}
if ctx.IsSet(TxPoolTotalBlobPoolLimit.Name) {
fullCfg.TxPool.TotalBlobPoolLimit = ctx.Uint64(TxPoolTotalBlobPoolLimit.Name)
cfg.TotalBlobPoolLimit = ctx.Uint64(TxPoolTotalBlobPoolLimit.Name)
}
if ctx.IsSet(TxPoolGlobalSlotsFlag.Name) {
cfg.GlobalSlots = ctx.Uint64(TxPoolGlobalSlotsFlag.Name)
}
if ctx.IsSet(TxPoolAccountQueueFlag.Name) {
cfg.AccountQueue = ctx.Uint64(TxPoolAccountQueueFlag.Name)
cfg.PendingSubPoolLimit = ctx.Int(TxPoolGlobalSlotsFlag.Name)
}
if ctx.IsSet(TxPoolGlobalQueueFlag.Name) {
cfg.GlobalQueue = ctx.Uint64(TxPoolGlobalQueueFlag.Name)
cfg.QueuedSubPoolLimit = ctx.Int(TxPoolGlobalQueueFlag.Name)
}
if ctx.IsSet(TxPoolGlobalBaseFeeSlotsFlag.Name) {
cfg.GlobalBaseFeeQueue = ctx.Uint64(TxPoolGlobalBaseFeeSlotsFlag.Name)
}
if ctx.IsSet(TxPoolLifetimeFlag.Name) {
cfg.Lifetime = ctx.Duration(TxPoolLifetimeFlag.Name)
cfg.BaseFeeSubPoolLimit = ctx.Int(TxPoolGlobalBaseFeeSlotsFlag.Name)
}
if ctx.IsSet(TxPoolTraceSendersFlag.Name) {
// Parse the command separated flag
Expand All @@ -1594,12 +1557,15 @@ func setTxPool(ctx *cli.Context, fullCfg *ethconfig.Config) {
}
}
if ctx.IsSet(TxPoolBlobPriceBumpFlag.Name) {
fullCfg.TxPool.BlobPriceBump = ctx.Uint64(TxPoolBlobPriceBumpFlag.Name)
cfg.BlobPriceBump = ctx.Uint64(TxPoolBlobPriceBumpFlag.Name)
}
if ctx.IsSet(DbWriteMapFlag.Name) {
fullCfg.TxPool.MdbxWriteMap = ctx.Bool(DbWriteMapFlag.Name)
cfg.MdbxWriteMap = ctx.Bool(DbWriteMapFlag.Name)
}
cfg.LogEvery = 3 * time.Minute
cfg.CommitEvery = libcommon.RandomizeDuration(ctx.Duration(TxPoolCommitEveryFlag.Name))
cfg.DBDir = dbDir
fullCfg.TxPool = cfg
}

func setShutter(ctx *cli.Context, chainName string, cfg *ethconfig.Config) {
Expand Down Expand Up @@ -1938,9 +1904,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
setEtherbase(ctx, cfg)
setGPO(ctx, &cfg.GPO)

setTxPool(ctx, cfg)
cfg.TxPool = ethconfig.DefaultTxPool2Config(cfg)
cfg.TxPool.DBDir = nodeConfig.Dirs.TxPool
setTxPool(ctx, nodeConfig.Dirs.TxPool, cfg)
setShutter(ctx, chain, cfg)

setEthash(ctx, nodeConfig.Dirs.DataDir, cfg)
Expand Down
45 changes: 3 additions & 42 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ import (
"github.com/erigontech/erigon/eth/consensuschain"
"github.com/erigontech/erigon/eth/ethconfig"
"github.com/erigontech/erigon/eth/ethconsensusconfig"
"github.com/erigontech/erigon/eth/ethutils"
"github.com/erigontech/erigon/eth/protocols/eth"
"github.com/erigontech/erigon/eth/stagedsync"
"github.com/erigontech/erigon/eth/stagedsync/stages"
Expand Down Expand Up @@ -649,7 +648,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
config.TxPool.NoGossip = config.DisableTxPoolGossip
var miningRPC txpoolproto.MiningServer
stateDiffClient := direct.NewStateDiffClientDirect(kvRPC)
if config.DeprecatedTxPool.Disable {
if config.TxPool.Disable {
backend.txPoolGrpcServer = &txpool.GrpcDisabled{}
} else {
backend.newTxs = make(chan txpool.Announcements, 1024)
Expand All @@ -662,7 +661,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
txnProvider = backend.txPool
}
if config.Shutter.Enabled {
if config.DeprecatedTxPool.Disable {
if config.TxPool.Disable {
panic("can't enable shutter pool when devp2p txpool is disabled")
}
backend.shutterPool = shutter.NewPool(logger, config.Shutter, txnProvider)
Expand Down Expand Up @@ -830,7 +829,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
// to initialize it properly.
// 2) we cannot propose for block 1 regardless.

if !config.DeprecatedTxPool.Disable {
if !config.TxPool.Disable {
backend.txPoolFetch.ConnectCore()
backend.txPoolFetch.ConnectSentries()
var newTxsBroadcaster *txpool.NewSlotsStreams
Expand Down Expand Up @@ -1154,44 +1153,6 @@ func (s *Ethereum) Etherbase() (eb libcommon.Address, err error) {
return libcommon.Address{}, errors.New("etherbase must be explicitly specified")
}

// isLocalBlock checks whether the specified block is mined
// by local miner accounts.
//
// We regard two types of accounts as local miner account: etherbase
// and accounts specified via `txpool.locals` flag.
func (s *Ethereum) isLocalBlock(block *types.Block) bool { //nolint
s.lock.RLock()
etherbase := s.etherbase
s.lock.RUnlock()
return ethutils.IsLocalBlock(s.engine, etherbase, s.config.DeprecatedTxPool.Locals, block.Header())
}

// shouldPreserve checks whether we should preserve the given block
// during the chain reorg depending on whether the author of block
// is a local account.
func (s *Ethereum) shouldPreserve(block *types.Block) bool { //nolint
// The reason we need to disable the self-reorg preserving for clique
// is it can be probable to introduce a deadlock.
//
// e.g. If there are 7 available signers
//
// r1 A
// r2 B
// r3 C
// r4 D
// r5 A [X] F G
// r6 [X]
//
// In the round5, the inturn signer E is offline, so the worst case
// is A, F and G sign the block of round5 and reject the block of opponents
// and in the round6, the last available signer B is offline, the whole
// network is stuck.
if _, ok := s.engine.(*clique.Clique); ok {
return false
}
return s.isLocalBlock(block)
}

// StartMining starts the miner with the given number of CPU threads. If mining
// is already running, this method adjust the number of threads allowed to use
// and updates the minimum price required by the transaction pool.
Expand Down
14 changes: 6 additions & 8 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ var Defaults = Config{
GasPrice: big.NewInt(params.GWei),
Recommit: 3 * time.Second,
},
DeprecatedTxPool: DeprecatedDefaultTxPoolConfig,
TxPool: txpoolcfg.DefaultConfig,
RPCGasCap: 50000000,
GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether
TxPool: txpoolcfg.DefaultConfig,
RPCGasCap: 50000000,
GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether

ImportMode: false,
Snapshot: BlocksFreezing{
Expand Down Expand Up @@ -211,9 +210,8 @@ type Config struct {
Aura chain.AuRaConfig

// Transaction pool options
DeprecatedTxPool DeprecatedTxPoolConfig
TxPool txpoolcfg.Config
Shutter shutter.Config
TxPool txpoolcfg.Config
Shutter shutter.Config

// Gas Price Oracle options
GPO gaspricecfg.Config
Expand Down
13 changes: 7 additions & 6 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7c5dead

Please sign in to comment.