Skip to content

Commit e01cc50

Browse files
authored
(chore):Simplify Mempool Config (#496)
* refactor mempool initialization to accept configs instead of objects * clean * add changelog
1 parent 48e3c83 commit e01cc50

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
- [\#467](https://github.com/cosmos/evm/pull/467) Replace GlobalEVMMempool by passing to JSONRPC on initiate.
1515
- [\#352](https://github.com/cosmos/evm/pull/352) Remove the creation of a Geth EVM instance, stateDB during the AnteHandler balance check.
16+
- [\#496](https://github.com/cosmos/evm/pull/496) Simplify mempool instantiation by using configs instead of objects.
1617

1718
### FEATURES
1819

mempool/mempool.go

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ type (
6767
// It allows customization of the underlying mempools, verification functions,
6868
// and broadcasting functions used by the sdkmempool.
6969
type EVMMempoolConfig struct {
70-
TxPool *txpool.TxPool
71-
CosmosPool sdkmempool.ExtMempool
72-
AnteHandler sdk.AnteHandler
73-
BroadCastTxFn func(txs []*ethtypes.Transaction) error
74-
BlockGasLimit uint64 // Block gas limit from consensus parameters
70+
LegacyPoolConfig *legacypool.Config
71+
CosmosPoolConfig *sdkmempool.PriorityNonceMempoolConfig[math.Int]
72+
AnteHandler sdk.AnteHandler
73+
BroadCastTxFn func(txs []*ethtypes.Transaction) error
74+
BlockGasLimit uint64 // Block gas limit from consensus parameters
7575
}
7676

7777
// NewExperimentalEVMMempool creates a new unified mempool for EVM and Cosmos transactions.
@@ -106,29 +106,30 @@ func NewExperimentalEVMMempool(getCtxCallback func(height int64, prove bool) (sd
106106
config.BlockGasLimit = 100_000_000
107107
}
108108

109-
// Default txPool
110-
txPool = config.TxPool
111-
if txPool == nil {
112-
legacyPool := legacypool.New(legacypool.DefaultConfig, blockchain)
109+
// Create txPool from configuration
110+
legacyConfig := legacypool.DefaultConfig
111+
if config.LegacyPoolConfig != nil {
112+
legacyConfig = *config.LegacyPoolConfig
113+
}
113114

114-
// Set up broadcast function using clientCtx
115-
if config.BroadCastTxFn != nil {
116-
legacyPool.BroadcastTxFn = config.BroadCastTxFn
117-
} else {
118-
// Create default broadcast function using clientCtx.
119-
// The EVM mempool will broadcast transactions when it promotes them
120-
// from queued into pending, noting their readiness to be executed.
121-
legacyPool.BroadcastTxFn = func(txs []*ethtypes.Transaction) error {
122-
logger.Debug("broadcasting EVM transactions", "tx_count", len(txs))
123-
return broadcastEVMTransactions(clientCtx, txConfig, txs)
124-
}
125-
}
115+
legacyPool := legacypool.New(legacyConfig, blockchain)
126116

127-
txPoolInit, err := txpool.New(uint64(0), blockchain, []txpool.SubPool{legacyPool})
128-
if err != nil {
129-
panic(err)
117+
// Set up broadcast function using clientCtx
118+
if config.BroadCastTxFn != nil {
119+
legacyPool.BroadcastTxFn = config.BroadCastTxFn
120+
} else {
121+
// Create default broadcast function using clientCtx.
122+
// The EVM mempool will broadcast transactions when it promotes them
123+
// from queued into pending, noting their readiness to be executed.
124+
legacyPool.BroadcastTxFn = func(txs []*ethtypes.Transaction) error {
125+
logger.Debug("broadcasting EVM transactions", "tx_count", len(txs))
126+
return broadcastEVMTransactions(clientCtx, txConfig, txs)
130127
}
131-
txPool = txPoolInit
128+
}
129+
130+
txPool, err := txpool.New(uint64(0), blockchain, []txpool.SubPool{legacyPool})
131+
if err != nil {
132+
panic(err)
132133
}
133134

134135
if len(txPool.Subpools) != 1 {
@@ -138,11 +139,12 @@ func NewExperimentalEVMMempool(getCtxCallback func(height int64, prove bool) (sd
138139
panic("tx pool should contain only legacypool")
139140
}
140141

141-
// Default Cosmos Mempool
142-
cosmosPool = config.CosmosPool
143-
if cosmosPool == nil {
144-
priorityConfig := sdkmempool.PriorityNonceMempoolConfig[math.Int]{}
145-
priorityConfig.TxPriority = sdkmempool.TxPriority[math.Int]{
142+
// Create Cosmos Mempool from configuration
143+
cosmosPoolConfig := config.CosmosPoolConfig
144+
if cosmosPoolConfig == nil {
145+
// Default configuration
146+
defaultConfig := sdkmempool.PriorityNonceMempoolConfig[math.Int]{}
147+
defaultConfig.TxPriority = sdkmempool.TxPriority[math.Int]{
146148
GetTxPriority: func(goCtx context.Context, tx sdk.Tx) math.Int {
147149
cosmosTxFee, ok := tx.(sdk.FeeTx)
148150
if !ok {
@@ -162,9 +164,11 @@ func NewExperimentalEVMMempool(getCtxCallback func(height int64, prove bool) (sd
162164
},
163165
MinValue: math.ZeroInt(),
164166
}
165-
cosmosPool = sdkmempool.NewPriorityMempool(priorityConfig)
167+
cosmosPoolConfig = &defaultConfig
166168
}
167169

170+
cosmosPool = sdkmempool.NewPriorityMempool(*cosmosPoolConfig)
171+
168172
evmMempool := &ExperimentalEVMMempool{
169173
vmKeeper: vmKeeper,
170174
txPool: txPool,

0 commit comments

Comments
 (0)