diff --git a/consensus/broadcast/delayedBroadcast.go b/consensus/broadcast/delayedBroadcast.go index 955a81f0f73..511ac6d79e6 100644 --- a/consensus/broadcast/delayedBroadcast.go +++ b/consensus/broadcast/delayedBroadcast.go @@ -644,7 +644,7 @@ func (dbb *delayedBlockBroadcaster) interceptedHeader(_ string, headerHash []byt ) alarmsToCancel := make([]string, 0) - dbb.mutDataForBroadcast.RLock() + dbb.mutDataForBroadcast.Lock() for i, broadcastData := range dbb.valHeaderBroadcastData { samePrevRandSeed := bytes.Equal(broadcastData.header.GetPrevRandSeed(), headerHandler.GetPrevRandSeed()) sameRound := broadcastData.header.GetRound() == headerHandler.GetRound() @@ -663,7 +663,7 @@ func (dbb *delayedBlockBroadcaster) interceptedHeader(_ string, headerHash []byt } } - dbb.mutDataForBroadcast.RUnlock() + dbb.mutDataForBroadcast.Unlock() for _, alarmID := range alarmsToCancel { dbb.alarm.Cancel(alarmID) diff --git a/dataRetriever/errors.go b/dataRetriever/errors.go index 3fa4aa55cbf..8b7b2f2e3dc 100644 --- a/dataRetriever/errors.go +++ b/dataRetriever/errors.go @@ -116,9 +116,6 @@ var ErrCacheConfigInvalidSize = errors.New("cache parameter [size] is not valid, // ErrCacheConfigInvalidShards signals that the cache parameter "shards" is invalid var ErrCacheConfigInvalidShards = errors.New("cache parameter [shards] is not valid, it must be a positive number") -// ErrCacheConfigInvalidEconomics signals that an economics parameter required by the cache is invalid -var ErrCacheConfigInvalidEconomics = errors.New("cache-economics parameter is not valid") - // ErrCacheConfigInvalidSharding signals that a sharding parameter required by the cache is invalid var ErrCacheConfigInvalidSharding = errors.New("cache-sharding parameter is not valid") @@ -265,6 +262,3 @@ var ErrNilValidatorInfoStorage = errors.New("nil validator info storage") // ErrValidatorInfoNotFound signals that no validator info was found var ErrValidatorInfoNotFound = errors.New("validator info not found") - -// ErrNilAccountNonceProvider signals that a nil AccountNonceProvider has been provided -var ErrNilAccountNonceProvider = errors.New("nil account nonce provider") diff --git a/dataRetriever/factory/dataPoolFactory.go b/dataRetriever/factory/dataPoolFactory.go index a41549363da..28f4b819f21 100644 --- a/dataRetriever/factory/dataPoolFactory.go +++ b/dataRetriever/factory/dataPoolFactory.go @@ -33,12 +33,11 @@ var log = logger.GetOrCreate("dataRetriever/factory") // ArgsDataPool holds the arguments needed for NewDataPoolFromConfig function type ArgsDataPool struct { - Config *config.Config - EconomicsData process.EconomicsDataHandler - ShardCoordinator sharding.Coordinator - Marshalizer marshal.Marshalizer - PathManager storage.PathManagerHandler - AccountNonceProvider dataRetriever.AccountNonceProvider + Config *config.Config + EconomicsData process.EconomicsDataHandler + ShardCoordinator sharding.Coordinator + Marshalizer marshal.Marshalizer + PathManager storage.PathManagerHandler } // NewDataPoolFromConfig will return a new instance of a PoolsHolder @@ -64,11 +63,10 @@ func NewDataPoolFromConfig(args ArgsDataPool) (dataRetriever.PoolsHolder, error) mainConfig := args.Config txPool, err := txpool.NewShardedTxPool(txpool.ArgShardedTxPool{ - Config: factory.GetCacherFromConfig(mainConfig.TxDataPool), - NumberOfShards: args.ShardCoordinator.NumberOfShards(), - SelfShardID: args.ShardCoordinator.SelfId(), - TxGasHandler: args.EconomicsData, - AccountNonceProvider: args.AccountNonceProvider, + Config: factory.GetCacherFromConfig(mainConfig.TxDataPool), + NumberOfShards: args.ShardCoordinator.NumberOfShards(), + SelfShardID: args.ShardCoordinator.SelfId(), + TxGasHandler: args.EconomicsData, }) if err != nil { return nil, fmt.Errorf("%w while creating the cache for the transactions", err) diff --git a/dataRetriever/factory/dataPoolFactory_test.go b/dataRetriever/factory/dataPoolFactory_test.go index 8cbb8dfa99b..b4896244ad9 100644 --- a/dataRetriever/factory/dataPoolFactory_test.go +++ b/dataRetriever/factory/dataPoolFactory_test.go @@ -52,12 +52,6 @@ func TestNewDataPoolFromConfig_MissingDependencyShouldErr(t *testing.T) { holder, err = NewDataPoolFromConfig(args) require.Nil(t, holder) require.Equal(t, dataRetriever.ErrNilPathManager, err) - - args = getGoodArgs() - args.AccountNonceProvider = nil - holder, err = NewDataPoolFromConfig(args) - require.Nil(t, holder) - require.ErrorContains(t, err, "nil account nonce provider while creating the cache for the transactions") } func TestNewDataPoolFromConfig_BadConfigShouldErr(t *testing.T) { @@ -153,11 +147,10 @@ func getGoodArgs() ArgsDataPool { config := testscommon.GetGeneralConfig() return ArgsDataPool{ - Config: &config, - EconomicsData: testEconomics, - ShardCoordinator: mock.NewMultipleShardsCoordinatorMock(), - Marshalizer: &mock.MarshalizerMock{}, - PathManager: &testscommon.PathManagerStub{}, - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), + Config: &config, + EconomicsData: testEconomics, + ShardCoordinator: mock.NewMultipleShardsCoordinatorMock(), + Marshalizer: &mock.MarshalizerMock{}, + PathManager: &testscommon.PathManagerStub{}, } } diff --git a/dataRetriever/interface.go b/dataRetriever/interface.go index 9231dad729c..930b6aca124 100644 --- a/dataRetriever/interface.go +++ b/dataRetriever/interface.go @@ -175,7 +175,6 @@ type ShardedDataCacherNotifier interface { RemoveSetOfDataFromPool(keys [][]byte, cacheId string) ImmunizeSetOfDataAgainstEviction(keys [][]byte, cacheId string) RemoveDataFromAllShards(key []byte) - ForgetAllAccountNoncesInMempool() MergeShardStores(sourceCacheID, destCacheID string) Clear() ClearShardStore(cacheId string) @@ -358,10 +357,3 @@ type PeerAuthenticationPayloadValidator interface { ValidateTimestamp(payloadTimestamp int64) error IsInterfaceNil() bool } - -// AccountNonceProvider defines the behavior of a component able to provide the nonce for an account -type AccountNonceProvider interface { - GetAccountNonce(accountKey []byte) (uint64, error) - SetAccountsAdapter(accountsAdapter state.AccountsAdapter) error - IsInterfaceNil() bool -} diff --git a/dataRetriever/requestHandlers/requestHandler.go b/dataRetriever/requestHandlers/requestHandler.go index 7166715dd3c..91e4992aee3 100644 --- a/dataRetriever/requestHandlers/requestHandler.go +++ b/dataRetriever/requestHandlers/requestHandler.go @@ -14,7 +14,7 @@ import ( "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/epochStart" "github.com/multiversx/mx-chain-go/process/factory" - "github.com/multiversx/mx-chain-logger-go" + logger "github.com/multiversx/mx-chain-logger-go" ) var _ epochStart.RequestHandler = (*resolverRequestHandler)(nil) @@ -571,10 +571,12 @@ func (rrh *resolverRequestHandler) RequestValidatorInfo(hash []byte) { return } + epoch := rrh.getEpoch() + log.Debug("requesting validator info messages from network", "topic", common.ValidatorInfoTopic, "hash", hash, - "epoch", rrh.epoch, + "epoch", epoch, ) requester, err := rrh.requestersFinder.MetaChainRequester(common.ValidatorInfoTopic) @@ -583,20 +585,20 @@ func (rrh *resolverRequestHandler) RequestValidatorInfo(hash []byte) { "error", err.Error(), "topic", common.ValidatorInfoTopic, "hash", hash, - "epoch", rrh.epoch, + "epoch", epoch, ) return } rrh.whiteList.Add([][]byte{hash}) - err = requester.RequestDataFromHash(hash, rrh.epoch) + err = requester.RequestDataFromHash(hash, epoch) if err != nil { log.Debug("RequestValidatorInfo.RequestDataFromHash", "error", err.Error(), "topic", common.ValidatorInfoTopic, "hash", hash, - "epoch", rrh.epoch, + "epoch", epoch, ) return } @@ -611,10 +613,12 @@ func (rrh *resolverRequestHandler) RequestValidatorsInfo(hashes [][]byte) { return } + epoch := rrh.getEpoch() + log.Debug("requesting validator info messages from network", "topic", common.ValidatorInfoTopic, "num hashes", len(unrequestedHashes), - "epoch", rrh.epoch, + "epoch", epoch, ) requester, err := rrh.requestersFinder.MetaChainRequester(common.ValidatorInfoTopic) @@ -623,7 +627,7 @@ func (rrh *resolverRequestHandler) RequestValidatorsInfo(hashes [][]byte) { "error", err.Error(), "topic", common.ValidatorInfoTopic, "num hashes", len(unrequestedHashes), - "epoch", rrh.epoch, + "epoch", epoch, ) return } @@ -636,13 +640,13 @@ func (rrh *resolverRequestHandler) RequestValidatorsInfo(hashes [][]byte) { rrh.whiteList.Add(unrequestedHashes) - err = validatorInfoRequester.RequestDataFromHashArray(unrequestedHashes, rrh.epoch) + err = validatorInfoRequester.RequestDataFromHashArray(unrequestedHashes, epoch) if err != nil { log.Debug("RequestValidatorInfo.RequestDataFromHash", "error", err.Error(), "topic", common.ValidatorInfoTopic, "num hashes", len(unrequestedHashes), - "epoch", rrh.epoch, + "epoch", epoch, ) return } @@ -827,11 +831,13 @@ func (rrh *resolverRequestHandler) GetNumPeersToQuery(key string) (int, int, err // RequestPeerAuthenticationsByHashes asks for peer authentication messages from specific peers hashes func (rrh *resolverRequestHandler) RequestPeerAuthenticationsByHashes(destShardID uint32, hashes [][]byte) { + epoch := rrh.getEpoch() + log.Debug("requesting peer authentication messages from network", "topic", common.PeerAuthenticationTopic, "shard", destShardID, "num hashes", len(hashes), - "epoch", rrh.epoch, + "epoch", epoch, ) requester, err := rrh.requestersFinder.MetaChainRequester(common.PeerAuthenticationTopic) @@ -840,7 +846,7 @@ func (rrh *resolverRequestHandler) RequestPeerAuthenticationsByHashes(destShardI "error", err.Error(), "topic", common.PeerAuthenticationTopic, "shard", destShardID, - "epoch", rrh.epoch, + "epoch", epoch, ) return } @@ -851,13 +857,13 @@ func (rrh *resolverRequestHandler) RequestPeerAuthenticationsByHashes(destShardI return } - err = peerAuthRequester.RequestDataFromHashArray(hashes, rrh.epoch) + err = peerAuthRequester.RequestDataFromHashArray(hashes, epoch) if err != nil { log.Debug("RequestPeerAuthenticationsByHashes.RequestDataFromHashArray", "error", err.Error(), "topic", common.PeerAuthenticationTopic, "shard", destShardID, - "epoch", rrh.epoch, + "epoch", epoch, ) } } diff --git a/dataRetriever/shardedData/shardedData.go b/dataRetriever/shardedData/shardedData.go index 2dc0fa6f5b9..785998164b9 100644 --- a/dataRetriever/shardedData/shardedData.go +++ b/dataRetriever/shardedData/shardedData.go @@ -4,6 +4,7 @@ import ( "fmt" "sync" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/counting" "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/dataRetriever" @@ -161,6 +162,9 @@ func (sd *shardedData) RemoveSetOfDataFromPool(keys [][]byte, cacheID string) { return } + stopWatch := core.NewStopWatch() + stopWatch.Start("removal") + numRemoved := 0 for _, key := range keys { if store.cache.RemoveWithResult(key) { @@ -168,7 +172,15 @@ func (sd *shardedData) RemoveSetOfDataFromPool(keys [][]byte, cacheID string) { } } - log.Trace("shardedData.removeTxBulk()", "name", sd.name, "cacheID", cacheID, "numToRemove", len(keys), "numRemoved", numRemoved) + stopWatch.Stop("removal") + + log.Debug("shardedData.removeTxBulk", + "name", sd.name, + "cacheID", cacheID, + "numToRemove", len(keys), + "numRemoved", numRemoved, + "duration", stopWatch.GetMeasurement("removal"), + ) } // ImmunizeSetOfDataAgainstEviction marks the items as non-evictable @@ -178,10 +190,6 @@ func (sd *shardedData) ImmunizeSetOfDataAgainstEviction(keys [][]byte, cacheID s log.Trace("shardedData.ImmunizeSetOfDataAgainstEviction()", "name", sd.name, "cacheID", cacheID, "len(keys)", len(keys), "numNow", numNow, "numFuture", numFuture) } -// ForgetAllAccountNoncesInMempool does nothing -func (sd *shardedData) ForgetAllAccountNoncesInMempool() { -} - // RemoveData will remove data hash from the corresponding shard store func (sd *shardedData) RemoveData(key []byte, cacheID string) { store := sd.shardStore(cacheID) diff --git a/dataRetriever/txpool/argShardedTxPool.go b/dataRetriever/txpool/argShardedTxPool.go index 0d98986979b..ddf26b04343 100644 --- a/dataRetriever/txpool/argShardedTxPool.go +++ b/dataRetriever/txpool/argShardedTxPool.go @@ -11,11 +11,10 @@ import ( // ArgShardedTxPool is the argument for ShardedTxPool's constructor type ArgShardedTxPool struct { - Config storageunit.CacheConfig - TxGasHandler txcache.TxGasHandler - AccountNonceProvider dataRetriever.AccountNonceProvider - NumberOfShards uint32 - SelfShardID uint32 + Config storageunit.CacheConfig + TxGasHandler txcache.TxGasHandler + NumberOfShards uint32 + SelfShardID uint32 } // TODO: Upon further analysis and brainstorming, add some sensible minimum accepted values for the appropriate fields. @@ -40,9 +39,6 @@ func (args *ArgShardedTxPool) verify() error { if check.IfNil(args.TxGasHandler) { return fmt.Errorf("%w: TxGasHandler is not valid", dataRetriever.ErrNilTxGasHandler) } - if check.IfNil(args.AccountNonceProvider) { - return dataRetriever.ErrNilAccountNonceProvider - } if args.NumberOfShards == 0 { return fmt.Errorf("%w: NumberOfShards is not valid", dataRetriever.ErrCacheConfigInvalidSharding) } diff --git a/dataRetriever/txpool/interface.go b/dataRetriever/txpool/interface.go index 1392c755034..6579659d692 100644 --- a/dataRetriever/txpool/interface.go +++ b/dataRetriever/txpool/interface.go @@ -9,8 +9,6 @@ type txCache interface { storage.Cacher AddTx(tx *txcache.WrappedTransaction) (ok bool, added bool) - NotifyAccountNonce(accountKey []byte, nonce uint64) - ForgetAllAccountNonces() GetByTxHash(txHash []byte) (*txcache.WrappedTransaction, bool) RemoveTxByHash(txHash []byte) bool ImmunizeTxsAgainstEviction(keys [][]byte) diff --git a/dataRetriever/txpool/memorytests/memory_test.go b/dataRetriever/txpool/memorytests/memory_test.go index f39d7c1d55d..2f26e574830 100644 --- a/dataRetriever/txpool/memorytests/memory_test.go +++ b/dataRetriever/txpool/memorytests/memory_test.go @@ -15,7 +15,6 @@ import ( "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dataRetriever/txpool" "github.com/multiversx/mx-chain-go/storage/storageunit" - "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/txcachemocks" "github.com/stretchr/testify/require" ) @@ -36,18 +35,18 @@ func TestShardedTxPool_MemoryFootprint(t *testing.T) { journals = append(journals, runScenario(t, newScenario(200, 1, core.MegabyteSize, "0"), memoryAssertion{200, 200}, memoryAssertion{0, 1})) journals = append(journals, runScenario(t, newScenario(10, 1000, 20480, "0"), memoryAssertion{190, 205}, memoryAssertion{1, 4})) - journals = append(journals, runScenario(t, newScenario(10000, 1, 1024, "0"), memoryAssertion{10, 16}, memoryAssertion{4, 10})) - journals = append(journals, runScenario(t, newScenario(1, 60000, 256, "0"), memoryAssertion{30, 40}, memoryAssertion{10, 16})) - journals = append(journals, runScenario(t, newScenario(10, 10000, 100, "0"), memoryAssertion{36, 52}, memoryAssertion{16, 24})) + journals = append(journals, runScenario(t, newScenario(10000, 1, 1024, "0"), memoryAssertion{10, 16}, memoryAssertion{0, 10})) + journals = append(journals, runScenario(t, newScenario(1, 60000, 256, "0"), memoryAssertion{30, 40}, memoryAssertion{10, 24})) + journals = append(journals, runScenario(t, newScenario(10, 10000, 100, "0"), memoryAssertion{36, 52}, memoryAssertion{16, 36})) journals = append(journals, runScenario(t, newScenario(100000, 1, 1024, "0"), memoryAssertion{120, 138}, memoryAssertion{32, 60})) // With larger memory footprint - journals = append(journals, runScenario(t, newScenario(100000, 3, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{80, 120})) - journals = append(journals, runScenario(t, newScenario(150000, 2, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{90, 140})) + journals = append(journals, runScenario(t, newScenario(100000, 3, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{80, 148})) + journals = append(journals, runScenario(t, newScenario(150000, 2, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{90, 160})) journals = append(journals, runScenario(t, newScenario(300000, 1, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{100, 190})) - journals = append(journals, runScenario(t, newScenario(30, 10000, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{60, 90})) - journals = append(journals, runScenario(t, newScenario(300, 1000, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{60, 90})) + journals = append(journals, runScenario(t, newScenario(30, 10000, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{60, 132})) + journals = append(journals, runScenario(t, newScenario(300, 1000, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{60, 148})) // Scenarios where destination == me @@ -111,11 +110,10 @@ func newPool() dataRetriever.ShardedDataCacherNotifier { } args := txpool.ArgShardedTxPool{ - Config: config, - TxGasHandler: txcachemocks.NewTxGasHandlerMock(), - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), - NumberOfShards: 2, - SelfShardID: 0, + Config: config, + TxGasHandler: txcachemocks.NewTxGasHandlerMock(), + NumberOfShards: 2, + SelfShardID: 0, } pool, err := txpool.NewShardedTxPool(args) if err != nil { diff --git a/dataRetriever/txpool/shardedTxPool.go b/dataRetriever/txpool/shardedTxPool.go index 54697c30876..c4ec79285f7 100644 --- a/dataRetriever/txpool/shardedTxPool.go +++ b/dataRetriever/txpool/shardedTxPool.go @@ -27,9 +27,7 @@ type shardedTxPool struct { configPrototypeDestinationMe txcache.ConfigDestinationMe configPrototypeSourceMe txcache.ConfigSourceMe selfShardID uint32 - selfShardIDAsString string txGasHandler txcache.TxGasHandler - accountNonceProvider dataRetriever.AccountNonceProvider } type txPoolShard struct { @@ -79,9 +77,7 @@ func NewShardedTxPool(args ArgShardedTxPool) (*shardedTxPool, error) { configPrototypeDestinationMe: configPrototypeDestinationMe, configPrototypeSourceMe: configPrototypeSourceMe, selfShardID: args.SelfShardID, - selfShardIDAsString: core.GetShardIDString(args.SelfShardID), txGasHandler: args.TxGasHandler, - accountNonceProvider: args.AccountNonceProvider, } return shardedTxPoolObject, nil @@ -185,12 +181,11 @@ func (txPool *shardedTxPool) AddData(key []byte, value interface{}, sizeInBytes Size: int64(sizeInBytes), } - sourceIsMe := sourceShardID == txPool.selfShardID - txPool.addTx(wrapper, cacheID, sourceIsMe) + txPool.addTx(wrapper, cacheID) } // addTx adds the transaction to the cache -func (txPool *shardedTxPool) addTx(tx *txcache.WrappedTransaction, cacheID string, shouldNotifyCacheAboutSenderNonce bool) { +func (txPool *shardedTxPool) addTx(tx *txcache.WrappedTransaction, cacheID string) { shard := txPool.getOrCreateShard(cacheID) cache := shard.Cache @@ -198,19 +193,6 @@ func (txPool *shardedTxPool) addTx(tx *txcache.WrappedTransaction, cacheID strin if added { txPool.onAdded(tx.TxHash, tx) } - - if !shouldNotifyCacheAboutSenderNonce { - return - } - - sender := tx.Tx.GetSndAddr() - senderNonce, err := txPool.accountNonceProvider.GetAccountNonce(sender) - if err != nil { - log.Debug("shardedTxPool.addTx(): cannot get sender nonce", "sender", sender, "err", err) - return - } - - cache.NotifyAccountNonce(sender, senderNonce) } func (txPool *shardedTxPool) onAdded(key []byte, value interface{}) { @@ -260,6 +242,9 @@ func (txPool *shardedTxPool) RemoveSetOfDataFromPool(keys [][]byte, cacheID stri func (txPool *shardedTxPool) removeTxBulk(txHashes [][]byte, cacheID string) { shard := txPool.getOrCreateShard(cacheID) + stopWatch := core.NewStopWatch() + stopWatch.Start("removal") + numRemoved := 0 for _, key := range txHashes { if shard.Cache.RemoveTxByHash(key) { @@ -267,8 +252,15 @@ func (txPool *shardedTxPool) removeTxBulk(txHashes [][]byte, cacheID string) { } } + stopWatch.Stop("removal") + // Transactions with lower / equal nonce are also removed, but the counter does not reflect that. - log.Debug("shardedTxPool.removeTxBulk()", "name", cacheID, "numToRemove", len(txHashes), "numRemoved", numRemoved) + log.Debug("shardedTxPool.removeTxBulk", + "cacheID", cacheID, + "numToRemove", len(txHashes), + "numRemoved", numRemoved, + "duration", stopWatch.GetMeasurement("removal"), + ) } // RemoveDataFromAllShards removes the transaction from the pool (it searches in all shards) @@ -287,12 +279,6 @@ func (txPool *shardedTxPool) removeTxFromAllShards(txHash []byte) { } } -// ForgetAllAccountNoncesInMempool forgets all account nonces in the mempool -func (txPool *shardedTxPool) ForgetAllAccountNoncesInMempool() { - cache := txPool.getOrCreateShard(txPool.selfShardIDAsString) - cache.Cache.ForgetAllAccountNonces() -} - // MergeShardStores merges two shards of the pool func (txPool *shardedTxPool) MergeShardStores(sourceCacheID, destCacheID string) { sourceCacheID = txPool.routeToCacheUnions(sourceCacheID) @@ -302,7 +288,7 @@ func (txPool *shardedTxPool) MergeShardStores(sourceCacheID, destCacheID string) sourceCache := sourceShard.Cache sourceCache.ForEachTransaction(func(txHash []byte, tx *txcache.WrappedTransaction) { - txPool.addTx(tx, destCacheID, false) + txPool.addTx(tx, destCacheID) }) txPool.mutexBackingMap.Lock() diff --git a/dataRetriever/txpool/shardedTxPool_test.go b/dataRetriever/txpool/shardedTxPool_test.go index a8ed74a980d..90638faff1f 100644 --- a/dataRetriever/txpool/shardedTxPool_test.go +++ b/dataRetriever/txpool/shardedTxPool_test.go @@ -12,10 +12,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/storage/storageunit" - "github.com/multiversx/mx-chain-go/testscommon" - "github.com/multiversx/mx-chain-go/testscommon/state" "github.com/multiversx/mx-chain-go/testscommon/txcachemocks" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -82,35 +79,20 @@ func Test_NewShardedTxPool_WhenBadConfig(t *testing.T) { require.NotNil(t, err) require.Errorf(t, err, dataRetriever.ErrNilTxGasHandler.Error()) - args = goodArgs - args.TxGasHandler = txcachemocks.NewTxGasHandlerMock().WithMinGasPrice(0) - pool, err = NewShardedTxPool(args) - require.Nil(t, pool) - require.NotNil(t, err) - require.Errorf(t, err, dataRetriever.ErrCacheConfigInvalidEconomics.Error()) - args = goodArgs args.NumberOfShards = 0 pool, err = NewShardedTxPool(args) require.Nil(t, pool) require.NotNil(t, err) require.Errorf(t, err, dataRetriever.ErrCacheConfigInvalidSharding.Error()) - - args = goodArgs - args.AccountNonceProvider = nil - pool, err = NewShardedTxPool(args) - require.Nil(t, pool) - require.NotNil(t, err) - require.Errorf(t, err, dataRetriever.ErrNilAccountNonceProvider.Error()) } func Test_NewShardedTxPool_ComputesCacheConfig(t *testing.T) { config := storageunit.CacheConfig{SizeInBytes: 419430400, SizeInBytesPerSender: 614400, Capacity: 600000, SizePerSender: 1000, Shards: 1} args := ArgShardedTxPool{ - Config: config, - TxGasHandler: txcachemocks.NewTxGasHandlerMock(), - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), - NumberOfShards: 2, + Config: config, + TxGasHandler: txcachemocks.NewTxGasHandlerMock(), + NumberOfShards: 2, } pool, err := NewShardedTxPool(args) @@ -212,74 +194,6 @@ func Test_AddData_CallsOnAddedHandlers(t *testing.T) { require.Equal(t, uint32(1), atomic.LoadUint32(&numAdded)) } -func TestShardedTxPool_AddData_CallsNotifyAccountNonce(t *testing.T) { - poolAsInterface, _ := newTxPoolToTest() - pool := poolAsInterface.(*shardedTxPool) - - accounts := &state.AccountsStub{ - GetExistingAccountCalled: func(_ []byte) (vmcommon.AccountHandler, error) { - return &state.UserAccountStub{ - Nonce: 30, - }, nil - }, - } - - err := pool.accountNonceProvider.SetAccountsAdapter(accounts) - require.NoError(t, err) - - breadcrumbs := make([]string, 0) - - _ = pool.getOrCreateShard("0") - _ = pool.getOrCreateShard("1_0") - - pool.backingMap["0"].Cache = &txcachemocks.TxCacheMock{ - NotifyAccountNonceCalled: func(accountKey []byte, nonce uint64) { - breadcrumbs = append(breadcrumbs, fmt.Sprintf("0::%s_%d", string(accountKey), nonce)) - }, - } - - pool.backingMap["1_0"].Cache = &txcachemocks.TxCacheMock{ - NotifyAccountNonceCalled: func(accountKey []byte, nonce uint64) { - breadcrumbs = append(breadcrumbs, fmt.Sprintf("1_0::%s_%d", string(accountKey), nonce)) - }, - } - - // AddData to "source is me" cache. - pool.AddData([]byte("hash-42"), createTx("alice", 42), 0, "0") - require.Equal(t, []string{"0::alice_30"}, breadcrumbs) - - // AddData to another cache (no notification). - pool.AddData([]byte("hash-43"), createTx("bob", 43), 0, "1_0") - require.Equal(t, []string{"0::alice_30"}, breadcrumbs) -} - -func TestShardedTxPool_AddData_ForgetAllAccountNoncesInMempool(t *testing.T) { - poolAsInterface, _ := newTxPoolToTest() - pool := poolAsInterface.(*shardedTxPool) - - _ = pool.getOrCreateShard("0") - _ = pool.getOrCreateShard("1_0") - - breadcrumbs := make([]string, 0) - - pool.backingMap["0"].Cache = &txcachemocks.TxCacheMock{ - ForgetAllAccountNoncesCalled: func() { - breadcrumbs = append(breadcrumbs, "0") - }, - } - - pool.backingMap["1_0"].Cache = &txcachemocks.TxCacheMock{ - ForgetAllAccountNoncesCalled: func() { - breadcrumbs = append(breadcrumbs, "1_0") - }, - } - - pool.ForgetAllAccountNoncesInMempool() - - // Only "source is me" cache is affected. - require.Equal(t, []string{"0"}, breadcrumbs) -} - func Test_SearchFirstData(t *testing.T) { poolAsInterface, _ := newTxPoolToTest() pool := poolAsInterface.(*shardedTxPool) @@ -458,11 +372,10 @@ func Test_routeToCacheUnions(t *testing.T) { Shards: 1, } args := ArgShardedTxPool{ - Config: config, - TxGasHandler: txcachemocks.NewTxGasHandlerMock(), - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), - NumberOfShards: 4, - SelfShardID: 42, + Config: config, + TxGasHandler: txcachemocks.NewTxGasHandlerMock(), + NumberOfShards: 4, + SelfShardID: 42, } pool, _ := NewShardedTxPool(args) @@ -499,11 +412,10 @@ func newTxPoolToTest() (dataRetriever.ShardedDataCacherNotifier, error) { Shards: 1, } args := ArgShardedTxPool{ - Config: config, - TxGasHandler: txcachemocks.NewTxGasHandlerMock(), - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), - NumberOfShards: 4, - SelfShardID: 0, + Config: config, + TxGasHandler: txcachemocks.NewTxGasHandlerMock(), + NumberOfShards: 4, + SelfShardID: 0, } return NewShardedTxPool(args) } diff --git a/epochStart/bootstrap/common.go b/epochStart/bootstrap/common.go index ad48045c8cd..da6e99fda1b 100644 --- a/epochStart/bootstrap/common.go +++ b/epochStart/bootstrap/common.go @@ -5,7 +5,6 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/common/statistics" - "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/epochStart" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" ) @@ -124,9 +123,6 @@ func checkArguments(args ArgsEpochStartBootstrap) error { if check.IfNil(args.NodesCoordinatorRegistryFactory) { return fmt.Errorf("%s: %w", baseErrorMessage, nodesCoordinator.ErrNilNodesCoordinatorRegistryFactory) } - if check.IfNil(args.AccountNonceProvider) { - return fmt.Errorf("%s: %w", baseErrorMessage, dataRetriever.ErrNilAccountNonceProvider) - } return nil } diff --git a/epochStart/bootstrap/process.go b/epochStart/bootstrap/process.go index fb4e5ab5e7c..dce9135e0a3 100644 --- a/epochStart/bootstrap/process.go +++ b/epochStart/bootstrap/process.go @@ -121,7 +121,6 @@ type epochStartBootstrap struct { nodeProcessingMode common.NodeProcessingMode nodeOperationMode common.NodeOperation stateStatsHandler common.StateStatisticsHandler - accountNonceProvider dataRetriever.AccountNonceProvider // created components requestHandler process.RequestHandler mainInterceptorContainer process.InterceptorsContainer @@ -191,7 +190,6 @@ type ArgsEpochStartBootstrap struct { NodeProcessingMode common.NodeProcessingMode StateStatsHandler common.StateStatisticsHandler NodesCoordinatorRegistryFactory nodesCoordinator.NodesCoordinatorRegistryFactory - AccountNonceProvider dataRetriever.AccountNonceProvider } type dataToSync struct { @@ -244,7 +242,6 @@ func NewEpochStartBootstrap(args ArgsEpochStartBootstrap) (*epochStartBootstrap, stateStatsHandler: args.StateStatsHandler, startEpoch: args.GeneralConfig.EpochStartConfig.GenesisEpoch, nodesCoordinatorRegistryFactory: args.NodesCoordinatorRegistryFactory, - accountNonceProvider: args.AccountNonceProvider, } if epochStartProvider.prefsConfig.FullArchive { @@ -357,12 +354,11 @@ func (e *epochStartBootstrap) Bootstrap() (Parameters, error) { e.dataPool, err = factoryDataPool.NewDataPoolFromConfig( factoryDataPool.ArgsDataPool{ - Config: &e.generalConfig, - EconomicsData: e.economicsData, - ShardCoordinator: e.shardCoordinator, - Marshalizer: e.coreComponentsHolder.InternalMarshalizer(), - PathManager: e.coreComponentsHolder.PathHandler(), - AccountNonceProvider: e.accountNonceProvider, + Config: &e.generalConfig, + EconomicsData: e.economicsData, + ShardCoordinator: e.shardCoordinator, + Marshalizer: e.coreComponentsHolder.InternalMarshalizer(), + PathManager: e.coreComponentsHolder.PathHandler(), }, ) if err != nil { diff --git a/epochStart/bootstrap/process_test.go b/epochStart/bootstrap/process_test.go index 4f614a8145e..ca3fd78a5b8 100644 --- a/epochStart/bootstrap/process_test.go +++ b/epochStart/bootstrap/process_test.go @@ -241,7 +241,6 @@ func createMockEpochStartBootstrapArgs( }, TrieSyncStatisticsProvider: &testscommon.SizeSyncStatisticsHandlerStub{}, StateStatsHandler: disabledStatistics.NewStateStatistics(), - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), } } diff --git a/epochStart/bootstrap/storageProcess.go b/epochStart/bootstrap/storageProcess.go index 49a9b156891..809b0dfbb8b 100644 --- a/epochStart/bootstrap/storageProcess.go +++ b/epochStart/bootstrap/storageProcess.go @@ -34,7 +34,6 @@ type ArgsStorageEpochStartBootstrap struct { ImportDbConfig config.ImportDbConfig ChanGracefullyClose chan endProcess.ArgEndProcess TimeToWaitForRequestedData time.Duration - AccountNonceProvider dataRetriever.AccountNonceProvider } type storageEpochStartBootstrap struct { @@ -45,7 +44,6 @@ type storageEpochStartBootstrap struct { chanGracefullyClose chan endProcess.ArgEndProcess chainID string timeToWaitForRequestedData time.Duration - accountNonceProvider dataRetriever.AccountNonceProvider } // NewStorageEpochStartBootstrap will return a new instance of storageEpochStartBootstrap that can bootstrap @@ -59,9 +57,6 @@ func NewStorageEpochStartBootstrap(args ArgsStorageEpochStartBootstrap) (*storag if args.ChanGracefullyClose == nil { return nil, dataRetriever.ErrNilGracefullyCloseChannel } - if check.IfNil(args.AccountNonceProvider) { - return nil, dataRetriever.ErrNilAccountNonceProvider - } sesb := &storageEpochStartBootstrap{ epochStartBootstrap: esb, @@ -69,7 +64,6 @@ func NewStorageEpochStartBootstrap(args ArgsStorageEpochStartBootstrap) (*storag chanGracefullyClose: args.ChanGracefullyClose, chainID: args.CoreComponentsHolder.ChainID(), timeToWaitForRequestedData: args.TimeToWaitForRequestedData, - accountNonceProvider: args.AccountNonceProvider, } return sesb, nil @@ -110,12 +104,11 @@ func (sesb *storageEpochStartBootstrap) Bootstrap() (Parameters, error) { sesb.dataPool, err = factoryDataPool.NewDataPoolFromConfig( factoryDataPool.ArgsDataPool{ - Config: &sesb.generalConfig, - EconomicsData: sesb.economicsData, - ShardCoordinator: sesb.shardCoordinator, - Marshalizer: sesb.coreComponentsHolder.InternalMarshalizer(), - PathManager: sesb.coreComponentsHolder.PathHandler(), - AccountNonceProvider: sesb.accountNonceProvider, + Config: &sesb.generalConfig, + EconomicsData: sesb.economicsData, + ShardCoordinator: sesb.shardCoordinator, + Marshalizer: sesb.coreComponentsHolder.InternalMarshalizer(), + PathManager: sesb.coreComponentsHolder.PathHandler(), }, ) if err != nil { diff --git a/epochStart/bootstrap/storageProcess_test.go b/epochStart/bootstrap/storageProcess_test.go index b05960fb31c..a59b0d125f2 100644 --- a/epochStart/bootstrap/storageProcess_test.go +++ b/epochStart/bootstrap/storageProcess_test.go @@ -35,7 +35,6 @@ func createMockStorageEpochStartBootstrapArgs( ImportDbConfig: config.ImportDbConfig{}, ChanGracefullyClose: make(chan endProcess.ArgEndProcess, 1), TimeToWaitForRequestedData: time.Second, - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), } } diff --git a/factory/bootstrap/bootstrapComponents.go b/factory/bootstrap/bootstrapComponents.go index 4d5eb2300aa..a9ef7851ccb 100644 --- a/factory/bootstrap/bootstrapComponents.go +++ b/factory/bootstrap/bootstrapComponents.go @@ -9,7 +9,6 @@ import ( nodeFactory "github.com/multiversx/mx-chain-go/cmd/node/factory" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" - "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/epochStart/bootstrap" "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/factory" @@ -42,7 +41,6 @@ type BootstrapComponentsFactoryArgs struct { CryptoComponents factory.CryptoComponentsHolder NetworkComponents factory.NetworkComponentsHolder StatusCoreComponents factory.StatusCoreComponentsHolder - AccountNonceProvider dataRetriever.AccountNonceProvider } type bootstrapComponentsFactory struct { @@ -55,7 +53,6 @@ type bootstrapComponentsFactory struct { cryptoComponents factory.CryptoComponentsHolder networkComponents factory.NetworkComponentsHolder statusCoreComponents factory.StatusCoreComponentsHolder - accountNonceProvider dataRetriever.AccountNonceProvider } type bootstrapComponents struct { @@ -96,9 +93,6 @@ func NewBootstrapComponentsFactory(args BootstrapComponentsFactoryArgs) (*bootst if check.IfNil(args.StatusCoreComponents.AppStatusHandler()) { return nil, errors.ErrNilAppStatusHandler } - if check.IfNil(args.AccountNonceProvider) { - return nil, dataRetriever.ErrNilAccountNonceProvider - } return &bootstrapComponentsFactory{ config: args.Config, @@ -110,7 +104,6 @@ func NewBootstrapComponentsFactory(args BootstrapComponentsFactoryArgs) (*bootst cryptoComponents: args.CryptoComponents, networkComponents: args.NetworkComponents, statusCoreComponents: args.StatusCoreComponents, - accountNonceProvider: args.AccountNonceProvider, }, nil } @@ -231,7 +224,6 @@ func (bcf *bootstrapComponentsFactory) Create() (*bootstrapComponents, error) { NodeProcessingMode: common.GetNodeProcessingMode(&bcf.importDbConfig), StateStatsHandler: bcf.statusCoreComponents.StateStatsHandler(), NodesCoordinatorRegistryFactory: nodesCoordinatorRegistryFactory, - AccountNonceProvider: bcf.accountNonceProvider, } var epochStartBootstrapper factory.EpochStartBootstrapper @@ -241,7 +233,6 @@ func (bcf *bootstrapComponentsFactory) Create() (*bootstrapComponents, error) { ImportDbConfig: bcf.importDbConfig, ChanGracefullyClose: bcf.coreComponents.ChanStopNodeProcess(), TimeToWaitForRequestedData: bootstrap.DefaultTimeToWaitForRequestedData, - AccountNonceProvider: bcf.accountNonceProvider, } epochStartBootstrapper, err = bootstrap.NewStorageEpochStartBootstrap(storageArg) diff --git a/factory/data/dataComponents.go b/factory/data/dataComponents.go index 1849549e685..4e0d72282b1 100644 --- a/factory/data/dataComponents.go +++ b/factory/data/dataComponents.go @@ -31,7 +31,6 @@ type DataComponentsFactoryArgs struct { CurrentEpoch uint32 CreateTrieEpochRootHashStorer bool NodeProcessingMode common.NodeProcessingMode - AccountNonceProvider dataRetriever.AccountNonceProvider } type dataComponentsFactory struct { @@ -45,7 +44,6 @@ type dataComponentsFactory struct { currentEpoch uint32 createTrieEpochRootHashStorer bool nodeProcessingMode common.NodeProcessingMode - accountNonceProvider dataRetriever.AccountNonceProvider } // dataComponents struct holds the data components @@ -72,9 +70,6 @@ func NewDataComponentsFactory(args DataComponentsFactoryArgs) (*dataComponentsFa if check.IfNil(args.Crypto) { return nil, errors.ErrNilCryptoComponents } - if check.IfNil(args.AccountNonceProvider) { - return nil, dataRetriever.ErrNilAccountNonceProvider - } return &dataComponentsFactory{ config: args.Config, @@ -87,7 +82,6 @@ func NewDataComponentsFactory(args DataComponentsFactoryArgs) (*dataComponentsFa flagsConfig: args.FlagsConfigs, nodeProcessingMode: args.NodeProcessingMode, crypto: args.Crypto, - accountNonceProvider: args.AccountNonceProvider, }, nil } @@ -105,12 +99,11 @@ func (dcf *dataComponentsFactory) Create() (*dataComponents, error) { } dataPoolArgs := dataRetrieverFactory.ArgsDataPool{ - Config: &dcf.config, - EconomicsData: dcf.core.EconomicsData(), - ShardCoordinator: dcf.shardCoordinator, - Marshalizer: dcf.core.InternalMarshalizer(), - PathManager: dcf.core.PathHandler(), - AccountNonceProvider: dcf.accountNonceProvider, + Config: &dcf.config, + EconomicsData: dcf.core.EconomicsData(), + ShardCoordinator: dcf.shardCoordinator, + Marshalizer: dcf.core.InternalMarshalizer(), + PathManager: dcf.core.PathHandler(), } datapool, err = dataRetrieverFactory.NewDataPoolFromConfig(dataPoolArgs) if err != nil { diff --git a/factory/disabled/txCoordinator.go b/factory/disabled/txCoordinator.go index fa4d25b26d2..9d8002fb034 100644 --- a/factory/disabled/txCoordinator.go +++ b/factory/disabled/txCoordinator.go @@ -61,10 +61,6 @@ func (txCoordinator *TxCoordinator) RemoveTxsFromPool(_ *block.Body) error { return nil } -// ForgetAllAccountNoncesInMempool does nothing as it is disabled -func (txCoordinator *TxCoordinator) ForgetAllAccountNoncesInMempool() { -} - // ProcessBlockTransaction does nothing as it is disabled func (txCoordinator *TxCoordinator) ProcessBlockTransaction(_ data.HeaderHandler, _ *block.Body, _ func() time.Duration) error { return nil diff --git a/factory/state/accountNonceProvider.go b/factory/state/accountNonceProvider.go deleted file mode 100644 index 2fb3a48544c..00000000000 --- a/factory/state/accountNonceProvider.go +++ /dev/null @@ -1,61 +0,0 @@ -package state - -import ( - "sync" - - "github.com/multiversx/mx-chain-core-go/core/check" - "github.com/multiversx/mx-chain-go/errors" - "github.com/multiversx/mx-chain-go/state" -) - -type accountNonceProvider struct { - accountsAdapter state.AccountsAdapter - mutex sync.RWMutex -} - -// NewAccountNonceProvider creates a new instance of accountNonceProvider. -// When the accounts adapter is not yet available, client code is allowed to pass a nil reference in the constructor. -// In that case, the accounts adapter should be set at a later time, by means of SetAccountsAdapter. -func NewAccountNonceProvider(accountsAdapter state.AccountsAdapter) (*accountNonceProvider, error) { - return &accountNonceProvider{ - accountsAdapter: accountsAdapter, - }, nil -} - -// SetAccountsAdapter sets the accounts adapter -func (provider *accountNonceProvider) SetAccountsAdapter(accountsAdapter state.AccountsAdapter) error { - if check.IfNil(accountsAdapter) { - return errors.ErrNilAccountsAdapter - } - - provider.mutex.Lock() - defer provider.mutex.Unlock() - - provider.accountsAdapter = accountsAdapter - return nil -} - -// GetAccountNonce returns the nonce for an account. -// Will be called by "shardedTxPool" on every transaction added to the pool. -func (provider *accountNonceProvider) GetAccountNonce(address []byte) (uint64, error) { - provider.mutex.RLock() - accountsAdapter := provider.accountsAdapter - provider.mutex.RUnlock() - - // No need for double check locking here (we are just guarding against a programming mistake, not against a specific runtime condition). - if check.IfNil(accountsAdapter) { - return 0, errors.ErrNilAccountsAdapter - } - - account, err := accountsAdapter.GetExistingAccount(address) - if err != nil { - return 0, err - } - - return account.GetNonce(), nil -} - -// IsInterfaceNil returns true if there is no value under the interface -func (provider *accountNonceProvider) IsInterfaceNil() bool { - return provider == nil -} diff --git a/factory/state/accountNonceProvider_test.go b/factory/state/accountNonceProvider_test.go deleted file mode 100644 index 2ba96710878..00000000000 --- a/factory/state/accountNonceProvider_test.go +++ /dev/null @@ -1,113 +0,0 @@ -package state - -import ( - "bytes" - "fmt" - "testing" - - "github.com/multiversx/mx-chain-go/errors" - "github.com/multiversx/mx-chain-go/testscommon/state" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/stretchr/testify/require" -) - -func TestAccountNonceProvider_SetAccountsAdapter(t *testing.T) { - t.Parallel() - - t.Run("with a nil the accounts adapter", func(t *testing.T) { - t.Parallel() - - provider, err := NewAccountNonceProvider(nil) - require.NoError(t, err) - require.NotNil(t, provider) - - err = provider.SetAccountsAdapter(nil) - require.ErrorIs(t, err, errors.ErrNilAccountsAdapter) - }) - - t.Run("with a non-nil accounts adapter", func(t *testing.T) { - t.Parallel() - - provider, err := NewAccountNonceProvider(nil) - require.NoError(t, err) - require.NotNil(t, provider) - - err = provider.SetAccountsAdapter(&state.AccountsStub{}) - require.NoError(t, err) - }) -} - -func TestAccountNonceProvider_GetAccountNonce(t *testing.T) { - t.Parallel() - - t.Run("without a backing the accounts adapter", func(t *testing.T) { - t.Parallel() - - provider, err := NewAccountNonceProvider(nil) - require.NoError(t, err) - require.NotNil(t, provider) - - nonce, err := provider.GetAccountNonce(nil) - require.ErrorIs(t, err, errors.ErrNilAccountsAdapter) - require.Equal(t, uint64(0), nonce) - }) - - t.Run("with a backing accounts adapter (provided in constructor)", func(t *testing.T) { - t.Parallel() - - userAddress := []byte("alice") - accounts := &state.AccountsStub{} - accounts.GetExistingAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { - if !bytes.Equal(address, userAddress) { - return nil, fmt.Errorf("account not found: %s", address) - } - - return &state.UserAccountStub{ - Nonce: 42, - }, nil - } - - provider, err := NewAccountNonceProvider(accounts) - require.NoError(t, err) - require.NotNil(t, provider) - - nonce, err := provider.GetAccountNonce(userAddress) - require.NoError(t, err) - require.Equal(t, uint64(42), nonce) - - nonce, err = provider.GetAccountNonce([]byte("bob")) - require.ErrorContains(t, err, "account not found: bob") - require.Equal(t, uint64(0), nonce) - }) - - t.Run("with a backing accounts adapter (provided using setter)", func(t *testing.T) { - t.Parallel() - - userAddress := []byte("alice") - accounts := &state.AccountsStub{} - accounts.GetExistingAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { - if !bytes.Equal(address, userAddress) { - return nil, fmt.Errorf("account not found: %s", address) - } - - return &state.UserAccountStub{ - Nonce: 42, - }, nil - } - - provider, err := NewAccountNonceProvider(nil) - require.NoError(t, err) - require.NotNil(t, provider) - - err = provider.SetAccountsAdapter(accounts) - require.NoError(t, err) - - nonce, err := provider.GetAccountNonce(userAddress) - require.NoError(t, err) - require.Equal(t, uint64(42), nonce) - - nonce, err = provider.GetAccountNonce([]byte("bob")) - require.ErrorContains(t, err, "account not found: bob") - require.Equal(t, uint64(0), nonce) - }) -} diff --git a/go.mod b/go.mod index c660a0a7c20..80695caf02b 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/multiversx/mx-chain-es-indexer-go v1.7.10 github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-scenario-go v1.4.4 - github.com/multiversx/mx-chain-storage-go v1.0.17 + github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241126200205-8a0cb502901f github.com/multiversx/mx-chain-vm-common-go v1.5.16 github.com/multiversx/mx-chain-vm-go v1.5.37 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 diff --git a/go.sum b/go.sum index 72ef263430a..6b677bd3d15 100644 --- a/go.sum +++ b/go.sum @@ -397,8 +397,8 @@ github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+w github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ= github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFzHeruelESfpTlf460= github.com/multiversx/mx-chain-scenario-go v1.4.4/go.mod h1:kI+TWR3oIEgUkbwkHCPo2CQ3VjIge+ezGTibiSGwMxo= -github.com/multiversx/mx-chain-storage-go v1.0.17 h1:Ett23thQ05qhK3I86sC4j/yK7NZqiXuKuNnV14A9fWk= -github.com/multiversx/mx-chain-storage-go v1.0.17/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= +github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241126200205-8a0cb502901f h1:vDXuO+Luf6SIfJwdfRD2+5FwSbL/juSwINeLBrNPYuo= +github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241126200205-8a0cb502901f/go.mod h1:eFDEOrG7Wiyk5I/ObpwcN2eoBlOnnfeEMTvTer1cymk= github.com/multiversx/mx-chain-vm-common-go v1.5.16 h1:g1SqYjxl7K66Y1O/q6tvDJ37fzpzlxCSfRzSm/woQQY= github.com/multiversx/mx-chain-vm-common-go v1.5.16/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= github.com/multiversx/mx-chain-vm-go v1.5.37 h1:Iy3KCvM+DOq1f9UPA7uYK/rI3ZbBOXc2CVNO2/vm5zw= diff --git a/integrationTests/factory/bootstrapComponents/bootstrapComponents_test.go b/integrationTests/factory/bootstrapComponents/bootstrapComponents_test.go index c8586390170..03601ec46b1 100644 --- a/integrationTests/factory/bootstrapComponents/bootstrapComponents_test.go +++ b/integrationTests/factory/bootstrapComponents/bootstrapComponents_test.go @@ -8,7 +8,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data/endProcess" "github.com/multiversx/mx-chain-go/integrationTests/factory" "github.com/multiversx/mx-chain-go/node" - "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/goroutines" "github.com/stretchr/testify/require" ) @@ -25,8 +24,6 @@ func TestBootstrapComponents_Create_Close_ShouldWork(t *testing.T) { idxInitial, _ := gc.Snapshot() factory.PrintStack() - accountNonceProvider := testscommon.NewAccountNonceProviderMock() - configs := factory.CreateDefaultConfig(t) chanStopNodeProcess := make(chan endProcess.ArgEndProcess) nr, err := node.NewNodeRunner(configs) @@ -44,7 +41,6 @@ func TestBootstrapComponents_Create_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedCryptoComponents, managedNetworkComponents, - accountNonceProvider, ) require.Nil(t, err) require.NotNil(t, managedBootstrapComponents) diff --git a/integrationTests/factory/consensusComponents/consensusComponents_test.go b/integrationTests/factory/consensusComponents/consensusComponents_test.go index aa5d0e64305..b68e9dd95cc 100644 --- a/integrationTests/factory/consensusComponents/consensusComponents_test.go +++ b/integrationTests/factory/consensusComponents/consensusComponents_test.go @@ -11,7 +11,6 @@ import ( bootstrapComp "github.com/multiversx/mx-chain-go/factory/bootstrap" "github.com/multiversx/mx-chain-go/integrationTests/factory" "github.com/multiversx/mx-chain-go/node" - "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/goroutines" "github.com/stretchr/testify/require" ) @@ -28,8 +27,6 @@ func TestConsensusComponents_Close_ShouldWork(t *testing.T) { idxInitial, _ := gc.Snapshot() factory.PrintStack() - accountNonceProvider := testscommon.NewAccountNonceProviderMock() - configs := factory.CreateDefaultConfig(t) chanStopNodeProcess := make(chan endProcess.ArgEndProcess) nr, err := node.NewNodeRunner(configs) @@ -47,7 +44,6 @@ func TestConsensusComponents_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedCryptoComponents, managedNetworkComponents, - accountNonceProvider, ) require.Nil(t, err) managedDataComponents, err := nr.CreateManagedDataComponents( @@ -55,7 +51,6 @@ func TestConsensusComponents_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedBootstrapComponents, managedCryptoComponents, - accountNonceProvider, ) require.Nil(t, err) managedStateComponents, err := nr.CreateManagedStateComponents(managedCoreComponents, managedDataComponents, managedStatusCoreComponents) diff --git a/integrationTests/factory/dataComponents/dataComponents_test.go b/integrationTests/factory/dataComponents/dataComponents_test.go index 8d575f509a1..d4727818994 100644 --- a/integrationTests/factory/dataComponents/dataComponents_test.go +++ b/integrationTests/factory/dataComponents/dataComponents_test.go @@ -8,7 +8,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data/endProcess" "github.com/multiversx/mx-chain-go/integrationTests/factory" "github.com/multiversx/mx-chain-go/node" - "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/goroutines" "github.com/stretchr/testify/require" ) @@ -24,8 +23,6 @@ func TestDataComponents_Create_Close_ShouldWork(t *testing.T) { idxInitial, _ := gc.Snapshot() factory.PrintStack() - accountNonceProvider := testscommon.NewAccountNonceProviderMock() - configs := factory.CreateDefaultConfig(t) chanStopNodeProcess := make(chan endProcess.ArgEndProcess) nr, err := node.NewNodeRunner(configs) @@ -44,7 +41,6 @@ func TestDataComponents_Create_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedCryptoComponents, managedNetworkComponents, - accountNonceProvider, ) require.Nil(t, err) managedDataComponents, err := nr.CreateManagedDataComponents( @@ -52,7 +48,6 @@ func TestDataComponents_Create_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedBootstrapComponents, managedCryptoComponents, - accountNonceProvider, ) require.Nil(t, err) require.NotNil(t, managedDataComponents) diff --git a/integrationTests/factory/heartbeatComponents/heartbeatComponents_test.go b/integrationTests/factory/heartbeatComponents/heartbeatComponents_test.go index caf07e51e2d..dd0a07ad91f 100644 --- a/integrationTests/factory/heartbeatComponents/heartbeatComponents_test.go +++ b/integrationTests/factory/heartbeatComponents/heartbeatComponents_test.go @@ -11,7 +11,6 @@ import ( bootstrapComp "github.com/multiversx/mx-chain-go/factory/bootstrap" "github.com/multiversx/mx-chain-go/integrationTests/factory" "github.com/multiversx/mx-chain-go/node" - "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/goroutines" "github.com/stretchr/testify/require" ) @@ -28,8 +27,6 @@ func TestHeartbeatComponents_Close_ShouldWork(t *testing.T) { idxInitial, _ := gc.Snapshot() factory.PrintStack() - accountNonceProvider := testscommon.NewAccountNonceProviderMock() - configs := factory.CreateDefaultConfig(t) chanStopNodeProcess := make(chan endProcess.ArgEndProcess) nr, err := node.NewNodeRunner(configs) @@ -47,7 +44,6 @@ func TestHeartbeatComponents_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedCryptoComponents, managedNetworkComponents, - accountNonceProvider, ) require.Nil(t, err) managedDataComponents, err := nr.CreateManagedDataComponents( @@ -55,7 +51,6 @@ func TestHeartbeatComponents_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedBootstrapComponents, managedCryptoComponents, - accountNonceProvider, ) require.Nil(t, err) managedStateComponents, err := nr.CreateManagedStateComponents(managedCoreComponents, managedDataComponents, managedStatusCoreComponents) diff --git a/integrationTests/factory/processComponents/processComponents_test.go b/integrationTests/factory/processComponents/processComponents_test.go index 11453db5d49..17860520ea9 100644 --- a/integrationTests/factory/processComponents/processComponents_test.go +++ b/integrationTests/factory/processComponents/processComponents_test.go @@ -11,7 +11,6 @@ import ( bootstrapComp "github.com/multiversx/mx-chain-go/factory/bootstrap" "github.com/multiversx/mx-chain-go/integrationTests/factory" "github.com/multiversx/mx-chain-go/node" - "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/goroutines" "github.com/stretchr/testify/require" ) @@ -28,8 +27,6 @@ func TestProcessComponents_Close_ShouldWork(t *testing.T) { idxInitial, _ := gc.Snapshot() factory.PrintStack() - accountNonceProvider := testscommon.NewAccountNonceProviderMock() - configs := factory.CreateDefaultConfig(t) chanStopNodeProcess := make(chan endProcess.ArgEndProcess) nr, err := node.NewNodeRunner(configs) @@ -48,7 +45,6 @@ func TestProcessComponents_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedCryptoComponents, managedNetworkComponents, - accountNonceProvider, ) require.Nil(t, err) managedDataComponents, err := nr.CreateManagedDataComponents( @@ -56,7 +52,6 @@ func TestProcessComponents_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedBootstrapComponents, managedCryptoComponents, - accountNonceProvider, ) require.Nil(t, err) managedStateComponents, err := nr.CreateManagedStateComponents(managedCoreComponents, managedDataComponents, managedStatusCoreComponents) diff --git a/integrationTests/factory/stateComponents/stateComponents_test.go b/integrationTests/factory/stateComponents/stateComponents_test.go index b3b9ce4dba1..18984a82bde 100644 --- a/integrationTests/factory/stateComponents/stateComponents_test.go +++ b/integrationTests/factory/stateComponents/stateComponents_test.go @@ -8,7 +8,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data/endProcess" "github.com/multiversx/mx-chain-go/integrationTests/factory" "github.com/multiversx/mx-chain-go/node" - "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/goroutines" "github.com/stretchr/testify/require" ) @@ -29,8 +28,6 @@ func TestStateComponents_Create_Close_ShouldWork(t *testing.T) { nr, err := node.NewNodeRunner(configs) require.Nil(t, err) - accountNonceProvider := testscommon.NewAccountNonceProviderMock() - managedCoreComponents, err := nr.CreateManagedCoreComponents(chanStopNodeProcess) require.Nil(t, err) managedStatusCoreComponents, err := nr.CreateManagedStatusCoreComponents(managedCoreComponents) @@ -45,7 +42,6 @@ func TestStateComponents_Create_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedCryptoComponents, managedNetworkComponents, - accountNonceProvider, ) require.Nil(t, err) managedDataComponents, err := nr.CreateManagedDataComponents( @@ -53,7 +49,6 @@ func TestStateComponents_Create_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedBootstrapComponents, managedCryptoComponents, - accountNonceProvider, ) require.Nil(t, err) managedStateComponents, err := nr.CreateManagedStateComponents(managedCoreComponents, managedDataComponents, managedStatusCoreComponents) diff --git a/integrationTests/factory/statusComponents/statusComponents_test.go b/integrationTests/factory/statusComponents/statusComponents_test.go index 0adde3783bf..dc5d3575b8c 100644 --- a/integrationTests/factory/statusComponents/statusComponents_test.go +++ b/integrationTests/factory/statusComponents/statusComponents_test.go @@ -11,7 +11,6 @@ import ( bootstrapComp "github.com/multiversx/mx-chain-go/factory/bootstrap" "github.com/multiversx/mx-chain-go/integrationTests/factory" "github.com/multiversx/mx-chain-go/node" - "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/goroutines" "github.com/stretchr/testify/require" ) @@ -33,8 +32,6 @@ func TestStatusComponents_Create_Close_ShouldWork(t *testing.T) { nr, err := node.NewNodeRunner(configs) require.Nil(t, err) - accountNonceProvider := testscommon.NewAccountNonceProviderMock() - managedCoreComponents, err := nr.CreateManagedCoreComponents(chanStopNodeProcess) require.Nil(t, err) managedStatusCoreComponents, err := nr.CreateManagedStatusCoreComponents(managedCoreComponents) @@ -48,7 +45,6 @@ func TestStatusComponents_Create_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedCryptoComponents, managedNetworkComponents, - accountNonceProvider, ) require.Nil(t, err) managedDataComponents, err := nr.CreateManagedDataComponents( @@ -56,7 +52,6 @@ func TestStatusComponents_Create_Close_ShouldWork(t *testing.T) { managedCoreComponents, managedBootstrapComponents, managedCryptoComponents, - accountNonceProvider, ) require.Nil(t, err) managedStateComponents, err := nr.CreateManagedStateComponents(managedCoreComponents, managedDataComponents, managedStatusCoreComponents) diff --git a/integrationTests/mock/transactionCoordinatorMock.go b/integrationTests/mock/transactionCoordinatorMock.go index 1ff93b7cb2b..c002c52cc0f 100644 --- a/integrationTests/mock/transactionCoordinatorMock.go +++ b/integrationTests/mock/transactionCoordinatorMock.go @@ -20,7 +20,6 @@ type TransactionCoordinatorMock struct { RestoreBlockDataFromStorageCalled func(body *block.Body) (int, error) RemoveBlockDataFromPoolCalled func(body *block.Body) error RemoveTxsFromPoolCalled func(body *block.Body) error - ForgetAllAccountNoncesInMempoolCalled func() ProcessBlockTransactionCalled func(header data.HeaderHandler, body *block.Body, haveTime func() time.Duration) error CreateBlockStartedCalled func() CreateMbsAndProcessCrossShardTransactionsDstMeCalled func(header data.HeaderHandler, processedMiniBlocksInfo map[string]*processedMb.ProcessedMiniBlockInfo, haveTime func() bool, haveAdditionalTime func() bool, scheduledMode bool) (block.MiniBlockSlice, uint32, bool, error) @@ -127,15 +126,6 @@ func (tcm *TransactionCoordinatorMock) RemoveTxsFromPool(body *block.Body) error return tcm.RemoveTxsFromPoolCalled(body) } -// ForgetAllAccountNoncesInMempool - -func (tcm *TransactionCoordinatorMock) ForgetAllAccountNoncesInMempool() { - if tcm.ForgetAllAccountNoncesInMempoolCalled == nil { - return - } - - tcm.ForgetAllAccountNoncesInMempool() -} - // ProcessBlockTransaction - func (tcm *TransactionCoordinatorMock) ProcessBlockTransaction(header data.HeaderHandler, body *block.Body, haveTime func() time.Duration) error { if tcm.ProcessBlockTransactionCalled == nil { diff --git a/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go b/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go index 68d3de6049e..ce933a22666 100644 --- a/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go +++ b/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go @@ -279,7 +279,6 @@ func testNodeStartsInEpoch(t *testing.T, shardID uint32, expectedHighestRound ui }, TrieSyncStatisticsProvider: &testscommon.SizeSyncStatisticsHandlerStub{}, StateStatsHandler: disabled.NewStateStatistics(), - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), } epochStartBootstrap, err := bootstrap.NewEpochStartBootstrap(argsBootstrapHandler) diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index 41ece5b81eb..70df89b466c 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -188,7 +188,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( } time.Sleep(time.Second) - roundToPropagateMultiShard := int64(25) + roundToPropagateMultiShard := int64(40) for i := int64(0); i <= roundToPropagateMultiShard; i++ { round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) @@ -200,7 +200,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( finalBalance.Mul(finalBalance, sendValue) checkSCBalance(t, ownerNode, scAddress, receiverAddress1, finalBalance) - checkSCBalance(t, ownerNode, scAddress, receiverAddress1, finalBalance) + checkSCBalance(t, ownerNode, scAddress, receiverAddress2, finalBalance) checkPlayerBalances(t, nodes, players) @@ -436,7 +436,7 @@ func checkSCBalance(t *testing.T, node *integrationTests.TestProcessorNode, scAd }) assert.Nil(t, err) actualBalance := big.NewInt(0).SetBytes(vmOutput.ReturnData[0]) - assert.Equal(t, 0, actualBalance.Cmp(balance)) + assert.Equal(t, balance.String(), actualBalance.String()) } func checkPlayerBalances( diff --git a/integrationTests/realcomponents/processorRunner.go b/integrationTests/realcomponents/processorRunner.go index fd6ce0dd747..3f3f4837201 100644 --- a/integrationTests/realcomponents/processorRunner.go +++ b/integrationTests/realcomponents/processorRunner.go @@ -57,7 +57,6 @@ type ProcessorRunner struct { NodesCoordinator nodesCoord.NodesCoordinator StatusComponents factory.StatusComponentsHolder ProcessComponents factory.ProcessComponentsHolder - AccountNonceProvider dataRetriever.AccountNonceProvider } // NewProcessorRunner returns a new instance of ProcessorRunner @@ -74,7 +73,6 @@ func NewProcessorRunner(tb testing.TB, config config.Configs) *ProcessorRunner { func (pr *ProcessorRunner) createComponents(tb testing.TB) { var err error - pr.AccountNonceProvider, err = factoryState.NewAccountNonceProvider(nil) require.Nil(tb, err) pr.createCoreComponents(tb) @@ -86,9 +84,6 @@ func (pr *ProcessorRunner) createComponents(tb testing.TB) { pr.createStateComponents(tb) pr.createStatusComponents(tb) pr.createProcessComponents(tb) - - err = pr.AccountNonceProvider.SetAccountsAdapter(pr.StateComponents.AccountsAdapterAPI()) - require.Nil(tb, err) } func (pr *ProcessorRunner) createCoreComponents(tb testing.TB) { @@ -214,7 +209,6 @@ func (pr *ProcessorRunner) createBootstrapComponents(tb testing.TB) { CryptoComponents: pr.CryptoComponents, NetworkComponents: pr.NetworkComponents, StatusCoreComponents: pr.StatusCoreComponents, - AccountNonceProvider: pr.AccountNonceProvider, } bootstrapFactory, err := factoryBootstrap.NewBootstrapComponentsFactory(argsBootstrap) @@ -243,7 +237,6 @@ func (pr *ProcessorRunner) createDataComponents(tb testing.TB) { CreateTrieEpochRootHashStorer: false, NodeProcessingMode: common.Normal, FlagsConfigs: config.ContextFlagsConfig{}, - AccountNonceProvider: pr.AccountNonceProvider, } dataFactory, err := factoryData.NewDataComponentsFactory(argsData) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index c7cfe0995de..80ba584c6b4 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -302,7 +302,6 @@ type ArgTestProcessorNode struct { StatusMetrics external.StatusMetricsHandler WithPeersRatingHandler bool NodeOperationMode common.NodeOperation - AccountNonceProvider dataRetriever.AccountNonceProvider } // TestProcessorNode represents a container type of class used in integration tests @@ -1690,6 +1689,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u txTypeHandler, _ := coordinator.NewTxTypeHandler(argsTxTypeHandler) tpn.GasHandler, _ = preprocess.NewGasComputation(tpn.EconomicsData, txTypeHandler, tpn.EnableEpochsHandler) badBlocksHandler, _ := tpn.InterimProcContainer.Get(dataBlock.InvalidBlock) + guardianChecker := &guardianMocks.GuardedAccountHandlerStub{} argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ VmContainer: tpn.VMContainer, @@ -1735,7 +1735,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u ScrForwarder: tpn.ScrForwarder, EnableRoundsHandler: tpn.EnableRoundsHandler, EnableEpochsHandler: tpn.EnableEpochsHandler, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + GuardianChecker: guardianChecker, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, TxLogsProcessor: tpn.TransactionLogProcessor, } diff --git a/node/chainSimulator/components/bootstrapComponents.go b/node/chainSimulator/components/bootstrapComponents.go index ba34884abed..7e0190ded2e 100644 --- a/node/chainSimulator/components/bootstrapComponents.go +++ b/node/chainSimulator/components/bootstrapComponents.go @@ -7,7 +7,6 @@ import ( "github.com/multiversx/mx-chain-core-go/core" nodeFactory "github.com/multiversx/mx-chain-go/cmd/node/factory" "github.com/multiversx/mx-chain-go/config" - "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/factory" bootstrapComp "github.com/multiversx/mx-chain-go/factory/bootstrap" "github.com/multiversx/mx-chain-go/process" @@ -27,7 +26,6 @@ type ArgsBootstrapComponentsHolder struct { PrefsConfig config.Preferences Config config.Config ShardIDStr string - AccountNonceProvider dataRetriever.AccountNonceProvider } type bootstrapComponentsHolder struct { @@ -59,7 +57,6 @@ func CreateBootstrapComponents(args ArgsBootstrapComponentsHolder) (*bootstrapCo CryptoComponents: args.CryptoComponents, NetworkComponents: args.NetworkComponents, StatusCoreComponents: args.StatusCoreComponents, - AccountNonceProvider: args.AccountNonceProvider, } bootstrapComponentsFactory, err := bootstrapComp.NewBootstrapComponentsFactory(bootstrapComponentsFactoryArgs) diff --git a/node/chainSimulator/components/bootstrapComponents_test.go b/node/chainSimulator/components/bootstrapComponents_test.go index c8199506aa3..7e4becdc52e 100644 --- a/node/chainSimulator/components/bootstrapComponents_test.go +++ b/node/chainSimulator/components/bootstrapComponents_test.go @@ -128,8 +128,7 @@ func createArgsBootstrapComponentsHolder() ArgsBootstrapComponentsHolder { Capacity: 123, }, }, - ShardIDStr: "0", - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), + ShardIDStr: "0", } } diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 54808feca13..efa4c12102c 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -17,7 +17,6 @@ import ( "github.com/multiversx/mx-chain-go/facade" "github.com/multiversx/mx-chain-go/factory" bootstrapComp "github.com/multiversx/mx-chain-go/factory/bootstrap" - factoryState "github.com/multiversx/mx-chain-go/factory/state" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/block/postprocess" @@ -132,12 +131,6 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces return nil, err } - // The accounts adapter isn't yet available, it will be set a bit later (see below). - accountNonceProvider, err := factoryState.NewAccountNonceProvider(nil) - if err != nil { - return nil, err - } - instance.BootstrapComponentsHolder, err = CreateBootstrapComponents(ArgsBootstrapComponentsHolder{ CoreComponents: instance.CoreComponentsHolder, CryptoComponents: instance.CryptoComponentsHolder, @@ -149,7 +142,6 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces PrefsConfig: *args.Configs.PreferencesConfig, Config: *args.Configs.GeneralConfig, ShardIDStr: args.ShardIDStr, - AccountNonceProvider: accountNonceProvider, }) if err != nil { return nil, err @@ -183,18 +175,12 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces return nil, err } - err = accountNonceProvider.SetAccountsAdapter(instance.StateComponentsHolder.AccountsAdapterAPI()) - if err != nil { - return nil, err - } - instance.DataPool, err = dataRetrieverFactory.NewDataPoolFromConfig(dataRetrieverFactory.ArgsDataPool{ - Config: args.Configs.GeneralConfig, - EconomicsData: instance.CoreComponentsHolder.EconomicsData(), - ShardCoordinator: instance.BootstrapComponentsHolder.ShardCoordinator(), - Marshalizer: instance.CoreComponentsHolder.InternalMarshalizer(), - PathManager: instance.CoreComponentsHolder.PathHandler(), - AccountNonceProvider: accountNonceProvider, + Config: args.Configs.GeneralConfig, + EconomicsData: instance.CoreComponentsHolder.EconomicsData(), + ShardCoordinator: instance.BootstrapComponentsHolder.ShardCoordinator(), + Marshalizer: instance.CoreComponentsHolder.InternalMarshalizer(), + PathManager: instance.CoreComponentsHolder.PathHandler(), }) if err != nil { return nil, err diff --git a/node/nodeRunner.go b/node/nodeRunner.go index ba5751157c1..1837c78b427 100644 --- a/node/nodeRunner.go +++ b/node/nodeRunner.go @@ -320,19 +320,12 @@ func (nr *nodeRunner) executeOneComponentCreationCycle( return true, err } - // The accounts adapter isn't yet available, it will be set a bit later (see below). - accountNonceProvider, err := stateComp.NewAccountNonceProvider(nil) - if err != nil { - return true, err - } - log.Debug("creating bootstrap components") managedBootstrapComponents, err := nr.CreateManagedBootstrapComponents( managedStatusCoreComponents, managedCoreComponents, managedCryptoComponents, managedNetworkComponents, - accountNonceProvider, ) if err != nil { return true, err @@ -346,7 +339,6 @@ func (nr *nodeRunner) executeOneComponentCreationCycle( managedCoreComponents, managedBootstrapComponents, managedCryptoComponents, - accountNonceProvider, ) if err != nil { return true, err @@ -362,11 +354,6 @@ func (nr *nodeRunner) executeOneComponentCreationCycle( return true, err } - err = accountNonceProvider.SetAccountsAdapter(managedStateComponents.AccountsAdapterAPI()) - if err != nil { - return true, err - } - log.Debug("creating metrics") // this should be called before setting the storer (done in the managedDataComponents creation) err = nr.createMetrics(managedStatusCoreComponents, managedCoreComponents, managedCryptoComponents, managedBootstrapComponents) @@ -1311,7 +1298,6 @@ func (nr *nodeRunner) CreateManagedDataComponents( coreComponents mainFactory.CoreComponentsHolder, bootstrapComponents mainFactory.BootstrapComponentsHolder, crypto mainFactory.CryptoComponentsHolder, - accountNonceProvider dataRetriever.AccountNonceProvider, ) (mainFactory.DataComponentsHandler, error) { configs := nr.configs storerEpoch := bootstrapComponents.EpochBootstrapParams().Epoch() @@ -1332,7 +1318,6 @@ func (nr *nodeRunner) CreateManagedDataComponents( CreateTrieEpochRootHashStorer: configs.ImportDbConfig.ImportDbSaveTrieEpochRootHash, FlagsConfigs: *configs.FlagsConfig, NodeProcessingMode: common.GetNodeProcessingMode(nr.configs.ImportDbConfig), - AccountNonceProvider: accountNonceProvider, } dataComponentsFactory, err := dataComp.NewDataComponentsFactory(dataArgs) @@ -1401,7 +1386,6 @@ func (nr *nodeRunner) CreateManagedBootstrapComponents( coreComponents mainFactory.CoreComponentsHolder, cryptoComponents mainFactory.CryptoComponentsHolder, networkComponents mainFactory.NetworkComponentsHolder, - accountNonceProvider dataRetriever.AccountNonceProvider, ) (mainFactory.BootstrapComponentsHandler, error) { bootstrapComponentsFactoryArgs := bootstrapComp.BootstrapComponentsFactoryArgs{ @@ -1414,7 +1398,6 @@ func (nr *nodeRunner) CreateManagedBootstrapComponents( CryptoComponents: cryptoComponents, NetworkComponents: networkComponents, StatusCoreComponents: statusCoreComponents, - AccountNonceProvider: accountNonceProvider, } bootstrapComponentsFactory, err := bootstrapComp.NewBootstrapComponentsFactory(bootstrapComponentsFactoryArgs) diff --git a/process/block/baseProcess.go b/process/block/baseProcess.go index a6aa60f7396..0e3c573b23d 100644 --- a/process/block/baseProcess.go +++ b/process/block/baseProcess.go @@ -1434,11 +1434,6 @@ func (bp *baseProcessor) updateStateStorage( func (bp *baseProcessor) RevertCurrentBlock() { bp.revertAccountState() bp.revertScheduledInfo() - - // In case of a reverted block, we ask the mempool to forget all the nonces of the accounts, - // so that it doesn't make badly informed decisions (transactions skipping) in the upcoming selections. - // Called synchronously (not in a goroutine): ~5 milliseconds for 100k accounts in the mempool. - bp.txCoordinator.ForgetAllAccountNoncesInMempool() } func (bp *baseProcessor) revertAccountState() { diff --git a/process/block/preprocess/accountStateProvider.go b/process/block/preprocess/accountStateProvider.go new file mode 100644 index 00000000000..736a9247659 --- /dev/null +++ b/process/block/preprocess/accountStateProvider.go @@ -0,0 +1,47 @@ +package preprocess + +import ( + "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-go/errors" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/state" + "github.com/multiversx/mx-chain-go/storage/txcache" +) + +type accountStateProvider struct { + accountsAdapter state.AccountsAdapter +} + +func newAccountStateProvider(accountsAdapter state.AccountsAdapter) (*accountStateProvider, error) { + if check.IfNil(accountsAdapter) { + return nil, process.ErrNilAccountsAdapter + } + + return &accountStateProvider{ + accountsAdapter: accountsAdapter, + }, nil +} + +// GetAccountState returns the state of an account. +// Will be called by mempool during transaction selection. +func (provider *accountStateProvider) GetAccountState(address []byte) (*txcache.AccountState, error) { + account, err := provider.accountsAdapter.GetExistingAccount(address) + if err != nil { + return nil, err + } + + userAccount, ok := account.(state.UserAccountHandler) + if !ok { + return nil, errors.ErrWrongTypeAssertion + } + + return &txcache.AccountState{ + Nonce: userAccount.GetNonce(), + Balance: userAccount.GetBalance(), + }, nil +} + +// IsInterfaceNil returns true if there is no value under the interface +func (provider *accountStateProvider) IsInterfaceNil() bool { + return provider == nil +} diff --git a/process/block/preprocess/accountStateProvider_test.go b/process/block/preprocess/accountStateProvider_test.go new file mode 100644 index 00000000000..b4ea6637308 --- /dev/null +++ b/process/block/preprocess/accountStateProvider_test.go @@ -0,0 +1,66 @@ +package preprocess + +import ( + "bytes" + "fmt" + "testing" + + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/testscommon/state" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/require" +) + +func TestNewAccountStateProvider(t *testing.T) { + t.Parallel() + + provider, err := newAccountStateProvider(nil) + require.Nil(t, provider) + require.ErrorIs(t, err, process.ErrNilAccountsAdapter) + + provider, err = newAccountStateProvider(&state.AccountsStub{}) + require.NoError(t, err) + require.NotNil(t, provider) +} + +func TestAccountStateProvider_GetAccountState(t *testing.T) { + t.Parallel() + + accounts := &state.AccountsStub{} + accounts.GetExistingAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { + if bytes.Equal(address, []byte("alice")) { + return &state.UserAccountStub{ + Address: []byte("alice"), + Nonce: 42, + }, nil + } + + if bytes.Equal(address, []byte("bob")) { + return &state.UserAccountStub{ + Address: []byte("bob"), + Nonce: 7, + IsGuardedCalled: func() bool { + return true + }, + }, nil + } + + return nil, fmt.Errorf("account not found: %s", address) + } + + provider, err := newAccountStateProvider(accounts) + require.NoError(t, err) + require.NotNil(t, provider) + + state, err := provider.GetAccountState([]byte("alice")) + require.NoError(t, err) + require.Equal(t, uint64(42), state.Nonce) + + state, err = provider.GetAccountState([]byte("bob")) + require.NoError(t, err) + require.Equal(t, uint64(7), state.Nonce) + + state, err = provider.GetAccountState([]byte("carol")) + require.ErrorContains(t, err, "account not found: carol") + require.Nil(t, state) +} diff --git a/process/block/preprocess/basePreProcess.go b/process/block/preprocess/basePreProcess.go index 56ea615559e..9cbbdb8727a 100644 --- a/process/block/preprocess/basePreProcess.go +++ b/process/block/preprocess/basePreProcess.go @@ -120,6 +120,7 @@ type basePreProcess struct { blockSizeComputation BlockSizeComputationHandler balanceComputation BalanceComputationHandler accounts state.AccountsAdapter + accountStateProvider *accountStateProvider pubkeyConverter core.PubkeyConverter processedMiniBlocksTracker process.ProcessedMiniBlocksTracker enableEpochsHandler common.EnableEpochsHandler diff --git a/process/block/preprocess/interfaces.go b/process/block/preprocess/interfaces.go index 352c9aa09f7..92e87f6ce05 100644 --- a/process/block/preprocess/interfaces.go +++ b/process/block/preprocess/interfaces.go @@ -2,21 +2,20 @@ package preprocess import ( "math/big" + "time" "github.com/multiversx/mx-chain-go/storage/txcache" ) // SortedTransactionsProvider defines the public API of the transactions cache type SortedTransactionsProvider interface { - GetSortedTransactions() []*txcache.WrappedTransaction - NotifyAccountNonce(accountKey []byte, nonce uint64) + GetSortedTransactions(accountStateProvider txcache.AccountStateProvider) []*txcache.WrappedTransaction IsInterfaceNil() bool } // TxCache defines the functionality for the transactions cache type TxCache interface { - SelectTransactions(gasRequested uint64, maxNum int) ([]*txcache.WrappedTransaction, uint64) - NotifyAccountNonce(accountKey []byte, nonce uint64) + SelectTransactions(accountStateProvider txcache.AccountStateProvider, gasRequested uint64, maxNum int, selectionLoopMaximumDuration time.Duration) ([]*txcache.WrappedTransaction, uint64) IsInterfaceNil() bool } diff --git a/process/block/preprocess/miniBlockBuilder.go b/process/block/preprocess/miniBlockBuilder.go index a1a2e2bc82e..d10e6ba6ee5 100644 --- a/process/block/preprocess/miniBlockBuilder.go +++ b/process/block/preprocess/miniBlockBuilder.go @@ -22,7 +22,6 @@ import ( type miniBlocksBuilderArgs struct { gasTracker gasTracker accounts state.AccountsAdapter - accountTxsShards *accountTxsShards blockSizeComputation BlockSizeComputationHandler balanceComputationHandler BalanceComputationHandler haveTime func() bool @@ -50,7 +49,6 @@ type miniBlockBuilderStats struct { type miniBlocksBuilder struct { gasTracker accounts state.AccountsAdapter - accountTxsShards *accountTxsShards balanceComputationHandler BalanceComputationHandler blockSizeComputation BlockSizeComputationHandler gasConsumedInReceiverShard map[uint32]uint64 @@ -75,7 +73,6 @@ func newMiniBlockBuilder(args miniBlocksBuilderArgs) (*miniBlocksBuilder, error) return &miniBlocksBuilder{ gasTracker: args.gasTracker, accounts: args.accounts, - accountTxsShards: args.accountTxsShards, balanceComputationHandler: args.balanceComputationHandler, blockSizeComputation: args.blockSizeComputation, miniBlocks: initializeMiniBlocksMap(args.gasTracker.shardCoordinator), @@ -117,9 +114,6 @@ func checkMiniBlocksBuilderArgs(args miniBlocksBuilderArgs) error { if check.IfNil(args.txPool) { return process.ErrNilTransactionPool } - if args.accountTxsShards == nil { - return process.ErrNilAccountTxsPerShard - } if args.haveTime == nil { return process.ErrNilHaveTimeHandler } @@ -136,15 +130,6 @@ func checkMiniBlocksBuilderArgs(args miniBlocksBuilderArgs) error { return nil } -func (mbb *miniBlocksBuilder) updateAccountShardsInfo(tx *transaction.Transaction, wtx *txcache.WrappedTransaction) { - mbb.accountTxsShards.Lock() - mbb.accountTxsShards.accountsInfo[string(tx.GetSndAddr())] = &txShardInfo{ - senderShardID: wtx.SenderShardID, - receiverShardID: wtx.ReceiverShardID, - } - mbb.accountTxsShards.Unlock() -} - // checkAddTransaction method returns a set of actions which could be done afterwards, by checking the given transaction func (mbb *miniBlocksBuilder) checkAddTransaction(wtx *txcache.WrappedTransaction) (*processingActions, *transaction.Transaction) { tx, ok := wtx.Tx.(*transaction.Transaction) diff --git a/process/block/preprocess/miniBlockBuilder_test.go b/process/block/preprocess/miniBlockBuilder_test.go index f656241c662..3ba49aa00a3 100644 --- a/process/block/preprocess/miniBlockBuilder_test.go +++ b/process/block/preprocess/miniBlockBuilder_test.go @@ -4,7 +4,6 @@ import ( "encoding/hex" "errors" "math/big" - "sync" "testing" "github.com/multiversx/mx-chain-core-go/data" @@ -82,16 +81,6 @@ func Test_checkMiniBlocksBuilderArgsNilBlockSizeComputationHandlerShouldErr(t *t require.Equal(t, process.ErrNilBlockSizeComputationHandler, err) } -func Test_checkMiniBlocksBuilderArgsNilAccountsTxsPerShardsShouldErr(t *testing.T) { - t.Parallel() - - args := createDefaultMiniBlockBuilderArgs() - args.accountTxsShards = nil - - err := checkMiniBlocksBuilderArgs(args) - require.Equal(t, process.ErrNilAccountTxsPerShard, err) -} - func Test_checkMiniBlocksBuilderArgsNilBalanceComputationHandlerShouldErr(t *testing.T) { t.Parallel() @@ -151,29 +140,6 @@ func Test_checkMiniBlocksBuilderArgsOK(t *testing.T) { require.Nil(t, err) } -func Test_MiniBlocksBuilderUpdateAccountShardsInfo(t *testing.T) { - t.Parallel() - - args := createDefaultMiniBlockBuilderArgs() - - mbb, _ := newMiniBlockBuilder(args) - senderAddr := []byte("senderAddr") - receiverAddr := []byte("receiverAddr") - tx := createDefaultTx(senderAddr, receiverAddr, 50000) - - senderShardID := uint32(0) - receiverShardID := uint32(0) - wtx := createWrappedTransaction(tx, senderShardID, receiverShardID) - - mbb.updateAccountShardsInfo(tx, wtx) - - addrShardInfo, ok := mbb.accountTxsShards.accountsInfo[string(tx.SndAddr)] - require.True(t, ok) - - require.Equal(t, senderShardID, addrShardInfo.senderShardID) - require.Equal(t, receiverShardID, addrShardInfo.receiverShardID) -} - func Test_MiniBlocksBuilderHandleGasRefundIntraShard(t *testing.T) { t.Parallel() @@ -881,11 +847,7 @@ func createDefaultMiniBlockBuilderArgs() miniBlocksBuilderArgs { }, }, }, - accounts: &stateMock.AccountsStub{}, - accountTxsShards: &accountTxsShards{ - accountsInfo: make(map[string]*txShardInfo), - RWMutex: sync.RWMutex{}, - }, + accounts: &stateMock.AccountsStub{}, blockSizeComputation: &testscommon.BlockSizeComputationStub{}, balanceComputationHandler: &testscommon.BalanceComputationStub{}, haveTime: haveTimeTrue, @@ -918,6 +880,6 @@ func createWrappedTransaction( Size: int64(len(txMarshalled)), } - wrappedTx.PricePerUnit.Store(1_000_000_000) + wrappedTx.PricePerUnit = 1_000_000_000 return wrappedTx } diff --git a/process/block/preprocess/rewardTxPreProcessor.go b/process/block/preprocess/rewardTxPreProcessor.go index 97a051014b3..e695d51e498 100644 --- a/process/block/preprocess/rewardTxPreProcessor.go +++ b/process/block/preprocess/rewardTxPreProcessor.go @@ -163,10 +163,6 @@ func (rtp *rewardTxPreprocessor) RemoveTxsFromPools(body *block.Body) error { return rtp.removeTxsFromPools(body, rtp.rewardTxPool, rtp.isMiniBlockCorrect) } -// ForgetAllAccountNoncesInMempool does nothing -func (rtp *rewardTxPreprocessor) ForgetAllAccountNoncesInMempool() { -} - // RestoreBlockDataIntoPools restores the reward transactions and miniblocks to associated pools func (rtp *rewardTxPreprocessor) RestoreBlockDataIntoPools( body *block.Body, diff --git a/process/block/preprocess/smartContractResults.go b/process/block/preprocess/smartContractResults.go index 26bbb5dddd6..3ac910a1834 100644 --- a/process/block/preprocess/smartContractResults.go +++ b/process/block/preprocess/smartContractResults.go @@ -181,10 +181,6 @@ func (scr *smartContractResults) RemoveTxsFromPools(body *block.Body) error { return scr.removeTxsFromPools(body, scr.scrPool, scr.isMiniBlockCorrect) } -// ForgetAllAccountNoncesInMempool does nothing -func (scr *smartContractResults) ForgetAllAccountNoncesInMempool() { -} - // RestoreBlockDataIntoPools restores the smart contract results and miniblocks to associated pools func (scr *smartContractResults) RestoreBlockDataIntoPools( body *block.Body, diff --git a/process/block/preprocess/sortedTransactionsProvider.go b/process/block/preprocess/sortedTransactionsProvider.go index 6da2e526467..e5811335a73 100644 --- a/process/block/preprocess/sortedTransactionsProvider.go +++ b/process/block/preprocess/sortedTransactionsProvider.go @@ -32,16 +32,11 @@ func newAdapterTxCacheToSortedTransactionsProvider(txCache TxCache) *adapterTxCa } // GetSortedTransactions gets the transactions from the cache -func (adapter *adapterTxCacheToSortedTransactionsProvider) GetSortedTransactions() []*txcache.WrappedTransaction { - txs, _ := adapter.txCache.SelectTransactions(process.TxCacheSelectionGasRequested, process.TxCacheSelectionMaxNumTxs) +func (adapter *adapterTxCacheToSortedTransactionsProvider) GetSortedTransactions(accountStateProvider txcache.AccountStateProvider) []*txcache.WrappedTransaction { + txs, _ := adapter.txCache.SelectTransactions(accountStateProvider, process.TxCacheSelectionGasRequested, process.TxCacheSelectionMaxNumTxs, process.TxCacheSelectionLoopMaximumDuration) return txs } -// NotifyAccountNonce notifies the cache about the current nonce of an account -func (adapter *adapterTxCacheToSortedTransactionsProvider) NotifyAccountNonce(accountKey []byte, nonce uint64) { - adapter.txCache.NotifyAccountNonce(accountKey, nonce) -} - // IsInterfaceNil returns true if there is no value under the interface func (adapter *adapterTxCacheToSortedTransactionsProvider) IsInterfaceNil() bool { return adapter == nil @@ -52,14 +47,10 @@ type disabledSortedTransactionsProvider struct { } // GetSortedTransactions returns an empty slice -func (adapter *disabledSortedTransactionsProvider) GetSortedTransactions() []*txcache.WrappedTransaction { +func (adapter *disabledSortedTransactionsProvider) GetSortedTransactions(_ txcache.AccountStateProvider) []*txcache.WrappedTransaction { return make([]*txcache.WrappedTransaction, 0) } -// NotifyAccountNonce does nothing -func (adapter *disabledSortedTransactionsProvider) NotifyAccountNonce(_ []byte, _ uint64) { -} - // IsInterfaceNil returns true if there is no value under the interface func (adapter *disabledSortedTransactionsProvider) IsInterfaceNil() bool { return adapter == nil diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index d484a67bd28..567569f6dc6 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -16,7 +16,6 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" logger "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" @@ -34,15 +33,10 @@ var _ process.PreProcessor = (*transactions)(nil) var log = logger.GetOrCreate("process/block/preprocess") // 200% bandwidth to allow 100% overshooting estimations -const selectionGasBandwidthIncreasePercent = 200 +const selectionGasBandwidthIncreasePercent = 400 // 130% to allow 30% overshooting estimations for scheduled SC calls -const selectionGasBandwidthIncreaseScheduledPercent = 130 - -type accountTxsShards struct { - accountsInfo map[string]*txShardInfo - sync.RWMutex -} +const selectionGasBandwidthIncreaseScheduledPercent = 260 // TODO: increase code coverage with unit test @@ -59,7 +53,6 @@ type transactions struct { mutOrderedTxs sync.RWMutex blockTracker BlockTracker blockType block.Type - accountTxsShards accountTxsShards emptyAddress []byte txTypeHandler process.TxTypeHandler scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler @@ -161,6 +154,11 @@ func NewTransactionPreprocessor( return nil, process.ErrNilTxExecutionOrderHandler } + stateProvider, err := newAccountStateProvider(args.Accounts) + if err != nil { + return nil, err + } + bpp := basePreProcess{ hasher: args.Hasher, marshalizer: args.Marshalizer, @@ -172,6 +170,7 @@ func NewTransactionPreprocessor( blockSizeComputation: args.BlockSizeComputation, balanceComputation: args.BalanceComputation, accounts: args.Accounts, + accountStateProvider: stateProvider, pubkeyConverter: args.PubkeyConverter, enableEpochsHandler: args.EnableEpochsHandler, processedMiniBlocksTracker: args.ProcessedMiniBlocksTracker, @@ -196,7 +195,6 @@ func NewTransactionPreprocessor( txs.txsForCurrBlock.txHashAndInfo = make(map[string]*txInfo) txs.orderedTxs = make(map[string][]data.TransactionHandler) txs.orderedTxHashes = make(map[string][][]byte) - txs.accountTxsShards.accountsInfo = make(map[string]*txShardInfo) txs.emptyAddress = make([]byte, txs.pubkeyConverter.Len()) @@ -241,11 +239,6 @@ func (txs *transactions) RemoveTxsFromPools(body *block.Body) error { return txs.removeTxsFromPools(body, txs.txPool, txs.isMiniBlockCorrect) } -// ForgetAllAccountNoncesInMempool forgets all account nonces in mempool -func (txs *transactions) ForgetAllAccountNoncesInMempool() { - txs.txPool.ForgetAllAccountNoncesInMempool() -} - // RestoreBlockDataIntoPools restores the transactions and miniblocks to associated pools func (txs *transactions) RestoreBlockDataIntoPools( body *block.Body, @@ -728,10 +721,6 @@ func (txs *transactions) createAndProcessScheduledMiniBlocksFromMeAsValidator( return make(block.MiniBlockSlice, 0), nil } - defer func() { - go txs.notifyTransactionProviderIfNeeded() - }() - scheduledTxsFromMe, err := txs.computeScheduledTxsFromMe(body) if err != nil { return nil, err @@ -806,10 +795,6 @@ func (txs *transactions) CreateBlockStarted() { txs.orderedTxHashes = make(map[string][][]byte) txs.mutOrderedTxs.Unlock() - txs.accountTxsShards.Lock() - txs.accountTxsShards.accountsInfo = make(map[string]*txShardInfo) - txs.accountTxsShards.Unlock() - txs.scheduledTxsExecutionHandler.Init() } @@ -925,44 +910,6 @@ func (txs *transactions) processAndRemoveBadTransaction( return err } -func (txs *transactions) notifyTransactionProviderIfNeeded() { - txs.accountTxsShards.RLock() - - log.Debug("notifyTransactionProviderIfNeeded", "len(txs.accountTxsShards.accountsInfo)", len(txs.accountTxsShards.accountsInfo)) - - for senderAddress, txShardInfoValue := range txs.accountTxsShards.accountsInfo { - if txShardInfoValue.senderShardID != txs.shardCoordinator.SelfId() { - continue - } - - account, err := txs.getAccountForAddress([]byte(senderAddress)) - if err != nil { - log.Debug("notifyTransactionProviderIfNeeded.getAccountForAddress", "error", err) - continue - } - - strCache := process.ShardCacherIdentifier(txShardInfoValue.senderShardID, txShardInfoValue.receiverShardID) - txShardPool := txs.txPool.ShardDataStore(strCache) - if check.IfNil(txShardPool) { - log.Trace("notifyTransactionProviderIfNeeded", "error", process.ErrNilTxDataPool) - continue - } - - sortedTransactionsProvider := createSortedTransactionsProvider(txShardPool) - sortedTransactionsProvider.NotifyAccountNonce([]byte(senderAddress), account.GetNonce()) - } - txs.accountTxsShards.RUnlock() -} - -func (txs *transactions) getAccountForAddress(address []byte) (vmcommon.AccountHandler, error) { - account, err := txs.accounts.GetExistingAccount(address) - if err != nil { - return nil, err - } - - return account, nil -} - // RequestTransactionsForMiniBlock requests missing transactions for a certain miniblock func (txs *transactions) RequestTransactionsForMiniBlock(miniBlock *block.MiniBlock) int { if miniBlock == nil { @@ -1157,10 +1104,6 @@ func (txs *transactions) createAndProcessScheduledMiniBlocksFromMeAsProposer( return make(block.MiniBlockSlice, 0), nil } - defer func() { - go txs.notifyTransactionProviderIfNeeded() - }() - startTime := time.Now() scheduledMiniBlocks, err := txs.createScheduledMiniBlocks( haveTime, @@ -1198,7 +1141,6 @@ func (txs *transactions) createAndProcessMiniBlocksFromMeV1( args := miniBlocksBuilderArgs{ gasTracker: txs.gasTracker, accounts: txs.accounts, - accountTxsShards: &txs.accountTxsShards, balanceComputationHandler: txs.balanceComputation, blockSizeComputation: txs.blockSizeComputation, haveTime: haveTime, @@ -1214,10 +1156,6 @@ func (txs *transactions) createAndProcessMiniBlocksFromMeV1( return nil, nil, err } - defer func() { - go txs.notifyTransactionProviderIfNeeded() - }() - remainingTxs := make([]*txcache.WrappedTransaction, 0) for idx, wtx := range sortedTxs { actions, tx := mbBuilder.checkAddTransaction(wtx) @@ -1301,7 +1239,6 @@ func (txs *transactions) processMiniBlockBuilderTx( ) elapsedTime := time.Since(startTime) mb.stats.totalProcessingTime += elapsedTime - mb.updateAccountShardsInfo(tx, wtx) if err != nil && !errors.Is(err, process.ErrFailedTransaction) { txs.handleBadTransaction(err, wtx, tx, mb, snapshot) @@ -1479,7 +1416,8 @@ func (txs *transactions) computeSortedTxs( sortedTransactionsProvider := createSortedTransactionsProvider(txShardPool) log.Debug("computeSortedTxs.GetSortedTransactions") - sortedTxs := sortedTransactionsProvider.GetSortedTransactions() + + sortedTxs := sortedTransactionsProvider.GetSortedTransactions(txs.accountStateProvider) // TODO: this could be moved to SortedTransactionsProvider selectedTxs, remainingTxs := txs.preFilterTransactionsWithMoveBalancePriority(sortedTxs, gasBandwidth) diff --git a/process/block/preprocess/transactionsV2.go b/process/block/preprocess/transactionsV2.go index 6391987983a..1eb46683894 100644 --- a/process/block/preprocess/transactionsV2.go +++ b/process/block/preprocess/transactionsV2.go @@ -25,10 +25,6 @@ func (txs *transactions) createAndProcessMiniBlocksFromMeV2( log.Debug("createAndProcessMiniBlocksFromMeV2", "totalGasConsumedInSelfShard", mbInfo.gasInfo.totalGasConsumedInSelfShard) - defer func() { - go txs.notifyTransactionProviderIfNeeded() - }() - remainingTxs := make([]*txcache.WrappedTransaction, 0) for index := range sortedTxs { if !haveTime() { @@ -175,10 +171,6 @@ func (txs *transactions) processTransaction( elapsedTime = time.Since(startTime) mbInfo.processingInfo.totalTimeUsedForProcess += elapsedTime - txs.accountTxsShards.Lock() - txs.accountTxsShards.accountsInfo[string(tx.GetSndAddr())] = &txShardInfo{senderShardID: senderShardID, receiverShardID: receiverShardID} - txs.accountTxsShards.Unlock() - if err != nil && !errors.Is(err, process.ErrFailedTransaction) { if errors.Is(err, process.ErrHigherNonceInTransaction) { mbInfo.senderAddressToSkip = tx.GetSndAddr() @@ -379,10 +371,6 @@ func (txs *transactions) verifyTransaction( elapsedTime = time.Since(startTime) mbInfo.schedulingInfo.totalTimeUsedForScheduledVerify += elapsedTime - txs.accountTxsShards.Lock() - txs.accountTxsShards.accountsInfo[string(tx.GetSndAddr())] = &txShardInfo{senderShardID: senderShardID, receiverShardID: receiverShardID} - txs.accountTxsShards.Unlock() - if err != nil { isTxTargetedForDeletion := errors.Is(err, process.ErrLowerNonceInTransaction) || errors.Is(err, process.ErrInsufficientFee) || errors.Is(err, process.ErrTransactionNotExecutable) if isTxTargetedForDeletion { diff --git a/process/block/preprocess/transactions_test.go b/process/block/preprocess/transactions_test.go index 7f489b4b05d..cf1bcca2ec8 100644 --- a/process/block/preprocess/transactions_test.go +++ b/process/block/preprocess/transactions_test.go @@ -446,6 +446,16 @@ func TestTxsPreprocessor_NewTransactionPreprocessorNilProcessedMiniBlocksTracker assert.Equal(t, process.ErrNilProcessedMiniBlocksTracker, err) } +func TestTxsPreprocessor_NewTransactionPreprocessorNilTxExecutionOrderHandler(t *testing.T) { + t.Parallel() + + args := createDefaultTransactionsProcessorArgs() + args.TxExecutionOrderHandler = nil + txs, err := NewTransactionPreprocessor(args) + assert.Nil(t, txs) + assert.Equal(t, process.ErrNilTxExecutionOrderHandler, err) +} + func TestTxsPreprocessor_NewTransactionPreprocessorOkValsShouldWork(t *testing.T) { t.Parallel() @@ -660,6 +670,14 @@ func TestTransactions_CreateAndProcessMiniBlockCrossShardGasLimitAddAll(t *testi return 0 }, } + args.Accounts = &stateMock.AccountsStub{ + GetExistingAccountCalled: func(_ []byte) (vmcommon.AccountHandler, error) { + return &stateMock.UserAccountStub{ + Nonce: 42, + Balance: big.NewInt(1000000000000000000), + }, nil + }, + } txs, _ := NewTransactionPreprocessor(args) assert.NotNil(t, txs) @@ -714,6 +732,14 @@ func TestTransactions_CreateAndProcessMiniBlockCrossShardGasLimitAddAllAsNoSCCal return 0 }, } + args.Accounts = &stateMock.AccountsStub{ + GetExistingAccountCalled: func(_ []byte) (vmcommon.AccountHandler, error) { + return &stateMock.UserAccountStub{ + Nonce: 42, + Balance: big.NewInt(1000000000000000000), + }, nil + }, + } args.TxDataPool, _ = dataRetrieverMock.CreateTxPool(2, 0) txs, _ := NewTransactionPreprocessor(args) assert.NotNil(t, txs) @@ -779,6 +805,14 @@ func TestTransactions_CreateAndProcessMiniBlockCrossShardGasLimitAddOnly5asSCCal RemoveGasRefundedCalled: func(hashes [][]byte) { }, } + args.Accounts = &stateMock.AccountsStub{ + GetExistingAccountCalled: func(_ []byte) (vmcommon.AccountHandler, error) { + return &stateMock.UserAccountStub{ + Nonce: 42, + Balance: big.NewInt(1000000000000000000), + }, nil + }, + } txs, _ := NewTransactionPreprocessor(args) diff --git a/process/block/preprocess/validatorInfoPreProcessor.go b/process/block/preprocess/validatorInfoPreProcessor.go index ce4bdb2d8d4..e7586f500e7 100644 --- a/process/block/preprocess/validatorInfoPreProcessor.go +++ b/process/block/preprocess/validatorInfoPreProcessor.go @@ -97,10 +97,6 @@ func (vip *validatorInfoPreprocessor) RemoveTxsFromPools(body *block.Body) error return vip.removeTxsFromPools(body, vip.validatorsInfoPool, vip.isMiniBlockCorrect) } -// ForgetAllAccountNoncesInMempool does nothing -func (vip *validatorInfoPreprocessor) ForgetAllAccountNoncesInMempool() { -} - // RestoreBlockDataIntoPools restores the peer miniblocks to the pool func (vip *validatorInfoPreprocessor) RestoreBlockDataIntoPools( body *block.Body, diff --git a/process/block/shardblock_test.go b/process/block/shardblock_test.go index 39797f8db0c..d029b44e65b 100644 --- a/process/block/shardblock_test.go +++ b/process/block/shardblock_test.go @@ -3053,6 +3053,12 @@ func TestShardProcessor_CreateMiniBlocksShouldWorkWithIntraShardTxs(t *testing.T JournalLenCalled: func() int { return 0 }, + GetExistingAccountCalled: func(_ []byte) (vmcommon.AccountHandler, error) { + return &stateMock.UserAccountStub{ + Nonce: 45, + Balance: big.NewInt(1000000000000000000), + }, nil + }, } totalGasProvided := uint64(0) diff --git a/process/constants.go b/process/constants.go index 5837605695f..f1eda761498 100644 --- a/process/constants.go +++ b/process/constants.go @@ -2,6 +2,7 @@ package process import ( "fmt" + "time" ) // BlockHeaderState specifies which is the state of the block header received @@ -143,3 +144,6 @@ const TxCacheSelectionGasRequested = 10_000_000_000 // TxCacheSelectionMaxNumTxs defines the maximum number of transactions that should be selected from the cache. const TxCacheSelectionMaxNumTxs = 50000 + +// TxCacheSelectionLoopMaximumDuration defines the maximum duration for the loop that selects transactions from the cache. +const TxCacheSelectionLoopMaximumDuration = 250 * time.Millisecond diff --git a/process/coordinator/process.go b/process/coordinator/process.go index 5514b1fc1ae..8a50d9f0b21 100644 --- a/process/coordinator/process.go +++ b/process/coordinator/process.go @@ -423,16 +423,6 @@ func (tc *transactionCoordinator) RemoveTxsFromPool(body *block.Body) error { return errFound } -// ForgetAllAccountNoncesInMempool instructs the mempool to forget all account nonces -func (tc *transactionCoordinator) ForgetAllAccountNoncesInMempool() { - preproc := tc.getPreProcessor(block.TxBlock) - if check.IfNil(preproc) { - return - } - - preproc.ForgetAllAccountNoncesInMempool() -} - // ProcessBlockTransaction processes transactions and updates state tries func (tc *transactionCoordinator) ProcessBlockTransaction( header data.HeaderHandler, diff --git a/process/coordinator/process_test.go b/process/coordinator/process_test.go index 9e45b18bf08..85eeabf1008 100644 --- a/process/coordinator/process_test.go +++ b/process/coordinator/process_test.go @@ -32,6 +32,7 @@ import ( "github.com/multiversx/mx-chain-go/process/factory" "github.com/multiversx/mx-chain-go/process/factory/shard" "github.com/multiversx/mx-chain-go/process/mock" + "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/database" "github.com/multiversx/mx-chain-go/storage/storageunit" @@ -586,6 +587,7 @@ func createInterimProcessorContainer() process.IntermediateProcessorContainer { func createPreProcessorContainerWithDataPool( dataPool dataRetriever.PoolsHolder, feeHandler process.FeeHandler, + accounts state.AccountsAdapter, ) process.PreProcessorsContainer { totalGasProvided := uint64(0) @@ -596,7 +598,7 @@ func createPreProcessorContainerWithDataPool( &hashingMocks.HasherMock{}, dataPool, createMockPubkeyConverter(), - &stateMock.AccountsStub{}, + accounts, &testscommon.RequestHandlerStub{}, &testscommon.TxProcessorMock{ ProcessTransactionCalled: func(transaction *transaction.Transaction) (vmcommon.ReturnCode, error) { @@ -1247,7 +1249,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessTransactionsFromMeNoTime(t *t tdp := initDataPool(txHash) argsTransactionCoordinator := createMockTransactionCoordinatorArguments() argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock(), argsTransactionCoordinator.Accounts) tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -1266,7 +1268,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessTransactionsFromMeNoSpace(t * tdp := initDataPool(txHash) argsTransactionCoordinator := createMockTransactionCoordinatorArguments() argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock(), argsTransactionCoordinator.Accounts) argsTransactionCoordinator.GasHandler = &testscommon.GasHandlerStub{ TotalGasProvidedCalled: func() uint64 { return totalGasProvided @@ -1295,9 +1297,18 @@ func TestTransactionCoordinator_CreateMbsAndProcessTransactionsFromMe(t *testing } argsTransactionCoordinator := createMockTransactionCoordinatorArguments() + argsTransactionCoordinator.Accounts = &stateMock.AccountsStub{ + GetExistingAccountCalled: func(_ []byte) (vmcommon.AccountHandler, error) { + return &stateMock.UserAccountStub{ + Nonce: 42, + Balance: big.NewInt(1000000000000000000), + }, nil + }, + } argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(nrShards) argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock(), argsTransactionCoordinator.Accounts) + tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -1333,9 +1344,17 @@ func TestTransactionCoordinator_CreateMbsAndProcessTransactionsFromMeMultipleMin } argsTransactionCoordinator := createMockTransactionCoordinatorArguments() + argsTransactionCoordinator.Accounts = &stateMock.AccountsStub{ + GetExistingAccountCalled: func(_ []byte) (vmcommon.AccountHandler, error) { + return &stateMock.UserAccountStub{ + Nonce: 0, + Balance: big.NewInt(1000000000000000000), + }, nil + }, + } argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(nrShards) argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock(), argsTransactionCoordinator.Accounts) tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -1386,6 +1405,14 @@ func TestTransactionCoordinator_CreateMbsAndProcessTransactionsFromMeMultipleMin } argsTransactionCoordinator := createMockTransactionCoordinatorArguments() + argsTransactionCoordinator.Accounts = &stateMock.AccountsStub{ + GetExistingAccountCalled: func(_ []byte) (vmcommon.AccountHandler, error) { + return &stateMock.UserAccountStub{ + Nonce: 0, + Balance: big.NewInt(1000000000000000000), + }, nil + }, + } argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(nrShards) argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool( @@ -1403,7 +1430,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessTransactionsFromMeMultipleMin ComputeGasLimitCalled: func(tx data.TransactionWithFeeHandler) uint64 { return gasLimit / uint64(numMiniBlocks) }, - }) + }, argsTransactionCoordinator.Accounts) tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -1449,6 +1476,14 @@ func TestTransactionCoordinator_CompactAndExpandMiniblocksShouldWork(t *testing. } argsTransactionCoordinator := createMockTransactionCoordinatorArguments() + argsTransactionCoordinator.Accounts = &stateMock.AccountsStub{ + GetExistingAccountCalled: func(_ []byte) (vmcommon.AccountHandler, error) { + return &stateMock.UserAccountStub{ + Nonce: 0, + Balance: big.NewInt(1000000000000000000), + }, nil + }, + } argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(nrShards) argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool( @@ -1466,7 +1501,7 @@ func TestTransactionCoordinator_CompactAndExpandMiniblocksShouldWork(t *testing. ComputeGasLimitCalled: func(tx data.TransactionWithFeeHandler) uint64 { return 0 }, - }) + }, argsTransactionCoordinator.Accounts) tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -1513,9 +1548,17 @@ func TestTransactionCoordinator_GetAllCurrentUsedTxs(t *testing.T) { } argsTransactionCoordinator := createMockTransactionCoordinatorArguments() + argsTransactionCoordinator.Accounts = &stateMock.AccountsStub{ + GetExistingAccountCalled: func(_ []byte) (vmcommon.AccountHandler, error) { + return &stateMock.UserAccountStub{ + Nonce: 42, + Balance: big.NewInt(1000000000000000000), + }, nil + }, + } argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(nrShards) argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock(), argsTransactionCoordinator.Accounts) argsTransactionCoordinator.GasHandler = &testscommon.GasHandlerStub{ ComputeGasProvidedByTxCalled: func(txSndShId uint32, txRcvShId uint32, txHandler data.TransactionHandler) (uint64, uint64, error) { return 0, 0, nil @@ -1558,7 +1601,7 @@ func TestTransactionCoordinator_RequestBlockTransactionsNilBody(t *testing.T) { argsTransactionCoordinator := createMockTransactionCoordinatorArguments() argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(nrShards) argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock(), argsTransactionCoordinator.Accounts) tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -1580,7 +1623,7 @@ func TestTransactionCoordinator_RequestBlockTransactionsRequestOne(t *testing.T) argsTransactionCoordinator := createMockTransactionCoordinatorArguments() argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(nrShards) argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock(), argsTransactionCoordinator.Accounts) tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -1610,7 +1653,7 @@ func TestTransactionCoordinator_IsDataPreparedForProcessing(t *testing.T) { argsTransactionCoordinator := createMockTransactionCoordinatorArguments() argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(nrShards) argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock(), argsTransactionCoordinator.Accounts) tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -1630,7 +1673,7 @@ func TestTransactionCoordinator_SaveTxsToStorage(t *testing.T) { argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(3) argsTransactionCoordinator.Accounts = initAccountsMock() argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock(), argsTransactionCoordinator.Accounts) tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -1666,7 +1709,7 @@ func TestTransactionCoordinator_RestoreBlockDataFromStorage(t *testing.T) { argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(3) argsTransactionCoordinator.Accounts = initAccountsMock() argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock(), argsTransactionCoordinator.Accounts) tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -1704,7 +1747,7 @@ func TestTransactionCoordinator_RemoveBlockDataFromPool(t *testing.T) { argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(3) argsTransactionCoordinator.Accounts = initAccountsMock() argsTransactionCoordinator.MiniBlockPool = dataPool.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), argsTransactionCoordinator.Accounts) tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -1811,7 +1854,7 @@ func TestTransactionCoordinator_ProcessBlockTransaction(t *testing.T) { argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(3) argsTransactionCoordinator.Accounts = initAccountsMock() argsTransactionCoordinator.MiniBlockPool = dataPool.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), argsTransactionCoordinator.Accounts) tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) assert.NotNil(t, tc) @@ -2366,7 +2409,7 @@ func TestTransactionCoordinator_SaveTxsToStorageCallsSaveIntermediate(t *testing argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(3) argsTransactionCoordinator.Accounts = initAccountsMock() argsTransactionCoordinator.MiniBlockPool = tdp.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(tdp, FeeHandlerMock(), argsTransactionCoordinator.Accounts) argsTransactionCoordinator.InterProcessors = &mock.InterimProcessorContainerMock{ KeysCalled: func() []block.Type { return []block.Type{block.SmartContractResultBlock} @@ -2404,7 +2447,7 @@ func TestTransactionCoordinator_PreprocessorsHasToBeOrderedRewardsAreLast(t *tes argsTransactionCoordinator.ShardCoordinator = mock.NewMultiShardsCoordinatorMock(3) argsTransactionCoordinator.Accounts = initAccountsMock() argsTransactionCoordinator.MiniBlockPool = dataPool.MiniBlocks() - argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()) + argsTransactionCoordinator.PreProcessors = createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), argsTransactionCoordinator.Accounts) argsTransactionCoordinator.InterProcessors = createInterimProcessorContainer() tc, err := NewTransactionCoordinator(argsTransactionCoordinator) assert.Nil(t, err) @@ -2588,14 +2631,16 @@ func TestTransactionCoordinator_VerifyCreatedMiniBlocksShouldReturnWhenEpochIsNo t.Parallel() dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -2633,14 +2678,16 @@ func TestTransactionCoordinator_VerifyCreatedMiniBlocksShouldErrMaxGasLimitPerMi maxGasLimitPerBlock := uint64(1500000000) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -2699,14 +2746,16 @@ func TestTransactionCoordinator_VerifyCreatedMiniBlocksShouldErrMaxAccumulatedFe maxGasLimitPerBlock := uint64(1500000000) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -2776,14 +2825,16 @@ func TestTransactionCoordinator_VerifyCreatedMiniBlocksShouldErrMaxDeveloperFees maxGasLimitPerBlock := uint64(1500000000) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -2853,14 +2904,16 @@ func TestTransactionCoordinator_VerifyCreatedMiniBlocksShouldWork(t *testing.T) maxGasLimitPerBlock := uint64(1500000000) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -2929,14 +2982,16 @@ func TestTransactionCoordinator_GetAllTransactionsShouldWork(t *testing.T) { t.Parallel() dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3002,14 +3057,16 @@ func TestTransactionCoordinator_VerifyGasLimitShouldErrMaxGasLimitPerMiniBlockIn tx3GasLimit := uint64(300000001) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3095,14 +3152,16 @@ func TestTransactionCoordinator_VerifyGasLimitShouldWork(t *testing.T) { tx3GasLimit := uint64(300) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3184,14 +3243,16 @@ func TestTransactionCoordinator_CheckGasProvidedByMiniBlockInReceiverShardShould t.Parallel() dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3226,14 +3287,16 @@ func TestTransactionCoordinator_CheckGasProvidedByMiniBlockInReceiverShardShould tx1GasLimit := uint64(100) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3283,14 +3346,16 @@ func TestTransactionCoordinator_CheckGasProvidedByMiniBlockInReceiverShardShould tx2GasLimit := uint64(1) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3345,14 +3410,16 @@ func TestTransactionCoordinator_CheckGasProvidedByMiniBlockInReceiverShardShould tx3GasLimit := uint64(300000001) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3412,14 +3479,16 @@ func TestTransactionCoordinator_CheckGasProvidedByMiniBlockInReceiverShardShould tx3GasLimit := uint64(300) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3476,14 +3545,16 @@ func TestTransactionCoordinator_VerifyFeesShouldErrMissingTransaction(t *testing t.Parallel() dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3531,14 +3602,16 @@ func TestTransactionCoordinator_VerifyFeesShouldErrMaxAccumulatedFeesExceeded(t tx1GasLimit := uint64(100) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3600,14 +3673,16 @@ func TestTransactionCoordinator_VerifyFeesShouldErrMaxDeveloperFeesExceeded(t *t tx1GasLimit := uint64(100) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3670,14 +3745,16 @@ func TestTransactionCoordinator_VerifyFeesShouldErrMaxAccumulatedFeesExceededWhe enableEpochsHandlerStub := enableEpochsHandlerMock.NewEnableEpochsHandlerStub() dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3754,14 +3831,16 @@ func TestTransactionCoordinator_VerifyFeesShouldErrMaxDeveloperFeesExceededWhenS enableEpochsHandlerStub := enableEpochsHandlerMock.NewEnableEpochsHandlerStub() dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3838,14 +3917,16 @@ func TestTransactionCoordinator_VerifyFeesShouldWork(t *testing.T) { enableEpochsHandlerStub := enableEpochsHandlerMock.NewEnableEpochsHandlerStub() dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3925,14 +4006,16 @@ func TestTransactionCoordinator_GetMaxAccumulatedAndDeveloperFeesShouldErr(t *te t.Parallel() dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -3977,14 +4060,16 @@ func TestTransactionCoordinator_GetMaxAccumulatedAndDeveloperFeesShouldWork(t *t tx3GasLimit := uint64(300) dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &testscommon.GasHandlerStub{}, FeeHandler: &mock.FeeAccumulatorStub{}, @@ -4043,14 +4128,16 @@ func TestTransactionCoordinator_RevertIfNeededShouldWork(t *testing.T) { numTxsFeesReverted := 0 dataPool := initDataPool(txHash) + accounts := initAccountsMock() + txCoordinatorArgs := ArgTransactionCoordinator{ Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, ShardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - Accounts: initAccountsMock(), + Accounts: accounts, MiniBlockPool: dataPool.MiniBlocks(), RequestHandler: &testscommon.RequestHandlerStub{}, - PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock()), + PreProcessors: createPreProcessorContainerWithDataPool(dataPool, FeeHandlerMock(), accounts), InterProcessors: createInterimProcessorContainer(), GasHandler: &mock.GasHandlerMock{ RestoreGasSinceLastResetCalled: func(key []byte) { diff --git a/process/errors.go b/process/errors.go index 83e8095dcb3..4088162fd7e 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1059,9 +1059,6 @@ var ErrNilIsMaxBlockSizeReachedHandler = errors.New("nil handler for max block s // ErrNilTxMaxTotalCostHandler signals a nil transaction max total cost var ErrNilTxMaxTotalCostHandler = errors.New("nil transaction max total cost") -// ErrNilAccountTxsPerShard signals a nil mapping for account transactions to shard -var ErrNilAccountTxsPerShard = errors.New("nil account transactions per shard mapping") - // ErrScheduledRootHashDoesNotMatch signals that scheduled root hash does not match var ErrScheduledRootHashDoesNotMatch = errors.New("scheduled root hash does not match") diff --git a/process/interface.go b/process/interface.go index 80eeb2845ad..747103f26ca 100644 --- a/process/interface.go +++ b/process/interface.go @@ -156,7 +156,6 @@ type TransactionCoordinator interface { RestoreBlockDataFromStorage(body *block.Body) (int, error) RemoveBlockDataFromPool(body *block.Body) error RemoveTxsFromPool(body *block.Body) error - ForgetAllAccountNoncesInMempool() ProcessBlockTransaction(header data.HeaderHandler, body *block.Body, haveTime func() time.Duration) error @@ -233,7 +232,6 @@ type PreProcessor interface { RemoveBlockDataFromPools(body *block.Body, miniBlockPool storage.Cacher) error RemoveTxsFromPools(body *block.Body) error - ForgetAllAccountNoncesInMempool() RestoreBlockDataIntoPools(body *block.Body, miniBlockPool storage.Cacher) (int, error) SaveTxsToStorage(body *block.Body) error diff --git a/process/mock/preprocessorMock.go b/process/mock/preprocessorMock.go index 01676c474d2..f3f026abd57 100644 --- a/process/mock/preprocessorMock.go +++ b/process/mock/preprocessorMock.go @@ -15,7 +15,6 @@ type PreProcessorMock struct { IsDataPreparedCalled func(requestedTxs int, haveTime func() time.Duration) error RemoveBlockDataFromPoolsCalled func(body *block.Body, miniBlockPool storage.Cacher) error RemoveTxsFromPoolsCalled func(body *block.Body) error - ForgetAllAccountNoncesInMempoolCalled func() RestoreBlockDataIntoPoolsCalled func(body *block.Body, miniBlockPool storage.Cacher) (int, error) SaveTxsToStorageCalled func(body *block.Body) error ProcessBlockTransactionsCalled func(header data.HeaderHandler, body *block.Body, haveTime func() bool) error @@ -61,14 +60,6 @@ func (ppm *PreProcessorMock) RemoveTxsFromPools(body *block.Body) error { return ppm.RemoveTxsFromPoolsCalled(body) } -// ForgetAllAccountNoncesInMempool - -func (ppm *PreProcessorMock) ForgetAllAccountNoncesInMempool() { - if ppm.ForgetAllAccountNoncesInMempoolCalled == nil { - return - } - ppm.ForgetAllAccountNoncesInMempoolCalled() -} - // RestoreBlockDataIntoPools - func (ppm *PreProcessorMock) RestoreBlockDataIntoPools(body *block.Body, miniBlockPool storage.Cacher) (int, error) { if ppm.RestoreBlockDataIntoPoolsCalled == nil { diff --git a/state/accountsDB.go b/state/accountsDB.go index 4274e5138d6..707361ae68d 100644 --- a/state/accountsDB.go +++ b/state/accountsDB.go @@ -482,9 +482,7 @@ func (adb *AccountsDB) saveDataTrie(accountHandler baseAccountHandler) error { } func (adb *AccountsDB) saveAccountToTrie(accountHandler vmcommon.AccountHandler, mainTrie common.Trie) error { - log.Trace("accountsDB.saveAccountToTrie", - "address", hex.EncodeToString(accountHandler.AddressBytes()), - ) + log.Trace("accountsDB.saveAccountToTrie", "address", accountHandler.AddressBytes()) // pass the reference to marshaller, otherwise it will fail marshalling balance buff, err := adb.marshaller.Marshal(accountHandler) @@ -601,9 +599,7 @@ func (adb *AccountsDB) LoadAccount(address []byte) (vmcommon.AccountHandler, err return nil, fmt.Errorf("%w in LoadAccount", ErrNilAddress) } - log.Trace("accountsDB.LoadAccount", - "address", hex.EncodeToString(address), - ) + log.Trace("accountsDB.LoadAccount", "address", address) mainTrie := adb.getMainTrie() acnt, err := adb.getAccount(address, mainTrie) @@ -653,9 +649,7 @@ func (adb *AccountsDB) GetExistingAccount(address []byte) (vmcommon.AccountHandl return nil, fmt.Errorf("%w in GetExistingAccount", ErrNilAddress) } - log.Trace("accountsDB.GetExistingAccount", - "address", hex.EncodeToString(address), - ) + log.Trace("accountsDB.GetExistingAccount", "address", address) mainTrie := adb.getMainTrie() acnt, err := adb.getAccount(address, mainTrie) diff --git a/storage/txcache/txcache.go b/storage/txcache/txcache.go index 218a3749805..bf0bbae8419 100644 --- a/storage/txcache/txcache.go +++ b/storage/txcache/txcache.go @@ -2,14 +2,21 @@ package txcache import ( "github.com/multiversx/mx-chain-storage-go/txcache" + "github.com/multiversx/mx-chain-storage-go/types" ) // WrappedTransaction contains a transaction, its hash and extra information type WrappedTransaction = txcache.WrappedTransaction +// AccountState represents the state of an account (as seen by the mempool) +type AccountState = types.AccountState + // TxGasHandler handles a transaction gas and gas cost type TxGasHandler = txcache.TxGasHandler +// AccountStateProvider provides the state of an account (as seen by the mempool) +type AccountStateProvider = txcache.AccountStateProvider + // ForEachTransaction is an iterator callback type ForEachTransaction = txcache.ForEachTransaction diff --git a/storage/txcache/txcache_test.go b/storage/txcache/txcache_test.go index e1864c236a2..f113216ce92 100644 --- a/storage/txcache/txcache_test.go +++ b/storage/txcache/txcache_test.go @@ -27,7 +27,7 @@ func TestNewTxCache(t *testing.T) { cache, err := NewTxCache(cfg, nil) assert.Nil(t, cache) - assert.Equal(t, common.ErrNilTxGasHandler, err) + assert.ErrorContains(t, err, "nil tx gas handler") }) t.Run("should work", func(t *testing.T) { t.Parallel() diff --git a/testscommon/accountNonceProviderMock.go b/testscommon/accountNonceProviderMock.go deleted file mode 100644 index 11992accc75..00000000000 --- a/testscommon/accountNonceProviderMock.go +++ /dev/null @@ -1,48 +0,0 @@ -package testscommon - -import ( - "errors" - - "github.com/multiversx/mx-chain-core-go/core/check" - "github.com/multiversx/mx-chain-go/state" -) - -type accountNonceProviderMock struct { - accountsAdapter state.AccountsAdapter - - GetAccountNonceCalled func(address []byte) (uint64, error) -} - -// NewAccountNonceProviderMock - -func NewAccountNonceProviderMock() *accountNonceProviderMock { - return &accountNonceProviderMock{} -} - -// GetAccountNonce - -func (stub *accountNonceProviderMock) GetAccountNonce(address []byte) (uint64, error) { - if stub.GetAccountNonceCalled != nil { - return stub.GetAccountNonceCalled(address) - } - - if !check.IfNil(stub.accountsAdapter) { - account, err := stub.accountsAdapter.GetExistingAccount(address) - if err != nil { - return 0, err - } - - return account.GetNonce(), nil - } - - return 0, errors.New("both accountNonceProviderStub.GetAccountNonceCalled() and accountNonceProviderStub.accountsAdapter are nil") -} - -// SetAccountsAdapter - -func (stub *accountNonceProviderMock) SetAccountsAdapter(accountsAdapter state.AccountsAdapter) error { - stub.accountsAdapter = accountsAdapter - return nil -} - -// IsInterfaceNil - -func (stub *accountNonceProviderMock) IsInterfaceNil() bool { - return stub == nil -} diff --git a/testscommon/components/components.go b/testscommon/components/components.go index fc20169095d..01828396e90 100644 --- a/testscommon/components/components.go +++ b/testscommon/components/components.go @@ -227,7 +227,6 @@ func GetDataArgs(coreComponents factory.CoreComponentsHolder, shardCoordinator s CreateTrieEpochRootHashStorer: false, NodeProcessingMode: common.Normal, FlagsConfigs: config.ContextFlagsConfig{}, - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), } } @@ -405,7 +404,6 @@ func GetBootStrapFactoryArgs() bootstrapComp.BootstrapComponentsFactoryArgs { FlagsConfig: config.ContextFlagsConfig{ ForceStartFromNetwork: false, }, - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), } } diff --git a/testscommon/dataRetriever/poolFactory.go b/testscommon/dataRetriever/poolFactory.go index 5ef793b7070..b621c9245b9 100644 --- a/testscommon/dataRetriever/poolFactory.go +++ b/testscommon/dataRetriever/poolFactory.go @@ -15,7 +15,6 @@ import ( "github.com/multiversx/mx-chain-go/storage/cache" storageFactory "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/storageunit" - "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/txcachemocks" "github.com/multiversx/mx-chain-go/trie/factory" ) @@ -39,10 +38,9 @@ func CreateTxPool(numShards uint32, selfShard uint32) (dataRetriever.ShardedData SizeInBytesPerSender: 33_554_432, Shards: 16, }, - NumberOfShards: numShards, - SelfShardID: selfShard, - TxGasHandler: txcachemocks.NewTxGasHandlerMock(), - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), + NumberOfShards: numShards, + SelfShardID: selfShard, + TxGasHandler: txcachemocks.NewTxGasHandlerMock(), }, ) } diff --git a/testscommon/dataRetriever/poolsHolderMock.go b/testscommon/dataRetriever/poolsHolderMock.go index 93a8464524c..6167b1eac6b 100644 --- a/testscommon/dataRetriever/poolsHolderMock.go +++ b/testscommon/dataRetriever/poolsHolderMock.go @@ -14,7 +14,6 @@ import ( "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/cache" "github.com/multiversx/mx-chain-go/storage/storageunit" - "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/txcachemocks" ) @@ -50,9 +49,8 @@ func NewPoolsHolderMock() *PoolsHolderMock { SizeInBytesPerSender: 10000000, Shards: 16, }, - TxGasHandler: txcachemocks.NewTxGasHandlerMock(), - AccountNonceProvider: testscommon.NewAccountNonceProviderMock(), - NumberOfShards: 1, + TxGasHandler: txcachemocks.NewTxGasHandlerMock(), + NumberOfShards: 1, }, ) panicIfError("NewPoolsHolderMock", err) diff --git a/testscommon/shardedDataCacheNotifierMock.go b/testscommon/shardedDataCacheNotifierMock.go index 45003ef5e2e..d5af2000ab3 100644 --- a/testscommon/shardedDataCacheNotifierMock.go +++ b/testscommon/shardedDataCacheNotifierMock.go @@ -77,10 +77,6 @@ func (mock *ShardedDataCacheNotifierMock) RemoveSetOfDataFromPool(keys [][]byte, func (mock *ShardedDataCacheNotifierMock) ImmunizeSetOfDataAgainstEviction(_ [][]byte, _ string) { } -// ForgetAllAccountNoncesInMempool - -func (mock *ShardedDataCacheNotifierMock) ForgetAllAccountNoncesInMempool() { -} - // RemoveDataFromAllShards - func (mock *ShardedDataCacheNotifierMock) RemoveDataFromAllShards(key []byte) { mock.mutCaches.RLock() diff --git a/testscommon/shardedDataStub.go b/testscommon/shardedDataStub.go index 4b795591008..2a082afe96f 100644 --- a/testscommon/shardedDataStub.go +++ b/testscommon/shardedDataStub.go @@ -73,10 +73,6 @@ func (sd *ShardedDataStub) RemoveDataFromAllShards(key []byte) { } } -// ForgetAllAccountNoncesInMempool - -func (sd *ShardedDataStub) ForgetAllAccountNoncesInMempool() { -} - // MergeShardStores - func (sd *ShardedDataStub) MergeShardStores(sourceCacheID, destCacheID string) { if sd.MergeShardStoresCalled != nil { diff --git a/testscommon/transactionCoordinatorMock.go b/testscommon/transactionCoordinatorMock.go index 9a0b82c1b97..a1889b0b753 100644 --- a/testscommon/transactionCoordinatorMock.go +++ b/testscommon/transactionCoordinatorMock.go @@ -20,7 +20,6 @@ type TransactionCoordinatorMock struct { RestoreBlockDataFromStorageCalled func(body *block.Body) (int, error) RemoveBlockDataFromPoolCalled func(body *block.Body) error RemoveTxsFromPoolCalled func(body *block.Body) error - ForgetAllAccountNoncesInMempoolCalled func() ProcessBlockTransactionCalled func(header data.HeaderHandler, body *block.Body, haveTime func() time.Duration) error CreateBlockStartedCalled func() CreateMbsAndProcessCrossShardTransactionsDstMeCalled func(header data.HeaderHandler, processedMiniBlocksInfo map[string]*processedMb.ProcessedMiniBlockInfo, haveTime func() bool, haveAdditionalTime func() bool, scheduledMode bool) (block.MiniBlockSlice, uint32, bool, error) @@ -129,15 +128,6 @@ func (tcm *TransactionCoordinatorMock) RemoveTxsFromPool(body *block.Body) error return tcm.RemoveTxsFromPoolCalled(body) } -// ForgetAllAccountNoncesInMempool - -func (tcm *TransactionCoordinatorMock) ForgetAllAccountNoncesInMempool() { - if tcm.ForgetAllAccountNoncesInMempoolCalled == nil { - return - } - - tcm.ForgetAllAccountNoncesInMempoolCalled() -} - // ProcessBlockTransaction - func (tcm *TransactionCoordinatorMock) ProcessBlockTransaction(header data.HeaderHandler, body *block.Body, haveTime func() time.Duration) error { if tcm.ProcessBlockTransactionCalled == nil { diff --git a/testscommon/txcachemocks/txCacheMock.go b/testscommon/txcachemocks/txCacheMock.go index d64ad967569..c34db2d53b0 100644 --- a/testscommon/txcachemocks/txCacheMock.go +++ b/testscommon/txcachemocks/txCacheMock.go @@ -20,8 +20,6 @@ type TxCacheMock struct { CloseCalled func() error AddTxCalled func(tx *txcache.WrappedTransaction) (ok bool, added bool) - NotifyAccountNonceCalled func(accountKey []byte, nonce uint64) - ForgetAllAccountNoncesCalled func() GetByTxHashCalled func(txHash []byte) (*txcache.WrappedTransaction, bool) RemoveTxByHashCalled func(txHash []byte) bool ImmunizeTxsAgainstEvictionCalled func(keys [][]byte) @@ -159,20 +157,6 @@ func (cache *TxCacheMock) AddTx(tx *txcache.WrappedTransaction) (ok bool, added return false, false } -// NotifyAccountNonce - -func (cache *TxCacheMock) NotifyAccountNonce(accountKey []byte, nonce uint64) { - if cache.NotifyAccountNonceCalled != nil { - cache.NotifyAccountNonceCalled(accountKey, nonce) - } -} - -// ForgetAllAccountNonces - -func (cache *TxCacheMock) ForgetAllAccountNonces() { - if cache.ForgetAllAccountNoncesCalled != nil { - cache.ForgetAllAccountNoncesCalled() - } -} - // GetByTxHash - func (cache *TxCacheMock) GetByTxHash(txHash []byte) (*txcache.WrappedTransaction, bool) { if cache.GetByTxHashCalled != nil { diff --git a/trie/patriciaMerkleTrie.go b/trie/patriciaMerkleTrie.go index 70df549011f..da9eb87a65f 100644 --- a/trie/patriciaMerkleTrie.go +++ b/trie/patriciaMerkleTrie.go @@ -11,13 +11,14 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/trie/keyBuilder" "github.com/multiversx/mx-chain-go/trie/statistics" - logger "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) var log = logger.GetOrCreate("trie") @@ -118,10 +119,7 @@ func (tr *patriciaMerkleTrie) Update(key, value []byte) error { tr.mutOperation.Lock() defer tr.mutOperation.Unlock() - log.Trace("update trie", - "key", hex.EncodeToString(key), - "val", hex.EncodeToString(value), - ) + log.Trace("update trie", "key", key, "val", value) return tr.update(key, value, core.NotSpecified) } @@ -131,11 +129,7 @@ func (tr *patriciaMerkleTrie) UpdateWithVersion(key []byte, value []byte, versio tr.mutOperation.Lock() defer tr.mutOperation.Unlock() - log.Trace("update trie with version", - "key", hex.EncodeToString(key), - "val", hex.EncodeToString(value), - "version", version, - ) + log.Trace("update trie with version", "key", key, "val", value, "version", version) return tr.update(key, value, version) } diff --git a/trie/patriciaMerkleTrie_test.go b/trie/patriciaMerkleTrie_test.go index 4612b8ee331..8a02a8edcd9 100644 --- a/trie/patriciaMerkleTrie_test.go +++ b/trie/patriciaMerkleTrie_test.go @@ -17,6 +17,10 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/hashing/keccak" "github.com/multiversx/mx-chain-core-go/marshal" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" "github.com/multiversx/mx-chain-go/common/holders" @@ -28,9 +32,6 @@ import ( "github.com/multiversx/mx-chain-go/trie" "github.com/multiversx/mx-chain-go/trie/keyBuilder" "github.com/multiversx/mx-chain-go/trie/mock" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var emptyTrieHash = make([]byte, 32) @@ -1708,3 +1709,28 @@ func BenchmarkPatriciaMerkleTrie_RootHashAfterChanging30000NodesInBatchesOf200(b } } } + +func BenchmarkPatriciaMerkleTrie_Update(b *testing.B) { + tr := emptyTrie() + hsh := keccak.NewKeccak() + + nrValuesInTrie := 2000000 + values := make([][]byte, nrValuesInTrie) + + for i := 0; i < nrValuesInTrie; i++ { + key := hsh.Compute(strconv.Itoa(i)) + value := append(key, []byte(strconv.Itoa(i))...) + + _ = tr.Update(key, value) + values[i] = key + } + _ = tr.Commit() + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + for j := 0; j < nrValuesInTrie; j++ { + _ = tr.Update(values[j], values[j]) + } + } +} diff --git a/update/mock/transactionCoordinatorMock.go b/update/mock/transactionCoordinatorMock.go index aac3f022c2a..c0bb061a713 100644 --- a/update/mock/transactionCoordinatorMock.go +++ b/update/mock/transactionCoordinatorMock.go @@ -20,7 +20,6 @@ type TransactionCoordinatorMock struct { RestoreBlockDataFromStorageCalled func(body *block.Body) (int, error) RemoveBlockDataFromPoolCalled func(body *block.Body) error RemoveTxsFromPoolCalled func(body *block.Body) error - ForgetAllAccountNoncesInMempoolCalled func() ProcessBlockTransactionCalled func(header data.HeaderHandler, body *block.Body, haveTime func() time.Duration) error CreateBlockStartedCalled func() CreateMbsAndProcessCrossShardTransactionsDstMeCalled func(header data.HeaderHandler, processedMiniBlocksInfo map[string]*processedMb.ProcessedMiniBlockInfo, haveTime func() bool, haveAdditionalTime func() bool, scheduledMode bool) (block.MiniBlockSlice, uint32, bool, error) @@ -118,15 +117,6 @@ func (tcm *TransactionCoordinatorMock) RemoveTxsFromPool(body *block.Body) error return tcm.RemoveTxsFromPoolCalled(body) } -// ForgetAllAccountNoncesInMempool - -func (tcm *TransactionCoordinatorMock) ForgetAllAccountNoncesInMempool() { - if tcm.ForgetAllAccountNoncesInMempoolCalled == nil { - return - } - - tcm.ForgetAllAccountNoncesInMempoolCalled() -} - // ProcessBlockTransaction - func (tcm *TransactionCoordinatorMock) ProcessBlockTransaction(header data.HeaderHandler, body *block.Body, haveTime func() time.Duration) error { if tcm.ProcessBlockTransactionCalled == nil {