diff --git a/mempool/internal/heightsync/heightsync.go b/mempool/internal/heightsync/heightsync.go index 1d40a21b8..00ceb7902 100644 --- a/mempool/internal/heightsync/heightsync.go +++ b/mempool/internal/heightsync/heightsync.go @@ -8,6 +8,8 @@ import ( "time" "github.com/ethereum/go-ethereum/metrics" + + "cosmossdk.io/log/v2" ) var ( @@ -26,6 +28,10 @@ var ( // hsDuration is the total time callers of Get spend from invocation to // return. hsDuration = metrics.NewRegisteredTimer("height_sync/duration", nil) + + // hsHeights it the total number of heights progressed through on the + // height sync + hsHeights = metrics.NewRegisteredMeter("height_sync/heights", nil) ) // HeightSync synchronizes access to a per-height tx store for mempool @@ -50,7 +56,7 @@ type HeightSync[Store any] struct { currentHeight *big.Int // reset is a function that returns a new store, called at every new height - reset func() *Store + reset func(logger log.Logger) *Store // store is the current Store that operations are happening on via Do and will // be returned via Get until a new height is started via StartNewHeight @@ -66,16 +72,19 @@ type HeightSync[Store any] struct { // mu protects all of the above fields; it does not protect internal // fields of the Store itself mu sync.RWMutex + + logger log.Logger } // New creates a new HeightSync starting at the given height. -func New[Store any](startHeight *big.Int, reset func() *Store) *HeightSync[Store] { +func New[Store any](startHeight *big.Int, reset func(logger log.Logger) *Store, logger log.Logger) *HeightSync[Store] { hs := &HeightSync[Store]{ currentHeight: startHeight, reset: reset, - store: reset(), + store: reset(logger), heightChanged: make(chan struct{}), done: make(chan struct{}), + logger: logger, } // initial height is considered immediately done hs.EndCurrentHeight() @@ -96,7 +105,7 @@ func (hs *HeightSync[Store]) StartNewHeight(height *big.Int) { // create new Store for this height hs.currentHeight = new(big.Int).Set(height) - hs.store = hs.reset() + hs.store = hs.reset(hs.logger) // close old channel and create new one to wake up consumers oldChan := hs.heightChanged @@ -117,6 +126,7 @@ func (hs *HeightSync[Store]) EndCurrentHeight() { if hs.isHeightEnded() { panic(fmt.Errorf("height %s already ended", hs.currentHeight.String())) } + hsHeights.Mark(1) close(hs.done) } diff --git a/mempool/internal/heightsync/heightsync_test.go b/mempool/internal/heightsync/heightsync_test.go index 827000a9b..ff747c70c 100644 --- a/mempool/internal/heightsync/heightsync_test.go +++ b/mempool/internal/heightsync/heightsync_test.go @@ -11,6 +11,8 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/evm/mempool/internal/heightsync" + + "cosmossdk.io/log/v2" ) // testStore is a simple store for testing the generic height-sync behavior. @@ -19,7 +21,7 @@ type testStore struct { mu sync.Mutex } -func newTestValue() *testStore { +func newTestValue(_ log.Logger) *testStore { return &testStore{} } @@ -36,7 +38,7 @@ func (s *testStore) get() []string { } func TestBasicGetAfterCompletion(t *testing.T) { - hv := heightsync.New(big.NewInt(1), newTestValue) + hv := heightsync.New(big.NewInt(1), newTestValue, log.NewNopLogger()) hv.StartNewHeight(big.NewInt(1)) hv.Do(func(s *testStore) { @@ -58,7 +60,7 @@ func TestBasicGetAfterCompletion(t *testing.T) { } func TestGetTimeoutBeforeHeight(t *testing.T) { - hv := heightsync.New(big.NewInt(1), newTestValue) + hv := heightsync.New(big.NewInt(1), newTestValue, log.NewNopLogger()) // request height 3 but don't advance to it ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) @@ -70,7 +72,7 @@ func TestGetTimeoutBeforeHeight(t *testing.T) { func TestGetPartialResults(t *testing.T) { synctest.Test(t, func(t *testing.T) { - hv := heightsync.New(big.NewInt(1), newTestValue) + hv := heightsync.New(big.NewInt(1), newTestValue, log.NewNopLogger()) // start new height but don't call EndCurrentHeight hv.StartNewHeight(big.NewInt(1)) @@ -90,7 +92,7 @@ func TestGetPartialResults(t *testing.T) { func TestGetBehindByOneHeight(t *testing.T) { synctest.Test(t, func(t *testing.T) { - hv := heightsync.New(big.NewInt(1), newTestValue) + hv := heightsync.New(big.NewInt(1), newTestValue, log.NewNopLogger()) hv.StartNewHeight(big.NewInt(1)) hv.Do(func(s *testStore) { s.add("height1") }) @@ -120,7 +122,7 @@ func TestGetBehindByOneHeight(t *testing.T) { func TestGetBehindByTwoHeights(t *testing.T) { synctest.Test(t, func(t *testing.T) { - hv := heightsync.New(big.NewInt(1), newTestValue) + hv := heightsync.New(big.NewInt(1), newTestValue, log.NewNopLogger()) hv.StartNewHeight(big.NewInt(1)) hv.Do(func(s *testStore) { s.add("height1") }) @@ -155,7 +157,7 @@ func TestGetBehindByTwoHeights(t *testing.T) { } func TestPanicOnOldHeight(t *testing.T) { - hv := heightsync.New(big.NewInt(1), newTestValue) + hv := heightsync.New(big.NewInt(1), newTestValue, log.NewNopLogger()) hv.StartNewHeight(big.NewInt(1)) hv.EndCurrentHeight() @@ -170,7 +172,7 @@ func TestPanicOnOldHeight(t *testing.T) { } func TestStartNewHeightResetsValue(t *testing.T) { - hv := heightsync.New(big.NewInt(1), newTestValue) + hv := heightsync.New(big.NewInt(1), newTestValue, log.NewNopLogger()) hv.StartNewHeight(big.NewInt(1)) hv.Do(func(s *testStore) { s.add("old") }) @@ -189,7 +191,7 @@ func TestStartNewHeightResetsValue(t *testing.T) { } func TestConcurrentDo(t *testing.T) { - hv := heightsync.New(big.NewInt(1), newTestValue) + hv := heightsync.New(big.NewInt(1), newTestValue, log.NewNopLogger()) hv.StartNewHeight(big.NewInt(1)) diff --git a/mempool/mempool.go b/mempool/mempool.go index 39bc8ff2b..19da35c95 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -157,6 +157,7 @@ func NewExperimentalEVMMempool( } legacyPool := legacypool.New( legacyConfig, + logger, blockchain, legacypool.WithRecheck(evmRechecker), ) @@ -213,7 +214,7 @@ func NewExperimentalEVMMempool( cosmosPool, tracker.NewHandle(-1), cosmosRechecker, - heightsync.New(blockchain.CurrentBlock().Number, NewCosmosTxStore), + heightsync.New(blockchain.CurrentBlock().Number, NewCosmosTxStore, logger.With("pool", "recheckpool")), blockchain, ) diff --git a/mempool/recheck_pool_test.go b/mempool/recheck_pool_test.go index 9bf750d1b..566a8b001 100644 --- a/mempool/recheck_pool_test.go +++ b/mempool/recheck_pool_test.go @@ -1192,7 +1192,7 @@ func noopAnteHandler(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) { // newTestRecheckedTxs creates a HeightSync[CosmosTxStore] for testing, starting at height 0. func newTestRecheckedTxs() *heightsync.HeightSync[mempool.CosmosTxStore] { - return heightsync.New(big.NewInt(0), mempool.NewCosmosTxStore) + return heightsync.New(big.NewInt(0), mempool.NewCosmosTxStore, log.NewNopLogger()) } // collectIteratorTxs drains an sdkmempool.Iterator into a slice. diff --git a/mempool/tx_store.go b/mempool/tx_store.go index c60e9b4cb..1c938efeb 100644 --- a/mempool/tx_store.go +++ b/mempool/tx_store.go @@ -3,6 +3,8 @@ package mempool import ( "sync" + "cosmossdk.io/log/v2" + sdk "github.com/cosmos/cosmos-sdk/types" sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool" ) @@ -19,7 +21,7 @@ type CosmosTxStore struct { } // NewCosmosTxStore creates a new CosmosTxStore. -func NewCosmosTxStore() *CosmosTxStore { +func NewCosmosTxStore(_ log.Logger) *CosmosTxStore { return &CosmosTxStore{ index: make(map[sdk.Tx]int), } diff --git a/mempool/tx_store_test.go b/mempool/tx_store_test.go index a6857eaa0..081f11149 100644 --- a/mempool/tx_store_test.go +++ b/mempool/tx_store_test.go @@ -8,6 +8,8 @@ import ( "github.com/cosmos/gogoproto/proto" + "cosmossdk.io/log/v2" + sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -26,7 +28,7 @@ func newMockTx(id int) sdk.Tx { } func TestCosmosTxStoreAddAndGet(t *testing.T) { - store := NewCosmosTxStore() + store := NewCosmosTxStore(log.NewNopLogger()) tx1 := newMockTx(1) tx2 := newMockTx(2) @@ -41,7 +43,7 @@ func TestCosmosTxStoreAddAndGet(t *testing.T) { } func TestCosmosTxStoreDedup(t *testing.T) { - store := NewCosmosTxStore() + store := NewCosmosTxStore(log.NewNopLogger()) tx := newMockTx(1) @@ -53,7 +55,7 @@ func TestCosmosTxStoreDedup(t *testing.T) { } func TestCosmosTxStoreIterator(t *testing.T) { - store := NewCosmosTxStore() + store := NewCosmosTxStore(log.NewNopLogger()) tx1 := newMockTx(1) tx2 := newMockTx(2) @@ -74,12 +76,12 @@ func TestCosmosTxStoreIterator(t *testing.T) { } func TestCosmosTxStoreIteratorEmpty(t *testing.T) { - store := NewCosmosTxStore() + store := NewCosmosTxStore(log.NewNopLogger()) require.Nil(t, store.Iterator()) } func TestCosmosTxStoreIteratorSnapshotIsolation(t *testing.T) { - store := NewCosmosTxStore() + store := NewCosmosTxStore(log.NewNopLogger()) tx1 := newMockTx(1) tx2 := newMockTx(2) diff --git a/mempool/txpool/legacypool/legacypool.go b/mempool/txpool/legacypool/legacypool.go index 671903e64..d1dfcce42 100644 --- a/mempool/txpool/legacypool/legacypool.go +++ b/mempool/txpool/legacypool/legacypool.go @@ -30,6 +30,7 @@ import ( "sync/atomic" "time" + cosmoslog "cosmossdk.io/log/v2" "github.com/cosmos/evm/mempool/internal/heightsync" "github.com/cosmos/evm/mempool/reserver" "github.com/ethereum/go-ethereum/common" @@ -383,7 +384,7 @@ func WithRecheck(rechecker Rechecker) Option { // New creates a new transaction pool to gather, sort and filter inbound // transactions from the network. -func New(config Config, chain BlockChain, opts ...Option) *LegacyPool { +func New(config Config, logger cosmoslog.Logger, chain BlockChain, opts ...Option) *LegacyPool { // Sanitize the input to ensure no vulnerable gas prices are set config = (&config).sanitize() @@ -398,7 +399,7 @@ func New(config Config, chain BlockChain, opts ...Option) *LegacyPool { beats: make(map[common.Address]time.Time), all: newLookup(), rechecker: newNopRechecker(), - validPendingTxs: heightsync.New(chain.CurrentBlock().Number, NewTxStore), + validPendingTxs: heightsync.New(chain.CurrentBlock().Number, NewTxStore, logger.With("pool", "legacypool")), reqResetCh: make(chan *txpoolResetRequest), reqPromoteCh: make(chan *accountSet), reqCancelResetCh: make(chan struct{}), diff --git a/mempool/txpool/legacypool/legacypool2_test.go b/mempool/txpool/legacypool/legacypool2_test.go index deb06aa61..f93c9d465 100644 --- a/mempool/txpool/legacypool/legacypool2_test.go +++ b/mempool/txpool/legacypool/legacypool2_test.go @@ -21,6 +21,7 @@ import ( "math/big" "testing" + "cosmossdk.io/log/v2" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/tracing" @@ -86,7 +87,7 @@ func TestTransactionFutureAttack(t *testing.T) { config := testTxPoolConfig config.GlobalQueue = 100 config.GlobalSlots = 100 - pool := New(config, blockchain) + pool := New(config, log.NewNopLogger(), blockchain) pool.Init(config.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -121,7 +122,7 @@ func TestTransactionFuture1559(t *testing.T) { // Create the pool to test the pricing enforcement with statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) blockchain := newTestBlockChain(eip1559Config, 1000000, statedb, new(event.Feed)) - pool := New(testTxPoolConfig, blockchain) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -154,7 +155,7 @@ func TestTransactionZAttack(t *testing.T) { // Create the pool to test the pricing enforcement with statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) blockchain := newTestBlockChain(eip1559Config, 1000000, statedb, new(event.Feed)) - pool := New(testTxPoolConfig, blockchain) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() // Create a number of test accounts, fund them and make transactions @@ -227,7 +228,7 @@ func BenchmarkFutureAttack(b *testing.B) { config := testTxPoolConfig config.GlobalQueue = 100 config.GlobalSlots = 100 - pool := New(config, blockchain) + pool := New(config, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() fillPool(b, pool) diff --git a/mempool/txpool/legacypool/legacypool_test.go b/mempool/txpool/legacypool/legacypool_test.go index ef1b4f924..08ed57e14 100644 --- a/mempool/txpool/legacypool/legacypool_test.go +++ b/mempool/txpool/legacypool/legacypool_test.go @@ -30,6 +30,7 @@ import ( "testing" "time" + "cosmossdk.io/log/v2" reserver2 "github.com/cosmos/evm/mempool/reserver" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -248,7 +249,7 @@ func setupPoolWithConfig(config *params.ChainConfig) (*LegacyPool, *MockRechecke key, _ := crypto.GenerateKey() rechecker := &MockRechecker{} - pool := New(testTxPoolConfig, blockchain, WithRecheck(rechecker)) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain, WithRecheck(rechecker)) if err := pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()); err != nil { panic(err) } @@ -381,7 +382,7 @@ func TestStateChangeDuringReset(t *testing.T) { tx0 := transaction(0, 100000, key) tx1 := transaction(1, 100000, key) - pool := New(testTxPoolConfig, blockchain) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -798,7 +799,7 @@ func TestPostponing(t *testing.T) { statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) blockchain := newTestBlockChain(params.TestChainConfig, 1000000, statedb, new(event.Feed)) - pool := New(testTxPoolConfig, blockchain) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -1008,7 +1009,7 @@ func TestQueueGlobalLimiting(t *testing.T) { config.NoLocals = true config.GlobalQueue = config.AccountQueue*3 - 1 // reduce the queue limits to shorten test time (-1 to make it non divisible) - pool := New(config, blockchain) + pool := New(config, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -1060,7 +1061,7 @@ func TestQueueTimeLimiting(t *testing.T) { config := testTxPoolConfig config.Lifetime = time.Second - pool := New(config, blockchain) + pool := New(config, log.NewNopLogger(), blockchain) pool.Init(config.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -1221,7 +1222,7 @@ func TestPendingGlobalLimiting(t *testing.T) { config := testTxPoolConfig config.GlobalSlots = config.AccountSlots * 10 - pool := New(config, blockchain) + pool := New(config, log.NewNopLogger(), blockchain) pool.Init(config.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -1320,7 +1321,7 @@ func TestCapClearsFromAll(t *testing.T) { config.AccountQueue = 2 config.GlobalSlots = 8 - pool := New(config, blockchain) + pool := New(config, log.NewNopLogger(), blockchain) pool.Init(config.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -1353,7 +1354,7 @@ func TestPendingMinimumAllowance(t *testing.T) { config := testTxPoolConfig config.GlobalSlots = 1 - pool := New(config, blockchain) + pool := New(config, log.NewNopLogger(), blockchain) pool.Init(config.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -1397,7 +1398,7 @@ func TestRepricing(t *testing.T) { statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) blockchain := newTestBlockChain(params.TestChainConfig, 1000000, statedb, new(event.Feed)) - pool := New(testTxPoolConfig, blockchain) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -1502,7 +1503,7 @@ func TestMinGasPriceEnforced(t *testing.T) { txPoolConfig := DefaultConfig txPoolConfig.NoLocals = true - pool := New(txPoolConfig, blockchain) + pool := New(txPoolConfig, log.NewNopLogger(), blockchain) pool.Init(txPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -1651,7 +1652,7 @@ func TestUnderpricing(t *testing.T) { config.GlobalSlots = 2 config.GlobalQueue = 2 - pool := New(config, blockchain) + pool := New(config, log.NewNopLogger(), blockchain) pool.Init(config.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -1741,7 +1742,7 @@ func TestStableUnderpricing(t *testing.T) { config.GlobalSlots = 128 config.GlobalQueue = 0 - pool := New(config, blockchain) + pool := New(config, log.NewNopLogger(), blockchain) pool.Init(config.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -1944,7 +1945,7 @@ func TestDeduplication(t *testing.T) { statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) blockchain := newTestBlockChain(params.TestChainConfig, 1000000, statedb, new(event.Feed)) - pool := New(testTxPoolConfig, blockchain) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -2011,7 +2012,7 @@ func TestReplacement(t *testing.T) { statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) blockchain := newTestBlockChain(params.TestChainConfig, 1000000, statedb, new(event.Feed)) - pool := New(testTxPoolConfig, blockchain) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -2203,7 +2204,7 @@ func TestStatusCheck(t *testing.T) { statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) blockchain := newTestBlockChain(params.TestChainConfig, 1000000, statedb, new(event.Feed)) - pool := New(testTxPoolConfig, blockchain) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -2276,7 +2277,7 @@ func TestSetCodeTransactions(t *testing.T) { statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) blockchain := newTestBlockChain(params.MergedTestChainConfig, 1000000, statedb, new(event.Feed)) - pool := New(testTxPoolConfig, blockchain) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -2574,7 +2575,7 @@ func TestSetCodeTransactionsReorg(t *testing.T) { statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) blockchain := newTestBlockChain(params.MergedTestChainConfig, 1000000, statedb, new(event.Feed)) - pool := New(testTxPoolConfig, blockchain) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain) pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) defer pool.Close() @@ -2633,7 +2634,7 @@ func TestRemoveTxTruncatePoolRace(t *testing.T) { statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) blockchain := newTestBlockChain(params.MergedTestChainConfig, 1000000, statedb, new(event.Feed)) - pool := New(testTxPoolConfig, blockchain) + pool := New(testTxPoolConfig, log.NewNopLogger(), blockchain) err := pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), newReserver()) if err != nil { t.Fatalf("failed to init pool: %v", err) diff --git a/mempool/txpool/legacypool/tx_store.go b/mempool/txpool/legacypool/tx_store.go index 5d427bec6..0b58d01f0 100644 --- a/mempool/txpool/legacypool/tx_store.go +++ b/mempool/txpool/legacypool/tx_store.go @@ -5,6 +5,7 @@ import ( "sort" "sync" + "cosmossdk.io/log/v2" "github.com/cosmos/evm/mempool/txpool" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -23,14 +24,19 @@ type TxStore struct { // lookup provides a fast lookup to determine if a tx is in the set or not lookup map[common.Hash]struct{} - mu sync.RWMutex + total uint64 + + logger log.Logger + mu sync.RWMutex } // NewTxStore creates a new TxStore. -func NewTxStore() *TxStore { +func NewTxStore(logger log.Logger) *TxStore { return &TxStore{ txs: make(map[common.Address]types.Transactions), + total: 0, lookup: make(map[common.Hash]struct{}), + logger: logger.With("txstore", "evm"), } } @@ -91,6 +97,7 @@ func (t *TxStore) Txs(filter txpool.PendingFilter) map[common.Address][]*txpool. } } + t.logger.Info("collected txs from evm tx store", "total_in_store", t.total, "num_selected", numSelected) txsCollected.Mark(int64(numSelected)) return pending } @@ -113,6 +120,13 @@ func (t *TxStore) AddTxs(addr common.Address, txs types.Transactions) { } else { t.txs[addr] = toAdd } + + // mark the txs in the lookup + for _, tx := range toAdd { + t.lookup[tx.Hash()] = struct{}{} + } + + t.total += uint64(len(toAdd)) } // AddTx adds a single tx to the store. @@ -139,6 +153,7 @@ func (t *TxStore) RemoveTx(addr common.Address, tx *types.Transaction) { // Swap with last element and truncate txs[i] = txs[len(txs)-1] t.txs[addr] = txs[:len(txs)-1] + t.total -= 1 return } } diff --git a/mempool/txpool/legacypool/tx_store_test.go b/mempool/txpool/legacypool/tx_store_test.go index ca0fa04f9..d328c29a0 100644 --- a/mempool/txpool/legacypool/tx_store_test.go +++ b/mempool/txpool/legacypool/tx_store_test.go @@ -5,6 +5,7 @@ import ( "sync" "testing" + "cosmossdk.io/log/v2" "github.com/cosmos/evm/mempool/txpool" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -28,7 +29,7 @@ func createTestTx(nonce uint64, gasTipCap *big.Int, gasFeeCap *big.Int) *types.T } func TestTxStoreAddAndGet(t *testing.T) { - store := NewTxStore() + store := NewTxStore(log.NewNopLogger()) addr1 := common.HexToAddress("0x1") addr2 := common.HexToAddress("0x2") @@ -47,7 +48,7 @@ func TestTxStoreAddAndGet(t *testing.T) { } func TestTxStoreMinTipFilter(t *testing.T) { - store := NewTxStore() + store := NewTxStore(log.NewNopLogger()) addr1 := common.HexToAddress("0x1") @@ -71,7 +72,7 @@ func TestTxStoreMinTipFilter(t *testing.T) { } func TestTxStoreSortedByNonce(t *testing.T) { - store := NewTxStore() + store := NewTxStore(log.NewNopLogger()) addr1 := common.HexToAddress("0x1") @@ -89,7 +90,7 @@ func TestTxStoreSortedByNonce(t *testing.T) { } func TestTxStoreRemoveTx(t *testing.T) { - store := NewTxStore() + store := NewTxStore(log.NewNopLogger()) addr1 := common.HexToAddress("0x1") tx1 := createTestTx(0, big.NewInt(1e9), big.NewInt(2e9)) @@ -105,7 +106,7 @@ func TestTxStoreRemoveTx(t *testing.T) { } func TestTxStoreConcurrentRemove(t *testing.T) { - store := NewTxStore() + store := NewTxStore(log.NewNopLogger()) addr1 := common.HexToAddress("0x1") var numTxs uint64 = 1000 @@ -131,7 +132,7 @@ func TestTxStoreConcurrentRemove(t *testing.T) { } func TestTxStoreBlobTxsFiltered(t *testing.T) { - store := NewTxStore() + store := NewTxStore(log.NewNopLogger()) addr1 := common.HexToAddress("0x1") store.AddTx(addr1, createTestTx(0, big.NewInt(1e9), big.NewInt(2e9))) diff --git a/mempool/txpool/txpool_test.go b/mempool/txpool/txpool_test.go index 1a07524d9..3a1cefbbb 100644 --- a/mempool/txpool/txpool_test.go +++ b/mempool/txpool/txpool_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "cosmossdk.io/log/v2" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/evm/mempool/reserver" "github.com/cosmos/evm/mempool/txpool" @@ -85,7 +86,7 @@ func TestTxPoolCosmosReorg(t *testing.T) { genesisState.On("GetCodeHash", mock.Anything).Return(types.EmptyCodeHash) recheckGuard := make(chan struct{}) - legacyPool := legacypool.New(legacypool.DefaultConfig, legacyChain, legacypool.WithRecheck(&BlockingRechecker{guard: recheckGuard})) + legacyPool := legacypool.New(legacypool.DefaultConfig, log.NewNopLogger(), legacyChain, legacypool.WithRecheck(&BlockingRechecker{guard: recheckGuard})) // handle txpool subscribing to new head events from the chain. grab the // reference to the chan that it is going to wait on so we can push mock