From 2fcbcc53c1ae39fdffe527b352ab9f6f294f9cd8 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Fri, 6 Oct 2023 17:37:53 +0300 Subject: [PATCH 1/3] - changed constant, adapted tests --- common/constants.go | 2 +- .../transaction/interceptedBulkTx/interceptedBulkTx_test.go | 3 ++- integrationTests/testProcessorNode.go | 5 ++--- integrationTests/vm/esdt/process/esdtProcess_test.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/constants.go b/common/constants.go index 831ce0b9bcc..223dcebd189 100644 --- a/common/constants.go +++ b/common/constants.go @@ -54,7 +54,7 @@ const DisabledShardIDAsObserver = uint32(0xFFFFFFFF) - 7 // MaxTxNonceDeltaAllowed specifies the maximum difference between an account's nonce and a received transaction's nonce // in order to mark the transaction as valid. -const MaxTxNonceDeltaAllowed = 30000 +const MaxTxNonceDeltaAllowed = 100 // MaxBulkTransactionSize specifies the maximum size of one bulk with txs which can be send over the network // TODO convert this const into a var and read it from config when this code moves to another binary diff --git a/integrationTests/singleShard/transaction/interceptedBulkTx/interceptedBulkTx_test.go b/integrationTests/singleShard/transaction/interceptedBulkTx/interceptedBulkTx_test.go index fab7310acb5..683aad582cf 100644 --- a/integrationTests/singleShard/transaction/interceptedBulkTx/interceptedBulkTx_test.go +++ b/integrationTests/singleShard/transaction/interceptedBulkTx/interceptedBulkTx_test.go @@ -12,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-crypto-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/process" "github.com/stretchr/testify/assert" @@ -43,7 +44,7 @@ func TestNode_GenerateSendInterceptBulkTransactionsWithMessenger(t *testing.T) { //set the account's nonce to startingNonce _ = n.SetAccountNonce(startingNonce) - noOfTx := 8000 + noOfTx := common.MaxTxNonceDeltaAllowed time.Sleep(stepDelay) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 99d47fa1fd4..9e599debbd7 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -189,7 +189,6 @@ var MinTxGasLimit = uint64(1000) // MaxGasLimitPerBlock defines maximum gas limit allowed per one block const MaxGasLimitPerBlock = uint64(3000000) -const maxTxNonceDeltaAllowed = 8000 const minConnectedPeers = 0 // OpGasValueForMockVm represents the gas value that it consumed by each operation called on the mock VM @@ -1304,7 +1303,7 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { FullArchiveMessenger: tpn.FullArchiveMessenger, Store: tpn.Storage, DataPool: tpn.DataPool, - MaxTxNonceDeltaAllowed: maxTxNonceDeltaAllowed, + MaxTxNonceDeltaAllowed: common.MaxTxNonceDeltaAllowed, TxFeeHandler: tpn.EconomicsData, BlockBlackList: tpn.BlockBlackListHandler, HeaderSigVerifier: tpn.HeaderSigVerifier, @@ -1372,7 +1371,7 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { FullArchiveMessenger: tpn.FullArchiveMessenger, Store: tpn.Storage, DataPool: tpn.DataPool, - MaxTxNonceDeltaAllowed: maxTxNonceDeltaAllowed, + MaxTxNonceDeltaAllowed: common.MaxTxNonceDeltaAllowed, TxFeeHandler: tpn.EconomicsData, BlockBlackList: tpn.BlockBlackListHandler, HeaderSigVerifier: tpn.HeaderSigVerifier, diff --git a/integrationTests/vm/esdt/process/esdtProcess_test.go b/integrationTests/vm/esdt/process/esdtProcess_test.go index b409104e0af..baae1e5346e 100644 --- a/integrationTests/vm/esdt/process/esdtProcess_test.go +++ b/integrationTests/vm/esdt/process/esdtProcess_test.go @@ -2098,7 +2098,7 @@ func TestIssueAndBurnESDT_MaxGasPerBlockExceeded(t *testing.T) { } numIssues := 22 - numBurns := 300 + numBurns := 50 numOfShards := 1 nodesPerShard := 1 From 788205e9f907003e5c70c0fbc6a7c6a73cf2e3ba Mon Sep 17 00:00:00 2001 From: jules01 Date: Mon, 9 Oct 2023 18:05:30 +0300 Subject: [PATCH 2/3] - added integration test --- .../transactions/transactionsRequest_test.go | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 integrationTests/resolvers/transactions/transactionsRequest_test.go diff --git a/integrationTests/resolvers/transactions/transactionsRequest_test.go b/integrationTests/resolvers/transactions/transactionsRequest_test.go new file mode 100644 index 00000000000..29ab8654206 --- /dev/null +++ b/integrationTests/resolvers/transactions/transactionsRequest_test.go @@ -0,0 +1,84 @@ +package transactions + +import ( + "math/big" + "sync" + "testing" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-crypto-go/signing" + ed255192 "github.com/multiversx/mx-chain-crypto-go/signing/ed25519" + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/integrationTests" + "github.com/multiversx/mx-chain-go/integrationTests/resolvers" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/state" +) + +func TestTransactionsRequestsShouldWorkForHigherMaxTxNonceDeltaAllowed(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + numTxs := common.MaxTxNonceDeltaAllowed * 3 + mutMap := sync.Mutex{} + txHashesMap := make(map[string]struct{}) + + rm := resolvers.NewReceiverMonitor(t) + shardIdResolver := uint32(0) + shardIdRequester := uint32(0) + nResolver, nRequester := resolvers.CreateResolverRequester(shardIdResolver, shardIdRequester) + defer func() { + nRequester.Close() + nResolver.Close() + }() + + nRequester.DataPool.Transactions().RegisterOnAdded(func(key []byte, value interface{}) { + hash := string(key) + + mutMap.Lock() + txHashesMap[hash] = struct{}{} + if len(txHashesMap) == numTxs { + rm.Done() + } + mutMap.Unlock() + }) + + txHashes := make([][]byte, 0, numTxs) + txSuite := ed255192.NewEd25519() + txKeyGen := signing.NewKeyGenerator(txSuite) + sk, pk := txKeyGen.GeneratePair() + senderBytes, _ := pk.ToByteArray() + if nResolver.ShardCoordinator.ComputeId(senderBytes) != shardIdResolver { + sk, pk = txKeyGen.GeneratePair() + senderBytes, _ = pk.ToByteArray() + } + + cacheId := process.ShardCacherIdentifier(shardIdRequester, shardIdResolver) + for i := 0; i < numTxs; i++ { + tx := integrationTests.GenerateTransferTx( + uint64(i), + sk, + pk, + big.NewInt(0), + integrationTests.MinTxGasPrice, + integrationTests.MinTxGasLimit, + integrationTests.ChainID, + 1, + ) + + txHash, _ := core.CalculateHash(integrationTests.TestMarshalizer, integrationTests.TestHasher, tx) + nResolver.DataPool.Transactions().AddData(txHash, tx, 0, cacheId) + txHashes = append(txHashes, txHash) + } + + account, _ := nRequester.AccntState.LoadAccount(senderBytes) + userAccount := account.(state.UserAccountHandler) + _ = userAccount.AddToBalance(big.NewInt(1000)) + _ = nRequester.AccntState.SaveAccount(account) + _, _ = nRequester.AccntState.Commit() + + nRequester.RequestHandler.RequestTransaction(shardIdResolver, txHashes) + + rm.WaitWithTimeout() +} From fba921bf386cdcb19bc24b4e197580670e014bff Mon Sep 17 00:00:00 2001 From: jules01 Date: Tue, 10 Oct 2023 10:14:09 +0300 Subject: [PATCH 3/3] - fix test --- .../resolvers/transactions/transactionsRequest_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/resolvers/transactions/transactionsRequest_test.go b/integrationTests/resolvers/transactions/transactionsRequest_test.go index 29ab8654206..fc116f02fda 100644 --- a/integrationTests/resolvers/transactions/transactionsRequest_test.go +++ b/integrationTests/resolvers/transactions/transactionsRequest_test.go @@ -49,7 +49,7 @@ func TestTransactionsRequestsShouldWorkForHigherMaxTxNonceDeltaAllowed(t *testin txKeyGen := signing.NewKeyGenerator(txSuite) sk, pk := txKeyGen.GeneratePair() senderBytes, _ := pk.ToByteArray() - if nResolver.ShardCoordinator.ComputeId(senderBytes) != shardIdResolver { + for nResolver.ShardCoordinator.ComputeId(senderBytes) != shardIdResolver { sk, pk = txKeyGen.GeneratePair() senderBytes, _ = pk.ToByteArray() }