Skip to content

Commit

Permalink
Merge pull request #5648 from multiversx/adjust-max-tx-nonce-delta-co…
Browse files Browse the repository at this point in the history
…nstant

Changed `MaxTxNonceDeltaAllowed` constant
  • Loading branch information
iulianpascalau authored Oct 10, 2023
2 parents 2ff8027 + 165ac12 commit 1eda4ce
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 6 deletions.
2 changes: 1 addition & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
for 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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions integrationTests/testProcessorNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion integrationTests/vm/esdt/process/esdtProcess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2098,7 +2098,7 @@ func TestIssueAndBurnESDT_MaxGasPerBlockExceeded(t *testing.T) {
}

numIssues := 22
numBurns := 300
numBurns := 50

numOfShards := 1
nodesPerShard := 1
Expand Down

0 comments on commit 1eda4ce

Please sign in to comment.