Skip to content

Commit

Permalink
Merge branch 'rc/v1.6.0' into dependabot/go_modules/master/github.com…
Browse files Browse the repository at this point in the history
…/beevik/ntp-1.3.0
  • Loading branch information
iulianpascalau authored Oct 11, 2023
2 parents d1e6846 + 1eda4ce commit 14820d2
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 37 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
4 changes: 3 additions & 1 deletion docker/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:1.20.7 as builder

RUN apt-get update && apt-get install -y
RUN apt-get update && apt-get upgrade -y
WORKDIR /go/mx-chain-go
COPY . .
RUN go mod tidy
Expand All @@ -11,8 +11,10 @@ RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-
RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-go | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer2/libvmexeccapi.so /lib/libvmexeccapi.so

WORKDIR /go/mx-chain-go/cmd/node

# ===== SECOND STAGE ======
FROM ubuntu:22.04
RUN apt-get update && apt-get upgrade -y
COPY --from=builder "/go/mx-chain-go/cmd/node" "/go/mx-chain-go/cmd/node/"
COPY --from=builder "/lib/libwasmer_linux_amd64.so" "/lib/libwasmer_linux_amd64.so"
COPY --from=builder "/lib/libvmexeccapi.so" "/lib/libvmexeccapi.so"
Expand Down
27 changes: 27 additions & 0 deletions examples/construction_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package examples

import (
"bytes"
"encoding/hex"
"fmt"
"math"
Expand Down Expand Up @@ -146,6 +147,32 @@ func TestConstructTransaction_WithDataWithLargeValue(t *testing.T) {
require.Equal(t, "e4a6048d92409cfe50f12e81218cb92f39966c618979a693b8d16320a06061c1", hex.EncodeToString(txHash))
}

func TestConstructTransaction_WithGuardianFields(t *testing.T) {
tx := &transaction.Transaction{
Nonce: 92,
Value: stringToBigInt("123456789000000000000000000000"),
RcvAddr: getPubkeyOfAddress(t, "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"),
SndAddr: getPubkeyOfAddress(t, "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"),
GasPrice: 1000000000,
GasLimit: 150000,
Data: []byte("test data field"),
ChainID: []byte("local-testnet"),
Version: 1,
}

tx.GuardianAddr = getPubkeyOfAddress(t, "erd1x23lzn8483xs2su4fak0r0dqx6w38enpmmqf2yrkylwq7mfnvyhsxqw57y")
tx.GuardianSignature = bytes.Repeat([]byte{0}, 64)

tx.Signature = computeTransactionSignature(t, alicePrivateKeyHex, tx)
require.Equal(t, "540ad16e46f379f9adcb7b26c07b16a56f10c624c489103679e488c0a0cb996c71dbc0d765cf925e58cd493d09d8c1d619946618ebd8a2fb924b236b8137c706", hex.EncodeToString(tx.Signature))

data, _ := contentMarshalizer.Marshal(tx)
require.Equal(t, "085c120e00018ee90ff6181f3761632000001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc0340f093094a0f746573742064617461206669656c64520d6c6f63616c2d746573746e657458016240540ad16e46f379f9adcb7b26c07b16a56f10c624c489103679e488c0a0cb996c71dbc0d765cf925e58cd493d09d8c1d619946618ebd8a2fb924b236b8137c706722032a3f14cf53c4d0543954f6cf1bda0369d13e661dec095107627dc0f6d33612f7a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", hex.EncodeToString(data))

txHash := contentHasher.Compute(string(data))
require.Equal(t, "a5e63b5bf3b7eeb347cad1aa742770a29c7a88e59ac99cdc60dc612ebdc8a7d4", hex.EncodeToString(txHash))
}

func TestConstructTransaction_WithNonceZero(t *testing.T) {
tx := &transaction.Transaction{
Nonce: 0,
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 Expand Up @@ -154,5 +155,5 @@ func TestNode_SendTransactionFromAnUnmintedAccountShouldReturnErrorAtApiLevel(t
tx.Signature, _ = node.OwnAccount.SingleSigner.Sign(node.OwnAccount.SkTxSign, txBuff)

err := node.Node.ValidateTransaction(tx)
assert.True(t, errors.Is(err, process.ErrAccountNotFound))
assert.True(t, errors.Is(err, process.ErrInsufficientFunds))
}
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
33 changes: 17 additions & 16 deletions node/external/blockAPI/baseBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (bap *baseAPIBlockProcessor) getIntrashardMiniblocksFromReceiptsStorage(hea

apiMiniblocks := make([]*api.MiniBlock, 0, len(receiptsHolder.GetMiniblocks()))
for _, miniblock := range receiptsHolder.GetMiniblocks() {
apiMiniblock, err := bap.convertMiniblockFromReceiptsStorageToApiMiniblock(miniblock, header.GetEpoch(), options)
apiMiniblock, err := bap.convertMiniblockFromReceiptsStorageToApiMiniblock(miniblock, header, options)
if err != nil {
return nil, err
}
Expand All @@ -82,7 +82,7 @@ func (bap *baseAPIBlockProcessor) getIntrashardMiniblocksFromReceiptsStorage(hea
return apiMiniblocks, nil
}

func (bap *baseAPIBlockProcessor) convertMiniblockFromReceiptsStorageToApiMiniblock(miniblock *block.MiniBlock, epoch uint32, options api.BlockQueryOptions) (*api.MiniBlock, error) {
func (bap *baseAPIBlockProcessor) convertMiniblockFromReceiptsStorageToApiMiniblock(miniblock *block.MiniBlock, header data.HeaderHandler, options api.BlockQueryOptions) (*api.MiniBlock, error) {
mbHash, err := core.CalculateHash(bap.marshalizer, bap.hasher, miniblock)
if err != nil {
return nil, err
Expand All @@ -102,7 +102,7 @@ func (bap *baseAPIBlockProcessor) convertMiniblockFromReceiptsStorageToApiMinibl
firstProcessed := int32(0)
lastProcessed := int32(len(miniblock.TxHashes) - 1)

err = bap.getAndAttachTxsToMbByEpoch(mbHash, miniblock, epoch, miniblockAPI, firstProcessed, lastProcessed, options)
err = bap.getAndAttachTxsToMbByEpoch(mbHash, miniblock, header, miniblockAPI, firstProcessed, lastProcessed, options)
if err != nil {
return nil, err
}
Expand All @@ -113,19 +113,19 @@ func (bap *baseAPIBlockProcessor) convertMiniblockFromReceiptsStorageToApiMinibl

func (bap *baseAPIBlockProcessor) getAndAttachTxsToMb(
mbHeader data.MiniBlockHeaderHandler,
epoch uint32,
header data.HeaderHandler,
apiMiniblock *api.MiniBlock,
options api.BlockQueryOptions,
) error {
miniblockHash := mbHeader.GetHash()
miniBlock, err := bap.getMiniblockByHashAndEpoch(miniblockHash, epoch)
miniBlock, err := bap.getMiniblockByHashAndEpoch(miniblockHash, header.GetEpoch())
if err != nil {
return err
}

firstProcessed := mbHeader.GetIndexOfFirstTxProcessed()
lastProcessed := mbHeader.GetIndexOfLastTxProcessed()
return bap.getAndAttachTxsToMbByEpoch(miniblockHash, miniBlock, epoch, apiMiniblock, firstProcessed, lastProcessed, options)
return bap.getAndAttachTxsToMbByEpoch(miniblockHash, miniBlock, header, apiMiniblock, firstProcessed, lastProcessed, options)
}

func (bap *baseAPIBlockProcessor) getMiniblockByHashAndEpoch(miniblockHash []byte, epoch uint32) (*block.MiniBlock, error) {
Expand All @@ -146,7 +146,7 @@ func (bap *baseAPIBlockProcessor) getMiniblockByHashAndEpoch(miniblockHash []byt
func (bap *baseAPIBlockProcessor) getAndAttachTxsToMbByEpoch(
miniblockHash []byte,
miniBlock *block.MiniBlock,
epoch uint32,
header data.HeaderHandler,
apiMiniblock *api.MiniBlock,
firstProcessedTxIndex int32,
lastProcessedTxIndex int32,
Expand All @@ -156,23 +156,23 @@ func (bap *baseAPIBlockProcessor) getAndAttachTxsToMbByEpoch(

switch miniBlock.Type {
case block.TxBlock:
apiMiniblock.Transactions, err = bap.getTxsFromMiniblock(miniBlock, miniblockHash, epoch, transaction.TxTypeNormal, dataRetriever.TransactionUnit, firstProcessedTxIndex, lastProcessedTxIndex)
apiMiniblock.Transactions, err = bap.getTxsFromMiniblock(miniBlock, miniblockHash, header, transaction.TxTypeNormal, dataRetriever.TransactionUnit, firstProcessedTxIndex, lastProcessedTxIndex)
case block.RewardsBlock:
apiMiniblock.Transactions, err = bap.getTxsFromMiniblock(miniBlock, miniblockHash, epoch, transaction.TxTypeReward, dataRetriever.RewardTransactionUnit, firstProcessedTxIndex, lastProcessedTxIndex)
apiMiniblock.Transactions, err = bap.getTxsFromMiniblock(miniBlock, miniblockHash, header, transaction.TxTypeReward, dataRetriever.RewardTransactionUnit, firstProcessedTxIndex, lastProcessedTxIndex)
case block.SmartContractResultBlock:
apiMiniblock.Transactions, err = bap.getTxsFromMiniblock(miniBlock, miniblockHash, epoch, transaction.TxTypeUnsigned, dataRetriever.UnsignedTransactionUnit, firstProcessedTxIndex, lastProcessedTxIndex)
apiMiniblock.Transactions, err = bap.getTxsFromMiniblock(miniBlock, miniblockHash, header, transaction.TxTypeUnsigned, dataRetriever.UnsignedTransactionUnit, firstProcessedTxIndex, lastProcessedTxIndex)
case block.InvalidBlock:
apiMiniblock.Transactions, err = bap.getTxsFromMiniblock(miniBlock, miniblockHash, epoch, transaction.TxTypeInvalid, dataRetriever.TransactionUnit, firstProcessedTxIndex, lastProcessedTxIndex)
apiMiniblock.Transactions, err = bap.getTxsFromMiniblock(miniBlock, miniblockHash, header, transaction.TxTypeInvalid, dataRetriever.TransactionUnit, firstProcessedTxIndex, lastProcessedTxIndex)
case block.ReceiptBlock:
apiMiniblock.Receipts, err = bap.getReceiptsFromMiniblock(miniBlock, epoch)
apiMiniblock.Receipts, err = bap.getReceiptsFromMiniblock(miniBlock, header.GetEpoch())
}

if err != nil {
return err
}

if options.WithLogs {
err = bap.logsFacade.IncludeLogsInTransactions(apiMiniblock.Transactions, miniBlock.TxHashes, epoch)
err = bap.logsFacade.IncludeLogsInTransactions(apiMiniblock.Transactions, miniBlock.TxHashes, header.GetEpoch())
if err != nil {
return err
}
Expand Down Expand Up @@ -210,7 +210,7 @@ func (bap *baseAPIBlockProcessor) getReceiptsFromMiniblock(miniblock *block.Mini
func (bap *baseAPIBlockProcessor) getTxsFromMiniblock(
miniblock *block.MiniBlock,
miniblockHash []byte,
epoch uint32,
header data.HeaderHandler,
txType transaction.TxType,
unit dataRetriever.UnitType,
firstProcessedTxIndex int32,
Expand All @@ -224,7 +224,7 @@ func (bap *baseAPIBlockProcessor) getTxsFromMiniblock(
start := time.Now()

executedTxHashes := extractExecutedTxHashes(miniblock.TxHashes, firstProcessedTxIndex, lastProcessedTxIndex)
marshalledTxs, err := storer.GetBulkFromEpoch(executedTxHashes, epoch)
marshalledTxs, err := storer.GetBulkFromEpoch(executedTxHashes, header.GetEpoch())
if err != nil {
return nil, fmt.Errorf("%w: %v, miniblock = %s", errCannotLoadTransactions, err, hex.EncodeToString(miniblockHash))
}
Expand All @@ -243,7 +243,8 @@ func (bap *baseAPIBlockProcessor) getTxsFromMiniblock(
tx.MiniBlockHash = hex.EncodeToString(miniblockHash)
tx.SourceShard = miniblock.SenderShardID
tx.DestinationShard = miniblock.ReceiverShardID
tx.Epoch = epoch
tx.Epoch = header.GetEpoch()
tx.Round = header.GetRound()
bap.apiTransactionHandler.PopulateComputedFields(tx)

// TODO : should check if tx is reward reverted
Expand Down
23 changes: 18 additions & 5 deletions node/external/blockAPI/baseBlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,12 @@ func TestBaseBlock_getAndAttachTxsToMb_MiniblockTxBlock(t *testing.T) {
Reserved: mbhrBytes,
}

testHeader := &block.Header{
Epoch: 0,
Round: 37,
}
apiMB := &api.MiniBlock{}
err := baseAPIBlockProc.getAndAttachTxsToMb(mbHeader, 0, apiMB, api.BlockQueryOptions{})
err := baseAPIBlockProc.getAndAttachTxsToMb(mbHeader, testHeader, apiMB, api.BlockQueryOptions{})
require.Nil(t, err)
require.Equal(t, &api.MiniBlock{
Transactions: []*transaction.ApiTransactionResult{
Expand All @@ -244,6 +248,8 @@ func TestBaseBlock_getAndAttachTxsToMb_MiniblockTxBlock(t *testing.T) {
Data: []byte("refund"),
MiniBlockType: "TxBlock",
MiniBlockHash: "6d6248617368",
Epoch: testHeader.GetEpoch(),
Round: testHeader.GetRound(),
},
},
}, apiMB)
Expand All @@ -252,11 +258,14 @@ func TestBaseBlock_getAndAttachTxsToMb_MiniblockTxBlock(t *testing.T) {
func TestBaseBlock_getAndAttachTxsToMbShouldIncludeLogsAsSpecified(t *testing.T) {
t.Parallel()

testEpoch := uint32(7)
testHeader := &block.Header{
Epoch: 7,
Round: 140,
}

marshalizer := &marshal.GogoProtoMarshalizer{}

storageService := genericMocks.NewChainStorerMock(testEpoch)
storageService := genericMocks.NewChainStorerMock(testHeader.GetEpoch())
processor := createBaseBlockProcessor()
processor.marshalizer = marshalizer
processor.store = storageService
Expand Down Expand Up @@ -308,7 +317,7 @@ func TestBaseBlock_getAndAttachTxsToMbShouldIncludeLogsAsSpecified(t *testing.T)
!bytes.Equal(logsKeys[2], []byte{0xcc}) {
return nil
}
if epoch != testEpoch {
if epoch != testHeader.GetEpoch() {
return nil
}

Expand All @@ -331,7 +340,7 @@ func TestBaseBlock_getAndAttachTxsToMbShouldIncludeLogsAsSpecified(t *testing.T)
// Now let's test the loading of transaction and logs
miniblockHeader := &block.MiniBlockHeader{Hash: miniblockHash}
miniblockOnApi := &api.MiniBlock{}
err := processor.getAndAttachTxsToMb(miniblockHeader, testEpoch, miniblockOnApi, api.BlockQueryOptions{WithLogs: true})
err := processor.getAndAttachTxsToMb(miniblockHeader, testHeader, miniblockOnApi, api.BlockQueryOptions{WithLogs: true})

require.Nil(t, err)
require.Len(t, miniblockOnApi.Transactions, 3)
Expand All @@ -341,6 +350,10 @@ func TestBaseBlock_getAndAttachTxsToMbShouldIncludeLogsAsSpecified(t *testing.T)
require.Equal(t, "first", miniblockOnApi.Transactions[0].Logs.Events[0].Identifier)
require.Nil(t, miniblockOnApi.Transactions[1].Logs)
require.Equal(t, "third", miniblockOnApi.Transactions[2].Logs.Events[0].Identifier)
for _, tx := range miniblockOnApi.Transactions {
require.Equal(t, testHeader.GetRound(), tx.Round)
require.Equal(t, testHeader.GetEpoch(), tx.Epoch)
}
}

func TestExtractExecutedTxHashes(t *testing.T) {
Expand Down
Loading

0 comments on commit 14820d2

Please sign in to comment.