From 6841919d9c6a18ae5c9dcfad70568215472324a6 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 26 Jul 2024 18:21:34 +0300 Subject: [PATCH 01/39] calculate hash only on log trace level set. --- trie/patriciaMerkleTrie.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/trie/patriciaMerkleTrie.go b/trie/patriciaMerkleTrie.go index 0f875999bd1..a97381b7f98 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,12 @@ 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), - ) + if log.GetLevel() == logger.LogTrace { + log.Trace("update trie", + "key", hex.EncodeToString(key), + "val", hex.EncodeToString(value), + ) + } return tr.update(key, value, core.NotSpecified) } @@ -131,11 +134,13 @@ 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, - ) + if log.GetLevel() == logger.LogTrace { + log.Trace("update trie with version", + "key", hex.EncodeToString(key), + "val", hex.EncodeToString(value), + "version", version, + ) + } return tr.update(key, value, version) } From 85d93ac7def79765b10e6b7c756e32242ac6d638 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 29 Jul 2024 14:16:23 +0300 Subject: [PATCH 02/39] add non-memory thrasher test. --- trie/patriciaMerkleTrie_test.go | 36 ++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/trie/patriciaMerkleTrie_test.go b/trie/patriciaMerkleTrie_test.go index 63278d43a1f..6d1888a46e4 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) @@ -1726,3 +1727,32 @@ func BenchmarkPatriciaMerkleTrie_RootHashAfterChanging30000NodesInBatchesOf200(b } } } + +func TestTrieUpdateTimer(t *testing.T) { + t.Skip() + tr := emptyTrie() + hsh := keccak.NewKeccak() + + nrValuesInTrie := 500000 + values := make([][]byte, nrValuesInTrie) + nrOfValuesToModify := 30000 + + 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() + + before := time.Now() + for i := 0; i < 10; i++ { + for j := 0; j < nrOfValuesToModify; j++ { + _ = tr.Update(values[j], values[j]) + } + } + + now := time.Since(before) + fmt.Println(now) +} From af01f4a9e49a2630c1bd2fe5332b827de5026906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Fri, 6 Sep 2024 15:01:57 +0300 Subject: [PATCH 03/39] Convert artificial test into a benchmark. --- trie/patriciaMerkleTrie_test.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/trie/patriciaMerkleTrie_test.go b/trie/patriciaMerkleTrie_test.go index cfc66c27fd8..8a02a8edcd9 100644 --- a/trie/patriciaMerkleTrie_test.go +++ b/trie/patriciaMerkleTrie_test.go @@ -1710,14 +1710,12 @@ func BenchmarkPatriciaMerkleTrie_RootHashAfterChanging30000NodesInBatchesOf200(b } } -func TestTrieUpdateTimer(t *testing.T) { - t.Skip() +func BenchmarkPatriciaMerkleTrie_Update(b *testing.B) { tr := emptyTrie() hsh := keccak.NewKeccak() - nrValuesInTrie := 500000 + nrValuesInTrie := 2000000 values := make([][]byte, nrValuesInTrie) - nrOfValuesToModify := 30000 for i := 0; i < nrValuesInTrie; i++ { key := hsh.Compute(strconv.Itoa(i)) @@ -1728,13 +1726,11 @@ func TestTrieUpdateTimer(t *testing.T) { } _ = tr.Commit() - before := time.Now() - for i := 0; i < 10; i++ { - for j := 0; j < nrOfValuesToModify; j++ { + b.ResetTimer() + + for i := 0; i < b.N; i++ { + for j := 0; j < nrValuesInTrie; j++ { _ = tr.Update(values[j], values[j]) } } - - now := time.Since(before) - fmt.Println(now) } From febe899abb2def6e2aef33c604d66790cf9377ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 13 Nov 2024 23:12:25 +0200 Subject: [PATCH 04/39] No more ForgetAllAccountNonces(). --- dataRetriever/interface.go | 1 - dataRetriever/shardedData/shardedData.go | 4 --- dataRetriever/txpool/interface.go | 1 - dataRetriever/txpool/shardedTxPool.go | 6 ----- dataRetriever/txpool/shardedTxPool_test.go | 27 ------------------- factory/disabled/txCoordinator.go | 4 --- .../mock/transactionCoordinatorMock.go | 10 ------- process/block/baseProcess.go | 5 ---- .../block/preprocess/rewardTxPreProcessor.go | 4 --- .../block/preprocess/smartContractResults.go | 4 --- process/block/preprocess/transactions.go | 5 ---- .../preprocess/validatorInfoPreProcessor.go | 4 --- process/coordinator/process.go | 10 ------- process/interface.go | 2 -- process/mock/preprocessorMock.go | 9 ------- testscommon/shardedDataCacheNotifierMock.go | 4 --- testscommon/shardedDataStub.go | 4 --- testscommon/transactionCoordinatorMock.go | 10 ------- testscommon/txcachemocks/txCacheMock.go | 8 ------ update/mock/transactionCoordinatorMock.go | 10 ------- 20 files changed, 132 deletions(-) diff --git a/dataRetriever/interface.go b/dataRetriever/interface.go index 9231dad729c..721b7b8fa20 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) diff --git a/dataRetriever/shardedData/shardedData.go b/dataRetriever/shardedData/shardedData.go index 2dc0fa6f5b9..acb0c3d9bec 100644 --- a/dataRetriever/shardedData/shardedData.go +++ b/dataRetriever/shardedData/shardedData.go @@ -178,10 +178,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/interface.go b/dataRetriever/txpool/interface.go index 1392c755034..9f9c673828f 100644 --- a/dataRetriever/txpool/interface.go +++ b/dataRetriever/txpool/interface.go @@ -10,7 +10,6 @@ type txCache interface { 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/shardedTxPool.go b/dataRetriever/txpool/shardedTxPool.go index 54697c30876..3d68fbc736b 100644 --- a/dataRetriever/txpool/shardedTxPool.go +++ b/dataRetriever/txpool/shardedTxPool.go @@ -287,12 +287,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) diff --git a/dataRetriever/txpool/shardedTxPool_test.go b/dataRetriever/txpool/shardedTxPool_test.go index a8ed74a980d..ac3ede603b9 100644 --- a/dataRetriever/txpool/shardedTxPool_test.go +++ b/dataRetriever/txpool/shardedTxPool_test.go @@ -253,33 +253,6 @@ func TestShardedTxPool_AddData_CallsNotifyAccountNonce(t *testing.T) { 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) 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/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/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/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/transactions.go b/process/block/preprocess/transactions.go index d484a67bd28..0f6e63639d9 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -241,11 +241,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, 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/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/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/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..a5c9705fcbd 100644 --- a/testscommon/txcachemocks/txCacheMock.go +++ b/testscommon/txcachemocks/txCacheMock.go @@ -21,7 +21,6 @@ type TxCacheMock struct { 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) @@ -166,13 +165,6 @@ func (cache *TxCacheMock) NotifyAccountNonce(accountKey []byte, nonce uint64) { } } -// 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/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 { From 535d51bf8f1519c3e13a70dcd4894de25d3ec9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 13 Nov 2024 23:18:36 +0200 Subject: [PATCH 05/39] Remove NotifyAccountNonce(). --- dataRetriever/txpool/interface.go | 1 - dataRetriever/txpool/shardedTxPool.go | 22 ++-------- dataRetriever/txpool/shardedTxPool_test.go | 43 ------------------- process/block/preprocess/interfaces.go | 2 - .../preprocess/sortedTransactionsProvider.go | 9 ---- process/block/preprocess/transactions.go | 41 ------------------ process/block/preprocess/transactionsV2.go | 4 -- testscommon/txcachemocks/txCacheMock.go | 8 ---- 8 files changed, 3 insertions(+), 127 deletions(-) diff --git a/dataRetriever/txpool/interface.go b/dataRetriever/txpool/interface.go index 9f9c673828f..6579659d692 100644 --- a/dataRetriever/txpool/interface.go +++ b/dataRetriever/txpool/interface.go @@ -9,7 +9,6 @@ type txCache interface { storage.Cacher AddTx(tx *txcache.WrappedTransaction) (ok bool, added bool) - NotifyAccountNonce(accountKey []byte, nonce uint64) GetByTxHash(txHash []byte) (*txcache.WrappedTransaction, bool) RemoveTxByHash(txHash []byte) bool ImmunizeTxsAgainstEviction(keys [][]byte) diff --git a/dataRetriever/txpool/shardedTxPool.go b/dataRetriever/txpool/shardedTxPool.go index 3d68fbc736b..caa0bfe5a95 100644 --- a/dataRetriever/txpool/shardedTxPool.go +++ b/dataRetriever/txpool/shardedTxPool.go @@ -27,7 +27,6 @@ type shardedTxPool struct { configPrototypeDestinationMe txcache.ConfigDestinationMe configPrototypeSourceMe txcache.ConfigSourceMe selfShardID uint32 - selfShardIDAsString string txGasHandler txcache.TxGasHandler accountNonceProvider dataRetriever.AccountNonceProvider } @@ -79,7 +78,6 @@ func NewShardedTxPool(args ArgShardedTxPool) (*shardedTxPool, error) { configPrototypeDestinationMe: configPrototypeDestinationMe, configPrototypeSourceMe: configPrototypeSourceMe, selfShardID: args.SelfShardID, - selfShardIDAsString: core.GetShardIDString(args.SelfShardID), txGasHandler: args.TxGasHandler, accountNonceProvider: args.AccountNonceProvider, } @@ -185,12 +183,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 +195,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{}) { @@ -296,7 +280,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 ac3ede603b9..41d796c0caa 100644 --- a/dataRetriever/txpool/shardedTxPool_test.go +++ b/dataRetriever/txpool/shardedTxPool_test.go @@ -13,9 +13,7 @@ import ( "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" ) @@ -212,47 +210,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 Test_SearchFirstData(t *testing.T) { poolAsInterface, _ := newTxPoolToTest() pool := poolAsInterface.(*shardedTxPool) diff --git a/process/block/preprocess/interfaces.go b/process/block/preprocess/interfaces.go index 352c9aa09f7..32cca6c30b3 100644 --- a/process/block/preprocess/interfaces.go +++ b/process/block/preprocess/interfaces.go @@ -9,14 +9,12 @@ import ( // SortedTransactionsProvider defines the public API of the transactions cache type SortedTransactionsProvider interface { GetSortedTransactions() []*txcache.WrappedTransaction - NotifyAccountNonce(accountKey []byte, nonce uint64) 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) IsInterfaceNil() bool } diff --git a/process/block/preprocess/sortedTransactionsProvider.go b/process/block/preprocess/sortedTransactionsProvider.go index 6da2e526467..7d14c3ba46e 100644 --- a/process/block/preprocess/sortedTransactionsProvider.go +++ b/process/block/preprocess/sortedTransactionsProvider.go @@ -37,11 +37,6 @@ func (adapter *adapterTxCacheToSortedTransactionsProvider) GetSortedTransactions 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 @@ -56,10 +51,6 @@ func (adapter *disabledSortedTransactionsProvider) GetSortedTransactions() []*tx 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 0f6e63639d9..c033a7444de 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -723,10 +723,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 @@ -920,35 +916,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 { @@ -1152,10 +1119,6 @@ func (txs *transactions) createAndProcessScheduledMiniBlocksFromMeAsProposer( return make(block.MiniBlockSlice, 0), nil } - defer func() { - go txs.notifyTransactionProviderIfNeeded() - }() - startTime := time.Now() scheduledMiniBlocks, err := txs.createScheduledMiniBlocks( haveTime, @@ -1209,10 +1172,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) diff --git a/process/block/preprocess/transactionsV2.go b/process/block/preprocess/transactionsV2.go index 6391987983a..dc688cf9a3b 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() { diff --git a/testscommon/txcachemocks/txCacheMock.go b/testscommon/txcachemocks/txCacheMock.go index a5c9705fcbd..c34db2d53b0 100644 --- a/testscommon/txcachemocks/txCacheMock.go +++ b/testscommon/txcachemocks/txCacheMock.go @@ -20,7 +20,6 @@ type TxCacheMock struct { CloseCalled func() error AddTxCalled func(tx *txcache.WrappedTransaction) (ok bool, added bool) - NotifyAccountNonceCalled func(accountKey []byte, nonce uint64) GetByTxHashCalled func(txHash []byte) (*txcache.WrappedTransaction, bool) RemoveTxByHashCalled func(txHash []byte) bool ImmunizeTxsAgainstEvictionCalled func(keys [][]byte) @@ -158,13 +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) - } -} - // GetByTxHash - func (cache *TxCacheMock) GetByTxHash(txHash []byte) (*txcache.WrappedTransaction, bool) { if cache.GetByTxHashCalled != nil { From bca90d936f1ecc49c6513843a1efc3ea3c1278a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 13 Nov 2024 23:22:39 +0200 Subject: [PATCH 06/39] Properly invoke NewTxCache(). --- dataRetriever/txpool/shardedTxPool.go | 2 +- storage/txcache/txcache.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dataRetriever/txpool/shardedTxPool.go b/dataRetriever/txpool/shardedTxPool.go index caa0bfe5a95..fd578ffb2a9 100644 --- a/dataRetriever/txpool/shardedTxPool.go +++ b/dataRetriever/txpool/shardedTxPool.go @@ -136,7 +136,7 @@ func (txPool *shardedTxPool) createTxCache(cacheID string) txCache { if isForSenderMe { config := txPool.configPrototypeSourceMe config.Name = cacheID - cache, err := txcache.NewTxCache(config, txPool.txGasHandler) + cache, err := txcache.NewTxCache(config, txPool.txGasHandler, txPool.accountNonceProvider) if err != nil { log.Error("shardedTxPool.createTxCache()", "err", err) return txcache.NewDisabledCache() diff --git a/storage/txcache/txcache.go b/storage/txcache/txcache.go index 218a3749805..a721d1887af 100644 --- a/storage/txcache/txcache.go +++ b/storage/txcache/txcache.go @@ -10,6 +10,9 @@ type WrappedTransaction = txcache.WrappedTransaction // TxGasHandler handles a transaction gas and gas cost type TxGasHandler = txcache.TxGasHandler +// AccountNonceProvider provides the nonce for an account +type AccountNonceProvider = txcache.AccountNonceProvider + // ForEachTransaction is an iterator callback type ForEachTransaction = txcache.ForEachTransaction @@ -29,8 +32,8 @@ type DisabledCache = txcache.DisabledCache type CrossTxCache = txcache.CrossTxCache // NewTxCache creates a new transaction cache -func NewTxCache(config ConfigSourceMe, txGasHandler TxGasHandler) (*TxCache, error) { - return txcache.NewTxCache(config, txGasHandler) +func NewTxCache(config ConfigSourceMe, txGasHandler TxGasHandler, accountNonceProvider AccountNonceProvider) (*TxCache, error) { + return txcache.NewTxCache(config, txGasHandler, accountNonceProvider) } // NewDisabledCache creates a new disabled cache From 278acf947fab3411bb1272bf3ac5453175f8deb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 14 Nov 2024 00:56:28 +0200 Subject: [PATCH 07/39] Reference new storage-go. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1d905051c15..56bc3f6bb26 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-0.20241113075709-8cd2eb02208e + github.com/multiversx/mx-chain-storage-go v1.0.17-0.20241113225050-4ca46fd08e11 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 27190977e42..1d120ea5644 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-0.20241113075709-8cd2eb02208e h1:kOII5SDG/avdfof5jW5gTpZnr6gZaNQpZlEWnaIKyC4= -github.com/multiversx/mx-chain-storage-go v1.0.17-0.20241113075709-8cd2eb02208e/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= +github.com/multiversx/mx-chain-storage-go v1.0.17-0.20241113225050-4ca46fd08e11 h1:vZtoj8Fdz999JgRYoeVMK7B/vegwo6Sye4Uj09kNVIQ= +github.com/multiversx/mx-chain-storage-go v1.0.17-0.20241113225050-4ca46fd08e11/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= 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= From f533a2b5d023b916c0ce9666b212f29410c1e3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 14 Nov 2024 09:45:39 +0200 Subject: [PATCH 08/39] Fix long test. --- dataRetriever/txpool/memorytests/memory_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataRetriever/txpool/memorytests/memory_test.go b/dataRetriever/txpool/memorytests/memory_test.go index 340ebf1c344..6aa5c863afc 100644 --- a/dataRetriever/txpool/memorytests/memory_test.go +++ b/dataRetriever/txpool/memorytests/memory_test.go @@ -36,7 +36,7 @@ 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(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, 16})) journals = append(journals, runScenario(t, newScenario(10, 10000, 100, "0"), memoryAssertion{36, 52}, memoryAssertion{16, 24})) journals = append(journals, runScenario(t, newScenario(100000, 1, 1024, "0"), memoryAssertion{120, 138}, memoryAssertion{32, 60})) From 4b8fb0a9f1302eb4301c4e4b265a92738cd3b8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 14 Nov 2024 14:45:07 +0200 Subject: [PATCH 09/39] Newer storage-go. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 56bc3f6bb26..3418459ffa0 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-0.20241113225050-4ca46fd08e11 + github.com/multiversx/mx-chain-storage-go v1.0.17-0.20241114122618-0f01e5c5f3c8 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 1d120ea5644..7f1e3b62e9a 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-0.20241113225050-4ca46fd08e11 h1:vZtoj8Fdz999JgRYoeVMK7B/vegwo6Sye4Uj09kNVIQ= -github.com/multiversx/mx-chain-storage-go v1.0.17-0.20241113225050-4ca46fd08e11/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= +github.com/multiversx/mx-chain-storage-go v1.0.17-0.20241114122618-0f01e5c5f3c8 h1:osiGPWXHTo1l/VzqFmIFudp3rWBL/V68N/4RfhKCiNU= +github.com/multiversx/mx-chain-storage-go v1.0.17-0.20241114122618-0f01e5c5f3c8/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= 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= From 0cb7187f64765bbb70d64f352858b1a3c33feb5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 14 Nov 2024 16:17:38 +0200 Subject: [PATCH 10/39] Sketch CS test: TestMempoolWithChainSimulator_Eviction. --- .../chainSimulator/mempool/mempool_test.go | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 integrationTests/chainSimulator/mempool/mempool_test.go diff --git a/integrationTests/chainSimulator/mempool/mempool_test.go b/integrationTests/chainSimulator/mempool/mempool_test.go new file mode 100644 index 00000000000..b08a99682f5 --- /dev/null +++ b/integrationTests/chainSimulator/mempool/mempool_test.go @@ -0,0 +1,152 @@ +package relayedTx + +import ( + "math/big" + "testing" + "time" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" + testsChainSimulator "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" + "github.com/multiversx/mx-chain-go/node/chainSimulator" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + "github.com/multiversx/mx-chain-go/storage" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/stretchr/testify/require" +) + +var ( + oneEGLD = big.NewInt(1000000000000000000) + log = logger.GetOrCreate("testing") +) + +func TestMempoolWithChainSimulator_Eviction(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + cs := startChainSimulator(t, func(cfg *config.Configs) {}) + node := cs.GetNodeHandler(0) + mempool := node.GetDataComponents().Datapool().Transactions() + + defer cs.Close() + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + + numSenders := 10000 + senders := make([]dtos.WalletAddress, numSenders) + sendersNonces := make([]uint64, numSenders) + + for i := 0; i < numSenders; i++ { + sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + senders[i] = sender + } + + receiver, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) + require.NoError(t, err) + + err = cs.GenerateBlocks(1) + require.Nil(t, err) + + numTransactionsPerSender := 30 + transactions := make([]*transaction.Transaction, 0, numSenders*numTransactionsPerSender) + + for i := 0; i < numSenders; i++ { + for j := 0; j < numTransactionsPerSender; j++ { + tx := &transaction.Transaction{ + Nonce: sendersNonces[i], + Value: oneEGLD, + SndAddr: senders[i].Bytes, + RcvAddr: receiver.Bytes, + Data: []byte{}, + GasLimit: 50000, + GasPrice: 1_000_000_000, + ChainID: []byte(configs.ChainID), + Version: 2, + Signature: []byte("signature"), + } + + sendersNonces[i]++ + transactions = append(transactions, tx) + } + } + + numSent, err := node.GetFacadeHandler().SendBulkTransactions(transactions) + require.NoError(t, err) + require.Equal(t, 300000, int(numSent)) + + time.Sleep(500 * time.Millisecond) + require.Equal(t, 300000, int(mempool.GetCounts().GetTotal())) + + // Send one more transaction (fill up the mempool) + node.GetFacadeHandler().SendBulkTransactions([]*transaction.Transaction{ + { + Nonce: 42, + Value: oneEGLD, + SndAddr: senders[7].Bytes, + RcvAddr: receiver.Bytes, + Data: []byte{}, + GasLimit: 50000, + GasPrice: 1_000_000_000, + ChainID: []byte(configs.ChainID), + Version: 2, + Signature: []byte("signature"), + }, + }) + + time.Sleep(42 * time.Millisecond) + require.Equal(t, 300001, int(mempool.GetCounts().GetTotal())) + + // Send one more transaction to trigger eviction + node.GetFacadeHandler().SendBulkTransactions([]*transaction.Transaction{ + { + Nonce: 42, + Value: oneEGLD, + SndAddr: senders[7].Bytes, + RcvAddr: receiver.Bytes, + Data: []byte{}, + GasLimit: 50000, + GasPrice: 1_000_000_000, + ChainID: []byte(configs.ChainID), + Version: 2, + Signature: []byte("signature"), + }, + }) + + time.Sleep(500 * time.Millisecond) + require.Equal(t, 300000+1+1-int(storage.TxPoolSourceMeNumItemsToPreemptivelyEvict), int(mempool.GetCounts().GetTotal())) +} + +func startChainSimulator(t *testing.T, alterConfigsFunction func(cfg *config.Configs), +) testsChainSimulator.ChainSimulator { + simulator, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: "../../../cmd/node/config/", + NumOfShards: 1, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: uint64(4000), + RoundsPerEpoch: core.OptionalUint64{ + HasValue: true, + Value: 10, + }, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: alterConfigsFunction, + }) + require.NoError(t, err) + require.NotNil(t, simulator) + + err = simulator.GenerateBlocksUntilEpochIsReached(1) + require.NoError(t, err) + + return simulator +} From c4f2db5b2d2084d47a84c5c51adfadcfa92bb411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 14 Nov 2024 19:27:47 +0200 Subject: [PATCH 11/39] Optimize GetExistingAccount(). Only encode address if log level is TRACE. --- state/accountsDB.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/state/accountsDB.go b/state/accountsDB.go index 4274e5138d6..2816c92ee5f 100644 --- a/state/accountsDB.go +++ b/state/accountsDB.go @@ -653,9 +653,9 @@ func (adb *AccountsDB) GetExistingAccount(address []byte) (vmcommon.AccountHandl return nil, fmt.Errorf("%w in GetExistingAccount", ErrNilAddress) } - log.Trace("accountsDB.GetExistingAccount", - "address", hex.EncodeToString(address), - ) + if log.GetLevel() == logger.LogTrace { + log.Trace("accountsDB.GetExistingAccount", "address", hex.EncodeToString(address)) + } mainTrie := adb.getMainTrie() acnt, err := adb.getAccount(address, mainTrie) From 26ddc026f2ae61c31aef8babb5c4e70fa431f3a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Fri, 15 Nov 2024 15:30:57 +0200 Subject: [PATCH 12/39] Pass account nonce provider (backed by the accounts adapter) to SelectTransactions(). --- dataRetriever/errors.go | 6 - dataRetriever/factory/dataPoolFactory.go | 20 ++-- dataRetriever/factory/dataPoolFactory_test.go | 17 +-- dataRetriever/txpool/argShardedTxPool.go | 12 +- .../txpool/memorytests/memory_test.go | 10 +- dataRetriever/txpool/shardedTxPool.go | 4 +- dataRetriever/txpool/shardedTxPool_test.go | 40 ++----- epochStart/bootstrap/common.go | 4 - epochStart/bootstrap/process.go | 14 +-- epochStart/bootstrap/process_test.go | 1 - epochStart/bootstrap/storageProcess.go | 17 +-- epochStart/bootstrap/storageProcess_test.go | 1 - factory/bootstrap/bootstrapComponents.go | 9 -- factory/data/dataComponents.go | 17 +-- factory/state/accountNonceProvider.go | 61 ---------- factory/state/accountNonceProvider_test.go | 113 ------------------ .../bootstrapComponents_test.go | 4 - .../consensusComponents_test.go | 5 - .../dataComponents/dataComponents_test.go | 5 - .../heartbeatComponents_test.go | 5 - .../processComponents_test.go | 5 - .../stateComponents/stateComponents_test.go | 5 - .../statusComponents/statusComponents_test.go | 5 - .../startInEpoch/startInEpoch_test.go | 1 - .../realcomponents/processorRunner.go | 7 -- .../components/bootstrapComponents.go | 3 - .../components/bootstrapComponents_test.go | 3 +- .../components/testOnlyProcessingNode.go | 24 +--- node/nodeRunner.go | 17 --- .../block/preprocess/accountNonceProvider.go | 40 +++++++ .../preprocess/accountNonceProvider_test.go | 52 ++++++++ process/block/preprocess/interfaces.go | 5 +- .../preprocess/sortedTransactionsProvider.go | 6 +- process/block/preprocess/transactions.go | 8 +- process/constants.go | 4 + storage/txcache/txcache.go | 4 +- testscommon/components/components.go | 2 - testscommon/dataRetriever/poolFactory.go | 8 +- testscommon/dataRetriever/poolsHolderMock.go | 6 +- 39 files changed, 171 insertions(+), 399 deletions(-) delete mode 100644 factory/state/accountNonceProvider.go delete mode 100644 factory/state/accountNonceProvider_test.go create mode 100644 process/block/preprocess/accountNonceProvider.go create mode 100644 process/block/preprocess/accountNonceProvider_test.go 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/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/memorytests/memory_test.go b/dataRetriever/txpool/memorytests/memory_test.go index 360e0bb7059..d0754eb7ef9 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" ) @@ -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 fd578ffb2a9..d04f8177bd1 100644 --- a/dataRetriever/txpool/shardedTxPool.go +++ b/dataRetriever/txpool/shardedTxPool.go @@ -28,7 +28,6 @@ type shardedTxPool struct { configPrototypeSourceMe txcache.ConfigSourceMe selfShardID uint32 txGasHandler txcache.TxGasHandler - accountNonceProvider dataRetriever.AccountNonceProvider } type txPoolShard struct { @@ -79,7 +78,6 @@ func NewShardedTxPool(args ArgShardedTxPool) (*shardedTxPool, error) { configPrototypeSourceMe: configPrototypeSourceMe, selfShardID: args.SelfShardID, txGasHandler: args.TxGasHandler, - accountNonceProvider: args.AccountNonceProvider, } return shardedTxPoolObject, nil @@ -136,7 +134,7 @@ func (txPool *shardedTxPool) createTxCache(cacheID string) txCache { if isForSenderMe { config := txPool.configPrototypeSourceMe config.Name = cacheID - cache, err := txcache.NewTxCache(config, txPool.txGasHandler, txPool.accountNonceProvider) + cache, err := txcache.NewTxCache(config, txPool.txGasHandler) if err != nil { log.Error("shardedTxPool.createTxCache()", "err", err) return txcache.NewDisabledCache() diff --git a/dataRetriever/txpool/shardedTxPool_test.go b/dataRetriever/txpool/shardedTxPool_test.go index 41d796c0caa..90638faff1f 100644 --- a/dataRetriever/txpool/shardedTxPool_test.go +++ b/dataRetriever/txpool/shardedTxPool_test.go @@ -12,7 +12,6 @@ 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/txcachemocks" "github.com/stretchr/testify/require" ) @@ -80,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) @@ -388,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) @@ -429,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/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/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/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/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/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/preprocess/accountNonceProvider.go b/process/block/preprocess/accountNonceProvider.go new file mode 100644 index 00000000000..3e7715e5e28 --- /dev/null +++ b/process/block/preprocess/accountNonceProvider.go @@ -0,0 +1,40 @@ +package preprocess + +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 +} + +func newAccountNonceProvider(accountsAdapter state.AccountsAdapter) (*accountNonceProvider, error) { + if check.IfNil(accountsAdapter) { + return nil, errors.ErrNilAccountsAdapter + } + + return &accountNonceProvider{ + accountsAdapter: accountsAdapter, + }, nil +} + +// GetAccountNonce returns the nonce for an account. +// Will be called by mempool during transaction selection. +func (provider *accountNonceProvider) GetAccountNonce(address []byte) (uint64, error) { + account, err := provider.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/process/block/preprocess/accountNonceProvider_test.go b/process/block/preprocess/accountNonceProvider_test.go new file mode 100644 index 00000000000..057bdd75261 --- /dev/null +++ b/process/block/preprocess/accountNonceProvider_test.go @@ -0,0 +1,52 @@ +package preprocess + +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 TestNewAccountNonceProvider(t *testing.T) { + t.Parallel() + + provider, err := newAccountNonceProvider(nil) + require.Nil(t, provider) + require.ErrorIs(t, err, errors.ErrNilAccountsAdapter) + + provider, err = newAccountNonceProvider(&state.AccountsStub{}) + require.NoError(t, err) + require.NotNil(t, provider) +} + +func TestAccountNonceProvider_GetAccountNonce(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) +} diff --git a/process/block/preprocess/interfaces.go b/process/block/preprocess/interfaces.go index 32cca6c30b3..bfc22a6e1ff 100644 --- a/process/block/preprocess/interfaces.go +++ b/process/block/preprocess/interfaces.go @@ -2,19 +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 + GetSortedTransactions(accountNonceProvider txcache.AccountNonceProvider) []*txcache.WrappedTransaction IsInterfaceNil() bool } // TxCache defines the functionality for the transactions cache type TxCache interface { - SelectTransactions(gasRequested uint64, maxNum int) ([]*txcache.WrappedTransaction, uint64) + SelectTransactions(accountNonceProvider txcache.AccountNonceProvider, gasRequested uint64, maxNum int, selectionLoopMaximumDuration time.Duration) ([]*txcache.WrappedTransaction, uint64) IsInterfaceNil() bool } diff --git a/process/block/preprocess/sortedTransactionsProvider.go b/process/block/preprocess/sortedTransactionsProvider.go index 7d14c3ba46e..a5af481faf4 100644 --- a/process/block/preprocess/sortedTransactionsProvider.go +++ b/process/block/preprocess/sortedTransactionsProvider.go @@ -32,8 +32,8 @@ 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(accountNonceProvider txcache.AccountNonceProvider) []*txcache.WrappedTransaction { + txs, _ := adapter.txCache.SelectTransactions(accountNonceProvider, process.TxCacheSelectionGasRequested, process.TxCacheSelectionMaxNumTxs, process.TxCacheSelectionLoopMaximumDuration) return txs } @@ -47,7 +47,7 @@ type disabledSortedTransactionsProvider struct { } // GetSortedTransactions returns an empty slice -func (adapter *disabledSortedTransactionsProvider) GetSortedTransactions() []*txcache.WrappedTransaction { +func (adapter *disabledSortedTransactionsProvider) GetSortedTransactions(_ txcache.AccountNonceProvider) []*txcache.WrappedTransaction { return make([]*txcache.WrappedTransaction, 0) } diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index c033a7444de..9c0b31d3ba1 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -1433,7 +1433,13 @@ func (txs *transactions) computeSortedTxs( sortedTransactionsProvider := createSortedTransactionsProvider(txShardPool) log.Debug("computeSortedTxs.GetSortedTransactions") - sortedTxs := sortedTransactionsProvider.GetSortedTransactions() + + accountNonceProvider, err := newAccountNonceProvider(txs.accounts) + if err != nil { + return nil, nil, err + } + + sortedTxs := sortedTransactionsProvider.GetSortedTransactions(accountNonceProvider) // TODO: this could be moved to SortedTransactionsProvider selectedTxs, remainingTxs := txs.preFilterTransactionsWithMoveBalancePriority(sortedTxs, gasBandwidth) 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/storage/txcache/txcache.go b/storage/txcache/txcache.go index a721d1887af..aa2869f3a6e 100644 --- a/storage/txcache/txcache.go +++ b/storage/txcache/txcache.go @@ -32,8 +32,8 @@ type DisabledCache = txcache.DisabledCache type CrossTxCache = txcache.CrossTxCache // NewTxCache creates a new transaction cache -func NewTxCache(config ConfigSourceMe, txGasHandler TxGasHandler, accountNonceProvider AccountNonceProvider) (*TxCache, error) { - return txcache.NewTxCache(config, txGasHandler, accountNonceProvider) +func NewTxCache(config ConfigSourceMe, txGasHandler TxGasHandler) (*TxCache, error) { + return txcache.NewTxCache(config, txGasHandler) } // NewDisabledCache creates a new disabled cache 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) From 38aeb55a5c0655f98d68088ec5b68c9e1ea72fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Fri, 15 Nov 2024 15:47:31 +0200 Subject: [PATCH 13/39] Optimized logging. Don't directly encode to hex before calling log.Trace(). Encoding will happen under the hood (if trace is active). --- state/accountsDB.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/state/accountsDB.go b/state/accountsDB.go index 2816c92ee5f..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) } - if log.GetLevel() == logger.LogTrace { - log.Trace("accountsDB.GetExistingAccount", "address", hex.EncodeToString(address)) - } + log.Trace("accountsDB.GetExistingAccount", "address", address) mainTrie := adb.getMainTrie() acnt, err := adb.getAccount(address, mainTrie) From 297e5305406ef59f0f5e6663bbb4f406ad3223bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Fri, 15 Nov 2024 15:53:18 +0200 Subject: [PATCH 14/39] Remove logic around "accountTxsShards" (was only needed for mempool notifications). --- process/block/preprocess/miniBlockBuilder.go | 15 ------- .../block/preprocess/miniBlockBuilder_test.go | 40 +------------------ process/block/preprocess/transactions.go | 13 ------ process/block/preprocess/transactionsV2.go | 8 ---- process/errors.go | 3 -- 5 files changed, 1 insertion(+), 78 deletions(-) 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..87f9011d906 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, diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index 9c0b31d3ba1..684e558eb64 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -39,11 +39,6 @@ const selectionGasBandwidthIncreasePercent = 200 // 130% to allow 30% overshooting estimations for scheduled SC calls const selectionGasBandwidthIncreaseScheduledPercent = 130 -type accountTxsShards struct { - accountsInfo map[string]*txShardInfo - sync.RWMutex -} - // TODO: increase code coverage with unit test type transactions struct { @@ -59,7 +54,6 @@ type transactions struct { mutOrderedTxs sync.RWMutex blockTracker BlockTracker blockType block.Type - accountTxsShards accountTxsShards emptyAddress []byte txTypeHandler process.TxTypeHandler scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler @@ -196,7 +190,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()) @@ -797,10 +790,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() } @@ -1156,7 +1145,6 @@ func (txs *transactions) createAndProcessMiniBlocksFromMeV1( args := miniBlocksBuilderArgs{ gasTracker: txs.gasTracker, accounts: txs.accounts, - accountTxsShards: &txs.accountTxsShards, balanceComputationHandler: txs.balanceComputation, blockSizeComputation: txs.blockSizeComputation, haveTime: haveTime, @@ -1255,7 +1243,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) diff --git a/process/block/preprocess/transactionsV2.go b/process/block/preprocess/transactionsV2.go index dc688cf9a3b..1eb46683894 100644 --- a/process/block/preprocess/transactionsV2.go +++ b/process/block/preprocess/transactionsV2.go @@ -171,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() @@ -375,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/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") From e1d4287a7be045d53e7b5657bd9ce74e2ef88832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Fri, 15 Nov 2024 15:54:12 +0200 Subject: [PATCH 15/39] Remove code not needed anymore. --- process/block/preprocess/transactions.go | 10 ----- testscommon/accountNonceProviderMock.go | 48 ------------------------ 2 files changed, 58 deletions(-) delete mode 100644 testscommon/accountNonceProviderMock.go diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index 684e558eb64..2fc746ad39f 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" @@ -905,15 +904,6 @@ func (txs *transactions) processAndRemoveBadTransaction( return err } -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 { 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 -} From f84a3c6fa2aac9c92f423cdc437c1e7ab32bf347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Fri, 15 Nov 2024 16:08:08 +0200 Subject: [PATCH 16/39] Minor refactoring around nonce account provider. --- process/block/preprocess/basePreProcess.go | 1 + process/block/preprocess/transactions.go | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/process/block/preprocess/basePreProcess.go b/process/block/preprocess/basePreProcess.go index 56ea615559e..e671539ce26 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 + accountNonceProvider *accountNonceProvider pubkeyConverter core.PubkeyConverter processedMiniBlocksTracker process.ProcessedMiniBlocksTracker enableEpochsHandler common.EnableEpochsHandler diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index 2fc746ad39f..cdaea673d08 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -154,6 +154,11 @@ func NewTransactionPreprocessor( return nil, process.ErrNilTxExecutionOrderHandler } + accountNonceProvider, err := newAccountNonceProvider(args.Accounts) + if err != nil { + return nil, err + } + bpp := basePreProcess{ hasher: args.Hasher, marshalizer: args.Marshalizer, @@ -165,6 +170,7 @@ func NewTransactionPreprocessor( blockSizeComputation: args.BlockSizeComputation, balanceComputation: args.BalanceComputation, accounts: args.Accounts, + accountNonceProvider: accountNonceProvider, pubkeyConverter: args.PubkeyConverter, enableEpochsHandler: args.EnableEpochsHandler, processedMiniBlocksTracker: args.ProcessedMiniBlocksTracker, @@ -1411,12 +1417,7 @@ func (txs *transactions) computeSortedTxs( sortedTransactionsProvider := createSortedTransactionsProvider(txShardPool) log.Debug("computeSortedTxs.GetSortedTransactions") - accountNonceProvider, err := newAccountNonceProvider(txs.accounts) - if err != nil { - return nil, nil, err - } - - sortedTxs := sortedTransactionsProvider.GetSortedTransactions(accountNonceProvider) + sortedTxs := sortedTransactionsProvider.GetSortedTransactions(txs.accountNonceProvider) // TODO: this could be moved to SortedTransactionsProvider selectedTxs, remainingTxs := txs.preFilterTransactionsWithMoveBalancePriority(sortedTxs, gasBandwidth) From 9aec5b9e94231e170433e7e20603c4725c475b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Fri, 15 Nov 2024 17:43:20 +0200 Subject: [PATCH 17/39] Sketch additional CS tests (WIP). --- .../chainSimulator/mempool/mempool_test.go | 91 +++++++++++++++++-- 1 file changed, 81 insertions(+), 10 deletions(-) diff --git a/integrationTests/chainSimulator/mempool/mempool_test.go b/integrationTests/chainSimulator/mempool/mempool_test.go index b08a99682f5..5e2cfa42fe1 100644 --- a/integrationTests/chainSimulator/mempool/mempool_test.go +++ b/integrationTests/chainSimulator/mempool/mempool_test.go @@ -28,32 +28,31 @@ func TestMempoolWithChainSimulator_Eviction(t *testing.T) { t.Skip("this is not a short test") } - cs := startChainSimulator(t, func(cfg *config.Configs) {}) - node := cs.GetNodeHandler(0) + simulator := startChainSimulator(t, func(cfg *config.Configs) {}) + node := simulator.GetNodeHandler(0) mempool := node.GetDataComponents().Datapool().Transactions() - defer cs.Close() - - initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + defer simulator.Close() numSenders := 10000 + numTransactionsPerSender := 30 + senders := make([]dtos.WalletAddress, numSenders) sendersNonces := make([]uint64, numSenders) for i := 0; i < numSenders; i++ { - sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + sender, err := simulator.GenerateAndMintWalletAddress(0, oneEGLD) require.NoError(t, err) senders[i] = sender } - receiver, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) + receiver, err := simulator.GenerateAndMintWalletAddress(0, big.NewInt(0)) require.NoError(t, err) - err = cs.GenerateBlocks(1) + err = simulator.GenerateBlocks(1) require.Nil(t, err) - numTransactionsPerSender := 30 transactions := make([]*transaction.Transaction, 0, numSenders*numTransactionsPerSender) for i := 0; i < numSenders; i++ { @@ -83,6 +82,78 @@ func TestMempoolWithChainSimulator_Eviction(t *testing.T) { time.Sleep(500 * time.Millisecond) require.Equal(t, 300000, int(mempool.GetCounts().GetTotal())) + err = simulator.GenerateBlocks(1) + require.Nil(t, err) + + currentBlock := node.GetDataComponents().Blockchain().GetCurrentBlockHeader() + require.Equal(t, 27755, int(currentBlock.GetTxCount())) + + miniblockHeader := currentBlock.GetMiniBlockHeaderHandlers()[0] + miniblockHash := miniblockHeader.GetHash() + + miniblocks, _ := node.GetDataComponents().MiniBlocksProvider().GetMiniBlocks([][]byte{miniblockHash}) + require.Equal(t, 1, len(miniblocks)) +} + +func TestMempoolWithChainSimulator_Eviction(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + simulator := startChainSimulator(t, func(cfg *config.Configs) {}) + node := simulator.GetNodeHandler(0) + mempool := node.GetDataComponents().Datapool().Transactions() + + defer simulator.Close() + + numSenders := 10000 + numTransactionsPerSender := 30 + + senders := make([]dtos.WalletAddress, numSenders) + sendersNonces := make([]uint64, numSenders) + + for i := 0; i < numSenders; i++ { + sender, err := simulator.GenerateAndMintWalletAddress(0, oneEGLD) + require.NoError(t, err) + + senders[i] = sender + } + + receiver, err := simulator.GenerateAndMintWalletAddress(0, big.NewInt(0)) + require.NoError(t, err) + + err = simulator.GenerateBlocks(1) + require.Nil(t, err) + + transactions := make([]*transaction.Transaction, 0, numSenders*numTransactionsPerSender) + + for i := 0; i < numSenders; i++ { + for j := 0; j < numTransactionsPerSender; j++ { + tx := &transaction.Transaction{ + Nonce: sendersNonces[i], + Value: oneEGLD, + SndAddr: senders[i].Bytes, + RcvAddr: receiver.Bytes, + Data: []byte{}, + GasLimit: 50000, + GasPrice: 1_000_000_000, + ChainID: []byte(configs.ChainID), + Version: 2, + Signature: []byte("signature"), + } + + sendersNonces[i]++ + transactions = append(transactions, tx) + } + } + + numSent, err := node.GetFacadeHandler().SendBulkTransactions(transactions) + require.NoError(t, err) + require.Equal(t, 300000, int(numSent)) + + time.Sleep(1 * time.Second) + require.Equal(t, 300000, int(mempool.GetCounts().GetTotal())) + // Send one more transaction (fill up the mempool) node.GetFacadeHandler().SendBulkTransactions([]*transaction.Transaction{ { @@ -118,7 +189,7 @@ func TestMempoolWithChainSimulator_Eviction(t *testing.T) { }, }) - time.Sleep(500 * time.Millisecond) + time.Sleep(1 * time.Second) require.Equal(t, 300000+1+1-int(storage.TxPoolSourceMeNumItemsToPreemptivelyEvict), int(mempool.GetCounts().GetTotal())) } From 5b937dba025aea63baa2c8b98083ca3b0fff6866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 18 Nov 2024 15:25:00 +0200 Subject: [PATCH 18/39] AccountNonceProvider becomes AccountStateProvider (more information from account state is necessary). --- dataRetriever/interface.go | 7 --- integrationTests/testProcessorNode.go | 1 - .../block/preprocess/accountNonceProvider.go | 40 --------------- .../block/preprocess/accountStateProvider.go | 49 +++++++++++++++++++ ...r_test.go => accountStateProvider_test.go} | 18 +++---- process/block/preprocess/basePreProcess.go | 2 +- process/block/preprocess/interfaces.go | 4 +- .../preprocess/sortedTransactionsProvider.go | 6 +-- process/block/preprocess/transactions.go | 6 +-- storage/txcache/txcache.go | 8 ++- 10 files changed, 73 insertions(+), 68 deletions(-) delete mode 100644 process/block/preprocess/accountNonceProvider.go create mode 100644 process/block/preprocess/accountStateProvider.go rename process/block/preprocess/{accountNonceProvider_test.go => accountStateProvider_test.go} (66%) diff --git a/dataRetriever/interface.go b/dataRetriever/interface.go index 721b7b8fa20..930b6aca124 100644 --- a/dataRetriever/interface.go +++ b/dataRetriever/interface.go @@ -357,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/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index c7cfe0995de..c6021aa99d3 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 diff --git a/process/block/preprocess/accountNonceProvider.go b/process/block/preprocess/accountNonceProvider.go deleted file mode 100644 index 3e7715e5e28..00000000000 --- a/process/block/preprocess/accountNonceProvider.go +++ /dev/null @@ -1,40 +0,0 @@ -package preprocess - -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 -} - -func newAccountNonceProvider(accountsAdapter state.AccountsAdapter) (*accountNonceProvider, error) { - if check.IfNil(accountsAdapter) { - return nil, errors.ErrNilAccountsAdapter - } - - return &accountNonceProvider{ - accountsAdapter: accountsAdapter, - }, nil -} - -// GetAccountNonce returns the nonce for an account. -// Will be called by mempool during transaction selection. -func (provider *accountNonceProvider) GetAccountNonce(address []byte) (uint64, error) { - account, err := provider.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/process/block/preprocess/accountStateProvider.go b/process/block/preprocess/accountStateProvider.go new file mode 100644 index 00000000000..0d0288895d1 --- /dev/null +++ b/process/block/preprocess/accountStateProvider.go @@ -0,0 +1,49 @@ +package preprocess + +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" + "github.com/multiversx/mx-chain-go/storage/txcache" +) + +type accountStateProvider struct { + accountsAdapter state.AccountsAdapter + mutex sync.RWMutex +} + +func newAccountStateProvider(accountsAdapter state.AccountsAdapter) (*accountStateProvider, error) { + if check.IfNil(accountsAdapter) { + return nil, errors.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/accountNonceProvider_test.go b/process/block/preprocess/accountStateProvider_test.go similarity index 66% rename from process/block/preprocess/accountNonceProvider_test.go rename to process/block/preprocess/accountStateProvider_test.go index 057bdd75261..7fecdb5aadb 100644 --- a/process/block/preprocess/accountNonceProvider_test.go +++ b/process/block/preprocess/accountStateProvider_test.go @@ -11,19 +11,19 @@ import ( "github.com/stretchr/testify/require" ) -func TestNewAccountNonceProvider(t *testing.T) { +func TestNewAccountStateProvider(t *testing.T) { t.Parallel() - provider, err := newAccountNonceProvider(nil) + provider, err := newAccountStateProvider(nil) require.Nil(t, provider) require.ErrorIs(t, err, errors.ErrNilAccountsAdapter) - provider, err = newAccountNonceProvider(&state.AccountsStub{}) + provider, err = newAccountStateProvider(&state.AccountsStub{}) require.NoError(t, err) require.NotNil(t, provider) } -func TestAccountNonceProvider_GetAccountNonce(t *testing.T) { +func TestAccountStateProvider_GetAccountState(t *testing.T) { t.Parallel() userAddress := []byte("alice") @@ -38,15 +38,15 @@ func TestAccountNonceProvider_GetAccountNonce(t *testing.T) { }, nil } - provider, err := newAccountNonceProvider(accounts) + provider, err := newAccountStateProvider(accounts) require.NoError(t, err) require.NotNil(t, provider) - nonce, err := provider.GetAccountNonce(userAddress) + state, err := provider.GetAccountState(userAddress) require.NoError(t, err) - require.Equal(t, uint64(42), nonce) + require.Equal(t, uint64(42), state.Nonce) - nonce, err = provider.GetAccountNonce([]byte("bob")) + state, err = provider.GetAccountState([]byte("bob")) require.ErrorContains(t, err, "account not found: bob") - require.Equal(t, uint64(0), nonce) + require.Nil(t, state) } diff --git a/process/block/preprocess/basePreProcess.go b/process/block/preprocess/basePreProcess.go index e671539ce26..9cbbdb8727a 100644 --- a/process/block/preprocess/basePreProcess.go +++ b/process/block/preprocess/basePreProcess.go @@ -120,7 +120,7 @@ type basePreProcess struct { blockSizeComputation BlockSizeComputationHandler balanceComputation BalanceComputationHandler accounts state.AccountsAdapter - accountNonceProvider *accountNonceProvider + 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 bfc22a6e1ff..92e87f6ce05 100644 --- a/process/block/preprocess/interfaces.go +++ b/process/block/preprocess/interfaces.go @@ -9,13 +9,13 @@ import ( // SortedTransactionsProvider defines the public API of the transactions cache type SortedTransactionsProvider interface { - GetSortedTransactions(accountNonceProvider txcache.AccountNonceProvider) []*txcache.WrappedTransaction + GetSortedTransactions(accountStateProvider txcache.AccountStateProvider) []*txcache.WrappedTransaction IsInterfaceNil() bool } // TxCache defines the functionality for the transactions cache type TxCache interface { - SelectTransactions(accountNonceProvider txcache.AccountNonceProvider, gasRequested uint64, maxNum int, selectionLoopMaximumDuration time.Duration) ([]*txcache.WrappedTransaction, uint64) + SelectTransactions(accountStateProvider txcache.AccountStateProvider, gasRequested uint64, maxNum int, selectionLoopMaximumDuration time.Duration) ([]*txcache.WrappedTransaction, uint64) IsInterfaceNil() bool } diff --git a/process/block/preprocess/sortedTransactionsProvider.go b/process/block/preprocess/sortedTransactionsProvider.go index a5af481faf4..e5811335a73 100644 --- a/process/block/preprocess/sortedTransactionsProvider.go +++ b/process/block/preprocess/sortedTransactionsProvider.go @@ -32,8 +32,8 @@ func newAdapterTxCacheToSortedTransactionsProvider(txCache TxCache) *adapterTxCa } // GetSortedTransactions gets the transactions from the cache -func (adapter *adapterTxCacheToSortedTransactionsProvider) GetSortedTransactions(accountNonceProvider txcache.AccountNonceProvider) []*txcache.WrappedTransaction { - txs, _ := adapter.txCache.SelectTransactions(accountNonceProvider, process.TxCacheSelectionGasRequested, process.TxCacheSelectionMaxNumTxs, process.TxCacheSelectionLoopMaximumDuration) +func (adapter *adapterTxCacheToSortedTransactionsProvider) GetSortedTransactions(accountStateProvider txcache.AccountStateProvider) []*txcache.WrappedTransaction { + txs, _ := adapter.txCache.SelectTransactions(accountStateProvider, process.TxCacheSelectionGasRequested, process.TxCacheSelectionMaxNumTxs, process.TxCacheSelectionLoopMaximumDuration) return txs } @@ -47,7 +47,7 @@ type disabledSortedTransactionsProvider struct { } // GetSortedTransactions returns an empty slice -func (adapter *disabledSortedTransactionsProvider) GetSortedTransactions(_ txcache.AccountNonceProvider) []*txcache.WrappedTransaction { +func (adapter *disabledSortedTransactionsProvider) GetSortedTransactions(_ txcache.AccountStateProvider) []*txcache.WrappedTransaction { return make([]*txcache.WrappedTransaction, 0) } diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index cdaea673d08..85ef9f5fc2e 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -154,7 +154,7 @@ func NewTransactionPreprocessor( return nil, process.ErrNilTxExecutionOrderHandler } - accountNonceProvider, err := newAccountNonceProvider(args.Accounts) + accountStateProvider, err := newAccountStateProvider(args.Accounts) if err != nil { return nil, err } @@ -170,7 +170,7 @@ func NewTransactionPreprocessor( blockSizeComputation: args.BlockSizeComputation, balanceComputation: args.BalanceComputation, accounts: args.Accounts, - accountNonceProvider: accountNonceProvider, + accountStateProvider: accountStateProvider, pubkeyConverter: args.PubkeyConverter, enableEpochsHandler: args.EnableEpochsHandler, processedMiniBlocksTracker: args.ProcessedMiniBlocksTracker, @@ -1417,7 +1417,7 @@ func (txs *transactions) computeSortedTxs( sortedTransactionsProvider := createSortedTransactionsProvider(txShardPool) log.Debug("computeSortedTxs.GetSortedTransactions") - sortedTxs := sortedTransactionsProvider.GetSortedTransactions(txs.accountNonceProvider) + sortedTxs := sortedTransactionsProvider.GetSortedTransactions(txs.accountStateProvider) // TODO: this could be moved to SortedTransactionsProvider selectedTxs, remainingTxs := txs.preFilterTransactionsWithMoveBalancePriority(sortedTxs, gasBandwidth) diff --git a/storage/txcache/txcache.go b/storage/txcache/txcache.go index aa2869f3a6e..54aa84eff78 100644 --- a/storage/txcache/txcache.go +++ b/storage/txcache/txcache.go @@ -2,16 +2,20 @@ 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 account state (as seen by the mempool) +type AccountState = types.AccountState + // TxGasHandler handles a transaction gas and gas cost type TxGasHandler = txcache.TxGasHandler -// AccountNonceProvider provides the nonce for an account -type AccountNonceProvider = txcache.AccountNonceProvider +// AccountStateProvider provides the nonce for an account +type AccountStateProvider = txcache.AccountStateProvider // ForEachTransaction is an iterator callback type ForEachTransaction = txcache.ForEachTransaction From 7741b4edc58b3dd5542c83d28050dd18b8fb3186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 19 Nov 2024 00:20:39 +0200 Subject: [PATCH 19/39] Fix tests, reference newer storage. --- dataRetriever/txpool/memorytests/memory_test.go | 8 ++++---- go.mod | 2 +- go.sum | 4 ++-- integrationTests/chainSimulator/mempool/mempool_test.go | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dataRetriever/txpool/memorytests/memory_test.go b/dataRetriever/txpool/memorytests/memory_test.go index d0754eb7ef9..b3b8facebfd 100644 --- a/dataRetriever/txpool/memorytests/memory_test.go +++ b/dataRetriever/txpool/memorytests/memory_test.go @@ -36,8 +36,8 @@ 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{0, 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(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, 30})) journals = append(journals, runScenario(t, newScenario(100000, 1, 1024, "0"), memoryAssertion{120, 138}, memoryAssertion{32, 60})) // With larger memory footprint @@ -45,8 +45,8 @@ func TestShardedTxPool_MemoryFootprint(t *testing.T) { 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(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, 100})) + journals = append(journals, runScenario(t, newScenario(300, 1000, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{60, 100})) // Scenarios where destination == me diff --git a/go.mod b/go.mod index c660a0a7c20..91c5fb55ede 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.20241118212528-c61ce2aabc45 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..255f50848a9 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.20241118212528-c61ce2aabc45 h1:sfu83k9o8m8qbnSm0phR5U81vWmZqcyW9txJDcgmQdA= +github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241118212528-c61ce2aabc45/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/chainSimulator/mempool/mempool_test.go b/integrationTests/chainSimulator/mempool/mempool_test.go index 5e2cfa42fe1..7c2666c2f31 100644 --- a/integrationTests/chainSimulator/mempool/mempool_test.go +++ b/integrationTests/chainSimulator/mempool/mempool_test.go @@ -23,7 +23,7 @@ var ( log = logger.GetOrCreate("testing") ) -func TestMempoolWithChainSimulator_Eviction(t *testing.T) { +func TestMempoolWithChainSimulator_Selection(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } From da369691a7a82154306c9f84021852291e346ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 19 Nov 2024 14:30:21 +0200 Subject: [PATCH 20/39] Fix long test. --- integrationTests/multiShard/relayedTx/relayedTx_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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( From 377cca54398f9fae386d645eb2324e41a3024a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 19 Nov 2024 14:45:38 +0200 Subject: [PATCH 21/39] Optimizations. Fix after self-review. --- trie/patriciaMerkleTrie.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/trie/patriciaMerkleTrie.go b/trie/patriciaMerkleTrie.go index 01905e0dcde..da9eb87a65f 100644 --- a/trie/patriciaMerkleTrie.go +++ b/trie/patriciaMerkleTrie.go @@ -119,12 +119,7 @@ func (tr *patriciaMerkleTrie) Update(key, value []byte) error { tr.mutOperation.Lock() defer tr.mutOperation.Unlock() - if log.GetLevel() == logger.LogTrace { - 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) } @@ -134,13 +129,7 @@ func (tr *patriciaMerkleTrie) UpdateWithVersion(key []byte, value []byte, versio tr.mutOperation.Lock() defer tr.mutOperation.Unlock() - if log.GetLevel() == logger.LogTrace { - 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) } From 5bb1b40eae211c4da0131c1931c1edc2cd3d993f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 19 Nov 2024 14:49:20 +0200 Subject: [PATCH 22/39] Fix old concurrency issue. --- .../requestHandlers/requestHandler.go | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) 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, ) } } From 0d295b80a58bcdbbc8d32241880044bcf5796428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 19 Nov 2024 14:54:09 +0200 Subject: [PATCH 23/39] Fix linter issues. --- integrationTests/chainSimulator/mempool/mempool_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integrationTests/chainSimulator/mempool/mempool_test.go b/integrationTests/chainSimulator/mempool/mempool_test.go index 7c2666c2f31..6b13803b80d 100644 --- a/integrationTests/chainSimulator/mempool/mempool_test.go +++ b/integrationTests/chainSimulator/mempool/mempool_test.go @@ -14,13 +14,11 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" "github.com/multiversx/mx-chain-go/storage" - logger "github.com/multiversx/mx-chain-logger-go" "github.com/stretchr/testify/require" ) var ( oneEGLD = big.NewInt(1000000000000000000) - log = logger.GetOrCreate("testing") ) func TestMempoolWithChainSimulator_Selection(t *testing.T) { @@ -155,7 +153,7 @@ func TestMempoolWithChainSimulator_Eviction(t *testing.T) { require.Equal(t, 300000, int(mempool.GetCounts().GetTotal())) // Send one more transaction (fill up the mempool) - node.GetFacadeHandler().SendBulkTransactions([]*transaction.Transaction{ + _, err = node.GetFacadeHandler().SendBulkTransactions([]*transaction.Transaction{ { Nonce: 42, Value: oneEGLD, @@ -169,12 +167,13 @@ func TestMempoolWithChainSimulator_Eviction(t *testing.T) { Signature: []byte("signature"), }, }) + require.NoError(t, err) time.Sleep(42 * time.Millisecond) require.Equal(t, 300001, int(mempool.GetCounts().GetTotal())) // Send one more transaction to trigger eviction - node.GetFacadeHandler().SendBulkTransactions([]*transaction.Transaction{ + _, err = node.GetFacadeHandler().SendBulkTransactions([]*transaction.Transaction{ { Nonce: 42, Value: oneEGLD, @@ -188,6 +187,7 @@ func TestMempoolWithChainSimulator_Eviction(t *testing.T) { Signature: []byte("signature"), }, }) + require.NoError(t, err) time.Sleep(1 * time.Second) require.Equal(t, 300000+1+1-int(storage.TxPoolSourceMeNumItemsToPreemptivelyEvict), int(mempool.GetCounts().GetTotal())) From f87f1c375aba03d32320a9438303795c3a50ea56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 19 Nov 2024 15:05:11 +0200 Subject: [PATCH 24/39] Remove unused field. --- process/block/preprocess/accountStateProvider.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/process/block/preprocess/accountStateProvider.go b/process/block/preprocess/accountStateProvider.go index 0d0288895d1..04e4f6e7765 100644 --- a/process/block/preprocess/accountStateProvider.go +++ b/process/block/preprocess/accountStateProvider.go @@ -1,8 +1,6 @@ package preprocess 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" @@ -11,7 +9,6 @@ import ( type accountStateProvider struct { accountsAdapter state.AccountsAdapter - mutex sync.RWMutex } func newAccountStateProvider(accountsAdapter state.AccountsAdapter) (*accountStateProvider, error) { From 48343720eaecfd0cf4b084660a94049cf18abfcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 19 Nov 2024 15:23:55 +0200 Subject: [PATCH 25/39] Sketch a simulator for transactions selection - called in CreateBlockStarted() - works for observers, as well. --- process/block/preprocess/transactions.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index 85ef9f5fc2e..e18b1f6cce2 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -31,6 +31,7 @@ var _ process.DataMarshalizer = (*transactions)(nil) var _ process.PreProcessor = (*transactions)(nil) var log = logger.GetOrCreate("process/block/preprocess") +var logSelectionSimulator = logger.GetOrCreate("process/block/preprocess/selectionSimulator") // 200% bandwidth to allow 100% overshooting estimations const selectionGasBandwidthIncreasePercent = 200 @@ -796,6 +797,26 @@ func (txs *transactions) CreateBlockStarted() { txs.mutOrderedTxs.Unlock() txs.scheduledTxsExecutionHandler.Init() + + txs.simulateTransactionsSelectionIfAppropriate() +} + +func (txs *transactions) simulateTransactionsSelectionIfAppropriate() { + if logSelectionSimulator.GetLevel() > logger.LogTrace { + return + } + + shardID := txs.shardCoordinator.SelfId() + cacheID := process.ShardCacherIdentifier(shardID, shardID) + mempool := txs.txPool.ShardDataStore(cacheID) + if check.IfNil(mempool) { + return + } + + sortedTransactionsProvider := createSortedTransactionsProvider(mempool) + transactions := sortedTransactionsProvider.GetSortedTransactions(txs.accountStateProvider) + + logSelectionSimulator.Trace("simulateTransactionsSelectionIfAppropriate", "num txs", len(transactions)) } // AddTxsFromMiniBlocks will add the transactions from the provided miniblocks into the internal cache From 9ff7f5cdc68662b6729ceb3e607be9edb35572d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 19 Nov 2024 17:40:12 +0200 Subject: [PATCH 26/39] Feed guardian checker into process/block/preprocess/transactions. --- factory/processing/blockProcessorCreator.go | 1 + genesis/process/shardGenesisBlockCreator.go | 1 + integrationTests/testProcessorNode.go | 4 ++- process/block/preprocess/transactions.go | 4 +++ .../block/preprocess/transactionsV2_test.go | 2 ++ process/block/preprocess/transactions_test.go | 22 +++++++++++++++ process/block/shardblock_test.go | 7 +++++ process/coordinator/process_test.go | 10 +++++++ .../preProcessorsContainerFactory.go | 2 ++ .../shard/preProcessorsContainerFactory.go | 7 +++++ .../preProcessorsContainerFactory_test.go | 27 +++++++++++++++++++ 11 files changed, 86 insertions(+), 1 deletion(-) diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 0721efc6a23..9ee02fd676d 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -351,6 +351,7 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( scheduledTxsExecutionHandler, processedMiniBlocksTracker, pcf.txExecutionOrderHandler, + pcf.bootstrapComponents.GuardedAccountHandler(), ) if err != nil { return nil, err diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 2347632d2d5..4fd5354d716 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -600,6 +600,7 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo disabledScheduledTxsExecutionHandler, disabledProcessedMiniBlocksTracker, arg.TxExecutionOrderHandler, + disabledGuardian.NewDisabledGuardedAccountHandler(), ) if err != nil { return nil, err diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index c6021aa99d3..c74b1a73f15 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1689,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, @@ -1734,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, } @@ -1774,6 +1775,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u scheduledTxsExecutionHandler, processedMiniBlocksTracker, tpn.TxExecutionOrderHandler, + guardianChecker, ) tpn.PreProcessorsContainer, _ = fact.Create() diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index e18b1f6cce2..1f68dba6867 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -81,6 +81,7 @@ type ArgsTransactionPreProcessor struct { ScheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler ProcessedMiniBlocksTracker process.ProcessedMiniBlocksTracker TxExecutionOrderHandler common.TxExecutionOrderHandler + GuardianChecker process.GuardianChecker } // NewTransactionPreprocessor creates a new transaction preprocessor object @@ -154,6 +155,9 @@ func NewTransactionPreprocessor( if check.IfNil(args.TxExecutionOrderHandler) { return nil, process.ErrNilTxExecutionOrderHandler } + if check.IfNil(args.GuardianChecker) { + return nil, process.ErrNilGuardianChecker + } accountStateProvider, err := newAccountStateProvider(args.Accounts) if err != nil { diff --git a/process/block/preprocess/transactionsV2_test.go b/process/block/preprocess/transactionsV2_test.go index 9d4fb1cf686..77c61877e65 100644 --- a/process/block/preprocess/transactionsV2_test.go +++ b/process/block/preprocess/transactionsV2_test.go @@ -18,6 +18,7 @@ import ( commonMocks "github.com/multiversx/mx-chain-go/testscommon/common" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" + "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -76,6 +77,7 @@ func createTransactionPreprocessor() *transactions { ScheduledTxsExecutionHandler: &testscommon.ScheduledTxsExecutionStub{}, ProcessedMiniBlocksTracker: &testscommon.ProcessedMiniBlocksTrackerStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, } preprocessor, _ := NewTransactionPreprocessor(txPreProcArgs) diff --git a/process/block/preprocess/transactions_test.go b/process/block/preprocess/transactions_test.go index 7f489b4b05d..593bb0eedf1 100644 --- a/process/block/preprocess/transactions_test.go +++ b/process/block/preprocess/transactions_test.go @@ -34,6 +34,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" + "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -238,6 +239,7 @@ func createDefaultTransactionsProcessorArgs() ArgsTransactionPreProcessor { ScheduledTxsExecutionHandler: &testscommon.ScheduledTxsExecutionStub{}, ProcessedMiniBlocksTracker: &testscommon.ProcessedMiniBlocksTrackerStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, } } @@ -446,6 +448,26 @@ 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_NewTransactionPreprocessorNilGuardianChecker(t *testing.T) { + t.Parallel() + + args := createDefaultTransactionsProcessorArgs() + args.GuardianChecker = nil + txs, err := NewTransactionPreprocessor(args) + assert.Nil(t, txs) + assert.Equal(t, process.ErrNilGuardianChecker, err) +} + func TestTxsPreprocessor_NewTransactionPreprocessorOkValsShouldWork(t *testing.T) { t.Parallel() diff --git a/process/block/shardblock_test.go b/process/block/shardblock_test.go index 39797f8db0c..f390d9a26c7 100644 --- a/process/block/shardblock_test.go +++ b/process/block/shardblock_test.go @@ -44,6 +44,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" + "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/outport" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -478,6 +479,7 @@ func TestShardProcessor_ProcessBlockWithInvalidTransactionShouldErr(t *testing.T &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() @@ -700,6 +702,7 @@ func TestShardProcessor_ProcessBlockWithErrOnProcessBlockTransactionsCallShouldR &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() @@ -2596,6 +2599,7 @@ func TestShardProcessor_MarshalizedDataToBroadcastShouldWork(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() @@ -2705,6 +2709,7 @@ func TestShardProcessor_MarshalizedDataMarshalWithoutSuccess(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() @@ -3100,6 +3105,7 @@ func TestShardProcessor_CreateMiniBlocksShouldWorkWithIntraShardTxs(t *testing.T &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() @@ -3282,6 +3288,7 @@ func TestShardProcessor_RestoreBlockIntoPoolsShouldWork(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() diff --git a/process/coordinator/process_test.go b/process/coordinator/process_test.go index 9e45b18bf08..e6105ff0126 100644 --- a/process/coordinator/process_test.go +++ b/process/coordinator/process_test.go @@ -40,6 +40,7 @@ import ( dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" + "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -559,6 +560,7 @@ func createPreProcessorContainer() process.PreProcessorsContainer { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -658,6 +660,7 @@ func createPreProcessorContainerWithDataPool( &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -928,6 +931,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessCrossShardTransactions(t *tes &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -1115,6 +1119,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessCrossShardTransactionsNilPreP &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -1224,6 +1229,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessTransactionsFromMeNothingToPr &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -1762,6 +1768,7 @@ func TestTransactionCoordinator_ProcessBlockTransactionProcessTxError(t *testing &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -1889,6 +1896,7 @@ func TestTransactionCoordinator_RequestMiniblocks(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -2030,6 +2038,7 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithOkTxsShouldExecuteThemAndNot &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -2172,6 +2181,7 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithErrorWhileProcessShouldCallR &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() diff --git a/process/factory/metachain/preProcessorsContainerFactory.go b/process/factory/metachain/preProcessorsContainerFactory.go index 4354a80ab1e..5d7f59bf8d7 100644 --- a/process/factory/metachain/preProcessorsContainerFactory.go +++ b/process/factory/metachain/preProcessorsContainerFactory.go @@ -11,6 +11,7 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/block/preprocess" "github.com/multiversx/mx-chain-go/process/factory/containers" + "github.com/multiversx/mx-chain-go/process/guardian/disabled" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/state" ) @@ -198,6 +199,7 @@ func (ppcm *preProcessorsContainerFactory) createTxPreProcessor() (process.PrePr ScheduledTxsExecutionHandler: ppcm.scheduledTxsExecutionHandler, ProcessedMiniBlocksTracker: ppcm.processedMiniBlocksTracker, TxExecutionOrderHandler: ppcm.txExecutionOrderHandler, + GuardianChecker: disabled.NewDisabledGuardedAccountHandler(), } txPreprocessor, err := preprocess.NewTransactionPreprocessor(args) diff --git a/process/factory/shard/preProcessorsContainerFactory.go b/process/factory/shard/preProcessorsContainerFactory.go index a561412737b..cd799b8857a 100644 --- a/process/factory/shard/preProcessorsContainerFactory.go +++ b/process/factory/shard/preProcessorsContainerFactory.go @@ -40,6 +40,7 @@ type preProcessorsContainerFactory struct { scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler processedMiniBlocksTracker process.ProcessedMiniBlocksTracker txExecutionOrderHandler common.TxExecutionOrderHandler + guardianChecker process.GuardianChecker } // NewPreProcessorsContainerFactory is responsible for creating a new preProcessors factory object @@ -66,6 +67,7 @@ func NewPreProcessorsContainerFactory( scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler, processedMiniBlocksTracker process.ProcessedMiniBlocksTracker, txExecutionOrderHandler common.TxExecutionOrderHandler, + guardianChecker process.GuardianChecker, ) (*preProcessorsContainerFactory, error) { if check.IfNil(shardCoordinator) { @@ -134,6 +136,9 @@ func NewPreProcessorsContainerFactory( if check.IfNil(txExecutionOrderHandler) { return nil, process.ErrNilTxExecutionOrderHandler } + if check.IfNil(guardianChecker) { + return nil, process.ErrNilGuardianChecker + } return &preProcessorsContainerFactory{ shardCoordinator: shardCoordinator, @@ -158,6 +163,7 @@ func NewPreProcessorsContainerFactory( scheduledTxsExecutionHandler: scheduledTxsExecutionHandler, processedMiniBlocksTracker: processedMiniBlocksTracker, txExecutionOrderHandler: txExecutionOrderHandler, + guardianChecker: guardianChecker, }, nil } @@ -230,6 +236,7 @@ func (ppcm *preProcessorsContainerFactory) createTxPreProcessor() (process.PrePr ScheduledTxsExecutionHandler: ppcm.scheduledTxsExecutionHandler, ProcessedMiniBlocksTracker: ppcm.processedMiniBlocksTracker, TxExecutionOrderHandler: ppcm.txExecutionOrderHandler, + GuardianChecker: ppcm.guardianChecker, } txPreprocessor, err := preprocess.NewTransactionPreprocessor(args) diff --git a/process/factory/shard/preProcessorsContainerFactory_test.go b/process/factory/shard/preProcessorsContainerFactory_test.go index f273a5e64f3..02c9ffe4d7f 100644 --- a/process/factory/shard/preProcessorsContainerFactory_test.go +++ b/process/factory/shard/preProcessorsContainerFactory_test.go @@ -11,6 +11,7 @@ import ( dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" + "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -47,6 +48,7 @@ func TestNewPreProcessorsContainerFactory_NilShardCoordinator(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilShardCoordinator, err) @@ -79,6 +81,7 @@ func TestNewPreProcessorsContainerFactory_NilStore(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilStore, err) @@ -111,6 +114,7 @@ func TestNewPreProcessorsContainerFactory_NilMarshalizer(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilMarshalizer, err) @@ -143,6 +147,7 @@ func TestNewPreProcessorsContainerFactory_NilHasher(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilHasher, err) @@ -175,6 +180,7 @@ func TestNewPreProcessorsContainerFactory_NilDataPool(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilDataPoolHolder, err) @@ -207,6 +213,7 @@ func TestNewPreProcessorsContainerFactory_NilAddrConv(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilPubkeyConverter, err) @@ -239,6 +246,7 @@ func TestNewPreProcessorsContainerFactory_NilAccounts(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilAccountsAdapter, err) @@ -271,6 +279,7 @@ func TestNewPreProcessorsContainerFactory_NilTxProcessor(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilTxProcessor, err) @@ -303,6 +312,7 @@ func TestNewPreProcessorsContainerFactory_NilSCProcessor(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilSmartContractProcessor, err) @@ -335,6 +345,7 @@ func TestNewPreProcessorsContainerFactory_NilSCR(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilSmartContractResultProcessor, err) @@ -367,6 +378,7 @@ func TestNewPreProcessorsContainerFactory_NilRewardTxProcessor(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilRewardsTxProcessor, err) @@ -399,6 +411,7 @@ func TestNewPreProcessorsContainerFactory_NilRequestHandler(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilRequestHandler, err) @@ -431,6 +444,7 @@ func TestNewPreProcessorsContainerFactory_NilFeeHandler(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilEconomicsFeeHandler, err) @@ -463,6 +477,7 @@ func TestNewPreProcessorsContainerFactory_NilGasHandler(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilGasHandler, err) @@ -495,6 +510,7 @@ func TestNewPreProcessorsContainerFactory_NilBlockTracker(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilBlockTracker, err) @@ -527,6 +543,7 @@ func TestNewPreProcessorsContainerFactory_NilBlockSizeComputationHandler(t *test &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilBlockSizeComputationHandler, err) @@ -559,6 +576,7 @@ func TestNewPreProcessorsContainerFactory_NilBalanceComputationHandler(t *testin &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilBalanceComputationHandler, err) @@ -591,6 +609,7 @@ func TestNewPreProcessorsContainerFactory_NilEnableEpochsHandler(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilEnableEpochsHandler, err) @@ -623,6 +642,7 @@ func TestNewPreProcessorsContainerFactory_NilTxTypeHandler(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilTxTypeHandler, err) @@ -655,6 +675,7 @@ func TestNewPreProcessorsContainerFactory_NilScheduledTxsExecutionHandler(t *tes nil, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilScheduledTxsExecutionHandler, err) @@ -687,6 +708,7 @@ func TestNewPreProcessorsContainerFactory_NilProcessedMiniBlocksTracker(t *testi &testscommon.ScheduledTxsExecutionStub{}, nil, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilProcessedMiniBlocksTracker, err) @@ -719,6 +741,7 @@ func TestNewPreProcessorsContainerFactory_NilTxExecutionOrderHandler(t *testing. &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, nil, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilTxExecutionOrderHandler, err) @@ -751,6 +774,7 @@ func TestNewPreProcessorsContainerFactory(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Nil(t, err) @@ -788,6 +812,7 @@ func TestPreProcessorsContainerFactory_CreateErrTxPreproc(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Nil(t, err) @@ -831,6 +856,7 @@ func TestPreProcessorsContainerFactory_CreateErrScrPreproc(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Nil(t, err) @@ -877,6 +903,7 @@ func TestPreProcessorsContainerFactory_Create(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, + &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Nil(t, err) From 0b5c262e8d61c9506d2fc409f32b935f5af07c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 19 Nov 2024 21:35:39 +0200 Subject: [PATCH 27/39] Enhance accountStateProvider - make it know about guardians. --- .../block/preprocess/accountStateProvider.go | 34 +++++++++-- .../preprocess/accountStateProvider_test.go | 58 ++++++++++++++----- process/block/preprocess/transactions.go | 2 +- 3 files changed, 76 insertions(+), 18 deletions(-) diff --git a/process/block/preprocess/accountStateProvider.go b/process/block/preprocess/accountStateProvider.go index 04e4f6e7765..e80ae906e46 100644 --- a/process/block/preprocess/accountStateProvider.go +++ b/process/block/preprocess/accountStateProvider.go @@ -3,21 +3,28 @@ 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" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) type accountStateProvider struct { accountsAdapter state.AccountsAdapter + guardianChecker process.GuardianChecker } -func newAccountStateProvider(accountsAdapter state.AccountsAdapter) (*accountStateProvider, error) { +func newAccountStateProvider(accountsAdapter state.AccountsAdapter, guardianChecker process.GuardianChecker) (*accountStateProvider, error) { if check.IfNil(accountsAdapter) { - return nil, errors.ErrNilAccountsAdapter + return nil, process.ErrNilAccountsAdapter + } + if check.IfNil(guardianChecker) { + return nil, process.ErrNilGuardianChecker } return &accountStateProvider{ accountsAdapter: accountsAdapter, + guardianChecker: guardianChecker, }, nil } @@ -34,12 +41,31 @@ func (provider *accountStateProvider) GetAccountState(address []byte) (*txcache. return nil, errors.ErrWrongTypeAssertion } + guardian, err := provider.getGuardian(userAccount) + if err != nil { + return nil, err + } + return &txcache.AccountState{ - Nonce: userAccount.GetNonce(), - Balance: userAccount.GetBalance(), + Nonce: userAccount.GetNonce(), + Balance: userAccount.GetBalance(), + Guardian: guardian, }, nil } +func (provider *accountStateProvider) getGuardian(userAccount state.UserAccountHandler) ([]byte, error) { + if !userAccount.IsGuarded() { + return nil, nil + } + + vmUserAccount, ok := userAccount.(vmcommon.UserAccountHandler) + if !ok { + return nil, errors.ErrWrongTypeAssertion + } + + return provider.guardianChecker.GetActiveGuardian(vmUserAccount) +} + // 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 index 7fecdb5aadb..4079c3bc324 100644 --- a/process/block/preprocess/accountStateProvider_test.go +++ b/process/block/preprocess/accountStateProvider_test.go @@ -5,7 +5,8 @@ import ( "fmt" "testing" - "github.com/multiversx/mx-chain-go/errors" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/state" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" @@ -14,11 +15,15 @@ import ( func TestNewAccountStateProvider(t *testing.T) { t.Parallel() - provider, err := newAccountStateProvider(nil) + provider, err := newAccountStateProvider(nil, &guardianMocks.GuardedAccountHandlerStub{}) require.Nil(t, provider) - require.ErrorIs(t, err, errors.ErrNilAccountsAdapter) + require.ErrorIs(t, err, process.ErrNilAccountsAdapter) - provider, err = newAccountStateProvider(&state.AccountsStub{}) + provider, err = newAccountStateProvider(&state.AccountsStub{}, nil) + require.Nil(t, provider) + require.ErrorIs(t, err, process.ErrNilGuardianChecker) + + provider, err = newAccountStateProvider(&state.AccountsStub{}, &guardianMocks.GuardedAccountHandlerStub{}) require.NoError(t, err) require.NotNil(t, provider) } @@ -26,27 +31,54 @@ func TestNewAccountStateProvider(t *testing.T) { func TestAccountStateProvider_GetAccountState(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) + // Alice has no guardian + if bytes.Equal(address, []byte("alice")) { + return &state.UserAccountStub{ + Address: []byte("alice"), + Nonce: 42, + }, nil + } + + // Bob has a Heidi as guardian + 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) + } + + guardianChecker := &guardianMocks.GuardedAccountHandlerStub{} + guardianChecker.GetActiveGuardianCalled = func(userAccount vmcommon.UserAccountHandler) ([]byte, error) { + if bytes.Equal(userAccount.AddressBytes(), []byte("bob")) { + return []byte("heidi"), nil } - return &state.UserAccountStub{ - Nonce: 42, - }, nil + return nil, nil } - provider, err := newAccountStateProvider(accounts) + provider, err := newAccountStateProvider(accounts, guardianChecker) require.NoError(t, err) require.NotNil(t, provider) - state, err := provider.GetAccountState(userAddress) + state, err := provider.GetAccountState([]byte("alice")) require.NoError(t, err) require.Equal(t, uint64(42), state.Nonce) + require.Nil(t, state.Guardian) state, err = provider.GetAccountState([]byte("bob")) - require.ErrorContains(t, err, "account not found: bob") + require.NoError(t, err) + require.Equal(t, uint64(7), state.Nonce) + require.Equal(t, []byte("heidi"), state.Guardian) + + state, err = provider.GetAccountState([]byte("carol")) + require.ErrorContains(t, err, "account not found: carol") require.Nil(t, state) } diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index 1f68dba6867..40f9dc79331 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -159,7 +159,7 @@ func NewTransactionPreprocessor( return nil, process.ErrNilGuardianChecker } - accountStateProvider, err := newAccountStateProvider(args.Accounts) + accountStateProvider, err := newAccountStateProvider(args.Accounts, args.GuardianChecker) if err != nil { return nil, err } From cf4f1a84504304ac11b1b179689f18dd77e92e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 20 Nov 2024 12:22:56 +0200 Subject: [PATCH 28/39] Reference newer storage-go. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 91c5fb55ede..997c9ed7f70 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.18-0.20241118212528-c61ce2aabc45 + github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241120101328-679a46567f75 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 255f50848a9..8b948fa9c59 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.18-0.20241118212528-c61ce2aabc45 h1:sfu83k9o8m8qbnSm0phR5U81vWmZqcyW9txJDcgmQdA= -github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241118212528-c61ce2aabc45/go.mod h1:eFDEOrG7Wiyk5I/ObpwcN2eoBlOnnfeEMTvTer1cymk= +github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241120101328-679a46567f75 h1:zGVj1O9RvQ7H7ipIYCu3Ynuwps5CKdmuVtOdjiACgYg= +github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241120101328-679a46567f75/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= From 1faa7f16d41e50d3f458a26350bfd48e8df0f881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 20 Nov 2024 13:13:52 +0200 Subject: [PATCH 29/39] Fix tests. --- dataRetriever/txpool/memorytests/memory_test.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/dataRetriever/txpool/memorytests/memory_test.go b/dataRetriever/txpool/memorytests/memory_test.go index b3b8facebfd..7a664223f82 100644 --- a/dataRetriever/txpool/memorytests/memory_test.go +++ b/dataRetriever/txpool/memorytests/memory_test.go @@ -25,10 +25,6 @@ const useMemPprof = false // We run all scenarios within a single test so that we minimize memory interferences (of tests running in parallel) func TestShardedTxPool_MemoryFootprint(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - journals := make([]*memoryFootprintJournal, 0) // Scenarios where source == me @@ -37,16 +33,16 @@ func TestShardedTxPool_MemoryFootprint(t *testing.T) { 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{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, 30})) + 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, 148})) 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, 100})) - journals = append(journals, runScenario(t, newScenario(300, 1000, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{60, 100})) + 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 From 5b005213057a1069b5fe8b9f0b76d114139bed95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 20 Nov 2024 15:28:57 +0200 Subject: [PATCH 30/39] Newer storage go. Additional tracing. --- dataRetriever/shardedData/shardedData.go | 14 +++++++++++++- dataRetriever/txpool/shardedTxPool.go | 12 +++++++++++- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/dataRetriever/shardedData/shardedData.go b/dataRetriever/shardedData/shardedData.go index acb0c3d9bec..f47aa2172cb 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.Trace("shardedData.removeTxBulk", + "name", sd.name, + "cacheID", cacheID, + "numToRemove", len(keys), + "numRemoved", numRemoved, + "duration", stopWatch.GetMeasurement("removal"), + ) } // ImmunizeSetOfDataAgainstEviction marks the items as non-evictable diff --git a/dataRetriever/txpool/shardedTxPool.go b/dataRetriever/txpool/shardedTxPool.go index d04f8177bd1..c4ec79285f7 100644 --- a/dataRetriever/txpool/shardedTxPool.go +++ b/dataRetriever/txpool/shardedTxPool.go @@ -242,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) { @@ -249,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) diff --git a/go.mod b/go.mod index 997c9ed7f70..5190c121542 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.18-0.20241120101328-679a46567f75 + github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241120132728-b2fa1cee26ce 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 8b948fa9c59..9cea32ad235 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.18-0.20241120101328-679a46567f75 h1:zGVj1O9RvQ7H7ipIYCu3Ynuwps5CKdmuVtOdjiACgYg= -github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241120101328-679a46567f75/go.mod h1:eFDEOrG7Wiyk5I/ObpwcN2eoBlOnnfeEMTvTer1cymk= +github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241120132728-b2fa1cee26ce h1:fft3/lHHAROtjtp9a6vgkuHaCeazDHMi95SHIN+SynU= +github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241120132728-b2fa1cee26ce/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= From e1cb834564afb2d6ff05a485e0d1deedde40f56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 20 Nov 2024 16:06:34 +0200 Subject: [PATCH 31/39] Fix tests. --- dataRetriever/shardedData/shardedData.go | 2 +- storage/txcache/txcache_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dataRetriever/shardedData/shardedData.go b/dataRetriever/shardedData/shardedData.go index f47aa2172cb..785998164b9 100644 --- a/dataRetriever/shardedData/shardedData.go +++ b/dataRetriever/shardedData/shardedData.go @@ -174,7 +174,7 @@ func (sd *shardedData) RemoveSetOfDataFromPool(keys [][]byte, cacheID string) { stopWatch.Stop("removal") - log.Trace("shardedData.removeTxBulk", + log.Debug("shardedData.removeTxBulk", "name", sd.name, "cacheID", cacheID, "numToRemove", len(keys), 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() From eca80293f613200c9672ed6b62916ffad104b6da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 21 Nov 2024 09:43:53 +0200 Subject: [PATCH 32/39] Reference new storage-go. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5190c121542..e180c82d4c1 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.18-0.20241120132728-b2fa1cee26ce + github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241121073828-1b8274da896a 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 9cea32ad235..d725e6a1deb 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.18-0.20241120132728-b2fa1cee26ce h1:fft3/lHHAROtjtp9a6vgkuHaCeazDHMi95SHIN+SynU= -github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241120132728-b2fa1cee26ce/go.mod h1:eFDEOrG7Wiyk5I/ObpwcN2eoBlOnnfeEMTvTer1cymk= +github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241121073828-1b8274da896a h1:IFyDLwwVKkbvPZYUu/3JQ8Wv/H888ZkU3HnNLRWqx2c= +github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241121073828-1b8274da896a/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= From 9005e76168058bc4895c0a3117f9344a0574ba9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 21 Nov 2024 14:30:22 +0200 Subject: [PATCH 33/39] Fix tests, fix after self-review. --- .../txpool/memorytests/memory_test.go | 6 +- .../preprocess/accountStateProvider_test.go | 2 +- .../block/preprocess/miniBlockBuilder_test.go | 2 +- process/block/preprocess/transactions_test.go | 24 ++ process/block/shardblock_test.go | 6 + process/coordinator/process_test.go | 209 +++++++++++++----- storage/txcache/txcache.go | 4 +- 7 files changed, 187 insertions(+), 66 deletions(-) diff --git a/dataRetriever/txpool/memorytests/memory_test.go b/dataRetriever/txpool/memorytests/memory_test.go index 7a664223f82..2f26e574830 100644 --- a/dataRetriever/txpool/memorytests/memory_test.go +++ b/dataRetriever/txpool/memorytests/memory_test.go @@ -25,6 +25,10 @@ const useMemPprof = false // We run all scenarios within a single test so that we minimize memory interferences (of tests running in parallel) func TestShardedTxPool_MemoryFootprint(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + journals := make([]*memoryFootprintJournal, 0) // Scenarios where source == me @@ -39,7 +43,7 @@ func TestShardedTxPool_MemoryFootprint(t *testing.T) { // With larger memory footprint 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, 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, 132})) journals = append(journals, runScenario(t, newScenario(300, 1000, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{60, 148})) diff --git a/process/block/preprocess/accountStateProvider_test.go b/process/block/preprocess/accountStateProvider_test.go index 4079c3bc324..5d5fb46f562 100644 --- a/process/block/preprocess/accountStateProvider_test.go +++ b/process/block/preprocess/accountStateProvider_test.go @@ -41,7 +41,7 @@ func TestAccountStateProvider_GetAccountState(t *testing.T) { }, nil } - // Bob has a Heidi as guardian + // Bob has Heidi as guardian if bytes.Equal(address, []byte("bob")) { return &state.UserAccountStub{ Address: []byte("bob"), diff --git a/process/block/preprocess/miniBlockBuilder_test.go b/process/block/preprocess/miniBlockBuilder_test.go index 87f9011d906..3ba49aa00a3 100644 --- a/process/block/preprocess/miniBlockBuilder_test.go +++ b/process/block/preprocess/miniBlockBuilder_test.go @@ -880,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/transactions_test.go b/process/block/preprocess/transactions_test.go index 593bb0eedf1..d0d2eb1d8b9 100644 --- a/process/block/preprocess/transactions_test.go +++ b/process/block/preprocess/transactions_test.go @@ -682,6 +682,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) @@ -736,6 +744,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) @@ -801,6 +817,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/shardblock_test.go b/process/block/shardblock_test.go index f390d9a26c7..e08bf3dd1c8 100644 --- a/process/block/shardblock_test.go +++ b/process/block/shardblock_test.go @@ -3058,6 +3058,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/coordinator/process_test.go b/process/coordinator/process_test.go index e6105ff0126..b2d782029ab 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" @@ -588,6 +589,7 @@ func createInterimProcessorContainer() process.IntermediateProcessorContainer { func createPreProcessorContainerWithDataPool( dataPool dataRetriever.PoolsHolder, feeHandler process.FeeHandler, + accounts state.AccountsAdapter, ) process.PreProcessorsContainer { totalGasProvided := uint64(0) @@ -598,7 +600,7 @@ func createPreProcessorContainerWithDataPool( &hashingMocks.HasherMock{}, dataPool, createMockPubkeyConverter(), - &stateMock.AccountsStub{}, + accounts, &testscommon.RequestHandlerStub{}, &testscommon.TxProcessorMock{ ProcessTransactionCalled: func(transaction *transaction.Transaction) (vmcommon.ReturnCode, error) { @@ -1253,7 +1255,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) @@ -1272,7 +1274,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 @@ -1301,9 +1303,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) @@ -1339,9 +1350,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) @@ -1392,6 +1411,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( @@ -1409,7 +1436,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) @@ -1455,6 +1482,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( @@ -1472,7 +1507,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) @@ -1519,9 +1554,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 @@ -1564,7 +1607,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) @@ -1586,7 +1629,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) @@ -1616,7 +1659,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) @@ -1636,7 +1679,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) @@ -1672,7 +1715,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) @@ -1710,7 +1753,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) @@ -1818,7 +1861,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) @@ -2376,7 +2419,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} @@ -2414,7 +2457,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) @@ -2598,14 +2641,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{}, @@ -2643,14 +2688,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{}, @@ -2709,14 +2756,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{}, @@ -2786,14 +2835,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{}, @@ -2863,14 +2914,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{}, @@ -2939,14 +2992,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{}, @@ -3012,14 +3067,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{}, @@ -3105,14 +3162,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{}, @@ -3194,14 +3253,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{}, @@ -3236,14 +3297,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{}, @@ -3293,14 +3356,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{}, @@ -3355,14 +3420,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{}, @@ -3422,14 +3489,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{}, @@ -3486,14 +3555,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{}, @@ -3541,14 +3612,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{}, @@ -3610,14 +3683,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{}, @@ -3680,14 +3755,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{}, @@ -3764,14 +3841,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{}, @@ -3848,14 +3927,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{}, @@ -3935,14 +4016,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{}, @@ -3987,14 +4070,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{}, @@ -4053,14 +4138,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/storage/txcache/txcache.go b/storage/txcache/txcache.go index 54aa84eff78..bf0bbae8419 100644 --- a/storage/txcache/txcache.go +++ b/storage/txcache/txcache.go @@ -8,13 +8,13 @@ import ( // WrappedTransaction contains a transaction, its hash and extra information type WrappedTransaction = txcache.WrappedTransaction -// AccountState represents the account state (as seen by the mempool) +// 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 nonce for an account +// AccountStateProvider provides the state of an account (as seen by the mempool) type AccountStateProvider = txcache.AccountStateProvider // ForEachTransaction is an iterator callback From cfd1ea871c68d89a14c6cbeed7673e0ab99fcd23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 21 Nov 2024 15:54:21 +0200 Subject: [PATCH 34/39] Remove chain simulator test (since it's not polished). Will be added at a later time. --- .../chainSimulator/mempool/mempool_test.go | 223 ------------------ 1 file changed, 223 deletions(-) delete mode 100644 integrationTests/chainSimulator/mempool/mempool_test.go diff --git a/integrationTests/chainSimulator/mempool/mempool_test.go b/integrationTests/chainSimulator/mempool/mempool_test.go deleted file mode 100644 index 6b13803b80d..00000000000 --- a/integrationTests/chainSimulator/mempool/mempool_test.go +++ /dev/null @@ -1,223 +0,0 @@ -package relayedTx - -import ( - "math/big" - "testing" - "time" - - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-go/config" - testsChainSimulator "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" - "github.com/multiversx/mx-chain-go/node/chainSimulator" - "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" - "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" - "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" - "github.com/multiversx/mx-chain-go/storage" - "github.com/stretchr/testify/require" -) - -var ( - oneEGLD = big.NewInt(1000000000000000000) -) - -func TestMempoolWithChainSimulator_Selection(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - simulator := startChainSimulator(t, func(cfg *config.Configs) {}) - node := simulator.GetNodeHandler(0) - mempool := node.GetDataComponents().Datapool().Transactions() - - defer simulator.Close() - - numSenders := 10000 - numTransactionsPerSender := 30 - - senders := make([]dtos.WalletAddress, numSenders) - sendersNonces := make([]uint64, numSenders) - - for i := 0; i < numSenders; i++ { - sender, err := simulator.GenerateAndMintWalletAddress(0, oneEGLD) - require.NoError(t, err) - - senders[i] = sender - } - - receiver, err := simulator.GenerateAndMintWalletAddress(0, big.NewInt(0)) - require.NoError(t, err) - - err = simulator.GenerateBlocks(1) - require.Nil(t, err) - - transactions := make([]*transaction.Transaction, 0, numSenders*numTransactionsPerSender) - - for i := 0; i < numSenders; i++ { - for j := 0; j < numTransactionsPerSender; j++ { - tx := &transaction.Transaction{ - Nonce: sendersNonces[i], - Value: oneEGLD, - SndAddr: senders[i].Bytes, - RcvAddr: receiver.Bytes, - Data: []byte{}, - GasLimit: 50000, - GasPrice: 1_000_000_000, - ChainID: []byte(configs.ChainID), - Version: 2, - Signature: []byte("signature"), - } - - sendersNonces[i]++ - transactions = append(transactions, tx) - } - } - - numSent, err := node.GetFacadeHandler().SendBulkTransactions(transactions) - require.NoError(t, err) - require.Equal(t, 300000, int(numSent)) - - time.Sleep(500 * time.Millisecond) - require.Equal(t, 300000, int(mempool.GetCounts().GetTotal())) - - err = simulator.GenerateBlocks(1) - require.Nil(t, err) - - currentBlock := node.GetDataComponents().Blockchain().GetCurrentBlockHeader() - require.Equal(t, 27755, int(currentBlock.GetTxCount())) - - miniblockHeader := currentBlock.GetMiniBlockHeaderHandlers()[0] - miniblockHash := miniblockHeader.GetHash() - - miniblocks, _ := node.GetDataComponents().MiniBlocksProvider().GetMiniBlocks([][]byte{miniblockHash}) - require.Equal(t, 1, len(miniblocks)) -} - -func TestMempoolWithChainSimulator_Eviction(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - simulator := startChainSimulator(t, func(cfg *config.Configs) {}) - node := simulator.GetNodeHandler(0) - mempool := node.GetDataComponents().Datapool().Transactions() - - defer simulator.Close() - - numSenders := 10000 - numTransactionsPerSender := 30 - - senders := make([]dtos.WalletAddress, numSenders) - sendersNonces := make([]uint64, numSenders) - - for i := 0; i < numSenders; i++ { - sender, err := simulator.GenerateAndMintWalletAddress(0, oneEGLD) - require.NoError(t, err) - - senders[i] = sender - } - - receiver, err := simulator.GenerateAndMintWalletAddress(0, big.NewInt(0)) - require.NoError(t, err) - - err = simulator.GenerateBlocks(1) - require.Nil(t, err) - - transactions := make([]*transaction.Transaction, 0, numSenders*numTransactionsPerSender) - - for i := 0; i < numSenders; i++ { - for j := 0; j < numTransactionsPerSender; j++ { - tx := &transaction.Transaction{ - Nonce: sendersNonces[i], - Value: oneEGLD, - SndAddr: senders[i].Bytes, - RcvAddr: receiver.Bytes, - Data: []byte{}, - GasLimit: 50000, - GasPrice: 1_000_000_000, - ChainID: []byte(configs.ChainID), - Version: 2, - Signature: []byte("signature"), - } - - sendersNonces[i]++ - transactions = append(transactions, tx) - } - } - - numSent, err := node.GetFacadeHandler().SendBulkTransactions(transactions) - require.NoError(t, err) - require.Equal(t, 300000, int(numSent)) - - time.Sleep(1 * time.Second) - require.Equal(t, 300000, int(mempool.GetCounts().GetTotal())) - - // Send one more transaction (fill up the mempool) - _, err = node.GetFacadeHandler().SendBulkTransactions([]*transaction.Transaction{ - { - Nonce: 42, - Value: oneEGLD, - SndAddr: senders[7].Bytes, - RcvAddr: receiver.Bytes, - Data: []byte{}, - GasLimit: 50000, - GasPrice: 1_000_000_000, - ChainID: []byte(configs.ChainID), - Version: 2, - Signature: []byte("signature"), - }, - }) - require.NoError(t, err) - - time.Sleep(42 * time.Millisecond) - require.Equal(t, 300001, int(mempool.GetCounts().GetTotal())) - - // Send one more transaction to trigger eviction - _, err = node.GetFacadeHandler().SendBulkTransactions([]*transaction.Transaction{ - { - Nonce: 42, - Value: oneEGLD, - SndAddr: senders[7].Bytes, - RcvAddr: receiver.Bytes, - Data: []byte{}, - GasLimit: 50000, - GasPrice: 1_000_000_000, - ChainID: []byte(configs.ChainID), - Version: 2, - Signature: []byte("signature"), - }, - }) - require.NoError(t, err) - - time.Sleep(1 * time.Second) - require.Equal(t, 300000+1+1-int(storage.TxPoolSourceMeNumItemsToPreemptivelyEvict), int(mempool.GetCounts().GetTotal())) -} - -func startChainSimulator(t *testing.T, alterConfigsFunction func(cfg *config.Configs), -) testsChainSimulator.ChainSimulator { - simulator, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: "../../../cmd/node/config/", - NumOfShards: 1, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: uint64(4000), - RoundsPerEpoch: core.OptionalUint64{ - HasValue: true, - Value: 10, - }, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: alterConfigsFunction, - }) - require.NoError(t, err) - require.NotNil(t, simulator) - - err = simulator.GenerateBlocksUntilEpochIsReached(1) - require.NoError(t, err) - - return simulator -} From e02d60795e54b2a4ad52c8b430480360dccc10ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Fri, 22 Nov 2024 11:22:18 +0200 Subject: [PATCH 35/39] In "interceptedHeader", handle concurrent access. --- consensus/broadcast/delayedBroadcast.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From 2d5281509c48a55d34c9eee76d021e61c29e37b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Sun, 24 Nov 2024 23:56:28 +0200 Subject: [PATCH 36/39] Handle non-executable transactions related to guardians in a separate PR. --- factory/processing/blockProcessorCreator.go | 1 - genesis/process/shardGenesisBlockCreator.go | 1 - go.mod | 2 +- go.sum | 4 +-- integrationTests/testProcessorNode.go | 1 - .../block/preprocess/accountStateProvider.go | 30 ++----------------- .../preprocess/accountStateProvider_test.go | 22 ++------------ process/block/preprocess/transactions.go | 6 +--- .../block/preprocess/transactionsV2_test.go | 2 -- process/block/preprocess/transactions_test.go | 12 -------- process/block/shardblock_test.go | 7 ----- process/coordinator/process_test.go | 10 ------- .../preProcessorsContainerFactory.go | 2 -- .../shard/preProcessorsContainerFactory.go | 6 ---- .../preProcessorsContainerFactory_test.go | 27 ----------------- 15 files changed, 10 insertions(+), 123 deletions(-) diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 9ee02fd676d..0721efc6a23 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -351,7 +351,6 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( scheduledTxsExecutionHandler, processedMiniBlocksTracker, pcf.txExecutionOrderHandler, - pcf.bootstrapComponents.GuardedAccountHandler(), ) if err != nil { return nil, err diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 4fd5354d716..2347632d2d5 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -600,7 +600,6 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo disabledScheduledTxsExecutionHandler, disabledProcessedMiniBlocksTracker, arg.TxExecutionOrderHandler, - disabledGuardian.NewDisabledGuardedAccountHandler(), ) if err != nil { return nil, err diff --git a/go.mod b/go.mod index e180c82d4c1..ec759eafde1 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.18-0.20241121073828-1b8274da896a + github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241124203643-93c958ad66cf 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 d725e6a1deb..6ab63332d8d 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.18-0.20241121073828-1b8274da896a h1:IFyDLwwVKkbvPZYUu/3JQ8Wv/H888ZkU3HnNLRWqx2c= -github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241121073828-1b8274da896a/go.mod h1:eFDEOrG7Wiyk5I/ObpwcN2eoBlOnnfeEMTvTer1cymk= +github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241124203643-93c958ad66cf h1:B+gMpLl+Jb9kZm25UfVy5cF4lsC6kS1l1wleX4J82/w= +github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241124203643-93c958ad66cf/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/testProcessorNode.go b/integrationTests/testProcessorNode.go index c74b1a73f15..80ba584c6b4 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1775,7 +1775,6 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u scheduledTxsExecutionHandler, processedMiniBlocksTracker, tpn.TxExecutionOrderHandler, - guardianChecker, ) tpn.PreProcessorsContainer, _ = fact.Create() diff --git a/process/block/preprocess/accountStateProvider.go b/process/block/preprocess/accountStateProvider.go index e80ae906e46..7a1f3576c49 100644 --- a/process/block/preprocess/accountStateProvider.go +++ b/process/block/preprocess/accountStateProvider.go @@ -6,7 +6,6 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage/txcache" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) type accountStateProvider struct { @@ -14,17 +13,13 @@ type accountStateProvider struct { guardianChecker process.GuardianChecker } -func newAccountStateProvider(accountsAdapter state.AccountsAdapter, guardianChecker process.GuardianChecker) (*accountStateProvider, error) { +func newAccountStateProvider(accountsAdapter state.AccountsAdapter) (*accountStateProvider, error) { if check.IfNil(accountsAdapter) { return nil, process.ErrNilAccountsAdapter } - if check.IfNil(guardianChecker) { - return nil, process.ErrNilGuardianChecker - } return &accountStateProvider{ accountsAdapter: accountsAdapter, - guardianChecker: guardianChecker, }, nil } @@ -41,31 +36,12 @@ func (provider *accountStateProvider) GetAccountState(address []byte) (*txcache. return nil, errors.ErrWrongTypeAssertion } - guardian, err := provider.getGuardian(userAccount) - if err != nil { - return nil, err - } - return &txcache.AccountState{ - Nonce: userAccount.GetNonce(), - Balance: userAccount.GetBalance(), - Guardian: guardian, + Nonce: userAccount.GetNonce(), + Balance: userAccount.GetBalance(), }, nil } -func (provider *accountStateProvider) getGuardian(userAccount state.UserAccountHandler) ([]byte, error) { - if !userAccount.IsGuarded() { - return nil, nil - } - - vmUserAccount, ok := userAccount.(vmcommon.UserAccountHandler) - if !ok { - return nil, errors.ErrWrongTypeAssertion - } - - return provider.guardianChecker.GetActiveGuardian(vmUserAccount) -} - // 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 index 5d5fb46f562..52edaaa0fd9 100644 --- a/process/block/preprocess/accountStateProvider_test.go +++ b/process/block/preprocess/accountStateProvider_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/multiversx/mx-chain-go/process" - "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/state" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" @@ -15,15 +14,11 @@ import ( func TestNewAccountStateProvider(t *testing.T) { t.Parallel() - provider, err := newAccountStateProvider(nil, &guardianMocks.GuardedAccountHandlerStub{}) + provider, err := newAccountStateProvider(nil) require.Nil(t, provider) require.ErrorIs(t, err, process.ErrNilAccountsAdapter) - provider, err = newAccountStateProvider(&state.AccountsStub{}, nil) - require.Nil(t, provider) - require.ErrorIs(t, err, process.ErrNilGuardianChecker) - - provider, err = newAccountStateProvider(&state.AccountsStub{}, &guardianMocks.GuardedAccountHandlerStub{}) + provider, err = newAccountStateProvider(&state.AccountsStub{}) require.NoError(t, err) require.NotNil(t, provider) } @@ -55,28 +50,17 @@ func TestAccountStateProvider_GetAccountState(t *testing.T) { return nil, fmt.Errorf("account not found: %s", address) } - guardianChecker := &guardianMocks.GuardedAccountHandlerStub{} - guardianChecker.GetActiveGuardianCalled = func(userAccount vmcommon.UserAccountHandler) ([]byte, error) { - if bytes.Equal(userAccount.AddressBytes(), []byte("bob")) { - return []byte("heidi"), nil - } - - return nil, nil - } - - provider, err := newAccountStateProvider(accounts, guardianChecker) + 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) - require.Nil(t, state.Guardian) state, err = provider.GetAccountState([]byte("bob")) require.NoError(t, err) require.Equal(t, uint64(7), state.Nonce) - require.Equal(t, []byte("heidi"), state.Guardian) state, err = provider.GetAccountState([]byte("carol")) require.ErrorContains(t, err, "account not found: carol") diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index 40f9dc79331..e18b1f6cce2 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -81,7 +81,6 @@ type ArgsTransactionPreProcessor struct { ScheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler ProcessedMiniBlocksTracker process.ProcessedMiniBlocksTracker TxExecutionOrderHandler common.TxExecutionOrderHandler - GuardianChecker process.GuardianChecker } // NewTransactionPreprocessor creates a new transaction preprocessor object @@ -155,11 +154,8 @@ func NewTransactionPreprocessor( if check.IfNil(args.TxExecutionOrderHandler) { return nil, process.ErrNilTxExecutionOrderHandler } - if check.IfNil(args.GuardianChecker) { - return nil, process.ErrNilGuardianChecker - } - accountStateProvider, err := newAccountStateProvider(args.Accounts, args.GuardianChecker) + accountStateProvider, err := newAccountStateProvider(args.Accounts) if err != nil { return nil, err } diff --git a/process/block/preprocess/transactionsV2_test.go b/process/block/preprocess/transactionsV2_test.go index 77c61877e65..9d4fb1cf686 100644 --- a/process/block/preprocess/transactionsV2_test.go +++ b/process/block/preprocess/transactionsV2_test.go @@ -18,7 +18,6 @@ import ( commonMocks "github.com/multiversx/mx-chain-go/testscommon/common" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" - "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -77,7 +76,6 @@ func createTransactionPreprocessor() *transactions { ScheduledTxsExecutionHandler: &testscommon.ScheduledTxsExecutionStub{}, ProcessedMiniBlocksTracker: &testscommon.ProcessedMiniBlocksTrackerStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, } preprocessor, _ := NewTransactionPreprocessor(txPreProcArgs) diff --git a/process/block/preprocess/transactions_test.go b/process/block/preprocess/transactions_test.go index d0d2eb1d8b9..cf1bcca2ec8 100644 --- a/process/block/preprocess/transactions_test.go +++ b/process/block/preprocess/transactions_test.go @@ -34,7 +34,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" - "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -239,7 +238,6 @@ func createDefaultTransactionsProcessorArgs() ArgsTransactionPreProcessor { ScheduledTxsExecutionHandler: &testscommon.ScheduledTxsExecutionStub{}, ProcessedMiniBlocksTracker: &testscommon.ProcessedMiniBlocksTrackerStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, } } @@ -458,16 +456,6 @@ func TestTxsPreprocessor_NewTransactionPreprocessorNilTxExecutionOrderHandler(t assert.Equal(t, process.ErrNilTxExecutionOrderHandler, err) } -func TestTxsPreprocessor_NewTransactionPreprocessorNilGuardianChecker(t *testing.T) { - t.Parallel() - - args := createDefaultTransactionsProcessorArgs() - args.GuardianChecker = nil - txs, err := NewTransactionPreprocessor(args) - assert.Nil(t, txs) - assert.Equal(t, process.ErrNilGuardianChecker, err) -} - func TestTxsPreprocessor_NewTransactionPreprocessorOkValsShouldWork(t *testing.T) { t.Parallel() diff --git a/process/block/shardblock_test.go b/process/block/shardblock_test.go index e08bf3dd1c8..d029b44e65b 100644 --- a/process/block/shardblock_test.go +++ b/process/block/shardblock_test.go @@ -44,7 +44,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" - "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/outport" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -479,7 +478,6 @@ func TestShardProcessor_ProcessBlockWithInvalidTransactionShouldErr(t *testing.T &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() @@ -702,7 +700,6 @@ func TestShardProcessor_ProcessBlockWithErrOnProcessBlockTransactionsCallShouldR &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() @@ -2599,7 +2596,6 @@ func TestShardProcessor_MarshalizedDataToBroadcastShouldWork(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() @@ -2709,7 +2705,6 @@ func TestShardProcessor_MarshalizedDataMarshalWithoutSuccess(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() @@ -3111,7 +3106,6 @@ func TestShardProcessor_CreateMiniBlocksShouldWorkWithIntraShardTxs(t *testing.T &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() @@ -3294,7 +3288,6 @@ func TestShardProcessor_RestoreBlockIntoPoolsShouldWork(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := factory.Create() diff --git a/process/coordinator/process_test.go b/process/coordinator/process_test.go index b2d782029ab..85eeabf1008 100644 --- a/process/coordinator/process_test.go +++ b/process/coordinator/process_test.go @@ -41,7 +41,6 @@ import ( dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" - "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -561,7 +560,6 @@ func createPreProcessorContainer() process.PreProcessorsContainer { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -662,7 +660,6 @@ func createPreProcessorContainerWithDataPool( &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -933,7 +930,6 @@ func TestTransactionCoordinator_CreateMbsAndProcessCrossShardTransactions(t *tes &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -1121,7 +1117,6 @@ func TestTransactionCoordinator_CreateMbsAndProcessCrossShardTransactionsNilPreP &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -1231,7 +1226,6 @@ func TestTransactionCoordinator_CreateMbsAndProcessTransactionsFromMeNothingToPr &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -1811,7 +1805,6 @@ func TestTransactionCoordinator_ProcessBlockTransactionProcessTxError(t *testing &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -1939,7 +1932,6 @@ func TestTransactionCoordinator_RequestMiniblocks(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -2081,7 +2073,6 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithOkTxsShouldExecuteThemAndNot &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() @@ -2224,7 +2215,6 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithErrorWhileProcessShouldCallR &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) container, _ := preFactory.Create() diff --git a/process/factory/metachain/preProcessorsContainerFactory.go b/process/factory/metachain/preProcessorsContainerFactory.go index 5d7f59bf8d7..4354a80ab1e 100644 --- a/process/factory/metachain/preProcessorsContainerFactory.go +++ b/process/factory/metachain/preProcessorsContainerFactory.go @@ -11,7 +11,6 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/block/preprocess" "github.com/multiversx/mx-chain-go/process/factory/containers" - "github.com/multiversx/mx-chain-go/process/guardian/disabled" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/state" ) @@ -199,7 +198,6 @@ func (ppcm *preProcessorsContainerFactory) createTxPreProcessor() (process.PrePr ScheduledTxsExecutionHandler: ppcm.scheduledTxsExecutionHandler, ProcessedMiniBlocksTracker: ppcm.processedMiniBlocksTracker, TxExecutionOrderHandler: ppcm.txExecutionOrderHandler, - GuardianChecker: disabled.NewDisabledGuardedAccountHandler(), } txPreprocessor, err := preprocess.NewTransactionPreprocessor(args) diff --git a/process/factory/shard/preProcessorsContainerFactory.go b/process/factory/shard/preProcessorsContainerFactory.go index cd799b8857a..232d115385c 100644 --- a/process/factory/shard/preProcessorsContainerFactory.go +++ b/process/factory/shard/preProcessorsContainerFactory.go @@ -67,7 +67,6 @@ func NewPreProcessorsContainerFactory( scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler, processedMiniBlocksTracker process.ProcessedMiniBlocksTracker, txExecutionOrderHandler common.TxExecutionOrderHandler, - guardianChecker process.GuardianChecker, ) (*preProcessorsContainerFactory, error) { if check.IfNil(shardCoordinator) { @@ -136,9 +135,6 @@ func NewPreProcessorsContainerFactory( if check.IfNil(txExecutionOrderHandler) { return nil, process.ErrNilTxExecutionOrderHandler } - if check.IfNil(guardianChecker) { - return nil, process.ErrNilGuardianChecker - } return &preProcessorsContainerFactory{ shardCoordinator: shardCoordinator, @@ -163,7 +159,6 @@ func NewPreProcessorsContainerFactory( scheduledTxsExecutionHandler: scheduledTxsExecutionHandler, processedMiniBlocksTracker: processedMiniBlocksTracker, txExecutionOrderHandler: txExecutionOrderHandler, - guardianChecker: guardianChecker, }, nil } @@ -236,7 +231,6 @@ func (ppcm *preProcessorsContainerFactory) createTxPreProcessor() (process.PrePr ScheduledTxsExecutionHandler: ppcm.scheduledTxsExecutionHandler, ProcessedMiniBlocksTracker: ppcm.processedMiniBlocksTracker, TxExecutionOrderHandler: ppcm.txExecutionOrderHandler, - GuardianChecker: ppcm.guardianChecker, } txPreprocessor, err := preprocess.NewTransactionPreprocessor(args) diff --git a/process/factory/shard/preProcessorsContainerFactory_test.go b/process/factory/shard/preProcessorsContainerFactory_test.go index 02c9ffe4d7f..f273a5e64f3 100644 --- a/process/factory/shard/preProcessorsContainerFactory_test.go +++ b/process/factory/shard/preProcessorsContainerFactory_test.go @@ -11,7 +11,6 @@ import ( dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" - "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -48,7 +47,6 @@ func TestNewPreProcessorsContainerFactory_NilShardCoordinator(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilShardCoordinator, err) @@ -81,7 +79,6 @@ func TestNewPreProcessorsContainerFactory_NilStore(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilStore, err) @@ -114,7 +111,6 @@ func TestNewPreProcessorsContainerFactory_NilMarshalizer(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilMarshalizer, err) @@ -147,7 +143,6 @@ func TestNewPreProcessorsContainerFactory_NilHasher(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilHasher, err) @@ -180,7 +175,6 @@ func TestNewPreProcessorsContainerFactory_NilDataPool(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilDataPoolHolder, err) @@ -213,7 +207,6 @@ func TestNewPreProcessorsContainerFactory_NilAddrConv(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilPubkeyConverter, err) @@ -246,7 +239,6 @@ func TestNewPreProcessorsContainerFactory_NilAccounts(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilAccountsAdapter, err) @@ -279,7 +271,6 @@ func TestNewPreProcessorsContainerFactory_NilTxProcessor(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilTxProcessor, err) @@ -312,7 +303,6 @@ func TestNewPreProcessorsContainerFactory_NilSCProcessor(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilSmartContractProcessor, err) @@ -345,7 +335,6 @@ func TestNewPreProcessorsContainerFactory_NilSCR(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilSmartContractResultProcessor, err) @@ -378,7 +367,6 @@ func TestNewPreProcessorsContainerFactory_NilRewardTxProcessor(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilRewardsTxProcessor, err) @@ -411,7 +399,6 @@ func TestNewPreProcessorsContainerFactory_NilRequestHandler(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilRequestHandler, err) @@ -444,7 +431,6 @@ func TestNewPreProcessorsContainerFactory_NilFeeHandler(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilEconomicsFeeHandler, err) @@ -477,7 +463,6 @@ func TestNewPreProcessorsContainerFactory_NilGasHandler(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilGasHandler, err) @@ -510,7 +495,6 @@ func TestNewPreProcessorsContainerFactory_NilBlockTracker(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilBlockTracker, err) @@ -543,7 +527,6 @@ func TestNewPreProcessorsContainerFactory_NilBlockSizeComputationHandler(t *test &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilBlockSizeComputationHandler, err) @@ -576,7 +559,6 @@ func TestNewPreProcessorsContainerFactory_NilBalanceComputationHandler(t *testin &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilBalanceComputationHandler, err) @@ -609,7 +591,6 @@ func TestNewPreProcessorsContainerFactory_NilEnableEpochsHandler(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilEnableEpochsHandler, err) @@ -642,7 +623,6 @@ func TestNewPreProcessorsContainerFactory_NilTxTypeHandler(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilTxTypeHandler, err) @@ -675,7 +655,6 @@ func TestNewPreProcessorsContainerFactory_NilScheduledTxsExecutionHandler(t *tes nil, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilScheduledTxsExecutionHandler, err) @@ -708,7 +687,6 @@ func TestNewPreProcessorsContainerFactory_NilProcessedMiniBlocksTracker(t *testi &testscommon.ScheduledTxsExecutionStub{}, nil, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilProcessedMiniBlocksTracker, err) @@ -741,7 +719,6 @@ func TestNewPreProcessorsContainerFactory_NilTxExecutionOrderHandler(t *testing. &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, nil, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Equal(t, process.ErrNilTxExecutionOrderHandler, err) @@ -774,7 +751,6 @@ func TestNewPreProcessorsContainerFactory(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Nil(t, err) @@ -812,7 +788,6 @@ func TestPreProcessorsContainerFactory_CreateErrTxPreproc(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Nil(t, err) @@ -856,7 +831,6 @@ func TestPreProcessorsContainerFactory_CreateErrScrPreproc(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Nil(t, err) @@ -903,7 +877,6 @@ func TestPreProcessorsContainerFactory_Create(t *testing.T) { &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonMock.TxExecutionOrderHandlerStub{}, - &guardianMocks.GuardedAccountHandlerStub{}, ) assert.Nil(t, err) From 2a160f321e4a3def497ed89cac5dd519fbfc12aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 25 Nov 2024 09:34:32 +0200 Subject: [PATCH 37/39] Fix linter issues. --- process/block/preprocess/accountStateProvider.go | 1 - process/factory/shard/preProcessorsContainerFactory.go | 1 - 2 files changed, 2 deletions(-) diff --git a/process/block/preprocess/accountStateProvider.go b/process/block/preprocess/accountStateProvider.go index 7a1f3576c49..736a9247659 100644 --- a/process/block/preprocess/accountStateProvider.go +++ b/process/block/preprocess/accountStateProvider.go @@ -10,7 +10,6 @@ import ( type accountStateProvider struct { accountsAdapter state.AccountsAdapter - guardianChecker process.GuardianChecker } func newAccountStateProvider(accountsAdapter state.AccountsAdapter) (*accountStateProvider, error) { diff --git a/process/factory/shard/preProcessorsContainerFactory.go b/process/factory/shard/preProcessorsContainerFactory.go index 232d115385c..a561412737b 100644 --- a/process/factory/shard/preProcessorsContainerFactory.go +++ b/process/factory/shard/preProcessorsContainerFactory.go @@ -40,7 +40,6 @@ type preProcessorsContainerFactory struct { scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler processedMiniBlocksTracker process.ProcessedMiniBlocksTracker txExecutionOrderHandler common.TxExecutionOrderHandler - guardianChecker process.GuardianChecker } // NewPreProcessorsContainerFactory is responsible for creating a new preProcessors factory object From 47159a50563846d3eb5ed7c261f7acd82a821c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 25 Nov 2024 11:14:53 +0200 Subject: [PATCH 38/39] (final) fix after self-review. --- .../preprocess/accountStateProvider_test.go | 2 -- process/block/preprocess/transactions.go | 21 ------------------- 2 files changed, 23 deletions(-) diff --git a/process/block/preprocess/accountStateProvider_test.go b/process/block/preprocess/accountStateProvider_test.go index 52edaaa0fd9..b4ea6637308 100644 --- a/process/block/preprocess/accountStateProvider_test.go +++ b/process/block/preprocess/accountStateProvider_test.go @@ -28,7 +28,6 @@ func TestAccountStateProvider_GetAccountState(t *testing.T) { accounts := &state.AccountsStub{} accounts.GetExistingAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { - // Alice has no guardian if bytes.Equal(address, []byte("alice")) { return &state.UserAccountStub{ Address: []byte("alice"), @@ -36,7 +35,6 @@ func TestAccountStateProvider_GetAccountState(t *testing.T) { }, nil } - // Bob has Heidi as guardian if bytes.Equal(address, []byte("bob")) { return &state.UserAccountStub{ Address: []byte("bob"), diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index e18b1f6cce2..85ef9f5fc2e 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -31,7 +31,6 @@ var _ process.DataMarshalizer = (*transactions)(nil) var _ process.PreProcessor = (*transactions)(nil) var log = logger.GetOrCreate("process/block/preprocess") -var logSelectionSimulator = logger.GetOrCreate("process/block/preprocess/selectionSimulator") // 200% bandwidth to allow 100% overshooting estimations const selectionGasBandwidthIncreasePercent = 200 @@ -797,26 +796,6 @@ func (txs *transactions) CreateBlockStarted() { txs.mutOrderedTxs.Unlock() txs.scheduledTxsExecutionHandler.Init() - - txs.simulateTransactionsSelectionIfAppropriate() -} - -func (txs *transactions) simulateTransactionsSelectionIfAppropriate() { - if logSelectionSimulator.GetLevel() > logger.LogTrace { - return - } - - shardID := txs.shardCoordinator.SelfId() - cacheID := process.ShardCacherIdentifier(shardID, shardID) - mempool := txs.txPool.ShardDataStore(cacheID) - if check.IfNil(mempool) { - return - } - - sortedTransactionsProvider := createSortedTransactionsProvider(mempool) - transactions := sortedTransactionsProvider.GetSortedTransactions(txs.accountStateProvider) - - logSelectionSimulator.Trace("simulateTransactionsSelectionIfAppropriate", "num txs", len(transactions)) } // AddTxsFromMiniBlocks will add the transactions from the provided miniblocks into the internal cache From 25b2594fcf93c5457f11328fc04b0523576ac3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 26 Nov 2024 22:14:14 +0200 Subject: [PATCH 39/39] Fix after review. --- go.mod | 2 +- go.sum | 4 ++-- process/block/preprocess/transactions.go | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index ec759eafde1..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.18-0.20241124203643-93c958ad66cf + 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 6ab63332d8d..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.18-0.20241124203643-93c958ad66cf h1:B+gMpLl+Jb9kZm25UfVy5cF4lsC6kS1l1wleX4J82/w= -github.com/multiversx/mx-chain-storage-go v1.0.18-0.20241124203643-93c958ad66cf/go.mod h1:eFDEOrG7Wiyk5I/ObpwcN2eoBlOnnfeEMTvTer1cymk= +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/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index 85ef9f5fc2e..567569f6dc6 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -33,10 +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 +const selectionGasBandwidthIncreaseScheduledPercent = 260 // TODO: increase code coverage with unit test @@ -154,7 +154,7 @@ func NewTransactionPreprocessor( return nil, process.ErrNilTxExecutionOrderHandler } - accountStateProvider, err := newAccountStateProvider(args.Accounts) + stateProvider, err := newAccountStateProvider(args.Accounts) if err != nil { return nil, err } @@ -170,7 +170,7 @@ func NewTransactionPreprocessor( blockSizeComputation: args.BlockSizeComputation, balanceComputation: args.BalanceComputation, accounts: args.Accounts, - accountStateProvider: accountStateProvider, + accountStateProvider: stateProvider, pubkeyConverter: args.PubkeyConverter, enableEpochsHandler: args.EnableEpochsHandler, processedMiniBlocksTracker: args.ProcessedMiniBlocksTracker,