@@ -404,45 +404,17 @@ func (m *ExperimentalEVMMempool) ReapNewValidTxs(maxBytes uint64, maxGas uint64)
404404func (m * ExperimentalEVMMempool ) Select (goCtx context.Context , i [][]byte ) sdkmempool.Iterator {
405405 m .mtx .Lock ()
406406 defer m .mtx .Unlock ()
407+ ctx := sdk .UnwrapSDKContext (goCtx )
407408
408- return m .buildIterator (goCtx , i )
409- }
410-
411- // SelectBy iterates through transactions until the provided filter function returns false.
412- // It uses the same unified iterator as Select but allows early termination based on
413- // custom criteria defined by the filter function.
414- func (m * ExperimentalEVMMempool ) SelectBy (goCtx context.Context , txs [][]byte , filter func (sdk.Tx ) bool ) {
415- m .mtx .Lock ()
416- defer m .mtx .Unlock ()
417-
418- iter := m .buildIterator (goCtx , txs )
419-
420- for iter != nil && filter (iter .Tx ()) {
421- iter = iter .Next ()
422- }
423- }
424-
425- // buildIterator ensures that EVM mempool has checked txs for reorgs up to COMMITTED
426- // block height and then returns a combined iterator over EVM & Cosmos txs.
427- func (m * ExperimentalEVMMempool ) buildIterator (ctx context.Context , txs [][]byte ) sdkmempool.Iterator {
428- sdkCtx := sdk .UnwrapSDKContext (ctx )
429-
430- // context has a block height of the next PROPOSED block,
431- // but we need to wait for the reorg to complete on the previous COMMITTED block.
432- committedHeight := sdkCtx .BlockHeight () - 1
409+ // Wait for the legacypool to Reset at >= blockHeight (this may have
410+ // already happened), to ensure all txs in pending pool are valid.
411+ m .legacyTxPool .WaitForReorgHeight (ctx , ctx .BlockHeight ())
433412
434- m . legacyTxPool . WaitForReorgHeight ( ctx , committedHeight )
413+ evmIterator , cosmosIterator := m . getIterators ( goCtx , i )
435414
436- evmIterator , cosmosIterator := m .getIterators (ctx , txs )
415+ combinedIterator := NewEVMMempoolIterator ( evmIterator , cosmosIterator , m . logger , m .txConfig , m . vmKeeper . GetEvmCoinInfo (ctx ). Denom , m . blockchain . Config (). ChainID , m . blockchain )
437416
438- return NewEVMMempoolIterator (
439- evmIterator ,
440- cosmosIterator ,
441- m .logger ,
442- m .txConfig ,
443- m .vmKeeper .GetEvmCoinInfo (sdkCtx ).Denom ,
444- m .blockchain ,
445- )
417+ return combinedIterator
446418}
447419
448420// CountTx returns the total number of transactions in both EVM and Cosmos pools.
@@ -547,6 +519,23 @@ func (m *ExperimentalEVMMempool) shouldRemoveFromEVMPool(hash common.Hash, reaso
547519 return true
548520}
549521
522+ // SelectBy iterates through transactions until the provided filter function returns false.
523+ // It uses the same unified iterator as Select but allows early termination based on
524+ // custom criteria defined by the filter function.
525+ func (m * ExperimentalEVMMempool ) SelectBy (goCtx context.Context , i [][]byte , f func (sdk.Tx ) bool ) {
526+ m .mtx .Lock ()
527+ defer m .mtx .Unlock ()
528+ ctx := sdk .UnwrapSDKContext (goCtx )
529+
530+ evmIterator , cosmosIterator := m .getIterators (goCtx , i )
531+
532+ combinedIterator := NewEVMMempoolIterator (evmIterator , cosmosIterator , m .logger , m .txConfig , m .vmKeeper .GetEvmCoinInfo (ctx ).Denom , m .blockchain .Config ().ChainID , m .blockchain )
533+
534+ for combinedIterator != nil && f (combinedIterator .Tx ()) {
535+ combinedIterator = combinedIterator .Next ()
536+ }
537+ }
538+
550539// SetEventBus sets CometBFT event bus to listen for new block header event.
551540func (m * ExperimentalEVMMempool ) SetEventBus (eventBus * cmttypes.EventBus ) {
552541 if m .HasEventBus () {
@@ -605,26 +594,29 @@ func (m *ExperimentalEVMMempool) getEVMMessage(tx sdk.Tx) (*evmtypes.MsgEthereum
605594// getIterators prepares iterators over pending EVM and Cosmos transactions.
606595// It configures EVM transactions with proper base fee filtering and priority ordering,
607596// while setting up the Cosmos iterator with the provided exclusion list.
608- func (m * ExperimentalEVMMempool ) getIterators (goCtx context.Context , txs [][]byte ) (* miner.TransactionsByPriceAndNonce , sdkmempool.Iterator ) {
597+ func (m * ExperimentalEVMMempool ) getIterators (goCtx context.Context , i [][]byte ) (* miner.TransactionsByPriceAndNonce , sdkmempool.Iterator ) {
609598 ctx := sdk .UnwrapSDKContext (goCtx )
610599 baseFee := m .vmKeeper .GetBaseFee (ctx )
611600 var baseFeeUint * uint256.Int
612601 if baseFee != nil {
613602 baseFeeUint = uint256 .MustFromBig (baseFee )
614603 }
615604
616- evmPendingTxs := m .txPool .Pending (txpool.PendingFilter {
605+ m .logger .Debug ("getting iterators" )
606+
607+ pendingFilter := txpool.PendingFilter {
617608 MinTip : m .minTip ,
618609 BaseFee : baseFeeUint ,
619610 BlobFee : nil ,
620611 OnlyPlainTxs : true ,
621612 OnlyBlobTxs : false ,
622- })
613+ }
614+ evmPendingTxes := m .txPool .Pending (pendingFilter )
615+ orderedEVMPendingTxes := miner .NewTransactionsByPriceAndNonce (nil , evmPendingTxes , baseFee )
623616
624- evmIterator := miner .NewTransactionsByPriceAndNonce (nil , evmPendingTxs , baseFee )
625- cosmosIterator := m .cosmosPool .Select (ctx , txs )
617+ cosmosPendingTxes := m .cosmosPool .Select (ctx , i )
626618
627- return evmIterator , cosmosIterator
619+ return orderedEVMPendingTxes , cosmosPendingTxes
628620}
629621
630622func (m * ExperimentalEVMMempool ) TrackTx (hash common.Hash ) error {
0 commit comments