This mempool is experimental and in active development. It is intended for testing and evaluation purposes. Use in production environments is not recommended without thorough testing and risk assessment.
Please report issues and submit feedback to help improve stability.
Overview
This guide explains how to integrate the EVM mempool in your Cosmos SDK chain to enable Ethereum-compatible transaction flows, including out-of-order transactions and nonce gap handling.Prerequisites
Before integrating the EVM mempool:- EVM Module Integration: Complete the EVM module integration first
- FeeMarket Module: Ensure the feemarket module is properly configured for base fee calculations
- Compatible AnteHandler: Your ante handler must support EVM transaction validation
Quick Start
Step 1: Add EVM Mempool to App Struct
Update yourapp/app.go
to include the EVM mempool:
Step 2: Configure Mempool in NewApp Constructor
The mempool must be initialized after the antehandler has been set in the app.
NewApp
constructor:
Configuration Options
TheEVMMempoolConfig
struct provides several configuration options for customizing the mempool behavior:
Minimal Configuration
Full Configuration Options
Custom Cosmos Mempool Configuration
The mempool uses aPriorityNonceMempool
for Cosmos transactions by default. You can customize the priority calculation:
Custom Block Gas Limit
Different chains may require different gas limits based on their capacity:Advanced Pool Parameter Customization
Modifying Hard-Coded Pool Limits
Several pool parameters are compiled into the source code and require modification for custom configurations:TxPool Configuration Parameters
File:mempool/txpool/legacypool/legacypool.go
Default Configuration (lines ~45-55):
High-Throughput Configuration
For chains handling high transaction volumes:Memory-Constrained Configuration
For resource-limited environments:Custom TxPool Implementation
For complete control over pool behavior, implement a custom TxPool: File: Createmempool/custom_pool.go
Architecture Components
The EVM mempool consists of several key components:ExperimentalEVMMempool
The main coordinator implementing Cosmos SDK’sExtMempool
interface (mempool/mempool.go
).
Key Methods:
Insert(ctx, tx)
: Routes transactions to appropriate poolsSelect(ctx, filter)
: Returns unified iterator over all transactionsRemove(tx)
: Handles transaction removal with EVM-specific logicInsertInvalidNonce(txBytes)
: Queues nonce-gapped EVM transactions locally
CheckTx Handler
Custom transaction validation that handles nonce gaps specially (mempool/check_tx.go
).
Special Handling: On ErrNonceGap
for EVM transactions:
TxPool
Direct port of Ethereum’s transaction pool managing both pending and queued transactions (mempool/txpool/
).
Key Features:
- Uses
vm.StateDB
interface for Cosmos state compatibility - Implements
BroadcastTxFn
callback for transaction promotion - Cosmos-specific reset logic for instant finality
PriorityNonceMempool
Standard Cosmos SDK mempool for non-EVM transactions with fee-based prioritization. Default Priority Calculation:Transaction Type Routing
The mempool handles different transaction types appropriately:Ethereum Transactions (MsgEthereumTx)
- Tier 1 (Local): EVM TxPool handles nonce gaps and promotion
- Tier 2 (Network): CometBFT broadcasts executable transactions
Cosmos Transactions (Bank, Staking, Gov, etc.)
- Direct to Tier 2: Always go directly to CometBFT mempool
- Standard Flow: Follow normal Cosmos SDK validation and broadcasting
- Priority-Based: Use PriorityNonceMempool for fee-based ordering
Unified Transaction Selection
During block building, both transaction types compete fairly based on their effective tips:- EVM:
gas_tip_cap
ormin(gas_tip_cap, gas_fee_cap - base_fee)
- Cosmos:
(fee_amount / gas_limit) - base_fee
- Selection: Higher effective tip gets selected first
Testing Your Integration
Verify Nonce Gap Handling
Test that transactions with nonce gaps are properly queued:Test Transaction Replacement
Verify that higher-fee transactions replace lower-fee ones:Verify Batch Deployments
Test typical deployment scripts (like Uniswap) that send many transactions at once:Monitoring and Debugging
Use the txpool RPC methods to monitor mempool state:txpool_status
: Get pending and queued transaction countstxpool_content
: View all transactions in the pooltxpool_inspect
: Get human-readable transaction summariestxpool_contentFrom
: View transactions from specific addresses
Related Documentation
- Mempool Concepts - Understanding mempool behavior and design
- EVM Module Integration - Prerequisites for mempool integration
- JSON-RPC Methods - Mempool query methods