From baa62660721f22eb67ce9f9904df7a119be823d7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 26 Jul 2024 15:39:09 +0300 Subject: [PATCH 01/99] fixed fee field for guardian operations --- common/forking/gasSchedule.go | 20 +++++++ factory/api/apiResolverFactory.go | 1 + genesis/process/disabled/feeHandler.go | 5 ++ go.mod | 2 +- go.sum | 4 +- .../mock/gasScheduleNotifierMock.go | 5 ++ .../testProcessorNodeWithTestWebServer.go | 1 + node/external/timemachine/fee/feeComputer.go | 6 +++ .../transactionAPI/apiTransactionArgs.go | 1 + .../transactionAPI/apiTransactionProcessor.go | 2 +- .../apiTransactionProcessor_test.go | 3 ++ node/external/transactionAPI/check.go | 3 ++ .../transactionAPI/gasUsedAndFeeProcessor.go | 52 +++++++++++++++++-- .../gasUsedAndFeeProcessor_test.go | 52 +++++++++++++++++-- node/external/transactionAPI/interface.go | 1 + process/interface.go | 1 + .../economicsDataHandlerStub.go | 9 ++++ .../economicsmocks/economicsHandlerMock.go | 8 +++ testscommon/feeComputerStub.go | 10 ++++ testscommon/gasScheduleNotifierMock.go | 10 ++++ 20 files changed, 182 insertions(+), 14 deletions(-) diff --git a/common/forking/gasSchedule.go b/common/forking/gasSchedule.go index 7da39fed41f..cac675387be 100644 --- a/common/forking/gasSchedule.go +++ b/common/forking/gasSchedule.go @@ -163,6 +163,26 @@ func (g *gasScheduleNotifier) LatestGasSchedule() map[string]map[string]uint64 { return g.lastGasSchedule } +// GasScheduleForEpoch returns the gas schedule for the specific epoch +func (g *gasScheduleNotifier) GasScheduleForEpoch(epoch uint32) (map[string]map[string]uint64, error) { + g.mutNotifier.RLock() + defer g.mutNotifier.RUnlock() + + currentVersion := g.getMatchingVersion(g.currentEpoch) + requestedVersion := g.getMatchingVersion(epoch) + if currentVersion == requestedVersion { + return g.lastGasSchedule, nil + } + + gasSchedule, err := common.LoadGasScheduleConfig(filepath.Join(g.configDir, requestedVersion.FileName)) + if err != nil { + log.Error("could not load the gas schedule", "epoch", requestedVersion.StartEpoch) + return nil, err + } + + return gasSchedule, nil +} + // LatestGasScheduleCopy returns a copy of the latest gas schedule func (g *gasScheduleNotifier) LatestGasScheduleCopy() map[string]map[string]uint64 { g.mutNotifier.RLock() diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index dfefa56ff94..67eb70aa4a9 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -244,6 +244,7 @@ func CreateApiResolver(args *ApiResolverArgs) (facade.ApiResolver, error) { TxTypeHandler: txTypeHandler, LogsFacade: logsFacade, DataFieldParser: dataFieldParser, + GasScheduleNotifier: args.GasScheduleNotifier, } apiTransactionProcessor, err := transactionAPI.NewAPITransactionProcessor(argsAPITransactionProc) if err != nil { diff --git a/genesis/process/disabled/feeHandler.go b/genesis/process/disabled/feeHandler.go index f81e7e978eb..1d4679e859f 100644 --- a/genesis/process/disabled/feeHandler.go +++ b/genesis/process/disabled/feeHandler.go @@ -87,6 +87,11 @@ func (fh *FeeHandler) ComputeMoveBalanceFee(_ data.TransactionWithFeeHandler) *b return big.NewInt(0) } +// ComputeMoveBalanceFeeInEpoch returns 0 +func (fh *FeeHandler) ComputeMoveBalanceFeeInEpoch(_ data.TransactionWithFeeHandler, _ uint32) *big.Int { + return big.NewInt(0) +} + // ComputeFeeForProcessing returns 0 func (fh *FeeHandler) ComputeFeeForProcessing(_ data.TransactionWithFeeHandler, _ uint64) *big.Int { return big.NewInt(0) diff --git a/go.mod b/go.mod index 140e76d10c8..98ec8bc66e9 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 diff --git a/go.sum b/go.sum index 1522bc6a3e5..5396bd3968b 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d h1:grQCJW4DCvvIQ6q84sy23oAp8XQ8Dxr3Js8aoh+m99M= github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d/go.mod h1:hFGM+O7rt+gWXSHFoRjC3/oN0OJfPfeFAxqXIac5UdQ= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 h1:Q7uUjTYTrt8Mw9oq5JWPv+WHhpxHTv6lhZZlhPuNcoQ= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc h1:COQlZ7wmOz15F40woVfRb6sl5CLQCKcRv13e9s/2PT0= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f h1:jydjrmVFvSllBOTppveOAkLITpOYKk0kma5z0bfDImI= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f/go.mod h1:9aSp//uBSvqFdzh4gvYISraoruhr1FCTXgPQalQ687k= github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca h1:9b2yFAarWDG/jTYePv0UqNWQ9gxeSZy9mGxtd8dFj2Y= diff --git a/integrationTests/mock/gasScheduleNotifierMock.go b/integrationTests/mock/gasScheduleNotifierMock.go index 6ef6ea2684c..ddcff3873fc 100644 --- a/integrationTests/mock/gasScheduleNotifierMock.go +++ b/integrationTests/mock/gasScheduleNotifierMock.go @@ -28,6 +28,11 @@ func (g *GasScheduleNotifierMock) LatestGasSchedule() map[string]map[string]uint return g.GasSchedule } +// GasScheduleForEpoch - +func (g *GasScheduleNotifierMock) GasScheduleForEpoch(_ uint32) (map[string]map[string]uint64, error) { + return g.GasSchedule, nil +} + // UnRegisterAll - func (g *GasScheduleNotifierMock) UnRegisterAll() { } diff --git a/integrationTests/testProcessorNodeWithTestWebServer.go b/integrationTests/testProcessorNodeWithTestWebServer.go index b380a643660..02849a7803a 100644 --- a/integrationTests/testProcessorNodeWithTestWebServer.go +++ b/integrationTests/testProcessorNodeWithTestWebServer.go @@ -236,6 +236,7 @@ func createFacadeComponents(tpn *TestProcessorNode) nodeFacade.ApiResolver { TxTypeHandler: txTypeHandler, LogsFacade: logsFacade, DataFieldParser: dataFieldParser, + GasScheduleNotifier: gasScheduleNotifier, } apiTransactionHandler, err := transactionAPI.NewAPITransactionProcessor(argsApiTransactionProc) log.LogIfError(err) diff --git a/node/external/timemachine/fee/feeComputer.go b/node/external/timemachine/fee/feeComputer.go index 6d19ce05ceb..ee4d67910db 100644 --- a/node/external/timemachine/fee/feeComputer.go +++ b/node/external/timemachine/fee/feeComputer.go @@ -42,6 +42,7 @@ func (computer *feeComputer) ComputeTxFeeBasedOnGasUsed(tx *transaction.ApiTrans // ComputeGasLimit computes a transaction gas limit, at a given epoch func (computer *feeComputer) ComputeGasLimit(tx *transaction.ApiTransactionResult) uint64 { + computer.economicsInstance.MaxGasPriceSetGuardian() return computer.economicsInstance.ComputeGasLimitInEpoch(tx.Tx, tx.Epoch) } @@ -50,6 +51,11 @@ func (computer *feeComputer) ComputeTransactionFee(tx *transaction.ApiTransactio return computer.economicsInstance.ComputeTxFeeInEpoch(tx.Tx, tx.Epoch) } +// ComputeMoveBalanceFee computes a transaction's move balance fee, at a given epoch +func (computer *feeComputer) ComputeMoveBalanceFee(tx *transaction.ApiTransactionResult) *big.Int { + return computer.economicsInstance.ComputeMoveBalanceFeeInEpoch(tx.Tx, tx.Epoch) +} + // IsInterfaceNil returns true if there is no value under the interface func (computer *feeComputer) IsInterfaceNil() bool { return computer == nil diff --git a/node/external/transactionAPI/apiTransactionArgs.go b/node/external/transactionAPI/apiTransactionArgs.go index bb1aa10a659..a4ad9421a31 100644 --- a/node/external/transactionAPI/apiTransactionArgs.go +++ b/node/external/transactionAPI/apiTransactionArgs.go @@ -27,4 +27,5 @@ type ArgAPITransactionProcessor struct { TxTypeHandler process.TxTypeHandler LogsFacade LogsFacade DataFieldParser DataFieldParser + GasScheduleNotifier core.GasScheduleNotifier } diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index b12aa9ac86f..6528d195026 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -65,7 +65,7 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti ) refundDetectorInstance := NewRefundDetector() - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(args.FeeComputer, args.AddressPubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(args.FeeComputer, args.GasScheduleNotifier, args.AddressPubKeyConverter) return &apiTransactionProcessor{ roundDuration: args.RoundDuration, diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index 7d86a1610c5..fa13f040037 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -59,6 +59,7 @@ func createMockArgAPITransactionProcessor() *ArgAPITransactionProcessor { return &datafield.ResponseParseData{} }, }, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } } @@ -459,6 +460,7 @@ func TestNode_GetTransactionWithResultsFromStorage(t *testing.T) { return &datafield.ResponseParseData{} }, }, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } apiTransactionProc, _ := NewAPITransactionProcessor(args) @@ -1027,6 +1029,7 @@ func createAPITransactionProc(t *testing.T, epoch uint32, withDbLookupExt bool) TxTypeHandler: &testscommon.TxTypeHandlerMock{}, LogsFacade: &testscommon.LogsFacadeStub{}, DataFieldParser: dataFieldParser, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } apiTransactionProc, err := NewAPITransactionProcessor(args) require.Nil(t, err) diff --git a/node/external/transactionAPI/check.go b/node/external/transactionAPI/check.go index 0959ba6c5db..bbb3e2ab9df 100644 --- a/node/external/transactionAPI/check.go +++ b/node/external/transactionAPI/check.go @@ -42,6 +42,9 @@ func checkNilArgs(arg *ArgAPITransactionProcessor) error { if check.IfNilReflect(arg.DataFieldParser) { return ErrNilDataFieldParser } + if check.IfNilReflect(arg.GasScheduleNotifier) { + return process.ErrNilGasSchedule + } return nil } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index f0036bc136b..6e6f48ebccb 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -5,18 +5,21 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/common" datafield "github.com/multiversx/mx-chain-vm-common-go/parsers/dataField" ) type gasUsedAndFeeProcessor struct { - feeComputer feeComputer - pubKeyConverter core.PubkeyConverter + feeComputer feeComputer + gasScheduleNotifier core.GasScheduleNotifier + pubKeyConverter core.PubkeyConverter } -func newGasUsedAndFeeProcessor(txFeeCalculator feeComputer, pubKeyConverter core.PubkeyConverter) *gasUsedAndFeeProcessor { +func newGasUsedAndFeeProcessor(txFeeCalculator feeComputer, gasScheduleNotifier core.GasScheduleNotifier, pubKeyConverter core.PubkeyConverter) *gasUsedAndFeeProcessor { return &gasUsedAndFeeProcessor{ - feeComputer: txFeeCalculator, - pubKeyConverter: pubKeyConverter, + feeComputer: txFeeCalculator, + gasScheduleNotifier: gasScheduleNotifier, + pubKeyConverter: pubKeyConverter, } } @@ -32,6 +35,21 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = tx.InitiallyPaidFee } + if gfp.isGuardianOperation(tx) { + gasUsed = gfp.feeComputer.ComputeGasLimit(tx) + guardianOperationCost := gfp.getGuardianOperationCost(tx) + gasUsed += guardianOperationCost + tx.GasUsed = gasUsed + + fee = big.NewInt(0).SetUint64(gasUsed * tx.GasPrice) + tx.Fee = fee.String() + + initiallyPaidFee := gfp.feeComputer.ComputeMoveBalanceFee(tx) + tx.InitiallyPaidFee = initiallyPaidFee.String() + + return + } + hasRefundForSender := false for _, scr := range tx.SmartContractResults { if !scr.IsRefund || scr.RcvAddr != tx.Sender { @@ -49,6 +67,30 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) } +func (gfp *gasUsedAndFeeProcessor) getGuardianOperationCost(tx *transaction.ApiTransactionResult) uint64 { + gasSchedule, err := gfp.gasScheduleNotifier.GasScheduleForEpoch(tx.Epoch) + if err != nil { + return 0 + } + + switch tx.Operation { + case core.BuiltInFunctionSetGuardian: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionSetGuardian] + case core.BuiltInFunctionGuardAccount: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionGuardAccount] + case core.BuiltInFunctionUnGuardAccount: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionUnGuardAccount] + default: + return 0 + } +} + +func (gfp *gasUsedAndFeeProcessor) isGuardianOperation(tx *transaction.ApiTransactionResult) bool { + return tx.Operation == core.BuiltInFunctionSetGuardian || + tx.Operation == core.BuiltInFunctionGuardAccount || + tx.Operation == core.BuiltInFunctionUnGuardAccount +} + func (gfp *gasUsedAndFeeProcessor) prepareTxWithResultsBasedOnLogs( tx *transaction.ApiTransactionResult, hasRefund bool, diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 99541bfef5d..9a35be6efa9 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -38,7 +38,7 @@ func TestComputeTransactionGasUsedAndFeeMoveBalance(t *testing.T) { feeComp, _ := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{})) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -68,7 +68,7 @@ func TestComputeTransactionGasUsedAndFeeLogWithError(t *testing.T) { })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -111,7 +111,7 @@ func TestComputeTransactionGasUsedAndFeeRelayedTxWithWriteLog(t *testing.T) { })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -149,7 +149,7 @@ func TestComputeTransactionGasUsedAndFeeTransactionWithScrWithRefund(t *testing. })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -197,7 +197,7 @@ func TestNFTTransferWithScCall(t *testing.T) { computer := fee.NewTestFeeComputer(feeComp) req.Nil(err) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -221,3 +221,45 @@ func TestNFTTransferWithScCall(t *testing.T) { req.Equal(uint64(55_000_000), tx.GasUsed) req.Equal("822250000000000", tx.Fee) } + +func TestComputeAndAttachGasUsedAndFeeSetGuardian(t *testing.T) { + t.Parallel() + + feeComp, err := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || flag == common.PenalizedTooMuchGasFlag + }, + })) + computer := fee.NewTestFeeComputer(feeComp) + require.NoError(t, err) + + gasSch := &testscommon.GasScheduleNotifierMock{ + GasSchedule: map[string]map[string]uint64{ + common.BuiltInCost: { + core.BuiltInFunctionSetGuardian: 250000, + }, + }, + } + + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, gasSch, pubKeyConverter) + + sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" + + tx := &transaction.ApiTransactionResult{ + Tx: &transaction.Transaction{ + GasLimit: 475_500, + GasPrice: 1000000000, + SndAddr: silentDecodeAddress(sender), + RcvAddr: silentDecodeAddress(sender), + Data: []byte("SetGuardian@835741dd7018300bb4ed14211f9a9118ea7049572402c3a553deb1141f9c89aa@4d756c7469766572735854435353657276696365"), + }, + GasLimit: 475_500, + Operation: "SetGuardian", + GasPrice: 1000000000, + } + tx.InitiallyPaidFee = feeComp.ComputeTransactionFee(tx).String() + + gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(tx) + require.Equal(t, uint64(475_500), tx.GasUsed) + require.Equal(t, "475500000000000", tx.Fee) +} diff --git a/node/external/transactionAPI/interface.go b/node/external/transactionAPI/interface.go index a32cac06184..77057e1de05 100644 --- a/node/external/transactionAPI/interface.go +++ b/node/external/transactionAPI/interface.go @@ -12,6 +12,7 @@ type feeComputer interface { ComputeTxFeeBasedOnGasUsed(tx *transaction.ApiTransactionResult, gasUsed uint64) *big.Int ComputeGasLimit(tx *transaction.ApiTransactionResult) uint64 ComputeTransactionFee(tx *transaction.ApiTransactionResult) *big.Int + ComputeMoveBalanceFee(tx *transaction.ApiTransactionResult) *big.Int IsInterfaceNil() bool } diff --git a/process/interface.go b/process/interface.go index 8e943d0a44e..e1c81fa6f96 100644 --- a/process/interface.go +++ b/process/interface.go @@ -680,6 +680,7 @@ type feeHandler interface { MaxGasLimitPerTx() uint64 ComputeGasLimit(tx data.TransactionWithFeeHandler) uint64 ComputeMoveBalanceFee(tx data.TransactionWithFeeHandler) *big.Int + ComputeMoveBalanceFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int ComputeTxFee(tx data.TransactionWithFeeHandler) *big.Int CheckValidityTxValues(tx data.TransactionWithFeeHandler) error ComputeFeeForProcessing(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int diff --git a/testscommon/economicsmocks/economicsDataHandlerStub.go b/testscommon/economicsmocks/economicsDataHandlerStub.go index bb59020bc27..c76ce6c59a2 100644 --- a/testscommon/economicsmocks/economicsDataHandlerStub.go +++ b/testscommon/economicsmocks/economicsDataHandlerStub.go @@ -49,6 +49,7 @@ type EconomicsHandlerStub struct { ComputeTxFeeBasedOnGasUsedInEpochCalled func(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int ComputeRelayedTxFeesCalled func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) SetTxTypeHandlerCalled func(txTypeHandler process.TxTypeHandler) error + ComputeMoveBalanceFeeInEpochCalled func(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int } // ComputeFeeForProcessing - @@ -228,6 +229,14 @@ func (e *EconomicsHandlerStub) ComputeMoveBalanceFee(tx data.TransactionWithFeeH return big.NewInt(0) } +// ComputeMoveBalanceFeeInEpoch - +func (e *EconomicsHandlerStub) ComputeMoveBalanceFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int { + if e.ComputeMoveBalanceFeeInEpochCalled != nil { + return e.ComputeMoveBalanceFeeInEpochCalled(tx, epoch) + } + return big.NewInt(0) +} + // ComputeTxFee - func (e *EconomicsHandlerStub) ComputeTxFee(tx data.TransactionWithFeeHandler) *big.Int { if e.ComputeTxFeeCalled != nil { diff --git a/testscommon/economicsmocks/economicsHandlerMock.go b/testscommon/economicsmocks/economicsHandlerMock.go index 3506d2ba9a7..0c92fff0238 100644 --- a/testscommon/economicsmocks/economicsHandlerMock.go +++ b/testscommon/economicsmocks/economicsHandlerMock.go @@ -27,6 +27,7 @@ type EconomicsHandlerMock struct { ComputeFeeCalled func(tx data.TransactionWithFeeHandler) *big.Int CheckValidityTxValuesCalled func(tx data.TransactionWithFeeHandler) error ComputeMoveBalanceFeeCalled func(tx data.TransactionWithFeeHandler) *big.Int + ComputeMoveBalanceFeeInEpochCalled func(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int ComputeTxFeeCalled func(tx data.TransactionWithFeeHandler) *big.Int DeveloperPercentageCalled func() float64 MinGasPriceCalled func() uint64 @@ -199,7 +200,14 @@ func (ehm *EconomicsHandlerMock) ComputeMoveBalanceFee(tx data.TransactionWithFe return ehm.ComputeMoveBalanceFeeCalled(tx) } return big.NewInt(0) +} +// ComputeMoveBalanceFeeInEpoch - +func (ehm *EconomicsHandlerMock) ComputeMoveBalanceFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int { + if ehm.ComputeMoveBalanceFeeInEpochCalled != nil { + return ehm.ComputeMoveBalanceFeeInEpochCalled(tx, epoch) + } + return big.NewInt(0) } // ComputeGasLimitBasedOnBalance - diff --git a/testscommon/feeComputerStub.go b/testscommon/feeComputerStub.go index 33dcfbb4e4b..884351576d9 100644 --- a/testscommon/feeComputerStub.go +++ b/testscommon/feeComputerStub.go @@ -12,6 +12,7 @@ type FeeComputerStub struct { ComputeGasUsedAndFeeBasedOnRefundValueCalled func(tx *transaction.ApiTransactionResult, refundValue *big.Int) (uint64, *big.Int) ComputeTxFeeBasedOnGasUsedCalled func(tx *transaction.ApiTransactionResult, gasUsed uint64) *big.Int ComputeGasLimitCalled func(tx *transaction.ApiTransactionResult) uint64 + ComputeMoveBalanceFeeCalled func(tx *transaction.ApiTransactionResult) *big.Int } // ComputeTransactionFee - @@ -49,6 +50,15 @@ func (stub *FeeComputerStub) ComputeGasLimit(tx *transaction.ApiTransactionResul return 0 } +// ComputeMoveBalanceFee - +func (stub *FeeComputerStub) ComputeMoveBalanceFee(tx *transaction.ApiTransactionResult) *big.Int { + if stub.ComputeMoveBalanceFeeCalled != nil { + return stub.ComputeMoveBalanceFeeCalled(tx) + } + + return big.NewInt(0) +} + // IsInterfaceNil returns true if there is no value under the interface func (stub *FeeComputerStub) IsInterfaceNil() bool { return false diff --git a/testscommon/gasScheduleNotifierMock.go b/testscommon/gasScheduleNotifierMock.go index dd0f728cfad..e7894c25e40 100644 --- a/testscommon/gasScheduleNotifierMock.go +++ b/testscommon/gasScheduleNotifierMock.go @@ -8,6 +8,7 @@ type GasScheduleNotifierMock struct { RegisterNotifyHandlerCalled func(handler core.GasScheduleSubscribeHandler) LatestGasScheduleCalled func() map[string]map[string]uint64 LatestGasScheduleCopyCalled func() map[string]map[string]uint64 + GasScheduleForEpochCalled func(epoch uint32) (map[string]map[string]uint64, error) } // NewGasScheduleNotifierMock - @@ -50,6 +51,15 @@ func (g *GasScheduleNotifierMock) LatestGasScheduleCopy() map[string]map[string] func (g *GasScheduleNotifierMock) UnRegisterAll() { } +// GasScheduleForEpoch - +func (g *GasScheduleNotifierMock) GasScheduleForEpoch(epoch uint32) (map[string]map[string]uint64, error) { + if g.GasScheduleForEpochCalled != nil { + return g.GasScheduleForEpochCalled(epoch) + } + + return g.GasSchedule, nil +} + // IsInterfaceNil - func (g *GasScheduleNotifierMock) IsInterfaceNil() bool { return g == nil From 8b4fb3a4003232e3eeda190f4d5e222bfcac9433 Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 5 Aug 2024 14:56:18 +0300 Subject: [PATCH 02/99] new endpoint --- api/errors/errors.go | 5 ++ api/groups/transactionGroup.go | 66 +++++++++++++++++++ api/mock/facadeStub.go | 10 +++ api/shared/interface.go | 1 + cmd/node/config/api.toml | 3 + facade/initial/initialNodeFacade.go | 5 ++ facade/interface.go | 1 + facade/nodeFacade.go | 4 ++ .../chainSimulator/vm/esdtTokens_test.go | 5 ++ integrationTests/interface.go | 1 + node/external/interface.go | 1 + node/external/nodeApiResolver.go | 4 ++ .../transactionAPI/apiTransactionProcessor.go | 43 ++++++++++++ .../transactionAPI/apiTransactionResults.go | 13 ++-- node/mock/apiTransactionHandlerStub.go | 10 +++ 15 files changed, 167 insertions(+), 5 deletions(-) diff --git a/api/errors/errors.go b/api/errors/errors.go index 30cfb923bbd..e2c22411dac 100644 --- a/api/errors/errors.go +++ b/api/errors/errors.go @@ -64,6 +64,8 @@ var ErrTxGenerationFailed = errors.New("transaction generation failed") // ErrValidationEmptyTxHash signals that an empty tx hash was provided var ErrValidationEmptyTxHash = errors.New("TxHash is empty") +var ErrValidationEmptySCRHash = errors.New("SCRHash is empty") + // ErrInvalidBlockNonce signals that an invalid block nonce was provided var ErrInvalidBlockNonce = errors.New("invalid block nonce") @@ -79,6 +81,9 @@ var ErrValidationEmptyBlockHash = errors.New("block hash is empty") // ErrGetTransaction signals an error happening when trying to fetch a transaction var ErrGetTransaction = errors.New("getting transaction failed") +// ErrGetSmartContractResults signals an error happening when trying to fetch smart contract results +var ErrGetSmartContractResults = errors.New("getting smart contract results failed") + // ErrGetBlock signals an error happening when trying to fetch a block var ErrGetBlock = errors.New("getting block failed") diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index 29d07de2640..1ae19424cb4 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -26,11 +26,13 @@ const ( simulateTransactionEndpoint = "/transaction/simulate" sendMultipleTransactionsEndpoint = "/transaction/send-multiple" getTransactionEndpoint = "/transaction/:hash" + getScrsByTxHashEndpoint = "/transaction/scrs-by-tx-hash/:txhash" sendTransactionPath = "/send" simulateTransactionPath = "/simulate" costPath = "/cost" sendMultiplePath = "/send-multiple" getTransactionPath = "/:txhash" + getScrsByTxHashPath = "/scrs-by-tx-hash/:txhash" getTransactionsPool = "/pool" queryParamWithResults = "withResults" @@ -39,6 +41,7 @@ const ( queryParamFields = "fields" queryParamLastNonce = "last-nonce" queryParamNonceGaps = "nonce-gaps" + queryParameterScrHash = "scrHash" ) // transactionFacadeHandler defines the methods to be implemented by a facade for transaction requests @@ -49,6 +52,7 @@ type transactionFacadeHandler interface { SendBulkTransactions([]*transaction.Transaction) (uint64, error) SimulateTransactionExecution(tx *transaction.Transaction) (*txSimData.SimulationResultsWithVMOutput, error) GetTransaction(hash string, withResults bool) (*transaction.ApiTransactionResult, error) + GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) GetTransactionsPool(fields string) (*common.TransactionsPoolAPIResponse, error) GetTransactionsPoolForSender(sender, fields string) (*common.TransactionsPoolForSenderApiResponse, error) GetLastPoolNonceForSender(sender string) (uint64, error) @@ -137,6 +141,17 @@ func NewTransactionGroup(facade transactionFacadeHandler) (*transactionGroup, er }, }, }, + { + Path: getScrsByTxHashPath, + Method: http.MethodGet, + Handler: tg.getTransaction, + AdditionalMiddlewares: []shared.AdditionalMiddleware{ + { + Middleware: middleware.CreateEndpointThrottlerFromFacade(getScrsByTxHashEndpoint, facade), + Position: shared.Before, + }, + }, + }, } tg.endpoints = endpoints @@ -421,6 +436,57 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) { ) } +func (tg *transactionGroup) getScrsByTxHash(c *gin.Context) { + txhash := c.Param("txhash") + if txhash == "" { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrValidation.Error(), errors.ErrValidationEmptyTxHash.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } + scrHashStr := c.Request.URL.Query().Get(queryParameterScrHash) + if scrHashStr == "" { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrValidation.Error(), errors.ErrValidationEmptySCRHash.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } + + start := time.Now() + scrs, err := tg.getFacade().GetSCRsByTxHash(txhash, scrHashStr) + if err != nil { + c.JSON( + http.StatusInternalServerError, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrGetSmartContractResults.Error(), err.Error()), + Code: shared.ReturnCodeInternalError, + }, + ) + return + } + logging.LogAPIActionDurationIfNeeded(start, "API call: GetSCRsByTxHash") + + c.JSON( + http.StatusOK, + shared.GenericAPIResponse{ + Data: gin.H{"scrs": scrs}, + Error: "", + Code: shared.ReturnCodeSuccess, + }, + ) +} + // getTransaction returns transaction details for a given txhash func (tg *transactionGroup) getTransaction(c *gin.Context) { txhash := c.Param("txhash") diff --git a/api/mock/facadeStub.go b/api/mock/facadeStub.go index e40645c1ac3..62de2febc81 100644 --- a/api/mock/facadeStub.go +++ b/api/mock/facadeStub.go @@ -97,6 +97,16 @@ type FacadeStub struct { GetWaitingEpochsLeftForPublicKeyCalled func(publicKey string) (uint32, error) P2PPrometheusMetricsEnabledCalled func() bool AuctionListHandler func() ([]*common.AuctionListValidatorAPIResponse, error) + GetSCRsByTxHashCalled func(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) +} + +// GetSCRsByTxHash - +func (f *FacadeStub) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + if f.GetSCRsByTxHashCalled != nil { + return f.GetSCRsByTxHashCalled(txHash, scrHash) + } + + return nil, nil } // GetTokenSupply - diff --git a/api/shared/interface.go b/api/shared/interface.go index 4b775ebdd39..206cea6ee30 100644 --- a/api/shared/interface.go +++ b/api/shared/interface.go @@ -135,6 +135,7 @@ type FacadeHandler interface { GetEligibleManagedKeys() ([]string, error) GetWaitingManagedKeys() ([]string, error) GetWaitingEpochsLeftForPublicKey(publicKey string) (uint32, error) + GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) P2PPrometheusMetricsEnabled() bool IsInterfaceNil() bool } diff --git a/cmd/node/config/api.toml b/cmd/node/config/api.toml index a10ec049554..af0567899d1 100644 --- a/cmd/node/config/api.toml +++ b/cmd/node/config/api.toml @@ -221,6 +221,9 @@ # /transaction/:txhash will return the transaction in JSON format based on its hash { Name = "/:txhash", Open = true }, + + # /transaction/scrs-by-tx-hash/:txhash will return the smart contract results generated by the provided transaction hash + { Name = "/transaction/scrs-by-tx-hash/:txhash", Open = true }, ] [APIPackages.block] diff --git a/facade/initial/initialNodeFacade.go b/facade/initial/initialNodeFacade.go index 7411a2078e9..d6043dbcd62 100644 --- a/facade/initial/initialNodeFacade.go +++ b/facade/initial/initialNodeFacade.go @@ -421,6 +421,11 @@ func (inf *initialNodeFacade) IsDataTrieMigrated(_ string, _ api.AccountQueryOpt return false, errNodeStarting } +// GetSCRsByTxHash return a nil slice and error +func (inf *initialNodeFacade) GetSCRsByTxHash(_ string, _ string) ([]*transaction.ApiSmartContractResult, error) { + return nil, errNodeStarting +} + // GetManagedKeysCount returns 0 func (inf *initialNodeFacade) GetManagedKeysCount() int { return 0 diff --git a/facade/interface.go b/facade/interface.go index 35f185874ed..309f6c98d6f 100644 --- a/facade/interface.go +++ b/facade/interface.go @@ -127,6 +127,7 @@ type ApiResolver interface { GetDirectStakedList(ctx context.Context) ([]*api.DirectStakedValue, error) GetDelegatorsList(ctx context.Context) ([]*api.Delegator, error) GetTransaction(hash string, withResults bool) (*transaction.ApiTransactionResult, error) + GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) GetTransactionsPool(fields string) (*common.TransactionsPoolAPIResponse, error) GetTransactionsPoolForSender(sender, fields string) (*common.TransactionsPoolForSenderApiResponse, error) GetLastPoolNonceForSender(sender string) (uint64, error) diff --git a/facade/nodeFacade.go b/facade/nodeFacade.go index 8bc696b6adc..479cb4f5412 100644 --- a/facade/nodeFacade.go +++ b/facade/nodeFacade.go @@ -304,6 +304,10 @@ func (nf *nodeFacade) GetTransaction(hash string, withResults bool) (*transactio return nf.apiResolver.GetTransaction(hash, withResults) } +func (nf *nodeFacade) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + return nf.apiResolver.GetSCRsByTxHash(txHash, scrHash) +} + // GetTransactionsPool will return a structure containing the transactions pool that is to be returned on API calls func (nf *nodeFacade) GetTransactionsPool(fields string) (*common.TransactionsPoolAPIResponse, error) { return nf.apiResolver.GetTransactionsPool(fields) diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index d12bfcbb550..1000265d8d0 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -107,6 +107,11 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + scrs, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().GetSCRsByTxHash(txResult.Hash, txResult.SmartContractResults[0].Hash) + require.Nil(t, err) + require.NotNil(t, scrs) + require.Equal(t, len(txResult.SmartContractResults), len(scrs)) + nftTokenID := txResult.Logs.Events[0].Topics[0] setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) nonce++ diff --git a/integrationTests/interface.go b/integrationTests/interface.go index e4be7fe388c..ad90ffbb6a3 100644 --- a/integrationTests/interface.go +++ b/integrationTests/interface.go @@ -118,5 +118,6 @@ type Facade interface { GetEligibleManagedKeys() ([]string, error) GetWaitingManagedKeys() ([]string, error) GetWaitingEpochsLeftForPublicKey(publicKey string) (uint32, error) + GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) IsInterfaceNil() bool } diff --git a/node/external/interface.go b/node/external/interface.go index a12ef177ce1..e70367e201d 100644 --- a/node/external/interface.go +++ b/node/external/interface.go @@ -61,6 +61,7 @@ type DelegatedListHandler interface { // APITransactionHandler defines what an API transaction handler should be able to do type APITransactionHandler interface { GetTransaction(txHash string, withResults bool) (*transaction.ApiTransactionResult, error) + GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) GetTransactionsPool(fields string) (*common.TransactionsPoolAPIResponse, error) GetTransactionsPoolForSender(sender, fields string) (*common.TransactionsPoolForSenderApiResponse, error) GetLastPoolNonceForSender(sender string) (uint64, error) diff --git a/node/external/nodeApiResolver.go b/node/external/nodeApiResolver.go index 0ae0356f4f7..b359c31b986 100644 --- a/node/external/nodeApiResolver.go +++ b/node/external/nodeApiResolver.go @@ -189,6 +189,10 @@ func (nar *nodeApiResolver) GetTransaction(hash string, withResults bool) (*tran return nar.apiTransactionHandler.GetTransaction(hash, withResults) } +func (nar *nodeApiResolver) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + return nar.apiTransactionHandler.GetSCRsByTxHash(txHash, scrHash) +} + // GetTransactionsPool will return a structure containing the transactions pool that is to be returned on API calls func (nar *nodeApiResolver) GetTransactionsPool(fields string) (*common.TransactionsPoolAPIResponse, error) { return nar.apiTransactionHandler.GetTransactionsPool(fields) diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index b12aa9ac86f..bcfb265df62 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -2,6 +2,7 @@ package transactionAPI import ( "encoding/hex" + "errors" "fmt" "sort" "strings" @@ -86,6 +87,48 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti }, nil } +func (atp *apiTransactionProcessor) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + decodedScrHash, err := hex.DecodeString(scrHash) + if err != nil { + return nil, err + } + + decodedTxHash, err := hex.DecodeString(txHash) + if err != nil { + return nil, err + } + + if !atp.historyRepository.IsEnabled() { + return []*transaction.ApiSmartContractResult{}, nil + } + + miniblockMetadata, err := atp.historyRepository.GetMiniblockMetadataByTxHash(decodedScrHash) + if err != nil { + return nil, fmt.Errorf("%s: %w", ErrTransactionNotFound.Error(), err) + } + + resultsHashes, err := atp.historyRepository.GetResultsHashesByTxHash(decodedTxHash, miniblockMetadata.Epoch) + if err != nil { + // It's perfectly normal to have transactions without SCRs. + if errors.Is(err, dblookupext.ErrNotFoundInStorage) { + return []*transaction.ApiSmartContractResult{}, nil + } + return nil, err + } + + scrsAPI := make([]*transaction.ApiSmartContractResult, 0) + for _, scrHashesEpoch := range resultsHashes.ScResultsHashesAndEpoch { + scrs, errGet := atp.transactionResultsProcessor.getSmartContractResultsInTransactionByHashesAndEpoch(scrHashesEpoch.ScResultsHashes, scrHashesEpoch.Epoch) + if errGet != nil { + return nil, errGet + } + + scrsAPI = append(scrsAPI, scrs...) + } + + return scrsAPI, nil +} + // GetTransaction gets the transaction based on the given hash. It will search in the cache and the storage and // will return the transaction in a format which can be respected by all types of transactions (normal, reward or unsigned) func (atp *apiTransactionProcessor) GetTransaction(txHash string, withResults bool) (*transaction.ApiTransactionResult, error) { diff --git a/node/external/transactionAPI/apiTransactionResults.go b/node/external/transactionAPI/apiTransactionResults.go index 125376f39da..d4a89edfd15 100644 --- a/node/external/transactionAPI/apiTransactionResults.go +++ b/node/external/transactionAPI/apiTransactionResults.go @@ -102,10 +102,12 @@ func (arp *apiTransactionResultsProcessor) putSmartContractResultsInTransaction( scrHashesEpoch []*dblookupext.ScResultsHashesAndEpoch, ) error { for _, scrHashesE := range scrHashesEpoch { - err := arp.putSmartContractResultsInTransactionByHashesAndEpoch(tx, scrHashesE.ScResultsHashes, scrHashesE.Epoch) + scrsAPI, err := arp.getSmartContractResultsInTransactionByHashesAndEpoch(scrHashesE.ScResultsHashes, scrHashesE.Epoch) if err != nil { return err } + + tx.SmartContractResults = append(tx.SmartContractResults, scrsAPI...) } statusFilters := filters.NewStatusFilters(arp.shardCoordinator.SelfId()) @@ -113,21 +115,22 @@ func (arp *apiTransactionResultsProcessor) putSmartContractResultsInTransaction( return nil } -func (arp *apiTransactionResultsProcessor) putSmartContractResultsInTransactionByHashesAndEpoch(tx *transaction.ApiTransactionResult, scrsHashes [][]byte, epoch uint32) error { +func (arp *apiTransactionResultsProcessor) getSmartContractResultsInTransactionByHashesAndEpoch(scrsHashes [][]byte, epoch uint32) ([]*transaction.ApiSmartContractResult, error) { + scrsAPI := make([]*transaction.ApiSmartContractResult, 0, len(scrsHashes)) for _, scrHash := range scrsHashes { scr, err := arp.getScrFromStorage(scrHash, epoch) if err != nil { - return fmt.Errorf("%w: %v, hash = %s", errCannotLoadContractResults, err, hex.EncodeToString(scrHash)) + return nil, fmt.Errorf("%w: %v, hash = %s", errCannotLoadContractResults, err, hex.EncodeToString(scrHash)) } scrAPI := arp.adaptSmartContractResult(scrHash, scr) arp.loadLogsIntoContractResults(scrHash, epoch, scrAPI) - tx.SmartContractResults = append(tx.SmartContractResults, scrAPI) + scrsAPI = append(scrsAPI, scrAPI) } - return nil + return scrsAPI, nil } func (arp *apiTransactionResultsProcessor) loadLogsIntoTransaction(hash []byte, tx *transaction.ApiTransactionResult, epoch uint32) { diff --git a/node/mock/apiTransactionHandlerStub.go b/node/mock/apiTransactionHandlerStub.go index 2ae18622197..4bd9ca4633f 100644 --- a/node/mock/apiTransactionHandlerStub.go +++ b/node/mock/apiTransactionHandlerStub.go @@ -15,6 +15,16 @@ type TransactionAPIHandlerStub struct { UnmarshalTransactionCalled func(txBytes []byte, txType transaction.TxType) (*transaction.ApiTransactionResult, error) UnmarshalReceiptCalled func(receiptBytes []byte) (*transaction.ApiReceipt, error) PopulateComputedFieldsCalled func(tx *transaction.ApiTransactionResult) + GetSCRsByTxHashCalled func(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) +} + +// GetSCRsByTxHash -- +func (tas *TransactionAPIHandlerStub) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + if tas.GetSCRsByTxHashCalled != nil { + return tas.GetSCRsByTxHashCalled(txHash, scrHash) + } + + return nil, nil } // GetTransaction - From 2bad2a74fad592e0cdcdf603777b9804af5db11c Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 5 Aug 2024 15:18:16 +0300 Subject: [PATCH 03/99] fix --- cmd/node/config/api.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/node/config/api.toml b/cmd/node/config/api.toml index af0567899d1..fcf9cf7fc0b 100644 --- a/cmd/node/config/api.toml +++ b/cmd/node/config/api.toml @@ -223,7 +223,7 @@ { Name = "/:txhash", Open = true }, # /transaction/scrs-by-tx-hash/:txhash will return the smart contract results generated by the provided transaction hash - { Name = "/transaction/scrs-by-tx-hash/:txhash", Open = true }, + { Name = "/scrs-by-tx-hash/:txhash", Open = true }, ] [APIPackages.block] From 792f6a7ac100590c2ca3dcbc3af91b81cd82dc84 Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 5 Aug 2024 15:24:58 +0300 Subject: [PATCH 04/99] fix endpoint --- api/groups/transactionGroup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index 1ae19424cb4..83eb97136b8 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -144,7 +144,7 @@ func NewTransactionGroup(facade transactionFacadeHandler) (*transactionGroup, er { Path: getScrsByTxHashPath, Method: http.MethodGet, - Handler: tg.getTransaction, + Handler: tg.getScrsByTxHash, AdditionalMiddlewares: []shared.AdditionalMiddleware{ { Middleware: middleware.CreateEndpointThrottlerFromFacade(getScrsByTxHashEndpoint, facade), From 6539ea4dd9f66e74b020893427895fee84fc33f7 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 6 Aug 2024 14:00:31 +0300 Subject: [PATCH 05/99] fix tests --- facade/mock/apiResolverStub.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/facade/mock/apiResolverStub.go b/facade/mock/apiResolverStub.go index 33bae8518aa..8e38ab6707d 100644 --- a/facade/mock/apiResolverStub.go +++ b/facade/mock/apiResolverStub.go @@ -50,6 +50,16 @@ type ApiResolverStub struct { GetEligibleManagedKeysCalled func() ([]string, error) GetWaitingManagedKeysCalled func() ([]string, error) GetWaitingEpochsLeftForPublicKeyCalled func(publicKey string) (uint32, error) + GetSCRsByTxHashCalled func(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) +} + +// GetSCRsByTxHash - +func (ars *ApiResolverStub) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + if ars.GetSCRsByTxHashCalled != nil { + return ars.GetSCRsByTxHashCalled(txHash, scrHash) + } + + return nil, nil } // GetTransaction - From 708e08e99b2fa9520966b9047f0535767b2eb69e Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 6 Aug 2024 14:26:47 +0300 Subject: [PATCH 06/99] unit tests --- .../apiTransactionProcessor_test.go | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index 7d86a1610c5..3101cf763f4 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -268,6 +268,93 @@ func TestNode_GetTransactionFromPool(t *testing.T) { require.Equal(t, transaction.TxStatusPending, actualG.Status) } +func TestNode_GetSCRs(t *testing.T) { + scResultHash := []byte("scHash") + txHash := []byte("txHash") + + marshalizer := &mock.MarshalizerFake{} + scResult := &smartContractResult.SmartContractResult{ + Nonce: 1, + SndAddr: []byte("snd"), + RcvAddr: []byte("rcv"), + OriginalTxHash: txHash, + Data: []byte("test"), + } + + resultHashesByTxHash := &dblookupext.ResultsHashesByTxHash{ + ScResultsHashesAndEpoch: []*dblookupext.ScResultsHashesAndEpoch{ + { + Epoch: 0, + ScResultsHashes: [][]byte{scResultHash}, + }, + }, + } + + chainStorer := &storageStubs.ChainStorerStub{ + GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) { + switch unitType { + case dataRetriever.UnsignedTransactionUnit: + return &storageStubs.StorerStub{ + GetFromEpochCalled: func(key []byte, epoch uint32) ([]byte, error) { + return marshalizer.Marshal(scResult) + }, + }, nil + default: + return nil, storage.ErrKeyNotFound + } + }, + } + + historyRepo := &dblookupextMock.HistoryRepositoryStub{ + GetMiniblockMetadataByTxHashCalled: func(hash []byte) (*dblookupext.MiniblockMetadata, error) { + return &dblookupext.MiniblockMetadata{}, nil + }, + GetEventsHashesByTxHashCalled: func(hash []byte, epoch uint32) (*dblookupext.ResultsHashesByTxHash, error) { + return resultHashesByTxHash, nil + }, + } + + feeComp := &testscommon.FeeComputerStub{ + ComputeTransactionFeeCalled: func(tx *transaction.ApiTransactionResult) *big.Int { + return big.NewInt(1000) + }, + } + + args := &ArgAPITransactionProcessor{ + RoundDuration: 0, + GenesisTime: time.Time{}, + Marshalizer: &mock.MarshalizerFake{}, + AddressPubKeyConverter: &testscommon.PubkeyConverterMock{}, + ShardCoordinator: &mock.ShardCoordinatorMock{}, + HistoryRepository: historyRepo, + StorageService: chainStorer, + DataPool: dataRetrieverMock.NewPoolsHolderMock(), + Uint64ByteSliceConverter: mock.NewNonceHashConverterMock(), + FeeComputer: feeComp, + TxTypeHandler: &testscommon.TxTypeHandlerMock{}, + LogsFacade: &testscommon.LogsFacadeStub{}, + DataFieldParser: &testscommon.DataFieldParserStub{ + ParseCalled: func(dataField []byte, sender, receiver []byte, _ uint32) *datafield.ResponseParseData { + return &datafield.ResponseParseData{} + }, + }, + } + apiTransactionProc, _ := NewAPITransactionProcessor(args) + + scrs, err := apiTransactionProc.GetSCRsByTxHash(hex.EncodeToString(txHash), hex.EncodeToString(scResultHash)) + require.Nil(t, err) + require.Equal(t, 1, len(scrs)) + require.Equal(t, &transaction.ApiSmartContractResult{ + Nonce: 1, + Data: "test", + Hash: "736348617368", + RcvAddr: "726376", + SndAddr: "736e64", + OriginalTxHash: "747848617368", + Receivers: []string{}, + }, scrs[0]) +} + func TestNode_GetTransactionFromStorage(t *testing.T) { t.Parallel() From d8f0a125205466cacd00a5ba20cadf4f1da7590d Mon Sep 17 00:00:00 2001 From: python-qa Date: Tue, 6 Aug 2024 10:11:03 +0300 Subject: [PATCH 07/99] pre-final version. Add gh-action yml that build mx-chain-simulator-go latest version with latest hash from mx-chain-go, and execute system tests --- ...hain_simulator_and_execute_system_test.yml | 341 ++++++++++++++++++ 1 file changed, 341 insertions(+) create mode 100644 .github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml new file mode 100644 index 00000000000..cd405ee65a6 --- /dev/null +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -0,0 +1,341 @@ +name: Build and Smoke Test + +on: + pull_request: + branches: + - 'main' + - 'master' + - 'rc/*' + workflow_dispatch: + issue_comment: + types: [created] + +permissions: + issues: write + pull-requests: write + contents: read + +jobs: + build-and-test: + if: | + github.event_name == 'pull_request' || + (github.event_name == 'issue_comment' && contains(github.event.comment.body, 'Run Tests:')) || + github.event_name == 'workflow_dispatch' + + strategy: + matrix: + #TODO Include Macos support later on + runs-on: [ubuntu-latest] + runs-on: ${{ matrix.runs-on }} + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + TARGET_BRANCH: "" + MX_CHAIN_GO_TARGET_BRANCH: "" + MX_CHAIN_SIMULATOR_TARGET_BRANCH: "" + MX_CHAIN_TESTING_SUITE_TARGET_BRANCH: "" + + steps: + - name: Fetch Latest Comment + if: github.event_name != 'issue_comment' + uses: actions/github-script@v7 + id: fetch_comment + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const comments = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + // Filter for comments containing "Run Tests:" + const latestComment = comments.data.reverse().find(comment => comment.body.includes('Run Tests:')); + + if (latestComment) { + core.setOutput('latest_comment', latestComment.body); + } else { + core.setOutput('latest_comment', ''); + } + env: + LATEST_COMMENT: ${{ steps.fetch_comment.outputs.latest_comment }} + + - name: Parse Comment for Branches + run: | + # Use fetched comment if available, otherwise use current event comment + COMMENT="${{ steps.fetch_comment.outputs.latest_comment || github.event.comment.body }}" + + # Debug print the comment being used + echo "Comment used for parsing: $COMMENT" + + # Extract branch names from the comment + if echo "$COMMENT" | grep -q "mx-chain-simulator-go:"; then + SIMULATOR_BRANCH=$(echo "$COMMENT" | grep "mx-chain-simulator-go:" | awk -F': ' '{print $2}') + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${SIMULATOR_BRANCH}" >> $GITHUB_ENV + fi + + if echo "$COMMENT" | grep -q "mx-chain-testing-suite:"; then + TESTING_SUITE_BRANCH=$(echo "$COMMENT" | grep "mx-chain-testing-suite:" | awk -F': ' '{print $2}') + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${TESTING_SUITE_BRANCH}" >> $GITHUB_ENV + fi + + - name: Set up Go 1.20.7 + uses: actions/setup-go@v3 + with: + go-version: 1.20.7 + id: go + + - name: Checkout mx-chain-go + uses: actions/checkout@v4 + with: + repository: 'multiversx/mx-chain-go' + ref: ${{ env.MX_CHAIN_GO_TARGET_BRANCH || github.head_ref || github.ref }} + fetch-depth: 0 + path: 'mx-chain-go' + + - name: Get Latest Commit Hash + run: | + cd mx-chain-go + current_branch=$(git symbolic-ref --short HEAD) + echo "CURRENT_BRANCH=${current_branch}" >> $GITHUB_ENV + git fetch origin ${current_branch} --prune + latest_commit_hash=$(git rev-parse origin/${current_branch}) + echo "LATEST_COMMIT_HASH=${latest_commit_hash}" >> $GITHUB_ENV + echo "Latest commit hash: ${latest_commit_hash}" + + - name: Determine Target Branches + id: target_branch + run: | + echo "CURRENT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" >> $GITHUB_ENV + + # Use branches from comment if they are set + if [ -n "${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" ]; then + echo "Using comment-specified mx-chain-simulator-go branch: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" >> $GITHUB_ENV + else + if [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV + elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV + elif [[ "${{ github.event.pull_request.base.ref }}" == rc/* || "${{ github.event.pull_request.base.ref }}" == integrate-sys-tests-ci* ]]; then + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + fi + fi + + if [ -n "${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" ]; then + echo "Using comment-specified mx-chain-testing-suite branch: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" >> $GITHUB_ENV + else + if [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV + elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV + elif [[ "${{ github.event.pull_request.base.ref }}" == rc/* || "${{ github.event.pull_request.base.ref }}" == integrate-sys-tests-ci* ]]; then + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + fi + fi + + # Always set MX_CHAIN_GO_TARGET_BRANCH based on the PR base branch + echo "MX_CHAIN_GO_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + + + - name: Print Target Branches + run: | + echo "Current branch mx-chain-go: ${{ env.CURRENT_BRANCH }}" + echo "mx-chain-go target branch: ${{ env.MX_CHAIN_GO_TARGET_BRANCH }}" + echo "mx-chain-simulator-go target branch: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" + echo "mx-chain-testing-suite target branch: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" + + - name: Checkout mx-chain-simulator-go + uses: actions/checkout@v4 + with: + repository: 'multiversx/mx-chain-simulator-go' + ref: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH || github.event.pull_request.base.ref }} + path: 'mx-chain-simulator-go' + + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: '3.10' + + - name: Install Python Dependencies and Update go.mod + run: | + cd mx-chain-simulator-go + pip install -r scripts/update_go_mod/requirements.txt + python scripts/update_go_mod/update_go_mod.py $LATEST_COMMIT_HASH + + + - name: Run go mod tidy and go build + run: | + cd mx-chain-simulator-go/cmd/chainsimulator + go mod tidy + go build + echo "CHAIN_SIMULATOR_BUILD_PATH=$(pwd)" >> $GITHUB_ENV + + - name: Checkout mx-chain-testing-suite + uses: actions/checkout@v4 + with: + repository: 'multiversx/mx-chain-testing-suite' + path: 'mx-chain-testing-suite' + fetch-depth: 0 + ref: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH || github.event.pull_request.base.ref }} + token: ${{ secrets.MVX_TESTER_GH_TOKEN }} + + - name: Install Dependencies + run: | + pip install -r mx-chain-testing-suite/requirements.txt + echo "PYTHONPATH=mx-chain-testing-suite" >> $GITHUB_ENV + + + - name: Run tests and generate HTML report + run: | + set +e + pytest mx-chain-testing-suite/scenarios/ --html=report.html --self-contained-html --continue-on-collection-errors + PYTEST_EXIT_CODE=$? + set -e + echo "PYTEST_EXIT_CODE=$PYTEST_EXIT_CODE" >> $GITHUB_ENV + echo "Pytest exit code: $PYTEST_EXIT_CODE" + if [ -f "report.html" ]; then + echo "Report generated successfully." + mkdir -p ./reports + mv report.html ./reports/ + else + echo "Report not found." + fi + + - name: Upload test report + if: always() + uses: actions/upload-artifact@v2 + with: + name: pytest-report-${{ github.run_id }} + path: reports/report.html + + - name: Deploy Report to GitHub Pages + if: always() + id: deploy_report + run: | + # Navigate to the mx-chain-testing-suite directory + cd mx-chain-testing-suite + + # Configure Git user + git config user.name "GitHub Action" + git config user.email "action@github.com" + + # Check if the report exists + if [ -f "../reports/report.html" ]; then + # Ensure we're on the 'gh-pages' branch and up to date + git fetch --all + git checkout gh-pages || git checkout --orphan gh-pages + + # Create a new directory for the report based on the current timestamp + TIMESTAMP=$(date +'%d%m%Y-%H%M%S') + echo "TIMESTAMP=$TIMESTAMP" >> $GITHUB_ENV + REPORT_DIR="reports/${BRANCH_NAME}/${TIMESTAMP}" + mkdir -p $REPORT_DIR + + # Move the report into the new directory + cp ../reports/report.html $REPORT_DIR/index.html + + # Add and commit only the new report + git add $REPORT_DIR/index.html + git commit -m "Deploy Test Report at $BRANCH_NAME/$TIMESTAMP" + + # Set remote URL with authentication token + git remote set-url origin https://x-access-token:${{ secrets.MVX_TESTER_GH_TOKEN }}@github.com/multiversx/mx-chain-testing-suite.git + + # Push changes to the remote 'gh-pages' branch + git push --force origin gh-pages + else + echo "Report file not found, skipping deployment." + fi + + + - name: Update Index Page + if: always() + run: | + cd mx-chain-testing-suite + git fetch --all + git checkout gh-pages || git checkout --orphan gh-pages + if [ -d "docs" ]; then + cd docs + echo "

Test Reports

    " > index.html + for report in $(ls ../reports); do + echo "
  • Report - $report
  • " >> index.html + done + echo "
" >> index.html + git add index.html + git commit -m "Update Index of Reports" + git push origin gh-pages --force + else + mkdir -p docs + cd docs + echo "

Test Reports

    " > index.html + echo "
" >> index.html + echo "Docs directory was not found and has been created." + fi + + - name: Comment PR with report link or error message + if: always() + uses: actions/github-script@v7 + env: + TIMESTAMP: ${{ env.TIMESTAMP }} + BRANCH_NAME: ${{ env.BRANCH_NAME }} + CURRENT_BRANCH: ${{ env.CURRENT_BRANCH }} + MX_CHAIN_GO_TARGET_BRANCH: ${{ env.MX_CHAIN_GO_TARGET_BRANCH }} + MX_CHAIN_SIMULATOR_TARGET_BRANCH: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }} + MX_CHAIN_TESTING_SUITE_TARGET_BRANCH: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }} + LATEST_COMMIT_HASH: ${{ env.LATEST_COMMIT_HASH }} + PYTEST_EXIT_CODE: ${{ env.PYTEST_EXIT_CODE }} + + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const timestamp = process.env.TIMESTAMP; + const branchName = process.env.BRANCH_NAME; + const currentBranch = process.env.CURRENT_BRANCH; + const goTargetBranch = process.env.MX_CHAIN_GO_TARGET_BRANCH; + const simulatorTargetBranch = process.env.MX_CHAIN_SIMULATOR_TARGET_BRANCH; + const testingSuiteTargetBranch = process.env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH; + const commitHash = process.env.LATEST_COMMIT_HASH; + const exitCode = process.env.PYTEST_EXIT_CODE; + const issue_number = context.issue.number; + const owner = context.repo.owner; + const repo = context.repo.repo; + let message; + + if (timestamp && branchName && timestamp !== "" && branchName !== "") { + const reportUrl = `https://multiversx.github.io/mx-chain-testing-suite/reports/${branchName}/${timestamp}/index.html`; + message = ` + 📊 **MultiversX Automated Test Report:** [View Report](${reportUrl}) + + 🔄 **Build Details:** + - **mx-chain-go Commit Hash:** \`${commitHash}\` + - **Current Branch:** \`${currentBranch}\` + - **mx-chain-go Target Branch:** \`${goTargetBranch}\` + - **mx-chain-simulator-go Target Branch:** \`${simulatorTargetBranch}\` + - **mx-chain-testing-suite Target Branch:** \`${testingSuiteTargetBranch}\` + + 🚀 **Environment Variables:** + - **TIMESTAMP:** \`${timestamp}\` + - **PYTEST_EXIT_CODE:** \`${exitCode}\` + 🎉 **MultiversX CI/CD Workflow Complete!** + `; + } else { + message = "⚠️ No report was generated due to an error or cancellation of the process.\nPlease checkout gh action logs for details"; + } + + github.rest.issues.createComment({ + issue_number: issue_number, + owner: owner, + repo: repo, + body: message + }); + + - name: Fail job if tests failed + if: always() + run: | + if [ "${{ env.PYTEST_EXIT_CODE }}" != "0" ]; then + echo "Tests failed with exit code ${{ env.PYTEST_EXIT_CODE }}" + exit 1 + else + echo "Tests passed successfully." + fi \ No newline at end of file From b60aa5278067d7cdd426d97cec1ff9df1e11ad0c Mon Sep 17 00:00:00 2001 From: python-qa Date: Wed, 7 Aug 2024 15:31:21 +0300 Subject: [PATCH 08/99] fix PR comments. Remove go Tidy from action and move it to the python script --- ...ild_and_run_chain_simulator_and_execute_system_test.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index cd405ee65a6..4ea0d71b04a 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: - #TODO Include Macos support later on + #TODO Include Macos support later on runs-on: [ubuntu-latest] runs-on: ${{ matrix.runs-on }} env: @@ -116,8 +116,6 @@ jobs: echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV - elif [[ "${{ github.event.pull_request.base.ref }}" == rc/* || "${{ github.event.pull_request.base.ref }}" == integrate-sys-tests-ci* ]]; then - echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV fi fi @@ -129,8 +127,6 @@ jobs: echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV - elif [[ "${{ github.event.pull_request.base.ref }}" == rc/* || "${{ github.event.pull_request.base.ref }}" == integrate-sys-tests-ci* ]]; then - echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV fi fi @@ -167,7 +163,6 @@ jobs: - name: Run go mod tidy and go build run: | cd mx-chain-simulator-go/cmd/chainsimulator - go mod tidy go build echo "CHAIN_SIMULATOR_BUILD_PATH=$(pwd)" >> $GITHUB_ENV From 75cb69565b9bcfb05c4eb3cea1d38fd5b6a21c6a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 8 Aug 2024 21:00:36 +0300 Subject: [PATCH 09/99] added fix for relayed move balance to non payables --- cmd/node/config/enableEpochs.toml | 3 + common/constants.go | 4 ++ common/enablers/enableEpochsHandler.go | 6 ++ common/enablers/enableEpochsHandler_test.go | 3 + config/epochConfig.go | 1 + config/tomlConfig_test.go | 4 ++ .../relayedTx/relayedTx_test.go | 70 +++++++++++++++++++ .../vm/esdtImprovements_test.go | 1 - .../multiShard/relayedTx/common.go | 1 + integrationTests/testProcessorNode.go | 1 + node/metrics/metrics.go | 1 + node/metrics/metrics_test.go | 2 + process/transaction/shardProcess.go | 39 +++++++++++ process/transaction/shardProcess_test.go | 63 +++++++++++++++++ statusHandler/statusMetricsProvider.go | 1 + statusHandler/statusMetricsProvider_test.go | 2 + 16 files changed, 201 insertions(+), 1 deletion(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index f088f7b549c..60884a826e0 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -330,6 +330,9 @@ # MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 9999999 + # FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled + FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 7 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/common/constants.go b/common/constants.go index 984dec87b07..2a7948ca9ee 100644 --- a/common/constants.go +++ b/common/constants.go @@ -737,6 +737,9 @@ const ( // MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign opcodes are enabled MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch = "erd_multi_esdt_transfer_execute_by_user_enable_epoch" + // MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non-payable sc is enabled + MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch = "erd_fix_relayed_move_balance_to_non_payable_sc_enable_epoch" + // MetricMaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MetricMaxNodesChangeEnableEpoch = "erd_max_nodes_change_enable_epoch" @@ -1233,5 +1236,6 @@ const ( RelayedTransactionsV3Flag core.EnableEpochFlag = "RelayedTransactionsV3Flag" FixRelayedBaseCostFlag core.EnableEpochFlag = "FixRelayedBaseCostFlag" MultiESDTNFTTransferAndExecuteByUserFlag core.EnableEpochFlag = "MultiESDTNFTTransferAndExecuteByUserFlag" + FixRelayedMoveBalanceToNonPayableSCFlag core.EnableEpochFlag = "FixRelayedMoveBalanceToNonPayableSCFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index d3df21b6bbb..01155e47dcf 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -774,6 +774,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, }, + common.FixRelayedMoveBalanceToNonPayableSCFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch, + }, } } diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 72fafc5a689..48497586187 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -122,6 +122,7 @@ func createEnableEpochsConfig() config.EnableEpochs { RelayedTransactionsV3EnableEpoch: 105, FixRelayedBaseCostEnableEpoch: 106, MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 107, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107, } } @@ -324,6 +325,7 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) { require.True(t, handler.IsFlagEnabled(common.DynamicESDTFlag)) require.True(t, handler.IsFlagEnabled(common.RelayedTransactionsV3Flag)) require.True(t, handler.IsFlagEnabled(common.FixRelayedBaseCostFlag)) + require.True(t, handler.IsFlagEnabled(common.FixRelayedMoveBalanceToNonPayableSCFlag)) } func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { @@ -446,6 +448,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.RelayedTransactionsV3EnableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV3Flag)) require.Equal(t, cfg.FixRelayedBaseCostEnableEpoch, handler.GetActivationEpoch(common.FixRelayedBaseCostFlag)) require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.MultiESDTNFTTransferAndExecuteByUserFlag)) + require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceToNonPayableSCFlag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { diff --git a/config/epochConfig.go b/config/epochConfig.go index 7f965e3c5c5..d449afe73af 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -121,6 +121,7 @@ type EnableEpochs struct { RelayedTransactionsV3EnableEpoch uint32 FixRelayedBaseCostEnableEpoch uint32 MultiESDTNFTTransferAndExecuteByUserEnableEpoch uint32 + FixRelayedMoveBalanceToNonPayableSCEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index c6cecedc774..ea9d1f6a46b 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -881,6 +881,9 @@ func TestEnableEpochConfig(t *testing.T) { # MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 101 + # FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled + FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 102 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -1000,6 +1003,7 @@ func TestEnableEpochConfig(t *testing.T) { RelayedTransactionsV3EnableEpoch: 99, FixRelayedBaseCostEnableEpoch: 100, MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 101, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 102, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 72bc9575763..6e71ae4bab9 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -267,6 +267,76 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t } } +func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInvalidInnerMoveBalance(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + cs := startChainSimulator(t, func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.FixRelayedBaseCostEnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 1 + }) + defer cs.Close() + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() + + // deploy adder contract + owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + err = cs.GenerateBlocks(1) + require.Nil(t, err) + + ownerNonce := uint64(0) + scCode := wasm.GetSCCode("testData/adder.wasm") + params := []string{scCode, wasm.VMTypeHex, "0000", "00"} + txDataDeploy := strings.Join(params, "@") + deployTx := generateTransaction(owner.Bytes, ownerNonce, make([]byte, 32), big.NewInt(0), txDataDeploy, 100000000) + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + scAddress := result.Logs.Events[0].Address + scAddressBytes, _ := pkConv.Decode(scAddress) + + balanceRelayerBefore := getBalance(t, cs, relayer) + balanceOwnerBefore := getBalance(t, cs, owner) + + // move balance to non-payable contract should only consume fees and sender's nonce + ownerNonce++ + innerTx1 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, oneEGLD, "", 50000) + innerTx1.RelayerAddr = relayer.Bytes + + // move balance to meta contract should only consume fees and sender's nonce + ownerNonce++ + innerTx2 := generateTransaction(owner.Bytes, ownerNonce, core.ESDTSCAddress, oneEGLD, "", 50000) + innerTx2.RelayerAddr = relayer.Bytes + + innerTxs := []*transaction.Transaction{innerTx1, innerTx2} + + relayedTxGasLimit := uint64(0) + for _, tx := range innerTxs { + relayedTxGasLimit += minGasLimit + tx.GasLimit + } + relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) + relayedTx.InnerTransactions = innerTxs + + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + balanceRelayerAfter := getBalance(t, cs, relayer) + balanceOwnerAfter := getBalance(t, cs, owner) + consumedRelayedFee := core.SafeMul(relayedTxGasLimit, minGasPrice) + expectedBalanceRelayerAfter := big.NewInt(0).Sub(balanceRelayerBefore, consumedRelayedFee) + require.Equal(t, balanceOwnerBefore.String(), balanceOwnerAfter.String()) + require.Equal(t, expectedBalanceRelayerAfter.String(), balanceRelayerAfter.String()) +} + func TestFixRelayedMoveBalanceWithChainSimulator(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index d8e5c065a45..438660658f3 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2343,7 +2343,6 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { []byte(core.ESDTRoleNFTUpdate), } tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[0].Bytes, tokenID, roles) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index c2bc8e5995c..6815d12802e 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -21,6 +21,7 @@ func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.T if !relayedV3Test { epochsConfig.RelayedTransactionsV3EnableEpoch = integrationTests.UnreachableEpoch epochsConfig.FixRelayedBaseCostEnableEpoch = integrationTests.UnreachableEpoch + epochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch = integrationTests.UnreachableEpoch } nodes, idxProposers := createAndMintNodes(initialVal, epochsConfig) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index ef55c21f54a..cf76e1582d0 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -3277,6 +3277,7 @@ func CreateEnableEpochsConfig() config.EnableEpochs { SCProcessorV2EnableEpoch: UnreachableEpoch, RelayedTransactionsV3EnableEpoch: UnreachableEpoch, FixRelayedBaseCostEnableEpoch: UnreachableEpoch, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: UnreachableEpoch, } } diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index c380c08b95d..bc84198eca5 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -202,6 +202,7 @@ func InitConfigMetrics( appStatusHandler.SetUInt64Value(common.MetricEGLDInMultiTransferEnableEpoch, uint64(enableEpochs.EGLDInMultiTransferEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricCryptoOpcodesV2EnableEpoch, uint64(enableEpochs.CryptoOpcodesV2EnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch, uint64(enableEpochs.MultiESDTNFTTransferAndExecuteByUserEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch, uint64(enableEpochs.FixRelayedMoveBalanceToNonPayableSCEnableEpoch)) for i, nodesChangeConfig := range enableEpochs.MaxNodesChangeEnableEpoch { epochEnable := fmt.Sprintf("%s%d%s", common.MetricMaxNodesChangeEnableEpoch, i, common.EpochEnableSuffix) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index 395d42afc15..bec9f099923 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -211,6 +211,7 @@ func TestInitConfigMetrics(t *testing.T) { RelayedTransactionsV3EnableEpoch: 104, FixRelayedBaseCostEnableEpoch: 105, MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 106, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107, MaxNodesChangeEnableEpoch: []config.MaxNodesChangeConfig{ { EpochEnable: 0, @@ -332,6 +333,7 @@ func TestInitConfigMetrics(t *testing.T) { "erd_relayed_transactions_v3_enable_epoch": uint32(104), "erd_fix_relayed_base_cost_enable_epoch": uint32(105), "erd_multi_esdt_transfer_execute_by_user_enable_epoch": uint32(106), + "erd_fix_relayed_move_balance_to_non_payable_sc_enable_epoch": uint32(107), "erd_max_nodes_change_enable_epoch": nil, "erd_total_supply": "12345", "erd_hysteresis": "0.100000", diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 129ad2c5db8..168eb19c539 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -500,14 +500,28 @@ func (txProc *txProcessor) processMoveBalance( isPayable, err := txProc.scProcessor.IsPayable(tx.SndAddr, tx.RcvAddr) if err != nil { + errRefund := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + if errRefund != nil { + log.Warn("failed to return funds to sender after check if receiver is payable", "error", errRefund) + } return err } if !isPayable { + err = txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + if err != nil { + log.Warn("failed to return funds to sender while transferring to non payable sc", "error", err) + } + return process.ErrAccountNotPayable } err = txProc.checkIfValidTxToMetaChain(tx, tx.RcvAddr) if err != nil { + errLocal := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + if errLocal != nil { + log.Warn("failed to return funds to sender while sending invalid tx to metachain", "error", errLocal) + } + return err } @@ -543,6 +557,31 @@ func (txProc *txProcessor) processMoveBalance( return nil } +func (txProc *txProcessor) removeConsumedValueFromSender( + tx *transaction.Transaction, + acntSrc state.UserAccountHandler, + isUserTxOfRelayed bool, +) error { + if !isUserTxOfRelayed { + return nil + } + + if !txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceToNonPayableSCFlag) { + return nil + } + + if check.IfNil(acntSrc) { + return nil + } + + err := acntSrc.AddToBalance(tx.Value) + if err != nil { + return err + } + + return txProc.accounts.SaveAccount(acntSrc) +} + func (txProc *txProcessor) processSCDeployment( tx *transaction.Transaction, acntSrc state.UserAccountHandler, diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 1f077525ae2..4c325a8f78e 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -3876,6 +3876,69 @@ func TestTxProcessor_AddNonExecutableLog(t *testing.T) { }) } +func TestTxProcessor_ProcessMoveBalanceToNonPayableContract(t *testing.T) { + t.Parallel() + + shardCoordinator := mock.NewOneShardCoordinatorMock() + + innerTx := transaction.Transaction{} + innerTx.Nonce = 1 + innerTx.SndAddr = []byte("SRC") + innerTx.RcvAddr = make([]byte, 32) + innerTx.Value = big.NewInt(100) + innerTx.RelayerAddr = []byte("SRC") + + tx := transaction.Transaction{} + tx.Nonce = 0 + tx.SndAddr = []byte("SRC") + tx.RcvAddr = []byte("SRC") + tx.Value = big.NewInt(0) + tx.InnerTransactions = []*transaction.Transaction{&innerTx} + + shardCoordinator.ComputeIdCalled = func(address []byte) uint32 { + return 0 + } + + acntSrc := createUserAcc(innerTx.SndAddr) + initialBalance := big.NewInt(100) + _ = acntSrc.AddToBalance(initialBalance) + acntDst := createUserAcc(innerTx.RcvAddr) + + adb := createAccountStub(innerTx.SndAddr, innerTx.RcvAddr, acntSrc, acntDst) + + args := createArgsForTxProcessor() + args.Accounts = adb + args.ShardCoordinator = shardCoordinator + cnt := 0 + args.TxTypeHandler = &testscommon.TxTypeHandlerMock{ + ComputeTransactionTypeCalled: func(tx data.TransactionHandler) (process.TransactionType, process.TransactionType) { + cnt++ + if cnt == 1 { + return process.RelayedTxV3, process.RelayedTxV3 + } + + return process.MoveBalance, process.MoveBalance + }, + } + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub( + common.RelayedTransactionsV3Flag, + common.FixRelayedBaseCostFlag, + common.FixRelayedMoveBalanceToNonPayableSCFlag, + ) + args.ScProcessor = &testscommon.SCProcessorMock{ + IsPayableCalled: func(sndAddress, recvAddress []byte) (bool, error) { + return false, nil + }, + } + execTx, _ := txproc.NewTxProcessor(args) + + _, err := execTx.ProcessTransaction(&tx) + assert.Nil(t, err) + + balance := acntSrc.GetBalance() + require.Equal(t, initialBalance, balance) // disabled economics data, testing only tx.value +} + func TestTxProcessor_IsInterfaceNil(t *testing.T) { t.Parallel() diff --git a/statusHandler/statusMetricsProvider.go b/statusHandler/statusMetricsProvider.go index 30ead1e5749..8050d335431 100644 --- a/statusHandler/statusMetricsProvider.go +++ b/statusHandler/statusMetricsProvider.go @@ -378,6 +378,7 @@ func (sm *statusMetrics) EnableEpochsMetrics() (map[string]interface{}, error) { enableEpochsMetrics[common.MetricEGLDInMultiTransferEnableEpoch] = sm.uint64Metrics[common.MetricEGLDInMultiTransferEnableEpoch] enableEpochsMetrics[common.MetricCryptoOpcodesV2EnableEpoch] = sm.uint64Metrics[common.MetricCryptoOpcodesV2EnableEpoch] enableEpochsMetrics[common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch] = sm.uint64Metrics[common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch] + enableEpochsMetrics[common.MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch] = sm.uint64Metrics[common.MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch] numNodesChangeConfig := sm.uint64Metrics[common.MetricMaxNodesChangeEnableEpoch+"_count"] diff --git a/statusHandler/statusMetricsProvider_test.go b/statusHandler/statusMetricsProvider_test.go index 02f33d62549..14b5b5225d3 100644 --- a/statusHandler/statusMetricsProvider_test.go +++ b/statusHandler/statusMetricsProvider_test.go @@ -401,6 +401,7 @@ func TestStatusMetrics_EnableEpochMetrics(t *testing.T) { sm.SetUInt64Value(common.MetricEGLDInMultiTransferEnableEpoch, uint64(4)) sm.SetUInt64Value(common.MetricCryptoOpcodesV2EnableEpoch, uint64(4)) sm.SetUInt64Value(common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch, uint64(4)) maxNodesChangeConfig := []map[string]uint64{ { @@ -531,6 +532,7 @@ func TestStatusMetrics_EnableEpochMetrics(t *testing.T) { common.MetricEGLDInMultiTransferEnableEpoch: uint64(4), common.MetricCryptoOpcodesV2EnableEpoch: uint64(4), common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch: uint64(4), + common.MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch: uint64(4), common.MetricMaxNodesChangeEnableEpoch: []map[string]interface{}{ { From d78614a8ca0f8961ec1adcf175cd980f6949cbfd Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 8 Aug 2024 23:02:42 +0300 Subject: [PATCH 10/99] - integrated new VM --- go.mod | 2 + go.sum | 4 +- .../wasmvm/mockcontracts/simpleChildSC.go | 50 ------------------- .../wasmvm/mockcontracts/simpleParentSC.go | 43 ---------------- 4 files changed, 4 insertions(+), 95 deletions(-) delete mode 100644 integrationTests/vm/wasm/wasmvm/mockcontracts/simpleChildSC.go delete mode 100644 integrationTests/vm/wasm/wasmvm/mockcontracts/simpleParentSC.go diff --git a/go.mod b/go.mod index 24474aeef37..e6154610617 100644 --- a/go.mod +++ b/go.mod @@ -188,3 +188,5 @@ require ( ) replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 + +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3 diff --git a/go.sum b/go.sum index ec1a900502b..4ff92ec601b 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 h1:wDrE+ZMoHH+BzG3n4ERUR9Luas2w+GvV6e3w4r9hFw0= -github.com/multiversx/mx-chain-vm-go v1.5.29-patch1/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3 h1:64gr6OyTPjrtHlEhH2KjY15zMeEmfD1vofVViKbMa2w= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= diff --git a/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleChildSC.go b/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleChildSC.go deleted file mode 100644 index 7e1bb9dbaf5..00000000000 --- a/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleChildSC.go +++ /dev/null @@ -1,50 +0,0 @@ -package mockcontracts - -import ( - "errors" - - mock "github.com/multiversx/mx-chain-vm-go/mock/context" - test "github.com/multiversx/mx-chain-vm-go/testcommon" - "github.com/multiversx/mx-chain-vm-go/vmhost" -) - -// SimpleCallChildMock is an exposed mock contract method -func SimpleCallChildMock(instanceMock *mock.InstanceMock, config interface{}) { - instanceMock.AddMockMethod("simpleChildFunction", func() *mock.InstanceMock { - testConfig := config.(*test.TestConfig) - host := instanceMock.Host - instance := mock.GetMockInstance(host) - - arguments := host.Runtime().Arguments() - if len(arguments) != 1 { - host.Runtime().SignalUserError("wrong num of arguments") - return instance - } - - host.Metering().UseGas(testConfig.GasUsedByChild) - - behavior := byte(0) - if len(arguments[0]) != 0 { - behavior = arguments[0][0] - } - err := handleChildBehaviorArgument(host, behavior) - if err != nil { - return instance - } - - _, _ = host.Storage().SetStorage(test.ChildKey, test.ChildData) - host.Output().Finish(test.ChildFinish) - - return instance - }) -} - -func handleChildBehaviorArgument(host vmhost.VMHost, behavior byte) error { - if behavior == 1 { - host.Runtime().SignalUserError("child error") - return errors.New("behavior / child error") - } - - host.Output().Finish([]byte{behavior}) - return nil -} diff --git a/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleParentSC.go b/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleParentSC.go deleted file mode 100644 index 63f4fcc5d4e..00000000000 --- a/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleParentSC.go +++ /dev/null @@ -1,43 +0,0 @@ -package mockcontracts - -import ( - "math/big" - - mock "github.com/multiversx/mx-chain-vm-go/mock/context" - test "github.com/multiversx/mx-chain-vm-go/testcommon" - "github.com/multiversx/mx-chain-vm-go/vmhost" - "github.com/multiversx/mx-chain-vm-go/vmhost/vmhooks" - "github.com/stretchr/testify/require" -) - -var failBehavior = []byte{1} - -// PerformOnDestCallFailParentMock is an exposed mock contract method -func PerformOnDestCallFailParentMock(instanceMock *mock.InstanceMock, config interface{}) { - instanceMock.AddMockMethod("performOnDestCallFail", func() *mock.InstanceMock { - testConfig := config.(*test.TestConfig) - host := instanceMock.Host - instance := mock.GetMockInstance(host) - t := instance.T - - err := host.Metering().UseGasBounded(testConfig.GasUsedByParent) - if err != nil { - host.Runtime().SetRuntimeBreakpointValue(vmhost.BreakpointOutOfGas) - return instance - } - - _, _ = host.Storage().SetStorage(test.ParentKeyA, test.ParentDataA) - host.Output().Finish(test.ParentFinishA) - - retVal := vmhooks.ExecuteOnDestContextWithTypedArgs( - host, - int64(testConfig.GasProvidedToChild), - big.NewInt(0), - []byte("simpleChildFunction"), - testConfig.ChildAddress, - [][]byte{failBehavior}) - require.Equal(t, retVal, int32(1)) - - return instance - }) -} From f289f70a2703b3dffd0602efa2c6bfedec7eb14a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 11:33:27 +0300 Subject: [PATCH 11/99] updated core-go after merge --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6001f2447b4..5a2ac5d99fd 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc + github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.7.4 github.com/multiversx/mx-chain-logger-go v1.0.15 diff --git a/go.sum b/go.sum index c22310babde..431460a09e2 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc h1:COQlZ7wmOz15F40woVfRb6sl5CLQCKcRv13e9s/2PT0= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc h1:EB25Psgi0GjWJfrNfgvGEMcuoqj63BnFrw0bqsl9Hdc= +github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= github.com/multiversx/mx-chain-es-indexer-go v1.7.4 h1:SjJk9G9SN8baz0sFIU2jymYCfx3XiikGEB2wW0jwvfw= From dab6bcd7a8a79930bd52a0e052f8572d9aeb350f Mon Sep 17 00:00:00 2001 From: python-qa Date: Fri, 9 Aug 2024 15:33:05 +0300 Subject: [PATCH 12/99] rename the action --- .../build_and_run_chain_simulator_and_execute_system_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index 4ea0d71b04a..1d5502d56a3 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -1,4 +1,4 @@ -name: Build and Smoke Test +name: Chain Simulator Build and Integration Test on: pull_request: From ffa43f71ecb0c4297aed5010ad61c7a9563ef3f0 Mon Sep 17 00:00:00 2001 From: python-qa Date: Fri, 9 Aug 2024 15:38:15 +0300 Subject: [PATCH 13/99] fix CS script path --- .../build_and_run_chain_simulator_and_execute_system_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index 1d5502d56a3..2b36714fdeb 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -156,8 +156,8 @@ jobs: - name: Install Python Dependencies and Update go.mod run: | cd mx-chain-simulator-go - pip install -r scripts/update_go_mod/requirements.txt - python scripts/update_go_mod/update_go_mod.py $LATEST_COMMIT_HASH + pip install -r scripts/update-go-mod/requirements.txt + python scripts/update-go-mod/update-go-mod.py $LATEST_COMMIT_HASH - name: Run go mod tidy and go build From db3bb47eb50980c2c1d8efb7fba4727867ea87cb Mon Sep 17 00:00:00 2001 From: python-qa Date: Fri, 9 Aug 2024 16:35:07 +0300 Subject: [PATCH 14/99] rename step --- .../build_and_run_chain_simulator_and_execute_system_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index 2b36714fdeb..0bb675230ae 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -160,7 +160,7 @@ jobs: python scripts/update-go-mod/update-go-mod.py $LATEST_COMMIT_HASH - - name: Run go mod tidy and go build + - name: Run go build run: | cd mx-chain-simulator-go/cmd/chainsimulator go build From 87cae3bd847ced041f61f0c8779609b4b923c655 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 16:49:25 +0300 Subject: [PATCH 15/99] fixes after review --- common/enablers/enableEpochsHandler_test.go | 2 +- integrationTests/chainSimulator/relayedTx/relayedTx_test.go | 2 +- process/transaction/shardProcess.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 48497586187..83977fa51b9 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -122,7 +122,7 @@ func createEnableEpochsConfig() config.EnableEpochs { RelayedTransactionsV3EnableEpoch: 105, FixRelayedBaseCostEnableEpoch: 106, MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 107, - FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 108, } } diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 6e71ae4bab9..8b5a5b9e525 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -267,7 +267,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t } } -func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInvalidInnerMoveBalance(t *testing.T) { +func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInnerMoveBalanceToNonPayableSC(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 168eb19c539..92aeaec8838 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -502,14 +502,14 @@ func (txProc *txProcessor) processMoveBalance( if err != nil { errRefund := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if errRefund != nil { - log.Warn("failed to return funds to sender after check if receiver is payable", "error", errRefund) + log.Error("failed to return funds to sender after check if receiver is payable", "error", errRefund) } return err } if !isPayable { err = txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if err != nil { - log.Warn("failed to return funds to sender while transferring to non payable sc", "error", err) + log.Error("failed to return funds to sender while transferring to non payable sc", "error", err) } return process.ErrAccountNotPayable @@ -519,7 +519,7 @@ func (txProc *txProcessor) processMoveBalance( if err != nil { errLocal := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if errLocal != nil { - log.Warn("failed to return funds to sender while sending invalid tx to metachain", "error", errLocal) + log.Error("failed to return funds to sender while sending invalid tx to metachain", "error", errLocal) } return err From 7d0ea8697d043ac4fbaf504a70d52dae0f89f1c6 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 17:03:14 +0300 Subject: [PATCH 16/99] fixed test after fixes --- common/enablers/enableEpochsHandler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 83977fa51b9..64e23a6e122 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -448,7 +448,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.RelayedTransactionsV3EnableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV3Flag)) require.Equal(t, cfg.FixRelayedBaseCostEnableEpoch, handler.GetActivationEpoch(common.FixRelayedBaseCostFlag)) require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.MultiESDTNFTTransferAndExecuteByUserFlag)) - require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceToNonPayableSCFlag)) + require.Equal(t, cfg.FixRelayedMoveBalanceToNonPayableSCEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceToNonPayableSCFlag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { From 760583c8229200683e3ca5957c07469cb6436960 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 17:28:32 +0300 Subject: [PATCH 17/99] missing fix --- process/transaction/shardProcess.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 92aeaec8838..50fa0c94d21 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -500,14 +500,14 @@ func (txProc *txProcessor) processMoveBalance( isPayable, err := txProc.scProcessor.IsPayable(tx.SndAddr, tx.RcvAddr) if err != nil { - errRefund := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + errRefund := txProc.revertConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if errRefund != nil { log.Error("failed to return funds to sender after check if receiver is payable", "error", errRefund) } return err } if !isPayable { - err = txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + err = txProc.revertConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if err != nil { log.Error("failed to return funds to sender while transferring to non payable sc", "error", err) } @@ -517,7 +517,7 @@ func (txProc *txProcessor) processMoveBalance( err = txProc.checkIfValidTxToMetaChain(tx, tx.RcvAddr) if err != nil { - errLocal := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + errLocal := txProc.revertConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if errLocal != nil { log.Error("failed to return funds to sender while sending invalid tx to metachain", "error", errLocal) } @@ -557,7 +557,7 @@ func (txProc *txProcessor) processMoveBalance( return nil } -func (txProc *txProcessor) removeConsumedValueFromSender( +func (txProc *txProcessor) revertConsumedValueFromSender( tx *transaction.Transaction, acntSrc state.UserAccountHandler, isUserTxOfRelayed bool, From 970a776943e38cf64c17aa06ec9b69f49f2022d0 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 17:40:26 +0300 Subject: [PATCH 18/99] fix fee field for other relayed cases --- factory/api/apiResolverFactory.go | 1 + .../relayedTx/relayedTx_test.go | 114 ++++++++++++++---- .../testProcessorNodeWithTestWebServer.go | 2 + .../transactionAPI/apiTransactionArgs.go | 1 + .../transactionAPI/apiTransactionProcessor.go | 9 +- .../apiTransactionProcessor_test.go | 14 +++ node/external/transactionAPI/check.go | 5 + .../transactionAPI/gasUsedAndFeeProcessor.go | 96 ++++++++++++++- .../gasUsedAndFeeProcessor_test.go | 48 +++++++- 9 files changed, 258 insertions(+), 32 deletions(-) diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index 67eb70aa4a9..621ff7a8d13 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -245,6 +245,7 @@ func CreateApiResolver(args *ApiResolverArgs) (facade.ApiResolver, error) { LogsFacade: logsFacade, DataFieldParser: dataFieldParser, GasScheduleNotifier: args.GasScheduleNotifier, + TxMarshaller: args.CoreComponents.TxMarshalizer(), } apiTransactionProcessor, err := transactionAPI.NewAPITransactionProcessor(argsAPITransactionProc) if err != nil { diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 72bc9575763..f10f9a705a8 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -30,6 +30,7 @@ const ( minGasLimit = 50_000 guardAccountCost = 250_000 extraGasLimitForGuarded = minGasLimit + gasPerDataByte = 1_500 txVersion = 2 mockTxSignature = "sig" maxNumOfBlocksToGenerateWhenExecutingTx = 10 @@ -177,16 +178,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t require.Nil(t, err) ownerNonce := uint64(0) - scCode := wasm.GetSCCode("testData/adder.wasm") - params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, "00"} - txDataDeploy := strings.Join(params, "@") - deployTx := generateTransaction(owner.Bytes, ownerNonce, make([]byte, 32), big.NewInt(0), txDataDeploy, 100000000) - - result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - scAddress := result.Logs.Events[0].Address - scAddressBytes, _ := pkConv.Decode(scAddress) + scAddressBytes := deployAdder(t, cs, owner, ownerNonce) scShard := shardC.ComputeId(scAddressBytes) scShardNodeHandler := cs.GetNodeHandler(scShard) @@ -235,7 +227,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) relayedTx.InnerTransactions = innerTxs - result, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) require.NoError(t, err) checkSum(t, scShardNodeHandler, scAddressBytes, owner.Bytes, 4) @@ -295,8 +287,6 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( cs := startChainSimulator(t, alterConfigsFunc) defer cs.Close() - pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() - initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) require.NoError(t, err) @@ -309,16 +299,8 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( err = cs.GenerateBlocks(1) require.NoError(t, err) - scCode := wasm.GetSCCode("testData/adder.wasm") - params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, "00"} - txDataDeploy := strings.Join(params, "@") - deployTx := generateTransaction(owner.Bytes, 0, make([]byte, 32), big.NewInt(0), txDataDeploy, 100000000) - - result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - scAddress := result.Logs.Events[0].Address - scAddressBytes, _ := pkConv.Decode(scAddress) + ownerNonce := uint64(0) + scAddressBytes := deployAdder(t, cs, owner, ownerNonce) // fast-forward until epoch 4 err = cs.GenerateBlocksUntilEpochIsReached(int32(4)) @@ -581,6 +563,67 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInnerNotExec checkBalance(t, cs, receiver, oneEGLD) } +func TestRelayedTransactionFeeField(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + cs := startChainSimulator(t, func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.RelayedTransactionsEnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.RelayedTransactionsV2EnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.FixRelayedBaseCostEnableEpoch = 1 + }) + defer cs.Close() + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + receiver, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) + require.NoError(t, err) + + err = cs.GenerateBlocks(1) + require.Nil(t, err) + + t.Run("relayed v1", func(t *testing.T) { + innerTx := generateTransaction(sender.Bytes, 0, receiver.Bytes, oneEGLD, "", minGasLimit) + buff, err := json.Marshal(innerTx) + require.NoError(t, err) + + txData := []byte("relayedTx@" + hex.EncodeToString(buff)) + gasLimit := minGasLimit + len(txData)*gasPerDataByte + int(innerTx.GasLimit) + relayedTx := generateTransaction(relayer.Bytes, 0, sender.Bytes, big.NewInt(0), string(txData), uint64(gasLimit)) + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + expectedFee := core.SafeMul(uint64(gasLimit), minGasPrice) + require.Equal(t, expectedFee.String(), result.Fee) + require.Equal(t, expectedFee.String(), result.InitiallyPaidFee) + require.Equal(t, uint64(gasLimit), result.GasUsed) + }) + t.Run("relayed v3", func(t *testing.T) { + innerTx := generateTransaction(sender.Bytes, 1, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx.RelayerAddr = relayer.Bytes + + gasLimit := minGasLimit + int(innerTx.GasLimit) + relayedTx := generateTransaction(relayer.Bytes, 1, relayer.Bytes, big.NewInt(0), "", uint64(gasLimit)) + relayedTx.InnerTransactions = []*transaction.Transaction{innerTx} + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + expectedFee := core.SafeMul(uint64(gasLimit), minGasPrice) + require.Equal(t, expectedFee.String(), result.Fee) + require.Equal(t, expectedFee.String(), result.InitiallyPaidFee) + require.Equal(t, uint64(gasLimit), result.GasUsed) + }) +} + func startChainSimulator( t *testing.T, alterConfigsFunction func(cfg *config.Configs), @@ -705,3 +748,28 @@ func checkBalance( balance := getBalance(t, cs, address) require.Equal(t, expectedBalance.String(), balance.String()) } + +func deployAdder( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + owner dtos.WalletAddress, + ownerNonce uint64, +) []byte { + pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() + + err := cs.GenerateBlocks(1) + require.Nil(t, err) + + scCode := wasm.GetSCCode("testData/adder.wasm") + params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, "00"} + txDataDeploy := strings.Join(params, "@") + deployTx := generateTransaction(owner.Bytes, ownerNonce, make([]byte, 32), big.NewInt(0), txDataDeploy, 100000000) + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + scAddress := result.Logs.Events[0].Address + scAddressBytes, _ := pkConv.Decode(scAddress) + + return scAddressBytes +} diff --git a/integrationTests/testProcessorNodeWithTestWebServer.go b/integrationTests/testProcessorNodeWithTestWebServer.go index 02849a7803a..c194695fb73 100644 --- a/integrationTests/testProcessorNodeWithTestWebServer.go +++ b/integrationTests/testProcessorNodeWithTestWebServer.go @@ -24,6 +24,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genesisMocks" + "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" "github.com/multiversx/mx-chain-go/testscommon/state" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts/defaults" "github.com/multiversx/mx-chain-vm-common-go/parsers" @@ -237,6 +238,7 @@ func createFacadeComponents(tpn *TestProcessorNode) nodeFacade.ApiResolver { LogsFacade: logsFacade, DataFieldParser: dataFieldParser, GasScheduleNotifier: gasScheduleNotifier, + TxMarshaller: &marshallerMock.MarshalizerMock{}, } apiTransactionHandler, err := transactionAPI.NewAPITransactionProcessor(argsApiTransactionProc) log.LogIfError(err) diff --git a/node/external/transactionAPI/apiTransactionArgs.go b/node/external/transactionAPI/apiTransactionArgs.go index a4ad9421a31..1c9a79b874d 100644 --- a/node/external/transactionAPI/apiTransactionArgs.go +++ b/node/external/transactionAPI/apiTransactionArgs.go @@ -28,4 +28,5 @@ type ArgAPITransactionProcessor struct { LogsFacade LogsFacade DataFieldParser DataFieldParser GasScheduleNotifier core.GasScheduleNotifier + TxMarshaller marshal.Marshalizer } diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index 6528d195026..7702d4ad053 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -19,6 +19,7 @@ import ( "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dblookupext" "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/process/txstatus" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/storage/txcache" @@ -65,7 +66,13 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti ) refundDetectorInstance := NewRefundDetector() - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(args.FeeComputer, args.GasScheduleNotifier, args.AddressPubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + args.FeeComputer, + args.GasScheduleNotifier, + args.AddressPubKeyConverter, + smartContract.NewArgumentParser(), + args.TxMarshaller, + ) return &apiTransactionProcessor{ roundDuration: args.RoundDuration, diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index fa13f040037..4609d0bdfb6 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -33,6 +33,7 @@ import ( dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" dblookupextMock "github.com/multiversx/mx-chain-go/testscommon/dblookupext" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" + "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/testscommon/txcachemocks" datafield "github.com/multiversx/mx-chain-vm-common-go/parsers/dataField" @@ -60,6 +61,7 @@ func createMockArgAPITransactionProcessor() *ArgAPITransactionProcessor { }, }, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, + TxMarshaller: &marshallerMock.MarshalizerMock{}, } } @@ -182,6 +184,16 @@ func TestNewAPITransactionProcessor(t *testing.T) { _, err := NewAPITransactionProcessor(arguments) require.Equal(t, ErrNilDataFieldParser, err) }) + + t.Run("NilTxMarshaller", func(t *testing.T) { + t.Parallel() + + arguments := createMockArgAPITransactionProcessor() + arguments.TxMarshaller = nil + + _, err := NewAPITransactionProcessor(arguments) + require.True(t, strings.Contains(err.Error(), process.ErrNilMarshalizer.Error())) + }) } func TestNode_GetTransactionInvalidHashShouldErr(t *testing.T) { @@ -461,6 +473,7 @@ func TestNode_GetTransactionWithResultsFromStorage(t *testing.T) { }, }, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, + TxMarshaller: &marshallerMock.MarshalizerMock{}, } apiTransactionProc, _ := NewAPITransactionProcessor(args) @@ -1030,6 +1043,7 @@ func createAPITransactionProc(t *testing.T, epoch uint32, withDbLookupExt bool) LogsFacade: &testscommon.LogsFacadeStub{}, DataFieldParser: dataFieldParser, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, + TxMarshaller: &marshallerMock.MarshalizerMock{}, } apiTransactionProc, err := NewAPITransactionProcessor(args) require.Nil(t, err) diff --git a/node/external/transactionAPI/check.go b/node/external/transactionAPI/check.go index bbb3e2ab9df..729391d4914 100644 --- a/node/external/transactionAPI/check.go +++ b/node/external/transactionAPI/check.go @@ -1,6 +1,8 @@ package transactionAPI import ( + "fmt" + "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/process" ) @@ -45,6 +47,9 @@ func checkNilArgs(arg *ArgAPITransactionProcessor) error { if check.IfNilReflect(arg.GasScheduleNotifier) { return process.ErrNilGasSchedule } + if check.IfNilReflect(arg.TxMarshaller) { + return fmt.Errorf("%w for tx marshaller", process.ErrNilMarshalizer) + } return nil } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 6e6f48ebccb..3916c28f798 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -5,7 +5,9 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/process" datafield "github.com/multiversx/mx-chain-vm-common-go/parsers/dataField" ) @@ -13,13 +15,23 @@ type gasUsedAndFeeProcessor struct { feeComputer feeComputer gasScheduleNotifier core.GasScheduleNotifier pubKeyConverter core.PubkeyConverter + argsParser process.ArgumentsParser + marshaller marshal.Marshalizer } -func newGasUsedAndFeeProcessor(txFeeCalculator feeComputer, gasScheduleNotifier core.GasScheduleNotifier, pubKeyConverter core.PubkeyConverter) *gasUsedAndFeeProcessor { +func newGasUsedAndFeeProcessor( + txFeeCalculator feeComputer, + gasScheduleNotifier core.GasScheduleNotifier, + pubKeyConverter core.PubkeyConverter, + argsParser process.ArgumentsParser, + marshaller marshal.Marshalizer, +) *gasUsedAndFeeProcessor { return &gasUsedAndFeeProcessor{ feeComputer: txFeeCalculator, gasScheduleNotifier: gasScheduleNotifier, pubKeyConverter: pubKeyConverter, + argsParser: argsParser, + marshaller: marshaller, } } @@ -30,7 +42,7 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.GasUsed = gasUsed tx.Fee = fee.String() - if tx.IsRelayed || gfp.isESDTOperationWithSCCall(tx) { + if gfp.isESDTOperationWithSCCall(tx) { tx.GasUsed = tx.GasLimit tx.Fee = tx.InitiallyPaidFee } @@ -50,6 +62,15 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction return } + if tx.IsRelayed { + totalFee, isRelayed := gfp.getFeeOfRelayed(tx) + if isRelayed { + tx.Fee = totalFee.String() + tx.InitiallyPaidFee = totalFee.String() + tx.GasUsed = big.NewInt(0).Div(totalFee, big.NewInt(0).SetUint64(tx.GasPrice)).Uint64() + } + } + hasRefundForSender := false for _, scr := range tx.SmartContractResults { if !scr.IsRefund || scr.RcvAddr != tx.Sender { @@ -67,6 +88,77 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) } +func (gfp *gasUsedAndFeeProcessor) getFeeOfRelayed(tx *transaction.ApiTransactionResult) (*big.Int, bool) { + if !tx.IsRelayed { + return nil, false + } + + if len(tx.InnerTransactions) > 0 { + return gfp.feeComputer.ComputeTransactionFee(tx), true + } + + if len(tx.Data) == 0 { + return nil, false + } + + funcName, args, err := gfp.argsParser.ParseCallData(string(tx.Data)) + if err != nil { + return nil, false + } + + if funcName == core.RelayedTransaction { + return gfp.handleRelayedV1(args, tx) + } + + if funcName == core.RelayedTransactionV2 { + return gfp.handleRelayedV2(args, tx) + } + + return nil, false +} + +func (gfp *gasUsedAndFeeProcessor) handleRelayedV1(args [][]byte, tx *transaction.ApiTransactionResult) (*big.Int, bool) { + if len(args) != 1 { + return nil, false + } + + innerTx := &transaction.Transaction{} + err := gfp.marshaller.Unmarshal(innerTx, args[0]) + if err != nil { + return nil, false + } + + gasUsed := gfp.feeComputer.ComputeGasLimit(tx) + fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) + + innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ + Tx: innerTx, + }) + + return big.NewInt(0).Add(fee, innerFee), true +} + +func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transaction.ApiTransactionResult) (*big.Int, bool) { + innerTx := &transaction.Transaction{} + innerTx.RcvAddr = args[0] + innerTx.Nonce = big.NewInt(0).SetBytes(args[1]).Uint64() + innerTx.Data = args[2] + innerTx.Signature = args[3] + innerTx.Value = big.NewInt(0) + innerTx.GasPrice = tx.GasPrice + innerTx.GasLimit = tx.GasLimit - gfp.feeComputer.ComputeGasLimit(tx) + innerTx.SndAddr = tx.Tx.GetRcvAddr() + + gasUsed := gfp.feeComputer.ComputeGasLimit(tx) + fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) + + innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ + Tx: innerTx, + }) + + return big.NewInt(0).Add(fee, innerFee), true +} + func (gfp *gasUsedAndFeeProcessor) getGuardianOperationCost(tx *transaction.ApiTransactionResult) uint64 { gasSchedule, err := gfp.gasScheduleNotifier.GasScheduleForEpoch(tx.Epoch) if err != nil { diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 9a35be6efa9..1a9c7f922f4 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -38,7 +38,13 @@ func TestComputeTransactionGasUsedAndFeeMoveBalance(t *testing.T) { feeComp, _ := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{})) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + &testscommon.GasScheduleNotifierMock{}, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -68,7 +74,13 @@ func TestComputeTransactionGasUsedAndFeeLogWithError(t *testing.T) { })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + &testscommon.GasScheduleNotifierMock{}, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -111,7 +123,13 @@ func TestComputeTransactionGasUsedAndFeeRelayedTxWithWriteLog(t *testing.T) { })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + &testscommon.GasScheduleNotifierMock{}, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -149,7 +167,13 @@ func TestComputeTransactionGasUsedAndFeeTransactionWithScrWithRefund(t *testing. })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + &testscommon.GasScheduleNotifierMock{}, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -197,7 +221,13 @@ func TestNFTTransferWithScCall(t *testing.T) { computer := fee.NewTestFeeComputer(feeComp) req.Nil(err) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + &testscommon.GasScheduleNotifierMock{}, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -241,7 +271,13 @@ func TestComputeAndAttachGasUsedAndFeeSetGuardian(t *testing.T) { }, } - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, gasSch, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + gasSch, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" From 8fd9fe80b8e7b374d9bc02c148e7034f1dc4b34d Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 9 Aug 2024 19:29:27 +0300 Subject: [PATCH 19/99] fix some tests and add more checks --- factory/processing/blockProcessorCreator.go | 5 ++++ go.mod | 2 +- go.sum | 4 +-- .../vm/esdtImprovements_test.go | 29 ++++++++++++++++++- integrationTests/vm/testInitializer.go | 1 + .../vm/txsFee/esdtMetaDataRecreate_test.go | 3 ++ .../vm/txsFee/esdtMetaDataUpdate_test.go | 3 ++ .../vm/txsFee/esdtModifyCreator_test.go | 3 ++ .../vm/txsFee/esdtModifyRoyalties_test.go | 3 ++ .../vm/txsFee/esdtSetNewURIs_test.go | 3 ++ 10 files changed, 52 insertions(+), 4 deletions(-) diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 93f3e1e95a3..c48a777f01c 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -178,6 +178,11 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( return nil, err } + err = builtInFuncFactory.SetBlockchainHook(vmFactory.BlockChainHookImpl()) + if err != nil { + return nil, err + } + argsFactory := shard.ArgsNewIntermediateProcessorsContainerFactory{ ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), Marshalizer: pcf.coreData.InternalMarshalizer(), diff --git a/go.mod b/go.mod index af2b74d188e..ab249b49c76 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.13 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc github.com/multiversx/mx-chain-vm-go v1.5.31 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 diff --git a/go.sum b/go.sum index 1dd242a3f9c..0c44a62b0f9 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.13 h1:ymnIHJW4Z4mFa0hZzla4fozkF30vjH5O1q+Y7Ftc+pQ= -github.com/multiversx/mx-chain-vm-common-go v1.5.13/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc h1:OBzqgjM7tPB6qM1wp9WKmg2gtgmuTkIhkuMKoC9ooQg= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= github.com/multiversx/mx-chain-vm-go v1.5.31 h1:ywyqbVE94bhbO3LvcP/28pWoSR0NfEXLJNe+q1cgQ78= github.com/multiversx/mx-chain-vm-go v1.5.31/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index d8e5c065a45..22f4e8d0ba0 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2321,6 +2321,9 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + err = cs.GenerateBlocks(10) + require.Nil(t, err) + log.Info("Send to separate shards") tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID) @@ -2399,8 +2402,32 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { log.Info("Step 2. check that the newest metadata is saved") shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData2) + + shard2ID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shard2ID, metaData) + + log.Info("Step 3. create new wallet is shard 2") + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(oneEGLD, mintValue) + newShard2Addr, err := cs.GenerateAndMintWalletAddress(2, mintValue) + require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + + log.Info("Step 4. send updated token to shard 2 ") + + tx = esdtNFTTransferTx(1, addrs[0].Bytes, newShard2Addr.Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + err = cs.GenerateBlocks(5) + + log.Info("Step 5. check meta data in shard 2 is updated to latest version ") + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shard2ID, sftMetaData2) } func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index fc129e36d90..c701007ca00 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -629,6 +629,7 @@ func CreateVMAndBlockchainHookAndDataPool( blockChainHook, _ := vmFactory.BlockChainHookImpl().(*hooks.BlockChainHookImpl) _ = builtInFuncFactory.SetPayableHandler(blockChainHook) + _ = builtInFuncFactory.SetBlockchainHook(blockChainHook) return vmContainer, blockChainHook, datapool } diff --git a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go index 8e46c5d613b..d5778000cbe 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go @@ -7,10 +7,12 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" + dataBlock "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/process" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -35,6 +37,7 @@ func runEsdtMetaDataRecreateTest(t *testing.T, tokenType string) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() + testContext.BlockchainHook.(process.BlockChainHookHandler).SetCurrentHeader(&dataBlock.Header{Round: 7}) createAccWithBalance(t, testContext.Accounts, sndAddr, big.NewInt(100000000)) createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) diff --git a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go index 53174e22a35..4eba58ca178 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go @@ -7,10 +7,12 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" + dataBlock "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/process" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -35,6 +37,7 @@ func runEsdtMetaDataUpdateTest(t *testing.T, tokenType string) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() + testContext.BlockchainHook.(process.BlockChainHookHandler).SetCurrentHeader(&dataBlock.Header{Round: 7}) createAccWithBalance(t, testContext.Accounts, sndAddr, big.NewInt(100000000)) createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) diff --git a/integrationTests/vm/txsFee/esdtModifyCreator_test.go b/integrationTests/vm/txsFee/esdtModifyCreator_test.go index ead51c5d61d..109e6e937e3 100644 --- a/integrationTests/vm/txsFee/esdtModifyCreator_test.go +++ b/integrationTests/vm/txsFee/esdtModifyCreator_test.go @@ -7,10 +7,12 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" + dataBlock "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/process" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -39,6 +41,7 @@ func runEsdtModifyCreatorTest(t *testing.T, tokenType string) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() + testContext.BlockchainHook.(process.BlockChainHookHandler).SetCurrentHeader(&dataBlock.Header{Round: 7}) createAccWithBalance(t, testContext.Accounts, newCreator, big.NewInt(100000000)) createAccWithBalance(t, testContext.Accounts, creatorAddr, big.NewInt(100000000)) diff --git a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go index f4ef7dc9f49..9d6def6a297 100644 --- a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go +++ b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go @@ -7,10 +7,12 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" + dataBlock "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/process" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -34,6 +36,7 @@ func runEsdtModifyRoyaltiesTest(t *testing.T, tokenType string) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() + testContext.BlockchainHook.(process.BlockChainHookHandler).SetCurrentHeader(&dataBlock.Header{Round: 7}) createAccWithBalance(t, testContext.Accounts, creatorAddr, big.NewInt(100000000)) createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) diff --git a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go index 66ec209c3ef..f97e9e0e651 100644 --- a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go +++ b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go @@ -7,10 +7,12 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" + dataBlock "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/process" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -35,6 +37,7 @@ func runEsdtSetNewURIsTest(t *testing.T, tokenType string) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() + testContext.BlockchainHook.(process.BlockChainHookHandler).SetCurrentHeader(&dataBlock.Header{Round: 7}) createAccWithBalance(t, testContext.Accounts, sndAddr, big.NewInt(100000000)) createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) From 3a16b1b9ba491cef29ecf54935c631292f2c762a Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 12 Aug 2024 09:33:37 +0300 Subject: [PATCH 20/99] update go mo --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 4667bd06e7e..843dda8b18c 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.13 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 diff --git a/go.sum b/go.sum index 11a9bc62556..17ed08cd677 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.13 h1:ymnIHJW4Z4mFa0hZzla4fozkF30vjH5O1q+Y7Ftc+pQ= -github.com/multiversx/mx-chain-vm-common-go v1.5.13/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc h1:OBzqgjM7tPB6qM1wp9WKmg2gtgmuTkIhkuMKoC9ooQg= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537 h1:x1Fn0tlkicBNsRB/co/c9TTjyvCrzmE/rVXA8uUWhII= github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= From 1494445465c7f130bb916515d86056729e4290d4 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 12 Aug 2024 09:48:08 +0300 Subject: [PATCH 21/99] linter fixes --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 1 + testscommon/esdtStorageHandlerStub.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 22f4e8d0ba0..eee8f50e204 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2424,6 +2424,7 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(5) + require.Nil(t, err) log.Info("Step 5. check meta data in shard 2 is updated to latest version ") diff --git a/testscommon/esdtStorageHandlerStub.go b/testscommon/esdtStorageHandlerStub.go index 47825717409..b6ff81f2b00 100644 --- a/testscommon/esdtStorageHandlerStub.go +++ b/testscommon/esdtStorageHandlerStub.go @@ -18,7 +18,7 @@ type EsdtStorageHandlerStub struct { SaveNFTMetaDataCalled func(tx data.TransactionHandler) error AddToLiquiditySystemAccCalled func(esdtTokenKey []byte, tokenType uint32, nonce uint64, transferValue *big.Int, keepMetadataOnZeroLiquidity bool) error SaveMetaDataToSystemAccountCalled func(tokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken) error - GetMetaDataFromSystemAccountCalled func(bytes []byte, u uint64) (*esdt.MetaData, error) + GetMetaDataFromSystemAccountCalled func(bytes []byte, u uint64) (*esdt.ESDigitalToken, error) } // SaveMetaDataToSystemAccount - @@ -31,7 +31,7 @@ func (e *EsdtStorageHandlerStub) SaveMetaDataToSystemAccount(tokenKey []byte, no } // GetMetaDataFromSystemAccount - -func (e *EsdtStorageHandlerStub) GetMetaDataFromSystemAccount(bytes []byte, u uint64) (*esdt.MetaData, error) { +func (e *EsdtStorageHandlerStub) GetMetaDataFromSystemAccount(bytes []byte, u uint64) (*esdt.ESDigitalToken, error) { if e.GetMetaDataFromSystemAccountCalled != nil { return e.GetMetaDataFromSystemAccountCalled(bytes, u) } From 23b065f6cb990b9fbc1748edb8ba801825d49fe4 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 12 Aug 2024 10:55:46 +0300 Subject: [PATCH 22/99] - new VM version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e6154610617..3d8e37c97c3 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61 diff --git a/go.sum b/go.sum index 4ff92ec601b..0a6945fd561 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3 h1:64gr6OyTPjrtHlEhH2KjY15zMeEmfD1vofVViKbMa2w= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61 h1:4YAzUQuXqaGELfbl3lCLWK18aiqo45sUqcofW0vA/co= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From a9e2b8f75992026f47fe8b87da51c33d411531fe Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 12 Aug 2024 11:44:04 +0300 Subject: [PATCH 23/99] update go mod --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 843dda8b18c..c6b99bc0214 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 17ed08cd677..d8ed7091831 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc h1:OBzqgjM7tPB6qM1wp9WKmg2gtgmuTkIhkuMKoC9ooQg= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537 h1:x1Fn0tlkicBNsRB/co/c9TTjyvCrzmE/rVXA8uUWhII= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 h1:RlHKl5enbGrleB0Aea9TinZLLymS4WvG0/xAt/iRb6E= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e h1:BkZtPUAQ9JlATkENydCLxPZ819hjop6laZtmC7Wzqec= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e/go.mod h1:j9FBeftA/BKfn0BbndKV7bNFJAzwCnYZuebsM/sufK0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From 42bf1a3142d5f8d9174b7c78a6023077366ada57 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 12 Aug 2024 15:11:18 +0300 Subject: [PATCH 24/99] fixes after review --- factory/processing/blockProcessorCreator.go | 1 + node/external/timemachine/fee/feeComputer.go | 1 - .../transactionAPI/gasUsedAndFeeProcessor.go | 2 + outport/process/factory/check_test.go | 1 + .../factory/outportDataProviderFactory.go | 14 +- outport/process/interface.go | 2 +- outport/process/outportDataProvider.go | 2 +- outport/process/outportDataProvider_test.go | 10 +- .../transactionsFeeProcessor.go | 164 ++++++++++++++++-- .../transactionsFeeProcessor_test.go | 47 +++-- 10 files changed, 196 insertions(+), 48 deletions(-) diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 93f3e1e95a3..f4ee93124a2 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -1052,6 +1052,7 @@ func (pcf *processComponentsFactory) createOutportDataProvider( MbsStorer: mbsStorer, EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), ExecutionOrderGetter: pcf.txExecutionOrderHandler, + GasScheduleNotifier: pcf.gasSchedule, }) } diff --git a/node/external/timemachine/fee/feeComputer.go b/node/external/timemachine/fee/feeComputer.go index ee4d67910db..9ad90d2b221 100644 --- a/node/external/timemachine/fee/feeComputer.go +++ b/node/external/timemachine/fee/feeComputer.go @@ -42,7 +42,6 @@ func (computer *feeComputer) ComputeTxFeeBasedOnGasUsed(tx *transaction.ApiTrans // ComputeGasLimit computes a transaction gas limit, at a given epoch func (computer *feeComputer) ComputeGasLimit(tx *transaction.ApiTransactionResult) uint64 { - computer.economicsInstance.MaxGasPriceSetGuardian() return computer.economicsInstance.ComputeGasLimitInEpoch(tx.Tx, tx.Epoch) } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 3916c28f798..30ac5cbc910 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -47,6 +47,8 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = tx.InitiallyPaidFee } + // if there is a guardian operation, SetGuardian/GuardAccount/UnGuardAccount + // the pre-configured cost of the operation must be added separately if gfp.isGuardianOperation(tx) { gasUsed = gfp.feeComputer.ComputeGasLimit(tx) guardianOperationCost := gfp.getGuardianOperationCost(tx) diff --git a/outport/process/factory/check_test.go b/outport/process/factory/check_test.go index 513a3c7305b..67b9a91b7dc 100644 --- a/outport/process/factory/check_test.go +++ b/outport/process/factory/check_test.go @@ -34,6 +34,7 @@ func createArgOutportDataProviderFactory() ArgOutportDataProviderFactory { MbsStorer: &genericMocks.StorerMock{}, EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ExecutionOrderGetter: &commonMocks.TxExecutionOrderHandlerStub{}, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } } diff --git a/outport/process/factory/outportDataProviderFactory.go b/outport/process/factory/outportDataProviderFactory.go index 68546df1c50..4350605b000 100644 --- a/outport/process/factory/outportDataProviderFactory.go +++ b/outport/process/factory/outportDataProviderFactory.go @@ -11,6 +11,7 @@ import ( "github.com/multiversx/mx-chain-go/outport/process/disabled" "github.com/multiversx/mx-chain-go/outport/process/transactionsfee" processTxs "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" @@ -36,6 +37,7 @@ type ArgOutportDataProviderFactory struct { MbsStorer storage.Storer EnableEpochsHandler common.EnableEpochsHandler ExecutionOrderGetter common.ExecutionOrderGetter + GasScheduleNotifier core.GasScheduleNotifier } // CreateOutportDataProvider will create a new instance of outport.DataProviderOutport @@ -60,11 +62,13 @@ func CreateOutportDataProvider(arg ArgOutportDataProviderFactory) (outport.DataP } transactionsFeeProc, err := transactionsfee.NewTransactionsFeeProcessor(transactionsfee.ArgTransactionsFeeProcessor{ - Marshaller: arg.Marshaller, - TransactionsStorer: arg.TransactionsStorer, - ShardCoordinator: arg.ShardCoordinator, - TxFeeCalculator: arg.EconomicsData, - PubKeyConverter: arg.AddressConverter, + Marshaller: arg.Marshaller, + TransactionsStorer: arg.TransactionsStorer, + ShardCoordinator: arg.ShardCoordinator, + TxFeeCalculator: arg.EconomicsData, + PubKeyConverter: arg.AddressConverter, + ArgsParser: smartContract.NewArgumentParser(), + GasScheduleNotifier: arg.GasScheduleNotifier, }) if err != nil { return nil, err diff --git a/outport/process/interface.go b/outport/process/interface.go index 5fcb19020f3..bec97f362b3 100644 --- a/outport/process/interface.go +++ b/outport/process/interface.go @@ -17,7 +17,7 @@ type AlteredAccountsProviderHandler interface { // TransactionsFeeHandler defines the functionality needed for computation of the transaction fee and gas used type TransactionsFeeHandler interface { - PutFeeAndGasUsed(pool *outport.TransactionPool) error + PutFeeAndGasUsed(pool *outport.TransactionPool, epoch uint32) error IsInterfaceNil() bool } diff --git a/outport/process/outportDataProvider.go b/outport/process/outportDataProvider.go index a99e0bc4827..aec1f15df8b 100644 --- a/outport/process/outportDataProvider.go +++ b/outport/process/outportDataProvider.go @@ -100,7 +100,7 @@ func (odp *outportDataProvider) PrepareOutportSaveBlockData(arg ArgPrepareOutpor return nil, err } - err = odp.transactionsFeeProcessor.PutFeeAndGasUsed(pool) + err = odp.transactionsFeeProcessor.PutFeeAndGasUsed(pool, arg.Header.GetEpoch()) if err != nil { return nil, fmt.Errorf("transactionsFeeProcessor.PutFeeAndGasUsed %w", err) } diff --git a/outport/process/outportDataProvider_test.go b/outport/process/outportDataProvider_test.go index c240fe50ab7..32193eef23f 100644 --- a/outport/process/outportDataProvider_test.go +++ b/outport/process/outportDataProvider_test.go @@ -25,10 +25,12 @@ import ( func createArgOutportDataProvider() ArgOutportDataProvider { txsFeeProc, _ := transactionsfee.NewTransactionsFeeProcessor(transactionsfee.ArgTransactionsFeeProcessor{ - Marshaller: &marshallerMock.MarshalizerMock{}, - TransactionsStorer: &genericMocks.StorerMock{}, - ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, - TxFeeCalculator: &mock.EconomicsHandlerMock{}, + Marshaller: &marshallerMock.MarshalizerMock{}, + TransactionsStorer: &genericMocks.StorerMock{}, + ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, + TxFeeCalculator: &mock.EconomicsHandlerMock{}, + ArgsParser: &testscommon.ArgumentParserMock{}, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, }) return ArgOutportDataProvider{ diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index 6520db7635d..be5689e4c62 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -8,7 +8,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" outportcore "github.com/multiversx/mx-chain-core-go/data/outport" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/storage" logger "github.com/multiversx/mx-chain-logger-go" @@ -19,19 +22,24 @@ const loggerName = "outport/process/transactionsfee" // ArgTransactionsFeeProcessor holds the arguments needed for creating a new instance of transactionsFeeProcessor type ArgTransactionsFeeProcessor struct { - Marshaller marshal.Marshalizer - TransactionsStorer storage.Storer - ShardCoordinator sharding.Coordinator - TxFeeCalculator FeesProcessorHandler - PubKeyConverter core.PubkeyConverter + Marshaller marshal.Marshalizer + TransactionsStorer storage.Storer + ShardCoordinator sharding.Coordinator + TxFeeCalculator FeesProcessorHandler + PubKeyConverter core.PubkeyConverter + GasScheduleNotifier core.GasScheduleNotifier + ArgsParser process.ArgumentsParser } type transactionsFeeProcessor struct { - txGetter transactionGetter - txFeeCalculator FeesProcessorHandler - shardCoordinator sharding.Coordinator - dataFieldParser dataFieldParser - log logger.Logger + txGetter transactionGetter + txFeeCalculator FeesProcessorHandler + shardCoordinator sharding.Coordinator + dataFieldParser dataFieldParser + log logger.Logger + marshaller marshal.Marshalizer + gasScheduleNotifier core.GasScheduleNotifier + argsParser process.ArgumentsParser } // NewTransactionsFeeProcessor will create a new instance of transactionsFeeProcessor @@ -50,11 +58,14 @@ func NewTransactionsFeeProcessor(arg ArgTransactionsFeeProcessor) (*transactions } return &transactionsFeeProcessor{ - txFeeCalculator: arg.TxFeeCalculator, - shardCoordinator: arg.ShardCoordinator, - txGetter: newTxGetter(arg.TransactionsStorer, arg.Marshaller), - log: logger.GetOrCreate(loggerName), - dataFieldParser: parser, + txFeeCalculator: arg.TxFeeCalculator, + shardCoordinator: arg.ShardCoordinator, + txGetter: newTxGetter(arg.TransactionsStorer, arg.Marshaller), + log: logger.GetOrCreate(loggerName), + dataFieldParser: parser, + marshaller: arg.Marshaller, + gasScheduleNotifier: arg.GasScheduleNotifier, + argsParser: arg.ArgsParser, }, nil } @@ -74,16 +85,22 @@ func checkArg(arg ArgTransactionsFeeProcessor) error { if check.IfNil(arg.PubKeyConverter) { return core.ErrNilPubkeyConverter } + if check.IfNil(arg.ArgsParser) { + return process.ErrNilArgumentParser + } + if check.IfNil(arg.GasScheduleNotifier) { + return process.ErrNilGasSchedule + } return nil } // PutFeeAndGasUsed will compute and set in transactions pool fee and gas used -func (tep *transactionsFeeProcessor) PutFeeAndGasUsed(pool *outportcore.TransactionPool) error { +func (tep *transactionsFeeProcessor) PutFeeAndGasUsed(pool *outportcore.TransactionPool, epoch uint32) error { tep.prepareInvalidTxs(pool) txsWithResultsMap := prepareTransactionsAndScrs(pool) - tep.prepareNormalTxs(txsWithResultsMap) + tep.prepareNormalTxs(txsWithResultsMap, epoch) return tep.prepareScrsNoTx(txsWithResultsMap) } @@ -97,7 +114,7 @@ func (tep *transactionsFeeProcessor) prepareInvalidTxs(pool *outportcore.Transac } } -func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *transactionsAndScrsHolder) { +func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *transactionsAndScrsHolder, epoch uint32) { for txHashHex, txWithResult := range transactionsAndScrs.txsWithResults { txHandler := txWithResult.GetTxHandler() @@ -110,16 +127,39 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans feeInfo.SetFee(fee) feeInfo.SetInitialPaidFee(initialPaidFee) - if isRelayedTx(txWithResult) || tep.isESDTOperationWithSCCall(txHandler) { + if tep.isESDTOperationWithSCCall(txHandler) { feeInfo.SetGasUsed(txWithResult.GetTxHandler().GetGasLimit()) feeInfo.SetFee(initialPaidFee) } + res := tep.dataFieldParser.Parse(txHandler.GetData(), txHandler.GetSndAddr(), txHandler.GetRcvAddr(), tep.shardCoordinator.NumberOfShards()) + if tep.isGuardianOperation(res.Operation) { + gasUsed = tep.txFeeCalculator.ComputeGasLimit(txHandler) + guardianOperationCost := tep.getGuardianOperationCost(res.Operation, epoch) + gasUsed += guardianOperationCost + feeInfo.SetGasUsed(gasUsed) + + fee = big.NewInt(0).SetUint64(gasUsed * txHandler.GetGasPrice()) + feeInfo.SetFee(fee) + feeInfo.SetInitialPaidFee(fee) + + return + } + if len(txHandler.GetUserTransactions()) > 0 { tep.prepareRelayedTxV3WithResults(txHashHex, txWithResult) continue } + if isRelayedTx(txWithResult) { + totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) + if isRelayed { + feeInfo.SetFee(totalFee) + feeInfo.SetInitialPaidFee(totalFee) + feeInfo.SetGasUsed(big.NewInt(0).Div(totalFee, big.NewInt(0).SetUint64(txHandler.GetGasPrice())).Uint64()) + } + } + tep.prepareTxWithResults(txHashHex, txWithResult) } } @@ -146,6 +186,92 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi } +func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) (*big.Int, bool) { + if len(tx.GetTxHandler().GetData()) == 0 { + return nil, false + } + + funcName, args, err := tep.argsParser.ParseCallData(string(tx.GetTxHandler().GetData())) + if err != nil { + return nil, false + } + + if funcName == core.RelayedTransaction { + return tep.handleRelayedV1(args, tx) + } + + if funcName == core.RelayedTransactionV2 { + return tep.handleRelayedV2(args, tx) + } + + return nil, false +} + +func (tep *transactionsFeeProcessor) handleRelayedV1(args [][]byte, tx *transactionWithResults) (*big.Int, bool) { + if len(args) != 1 { + return nil, false + } + + innerTx := &transaction.Transaction{} + err := tep.marshaller.Unmarshal(innerTx, args[0]) + if err != nil { + return nil, false + } + + txHandler := tx.GetTxHandler() + gasUsed := tep.txFeeCalculator.ComputeGasLimit(txHandler) + fee := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(txHandler, gasUsed) + + innerFee := tep.txFeeCalculator.ComputeTxFee(innerTx) + + return big.NewInt(0).Add(fee, innerFee), true +} + +func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transactionWithResults) (*big.Int, bool) { + txHandler := tx.GetTxHandler() + + innerTx := &transaction.Transaction{} + innerTx.RcvAddr = args[0] + innerTx.Nonce = big.NewInt(0).SetBytes(args[1]).Uint64() + innerTx.Data = args[2] + innerTx.Signature = args[3] + innerTx.Value = big.NewInt(0) + innerTx.GasPrice = txHandler.GetGasPrice() + innerTx.GasLimit = txHandler.GetGasLimit() - tep.txFeeCalculator.ComputeGasLimit(txHandler) + innerTx.SndAddr = txHandler.GetRcvAddr() + + gasUsed := tep.txFeeCalculator.ComputeGasLimit(txHandler) + fee := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(txHandler, gasUsed) + + innerFee := tep.txFeeCalculator.ComputeTxFee(innerTx) + + return big.NewInt(0).Add(fee, innerFee), true +} + +func (tep *transactionsFeeProcessor) getGuardianOperationCost(operation string, epoch uint32) uint64 { + gasSchedule, err := tep.gasScheduleNotifier.GasScheduleForEpoch(epoch) + if err != nil { + return 0 + } + + switch operation { + case core.BuiltInFunctionSetGuardian: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionSetGuardian] + case core.BuiltInFunctionGuardAccount: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionGuardAccount] + case core.BuiltInFunctionUnGuardAccount: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionUnGuardAccount] + default: + return 0 + } +} + +func (tep *transactionsFeeProcessor) isGuardianOperation(operation string) bool { + return operation == core.BuiltInFunctionSetGuardian || + operation == core.BuiltInFunctionGuardAccount || + operation == core.BuiltInFunctionUnGuardAccount +} + func (tep *transactionsFeeProcessor) prepareRelayedTxV3WithResults(txHashHex string, txWithResults *transactionWithResults) { refundsValue := big.NewInt(0) for _, scrHandler := range txWithResults.scrs { diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index 8ff4cf14501..8e6d6d7156d 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -11,6 +11,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/outport/mock" + "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" @@ -22,11 +23,13 @@ var pubKeyConverter, _ = pubkeyConverter.NewBech32PubkeyConverter(32, "erd") func prepareMockArg() ArgTransactionsFeeProcessor { return ArgTransactionsFeeProcessor{ - Marshaller: marshallerMock.MarshalizerMock{}, - TransactionsStorer: genericMocks.NewStorerMock(), - ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, - TxFeeCalculator: &mock.EconomicsHandlerMock{}, - PubKeyConverter: pubKeyConverter, + Marshaller: marshallerMock.MarshalizerMock{}, + TransactionsStorer: genericMocks.NewStorerMock(), + ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, + TxFeeCalculator: &mock.EconomicsHandlerMock{}, + PubKeyConverter: pubKeyConverter, + ArgsParser: &testscommon.ArgumentParserMock{}, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } } @@ -53,6 +56,16 @@ func TestNewTransactionFeeProcessor(t *testing.T) { _, err = NewTransactionsFeeProcessor(arg) require.Equal(t, ErrNilTransactionFeeCalculator, err) + arg = prepareMockArg() + arg.ArgsParser = nil + _, err = NewTransactionsFeeProcessor(arg) + require.Equal(t, process.ErrNilArgumentParser, err) + + arg = prepareMockArg() + arg.GasScheduleNotifier = nil + _, err = NewTransactionsFeeProcessor(arg) + require.Equal(t, process.ErrNilGasSchedule, err) + arg = prepareMockArg() txsFeeProc, err := NewTransactionsFeeProcessor(arg) require.NotNil(t, txsFeeProc) @@ -125,7 +138,7 @@ func TestPutFeeAndGasUsedTx1(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(1673728170000000), initialTx.GetFeeInfo().GetFee()) require.Equal(t, uint64(7982817), initialTx.GetFeeInfo().GetGasUsed()) @@ -175,7 +188,7 @@ func TestPutFeeAndGasUsedScrNoTx(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(123001460000000), scr.GetFeeInfo().GetFee()) require.Equal(t, uint64(7350146), scr.GetFeeInfo().GetGasUsed()) @@ -203,7 +216,7 @@ func TestPutFeeAndGasUsedInvalidTxs(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(349500000000000), tx.GetFeeInfo().GetFee()) require.Equal(t, tx.GetTxHandler().GetGasLimit(), tx.GetFeeInfo().GetGasUsed()) @@ -284,7 +297,7 @@ func TestPutFeeAndGasUsedLogWithErrorAndInformative(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, tx1.GetTxHandler().GetGasLimit(), tx1.GetFeeInfo().GetGasUsed()) @@ -335,10 +348,10 @@ func TestPutFeeAndGasUsedWrongRelayedTx(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) - require.Equal(t, big.NewInt(6103405000000000), initialTx.GetFeeInfo().GetFee()) - require.Equal(t, uint64(550000000), initialTx.GetFeeInfo().GetGasUsed()) + require.Equal(t, big.NewInt(609500000000000), initialTx.GetFeeInfo().GetFee()) + require.Equal(t, uint64(609500), initialTx.GetFeeInfo().GetGasUsed()) require.Equal(t, "6103405000000000", initialTx.GetFeeInfo().GetInitialPaidFee().String()) } @@ -370,7 +383,7 @@ func TestPutFeeAndGasUsedESDTWithScCall(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(820765000000000), tx.GetFeeInfo().GetFee()) require.Equal(t, uint64(55_000_000), tx.GetFeeInfo().GetGasUsed()) @@ -425,7 +438,7 @@ func TestPutFeeAndGasUsedScrWithRefundNoTx(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(0), scr.GetFeeInfo().GetFee()) require.Equal(t, uint64(0), scr.GetFeeInfo().GetGasUsed()) @@ -474,7 +487,7 @@ func TestPutFeeAndGasUsedScrWithRefundNotForInitialSender(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(0), scr.GetFeeInfo().GetFee()) require.Equal(t, uint64(0), scr.GetFeeInfo().GetGasUsed()) @@ -522,7 +535,7 @@ func TestPutFeeAndGasUsedScrWithRefund(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(552865000000000), initialTx.GetFeeInfo().GetFee()) require.Equal(t, uint64(50_336_500), initialTx.GetFeeInfo().GetGasUsed()) @@ -579,7 +592,7 @@ func TestMoveBalanceWithSignalError(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, uint64(225_500), initialTx.GetFeeInfo().GetGasUsed()) } From dd0576468d6db957240354317ce0d81451f26636 Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 12 Aug 2024 15:07:57 +0300 Subject: [PATCH 25/99] fixes after review --- api/groups/transactionGroup_test.go | 71 +++++++++++++++++++ facade/nodeFacade.go | 1 + node/external/nodeApiResolver.go | 1 + .../transactionAPI/apiTransactionProcessor.go | 3 +- node/external/transactionAPI/errors.go | 3 + 5 files changed, 78 insertions(+), 1 deletion(-) diff --git a/api/groups/transactionGroup_test.go b/api/groups/transactionGroup_test.go index f183dd30b4c..e517f51f8bd 100644 --- a/api/groups/transactionGroup_test.go +++ b/api/groups/transactionGroup_test.go @@ -343,6 +343,76 @@ func TestTransactionGroup_sendTransaction(t *testing.T) { }) } +func TestTransactionsGroup_getSCRsByTxHash(t *testing.T) { + t.Parallel() + + t.Run("get SCRsByTxHash empty scr hash should error", func(t *testing.T) { + facade := &mock.FacadeStub{} + + transactionGroup, err := groups.NewTransactionGroup(facade) + require.NoError(t, err) + + ws := startWebServer(transactionGroup, "transaction", getTransactionRoutesConfig()) + + req, _ := http.NewRequest(http.MethodGet, "/transaction/scrs-by-tx-hash/txHash", bytes.NewBuffer([]byte{})) + resp := httptest.NewRecorder() + ws.ServeHTTP(resp, req) + + txResp := shared.GenericAPIResponse{} + loadResponse(resp.Body, &txResp) + + assert.Equal(t, http.StatusBadRequest, resp.Code) + assert.True(t, strings.Contains(txResp.Error, apiErrors.ErrValidationEmptySCRHash.Error())) + assert.Empty(t, txResp.Data) + }) + t.Run("get scrs facade error", func(t *testing.T) { + localErr := fmt.Errorf("error") + facade := &mock.FacadeStub{ + GetSCRsByTxHashCalled: func(txHash string, scrHash string) ([]*dataTx.ApiSmartContractResult, error) { + return nil, localErr + }, + } + + transactionGroup, err := groups.NewTransactionGroup(facade) + require.NoError(t, err) + + ws := startWebServer(transactionGroup, "transaction", getTransactionRoutesConfig()) + + req, _ := http.NewRequest(http.MethodGet, "/transaction/scrs-by-tx-hash/txhash?scrHash=hash", bytes.NewBuffer([]byte{})) + resp := httptest.NewRecorder() + ws.ServeHTTP(resp, req) + + txResp := shared.GenericAPIResponse{} + loadResponse(resp.Body, &txResp) + + assert.Equal(t, http.StatusInternalServerError, resp.Code) + assert.True(t, strings.Contains(txResp.Error, localErr.Error())) + assert.Empty(t, txResp.Data) + }) + t.Run("get scrs should work", func(t *testing.T) { + facade := &mock.FacadeStub{ + GetSCRsByTxHashCalled: func(txHash string, scrHash string) ([]*dataTx.ApiSmartContractResult, error) { + return []*dataTx.ApiSmartContractResult{}, nil + }, + } + + transactionGroup, err := groups.NewTransactionGroup(facade) + require.NoError(t, err) + + ws := startWebServer(transactionGroup, "transaction", getTransactionRoutesConfig()) + + req, _ := http.NewRequest(http.MethodGet, "/transaction/scrs-by-tx-hash/txhash?scrHash=hash", bytes.NewBuffer([]byte{})) + resp := httptest.NewRecorder() + ws.ServeHTTP(resp, req) + + txResp := shared.GenericAPIResponse{} + loadResponse(resp.Body, &txResp) + + assert.Equal(t, http.StatusOK, resp.Code) + assert.Equal(t, "", txResp.Error) + }) +} + func TestTransactionGroup_sendMultipleTransactions(t *testing.T) { t.Parallel() @@ -1125,6 +1195,7 @@ func getTransactionRoutesConfig() config.ApiRoutesConfig { {Name: "/:txhash", Open: true}, {Name: "/:txhash/status", Open: true}, {Name: "/simulate", Open: true}, + {Name: "/scrs-by-tx-hash/:txhash", Open: true}, }, }, }, diff --git a/facade/nodeFacade.go b/facade/nodeFacade.go index 479cb4f5412..c3a7f290edf 100644 --- a/facade/nodeFacade.go +++ b/facade/nodeFacade.go @@ -304,6 +304,7 @@ func (nf *nodeFacade) GetTransaction(hash string, withResults bool) (*transactio return nf.apiResolver.GetTransaction(hash, withResults) } +// GetSCRsByTxHash will return a list of smart contract results based on a provided tx hash and smart contract result hash func (nf *nodeFacade) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { return nf.apiResolver.GetSCRsByTxHash(txHash, scrHash) } diff --git a/node/external/nodeApiResolver.go b/node/external/nodeApiResolver.go index b359c31b986..7f1bd2269b4 100644 --- a/node/external/nodeApiResolver.go +++ b/node/external/nodeApiResolver.go @@ -189,6 +189,7 @@ func (nar *nodeApiResolver) GetTransaction(hash string, withResults bool) (*tran return nar.apiTransactionHandler.GetTransaction(hash, withResults) } +// GetSCRsByTxHash will return a list of smart contract results based on a provided tx hash and smart contract result hash func (nar *nodeApiResolver) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { return nar.apiTransactionHandler.GetSCRsByTxHash(txHash, scrHash) } diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index bcfb265df62..e1a3d14e93e 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -87,6 +87,7 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti }, nil } +// GetSCRsByTxHash will return a list of smart contract results based on a provided tx hash and smart contract result hash func (atp *apiTransactionProcessor) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { decodedScrHash, err := hex.DecodeString(scrHash) if err != nil { @@ -99,7 +100,7 @@ func (atp *apiTransactionProcessor) GetSCRsByTxHash(txHash string, scrHash strin } if !atp.historyRepository.IsEnabled() { - return []*transaction.ApiSmartContractResult{}, nil + return nil, fmt.Errorf("cannot return smat contract results: %w", ErrDBLookExtensionIsNotEnabled) } miniblockMetadata, err := atp.historyRepository.GetMiniblockMetadataByTxHash(decodedScrHash) diff --git a/node/external/transactionAPI/errors.go b/node/external/transactionAPI/errors.go index 924bd6040a5..105d6c3e930 100644 --- a/node/external/transactionAPI/errors.go +++ b/node/external/transactionAPI/errors.go @@ -31,3 +31,6 @@ var ErrCannotRetrieveTransactions = errors.New("transactions cannot be retrieved // ErrInvalidAddress signals that the address is invalid var ErrInvalidAddress = errors.New("invalid address") + +// ErrDBLookExtensionIsNotEnabled signals that the db look extension is not enabled +var ErrDBLookExtensionIsNotEnabled = errors.New("db look extension is not enabled") From 75b2aaa5dd54af3fb27c16f3fe730d231cdd78cf Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 12 Aug 2024 15:21:07 +0300 Subject: [PATCH 26/99] small fix --- node/external/transactionAPI/apiTransactionProcessor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index e1a3d14e93e..c87cbea5d9e 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -117,7 +117,7 @@ func (atp *apiTransactionProcessor) GetSCRsByTxHash(txHash string, scrHash strin return nil, err } - scrsAPI := make([]*transaction.ApiSmartContractResult, 0) + scrsAPI := make([]*transaction.ApiSmartContractResult, 0, len(resultsHashes.ScResultsHashesAndEpoch)) for _, scrHashesEpoch := range resultsHashes.ScResultsHashesAndEpoch { scrs, errGet := atp.transactionResultsProcessor.getSmartContractResultsInTransactionByHashesAndEpoch(scrHashesEpoch.ScResultsHashes, scrHashesEpoch.Epoch) if errGet != nil { From 1745d470be0b3d70793e10c56250c1bbec53d05f Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 12 Aug 2024 15:45:01 +0300 Subject: [PATCH 27/99] comment --- api/errors/errors.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/errors/errors.go b/api/errors/errors.go index e2c22411dac..3f4e495b9d2 100644 --- a/api/errors/errors.go +++ b/api/errors/errors.go @@ -64,6 +64,7 @@ var ErrTxGenerationFailed = errors.New("transaction generation failed") // ErrValidationEmptyTxHash signals that an empty tx hash was provided var ErrValidationEmptyTxHash = errors.New("TxHash is empty") +// ErrValidationEmptySCRHash signals that provided smart contract result hash is empty var ErrValidationEmptySCRHash = errors.New("SCRHash is empty") // ErrInvalidBlockNonce signals that an invalid block nonce was provided From c78c99562d8be493af11815b6e60e3787dfb3aa6 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 13 Aug 2024 11:39:06 +0300 Subject: [PATCH 28/99] - new VM version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3d8e37c97c3..50506f20018 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79 diff --git a/go.sum b/go.sum index 0a6945fd561..4a7a2b9d06b 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61 h1:4YAzUQuXqaGELfbl3lCLWK18aiqo45sUqcofW0vA/co= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79 h1:XCL3LLJ2hgVPuYwuMmM9RtJDStLn822bOvRHMCkbnYM= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From a7a39d34e5049dd98be4d2d85e70977d3641c11e Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 13 Aug 2024 12:11:06 +0300 Subject: [PATCH 29/99] further fixes after review-testing --- factory/api/apiResolverFactory.go | 1 + .../testProcessorNodeWithTestWebServer.go | 1 + .../external/transactionAPI/apiTransactionArgs.go | 2 ++ .../transactionAPI/apiTransactionProcessor.go | 10 ++++++++++ .../apiTransactionProcessor_test.go | 14 +++++++++++++- node/external/transactionAPI/check.go | 5 ++++- .../transactionAPI/gasUsedAndFeeProcessor.go | 15 +++++++++------ .../transactionAPI/gasUsedAndFeeProcessor_test.go | 11 ++++++++++- .../process/factory/outportDataProviderFactory.go | 1 + outport/process/outportDataProvider_test.go | 2 ++ .../transactionsfee/transactionsFeeProcessor.go | 15 ++++++++++++--- .../transactionsFeeProcessor_test.go | 11 +++++++++-- 12 files changed, 74 insertions(+), 14 deletions(-) diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index 621ff7a8d13..a33fa09b4a8 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -246,6 +246,7 @@ func CreateApiResolver(args *ApiResolverArgs) (facade.ApiResolver, error) { DataFieldParser: dataFieldParser, GasScheduleNotifier: args.GasScheduleNotifier, TxMarshaller: args.CoreComponents.TxMarshalizer(), + EnableEpochsHandler: args.CoreComponents.EnableEpochsHandler(), } apiTransactionProcessor, err := transactionAPI.NewAPITransactionProcessor(argsAPITransactionProc) if err != nil { diff --git a/integrationTests/testProcessorNodeWithTestWebServer.go b/integrationTests/testProcessorNodeWithTestWebServer.go index c194695fb73..8a4d6483970 100644 --- a/integrationTests/testProcessorNodeWithTestWebServer.go +++ b/integrationTests/testProcessorNodeWithTestWebServer.go @@ -239,6 +239,7 @@ func createFacadeComponents(tpn *TestProcessorNode) nodeFacade.ApiResolver { DataFieldParser: dataFieldParser, GasScheduleNotifier: gasScheduleNotifier, TxMarshaller: &marshallerMock.MarshalizerMock{}, + EnableEpochsHandler: tpn.EnableEpochsHandler, } apiTransactionHandler, err := transactionAPI.NewAPITransactionProcessor(argsApiTransactionProc) log.LogIfError(err) diff --git a/node/external/transactionAPI/apiTransactionArgs.go b/node/external/transactionAPI/apiTransactionArgs.go index 1c9a79b874d..8083a4096cb 100644 --- a/node/external/transactionAPI/apiTransactionArgs.go +++ b/node/external/transactionAPI/apiTransactionArgs.go @@ -6,6 +6,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/typeConverters" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dblookupext" "github.com/multiversx/mx-chain-go/process" @@ -29,4 +30,5 @@ type ArgAPITransactionProcessor struct { DataFieldParser DataFieldParser GasScheduleNotifier core.GasScheduleNotifier TxMarshaller marshal.Marshalizer + EnableEpochsHandler common.EnableEpochsHandler } diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index 7702d4ad053..3568175af14 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -44,6 +44,7 @@ type apiTransactionProcessor struct { transactionResultsProcessor *apiTransactionResultsProcessor refundDetector *refundDetector gasUsedAndFeeProcessor *gasUsedAndFeeProcessor + enableEpochsHandler common.EnableEpochsHandler } // NewAPITransactionProcessor will create a new instance of apiTransactionProcessor @@ -72,6 +73,7 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti args.AddressPubKeyConverter, smartContract.NewArgumentParser(), args.TxMarshaller, + args.EnableEpochsHandler, ) return &apiTransactionProcessor{ @@ -90,6 +92,7 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti transactionResultsProcessor: txResultsProc, refundDetector: refundDetectorInstance, gasUsedAndFeeProcessor: gasUsedAndFeeProc, + enableEpochsHandler: args.EnableEpochsHandler, }, nil } @@ -151,6 +154,13 @@ func (atp *apiTransactionProcessor) populateComputedFieldInitiallyPaidFee(tx *tr fee := atp.feeComputer.ComputeTransactionFee(tx) // For user-initiated transactions, we can assume the fee is always strictly positive (note: BigInt(0) is stringified as ""). tx.InitiallyPaidFee = fee.String() + + isFeeFixActive := atp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) + isRelayedAfterFix := tx.IsRelayed && isFeeFixActive + if isRelayedAfterFix { + fee, _ = atp.gasUsedAndFeeProcessor.getFeeOfRelayed(tx) + tx.InitiallyPaidFee = fee.String() + } } func (atp *apiTransactionProcessor) populateComputedFieldIsRefund(tx *transaction.ApiTransactionResult) { diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index 4609d0bdfb6..0a36b4b304f 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -32,6 +32,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon" dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" dblookupextMock "github.com/multiversx/mx-chain-go/testscommon/dblookupext" + "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -62,6 +63,7 @@ func createMockArgAPITransactionProcessor() *ArgAPITransactionProcessor { }, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } } @@ -184,7 +186,6 @@ func TestNewAPITransactionProcessor(t *testing.T) { _, err := NewAPITransactionProcessor(arguments) require.Equal(t, ErrNilDataFieldParser, err) }) - t.Run("NilTxMarshaller", func(t *testing.T) { t.Parallel() @@ -194,6 +195,15 @@ func TestNewAPITransactionProcessor(t *testing.T) { _, err := NewAPITransactionProcessor(arguments) require.True(t, strings.Contains(err.Error(), process.ErrNilMarshalizer.Error())) }) + t.Run("NilEnableEpochsHandler", func(t *testing.T) { + t.Parallel() + + arguments := createMockArgAPITransactionProcessor() + arguments.EnableEpochsHandler = nil + + _, err := NewAPITransactionProcessor(arguments) + require.Equal(t, process.ErrNilEnableEpochsHandler, err) + }) } func TestNode_GetTransactionInvalidHashShouldErr(t *testing.T) { @@ -474,6 +484,7 @@ func TestNode_GetTransactionWithResultsFromStorage(t *testing.T) { }, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } apiTransactionProc, _ := NewAPITransactionProcessor(args) @@ -1044,6 +1055,7 @@ func createAPITransactionProc(t *testing.T, epoch uint32, withDbLookupExt bool) DataFieldParser: dataFieldParser, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } apiTransactionProc, err := NewAPITransactionProcessor(args) require.Nil(t, err) diff --git a/node/external/transactionAPI/check.go b/node/external/transactionAPI/check.go index 729391d4914..ce45c38bae4 100644 --- a/node/external/transactionAPI/check.go +++ b/node/external/transactionAPI/check.go @@ -47,9 +47,12 @@ func checkNilArgs(arg *ArgAPITransactionProcessor) error { if check.IfNilReflect(arg.GasScheduleNotifier) { return process.ErrNilGasSchedule } - if check.IfNilReflect(arg.TxMarshaller) { + if check.IfNil(arg.TxMarshaller) { return fmt.Errorf("%w for tx marshaller", process.ErrNilMarshalizer) } + if check.IfNil(arg.EnableEpochsHandler) { + return process.ErrNilEnableEpochsHandler + } return nil } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 30ac5cbc910..1ad96c810f9 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -17,6 +17,7 @@ type gasUsedAndFeeProcessor struct { pubKeyConverter core.PubkeyConverter argsParser process.ArgumentsParser marshaller marshal.Marshalizer + enableEpochsHandler common.EnableEpochsHandler } func newGasUsedAndFeeProcessor( @@ -25,6 +26,7 @@ func newGasUsedAndFeeProcessor( pubKeyConverter core.PubkeyConverter, argsParser process.ArgumentsParser, marshaller marshal.Marshalizer, + enableEpochsHandler common.EnableEpochsHandler, ) *gasUsedAndFeeProcessor { return &gasUsedAndFeeProcessor{ feeComputer: txFeeCalculator, @@ -32,6 +34,7 @@ func newGasUsedAndFeeProcessor( pubKeyConverter: pubKeyConverter, argsParser: argsParser, marshaller: marshaller, + enableEpochsHandler: enableEpochsHandler, } } @@ -42,14 +45,16 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.GasUsed = gasUsed tx.Fee = fee.String() - if gfp.isESDTOperationWithSCCall(tx) { + isFeeFixActive := gfp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) + isRelayedBeforeFix := tx.IsRelayed && !isFeeFixActive + if isRelayedBeforeFix || gfp.isESDTOperationWithSCCall(tx) { tx.GasUsed = tx.GasLimit tx.Fee = tx.InitiallyPaidFee } // if there is a guardian operation, SetGuardian/GuardAccount/UnGuardAccount // the pre-configured cost of the operation must be added separately - if gfp.isGuardianOperation(tx) { + if gfp.isGuardianOperation(tx) && isFeeFixActive { gasUsed = gfp.feeComputer.ComputeGasLimit(tx) guardianOperationCost := gfp.getGuardianOperationCost(tx) gasUsed += guardianOperationCost @@ -57,14 +62,12 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction fee = big.NewInt(0).SetUint64(gasUsed * tx.GasPrice) tx.Fee = fee.String() - - initiallyPaidFee := gfp.feeComputer.ComputeMoveBalanceFee(tx) - tx.InitiallyPaidFee = initiallyPaidFee.String() + tx.InitiallyPaidFee = fee.String() return } - if tx.IsRelayed { + if tx.IsRelayed && isFeeFixActive { totalFee, isRelayed := gfp.getFeeOfRelayed(tx) if isRelayed { tx.Fee = totalFee.String() diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 1a9c7f922f4..f6af8464428 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -44,6 +44,7 @@ func TestComputeTransactionGasUsedAndFeeMoveBalance(t *testing.T) { pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -80,6 +81,7 @@ func TestComputeTransactionGasUsedAndFeeLogWithError(t *testing.T) { pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -129,6 +131,7 @@ func TestComputeTransactionGasUsedAndFeeRelayedTxWithWriteLog(t *testing.T) { pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -173,6 +176,7 @@ func TestComputeTransactionGasUsedAndFeeTransactionWithScrWithRefund(t *testing. pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -227,6 +231,7 @@ func TestNFTTransferWithScCall(t *testing.T) { pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -277,6 +282,11 @@ func TestComputeAndAttachGasUsedAndFeeSetGuardian(t *testing.T) { pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.FixRelayedBaseCostFlag + }, + }, ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -293,7 +303,6 @@ func TestComputeAndAttachGasUsedAndFeeSetGuardian(t *testing.T) { Operation: "SetGuardian", GasPrice: 1000000000, } - tx.InitiallyPaidFee = feeComp.ComputeTransactionFee(tx).String() gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(tx) require.Equal(t, uint64(475_500), tx.GasUsed) diff --git a/outport/process/factory/outportDataProviderFactory.go b/outport/process/factory/outportDataProviderFactory.go index 4350605b000..c57f2a09282 100644 --- a/outport/process/factory/outportDataProviderFactory.go +++ b/outport/process/factory/outportDataProviderFactory.go @@ -69,6 +69,7 @@ func CreateOutportDataProvider(arg ArgOutportDataProviderFactory) (outport.DataP PubKeyConverter: arg.AddressConverter, ArgsParser: smartContract.NewArgumentParser(), GasScheduleNotifier: arg.GasScheduleNotifier, + EnableEpochsHandler: arg.EnableEpochsHandler, }) if err != nil { return nil, err diff --git a/outport/process/outportDataProvider_test.go b/outport/process/outportDataProvider_test.go index 32193eef23f..96527e6404a 100644 --- a/outport/process/outportDataProvider_test.go +++ b/outport/process/outportDataProvider_test.go @@ -16,6 +16,7 @@ import ( "github.com/multiversx/mx-chain-go/outport/process/transactionsfee" "github.com/multiversx/mx-chain-go/testscommon" commonMocks "github.com/multiversx/mx-chain-go/testscommon/common" + "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" @@ -31,6 +32,7 @@ func createArgOutportDataProvider() ArgOutportDataProvider { TxFeeCalculator: &mock.EconomicsHandlerMock{}, ArgsParser: &testscommon.ArgumentParserMock{}, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), }) return ArgOutportDataProvider{ diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index be5689e4c62..61f87666d2d 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -29,6 +29,7 @@ type ArgTransactionsFeeProcessor struct { PubKeyConverter core.PubkeyConverter GasScheduleNotifier core.GasScheduleNotifier ArgsParser process.ArgumentsParser + EnableEpochsHandler common.EnableEpochsHandler } type transactionsFeeProcessor struct { @@ -40,6 +41,7 @@ type transactionsFeeProcessor struct { marshaller marshal.Marshalizer gasScheduleNotifier core.GasScheduleNotifier argsParser process.ArgumentsParser + enableEpochsHandler common.EnableEpochsHandler } // NewTransactionsFeeProcessor will create a new instance of transactionsFeeProcessor @@ -66,6 +68,7 @@ func NewTransactionsFeeProcessor(arg ArgTransactionsFeeProcessor) (*transactions marshaller: arg.Marshaller, gasScheduleNotifier: arg.GasScheduleNotifier, argsParser: arg.ArgsParser, + enableEpochsHandler: arg.EnableEpochsHandler, }, nil } @@ -91,6 +94,9 @@ func checkArg(arg ArgTransactionsFeeProcessor) error { if check.IfNil(arg.GasScheduleNotifier) { return process.ErrNilGasSchedule } + if check.IfNil(arg.EnableEpochsHandler) { + return process.ErrNilEnableEpochsHandler + } return nil } @@ -127,13 +133,16 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans feeInfo.SetFee(fee) feeInfo.SetInitialPaidFee(initialPaidFee) - if tep.isESDTOperationWithSCCall(txHandler) { + isRelayed := isRelayedTx(txWithResult) + isFeeFixActive := tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) + isRelayedBeforeFix := isRelayed && !isFeeFixActive + if isRelayedBeforeFix || tep.isESDTOperationWithSCCall(txHandler) { feeInfo.SetGasUsed(txWithResult.GetTxHandler().GetGasLimit()) feeInfo.SetFee(initialPaidFee) } res := tep.dataFieldParser.Parse(txHandler.GetData(), txHandler.GetSndAddr(), txHandler.GetRcvAddr(), tep.shardCoordinator.NumberOfShards()) - if tep.isGuardianOperation(res.Operation) { + if tep.isGuardianOperation(res.Operation) && isFeeFixActive { gasUsed = tep.txFeeCalculator.ComputeGasLimit(txHandler) guardianOperationCost := tep.getGuardianOperationCost(res.Operation, epoch) gasUsed += guardianOperationCost @@ -151,7 +160,7 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans continue } - if isRelayedTx(txWithResult) { + if isRelayedTx(txWithResult) && isFeeFixActive { totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) if isRelayed { feeInfo.SetFee(totalFee) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index 8e6d6d7156d..b3bda2cc9c9 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -13,6 +13,7 @@ import ( "github.com/multiversx/mx-chain-go/outport/mock" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon" + "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" logger "github.com/multiversx/mx-chain-logger-go" @@ -30,6 +31,7 @@ func prepareMockArg() ArgTransactionsFeeProcessor { PubKeyConverter: pubKeyConverter, ArgsParser: &testscommon.ArgumentParserMock{}, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } } @@ -66,6 +68,11 @@ func TestNewTransactionFeeProcessor(t *testing.T) { _, err = NewTransactionsFeeProcessor(arg) require.Equal(t, process.ErrNilGasSchedule, err) + arg = prepareMockArg() + arg.EnableEpochsHandler = nil + _, err = NewTransactionsFeeProcessor(arg) + require.Equal(t, process.ErrNilEnableEpochsHandler, err) + arg = prepareMockArg() txsFeeProc, err := NewTransactionsFeeProcessor(arg) require.NotNil(t, txsFeeProc) @@ -350,8 +357,8 @@ func TestPutFeeAndGasUsedWrongRelayedTx(t *testing.T) { err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) - require.Equal(t, big.NewInt(609500000000000), initialTx.GetFeeInfo().GetFee()) - require.Equal(t, uint64(609500), initialTx.GetFeeInfo().GetGasUsed()) + require.Equal(t, big.NewInt(6103405000000000), initialTx.GetFeeInfo().GetFee()) + require.Equal(t, uint64(550000000), initialTx.GetFeeInfo().GetGasUsed()) require.Equal(t, "6103405000000000", initialTx.GetFeeInfo().GetInitialPaidFee().String()) } From cff7df6f8d0fbf0355a6c8d1ed9d974e69604a4c Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 13 Aug 2024 12:44:37 +0300 Subject: [PATCH 30/99] integration of flag --- cmd/node/config/enableEpochs.toml | 3 +++ common/constants.go | 1 + common/enablers/enableEpochsHandler.go | 6 ++++++ common/enablers/enableEpochsHandler_test.go | 2 ++ config/epochConfig.go | 1 + config/tomlConfig_test.go | 4 ++++ 6 files changed, 17 insertions(+) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index dce2d48be2c..779ba4ba6b5 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -309,6 +309,9 @@ # AlwaysMergeContextsInEEIEnableEpoch represents the epoch in which the EEI will always merge the contexts AlwaysMergeContextsInEEIEnableEpoch = 1 + # UseGasBoundedShouldFailExecutionEnableEpoch represents the epoch when use bounded gas function should fail execution in case of error + UseGasBoundedShouldFailExecutionEnableEpoch = 1 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/common/constants.go b/common/constants.go index 5320ee675c1..53f5a242b2c 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1014,5 +1014,6 @@ const ( CleanupAuctionOnLowWaitingListFlag core.EnableEpochFlag = "CleanupAuctionOnLowWaitingListFlag" StakingV4StartedFlag core.EnableEpochFlag = "StakingV4StartedFlag" AlwaysMergeContextsInEEIFlag core.EnableEpochFlag = "AlwaysMergeContextsInEEIFlag" + UseGasBoundedShouldFailExecutionFlag core.EnableEpochFlag = "UseGasBoundedShouldFailExecutionFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index 5ce3812742f..ed3ee5960fc 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -732,6 +732,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.AlwaysMergeContextsInEEIEnableEpoch, }, + common.UseGasBoundedShouldFailExecutionFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.UseGasBoundedShouldFailExecutionEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.UseGasBoundedShouldFailExecutionEnableEpoch, + }, } } diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 2c568f2043b..807394e131f 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -116,6 +116,7 @@ func createEnableEpochsConfig() config.EnableEpochs { StakingV4Step3EnableEpoch: 98, CleanupAuctionOnLowWaitingListEnableEpoch: 96, AlwaysMergeContextsInEEIEnableEpoch: 99, + UseGasBoundedShouldFailExecutionEnableEpoch: 100, } } @@ -431,6 +432,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.CleanupAuctionOnLowWaitingListEnableEpoch, handler.GetActivationEpoch(common.CleanupAuctionOnLowWaitingListFlag)) require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4StartedFlag)) require.Equal(t, cfg.AlwaysMergeContextsInEEIEnableEpoch, handler.GetActivationEpoch(common.AlwaysMergeContextsInEEIFlag)) + require.Equal(t, cfg.UseGasBoundedShouldFailExecutionEnableEpoch, handler.GetActivationEpoch(common.UseGasBoundedShouldFailExecutionFlag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { diff --git a/config/epochConfig.go b/config/epochConfig.go index 764970ae050..cd7c74e490f 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -114,6 +114,7 @@ type EnableEpochs struct { StakingV4Step3EnableEpoch uint32 CleanupAuctionOnLowWaitingListEnableEpoch uint32 AlwaysMergeContextsInEEIEnableEpoch uint32 + UseGasBoundedShouldFailExecutionEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index eaeb4e6e2ae..eefbc9498e7 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -847,6 +847,9 @@ func TestEnableEpochConfig(t *testing.T) { # CleanupAuctionOnLowWaitingListEnableEpoch represents the epoch when the cleanup auction on low waiting list is enabled CleanupAuctionOnLowWaitingListEnableEpoch = 95 + # UseGasBoundedShouldFailExecutionEnableEpoch represents the epoch when use bounded gas function should fail execution in case of error + UseGasBoundedShouldFailExecutionEnableEpoch = 96 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -960,6 +963,7 @@ func TestEnableEpochConfig(t *testing.T) { CurrentRandomnessOnSortingEnableEpoch: 93, AlwaysMergeContextsInEEIEnableEpoch: 94, CleanupAuctionOnLowWaitingListEnableEpoch: 95, + UseGasBoundedShouldFailExecutionEnableEpoch: 96, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, From e8f7d9f8fa5c71eef00944d9854f29f230dae1ea Mon Sep 17 00:00:00 2001 From: python-qa Date: Tue, 13 Aug 2024 16:00:21 +0300 Subject: [PATCH 31/99] fix gh action --- ...hain_simulator_and_execute_system_test.yml | 118 ++++++++---------- 1 file changed, 49 insertions(+), 69 deletions(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index 0bb675230ae..00c329dd3fa 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -35,48 +35,68 @@ jobs: MX_CHAIN_TESTING_SUITE_TARGET_BRANCH: "" steps: - - name: Fetch Latest Comment - if: github.event_name != 'issue_comment' + - name: Determine Target Branches + id: target_branch + run: | + echo "CURRENT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" >> $GITHUB_ENV + + # Default target branches based on the PR base branch + if [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV + elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV + else + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + fi + + # Always set MX_CHAIN_GO_TARGET_BRANCH based on the PR base branch + echo "MX_CHAIN_GO_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + + + - name: Fetch and Parse Last Comment for Branches uses: actions/github-script@v7 - id: fetch_comment + id: fetch_and_parse_last_comment with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | + // Get the latest comment const comments = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }); - // Filter for comments containing "Run Tests:" - const latestComment = comments.data.reverse().find(comment => comment.body.includes('Run Tests:')); + const lastComment = comments.data.pop(); // Get the last comment + + if (lastComment && lastComment.body.includes('Run Tests:')) { + const body = lastComment.body.trim(); + core.setOutput('latest_comment', body); - if (latestComment) { - core.setOutput('latest_comment', latestComment.body); + // Parse the branches from the last comment + const simulatorBranchMatch = body.match(/mx-chain-simulator-go:\s*(\S+)/); + const testingSuiteBranchMatch = body.match(/mx-chain-testing-suite:\s*(\S+)/); + + // Override the target branches if specified + if (simulatorBranchMatch) { + core.exportVariable('MX_CHAIN_SIMULATOR_TARGET_BRANCH', simulatorBranchMatch[1]); + } + if (testingSuiteBranchMatch) { + core.exportVariable('MX_CHAIN_TESTING_SUITE_TARGET_BRANCH', testingSuiteBranchMatch[1]); + } } else { - core.setOutput('latest_comment', ''); + core.info('The last comment does not contain "Run Tests:". Skipping branch override.'); } - env: - LATEST_COMMENT: ${{ steps.fetch_comment.outputs.latest_comment }} + - - name: Parse Comment for Branches + - name: Print Target Branches run: | - # Use fetched comment if available, otherwise use current event comment - COMMENT="${{ steps.fetch_comment.outputs.latest_comment || github.event.comment.body }}" - - # Debug print the comment being used - echo "Comment used for parsing: $COMMENT" - - # Extract branch names from the comment - if echo "$COMMENT" | grep -q "mx-chain-simulator-go:"; then - SIMULATOR_BRANCH=$(echo "$COMMENT" | grep "mx-chain-simulator-go:" | awk -F': ' '{print $2}') - echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${SIMULATOR_BRANCH}" >> $GITHUB_ENV - fi - - if echo "$COMMENT" | grep -q "mx-chain-testing-suite:"; then - TESTING_SUITE_BRANCH=$(echo "$COMMENT" | grep "mx-chain-testing-suite:" | awk -F': ' '{print $2}') - echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${TESTING_SUITE_BRANCH}" >> $GITHUB_ENV - fi + echo "Current branch mx-chain-go: ${{ env.CURRENT_BRANCH }}" + echo "mx-chain-go target branch: ${{ env.MX_CHAIN_GO_TARGET_BRANCH }}" + echo "mx-chain-simulator-go target branch: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" + echo "mx-chain-testing-suite target branch: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" - name: Set up Go 1.20.7 uses: actions/setup-go@v3 @@ -88,11 +108,11 @@ jobs: uses: actions/checkout@v4 with: repository: 'multiversx/mx-chain-go' - ref: ${{ env.MX_CHAIN_GO_TARGET_BRANCH || github.head_ref || github.ref }} + ref: ${{ github.head_ref }} fetch-depth: 0 path: 'mx-chain-go' - - name: Get Latest Commit Hash + - name: Get Latest mx-chain-go Commit Hash run: | cd mx-chain-go current_branch=$(git symbolic-ref --short HEAD) @@ -102,45 +122,6 @@ jobs: echo "LATEST_COMMIT_HASH=${latest_commit_hash}" >> $GITHUB_ENV echo "Latest commit hash: ${latest_commit_hash}" - - name: Determine Target Branches - id: target_branch - run: | - echo "CURRENT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" >> $GITHUB_ENV - - # Use branches from comment if they are set - if [ -n "${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" ]; then - echo "Using comment-specified mx-chain-simulator-go branch: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" - echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" >> $GITHUB_ENV - else - if [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then - echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV - elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then - echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV - fi - fi - - if [ -n "${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" ]; then - echo "Using comment-specified mx-chain-testing-suite branch: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" - echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" >> $GITHUB_ENV - else - if [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then - echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV - elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then - echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV - fi - fi - - # Always set MX_CHAIN_GO_TARGET_BRANCH based on the PR base branch - echo "MX_CHAIN_GO_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV - - - - name: Print Target Branches - run: | - echo "Current branch mx-chain-go: ${{ env.CURRENT_BRANCH }}" - echo "mx-chain-go target branch: ${{ env.MX_CHAIN_GO_TARGET_BRANCH }}" - echo "mx-chain-simulator-go target branch: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" - echo "mx-chain-testing-suite target branch: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" - - name: Checkout mx-chain-simulator-go uses: actions/checkout@v4 with: @@ -159,7 +140,6 @@ jobs: pip install -r scripts/update-go-mod/requirements.txt python scripts/update-go-mod/update-go-mod.py $LATEST_COMMIT_HASH - - name: Run go build run: | cd mx-chain-simulator-go/cmd/chainsimulator From fc42f1fc895bca6bfdebb8f4e8b3b5b259b356ea Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 13 Aug 2024 17:11:53 +0300 Subject: [PATCH 32/99] debug --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 50506f20018..f0f14d283c0 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9 diff --git a/go.sum b/go.sum index 4a7a2b9d06b..0b739180652 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79 h1:XCL3LLJ2hgVPuYwuMmM9RtJDStLn822bOvRHMCkbnYM= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9 h1:bq4Dqa8N8hgqXBWicQ6IwvTJtuEfCZmkj0/QponsmE4= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From f1a3ceb4589e2d512d8fbbb41108115454ad45af Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 13 Aug 2024 17:39:29 +0300 Subject: [PATCH 33/99] new vm --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f0f14d283c0..247a43b09ef 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9 diff --git a/go.sum b/go.sum index 0b739180652..f5ec4b8cf9c 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9 h1:bq4Dqa8N8hgqXBWicQ6IwvTJtuEfCZmkj0/QponsmE4= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9 h1:eWd7ycVjsozzqfJLp8jMgAni8vu3taF2I/OVUZuyrcM= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From d7e5ef83299b73654c135e76bfbd9609304be32d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 13 Aug 2024 19:59:03 +0300 Subject: [PATCH 34/99] reverted fix for guarded operations, not needed --- common/forking/gasSchedule.go | 20 ------- factory/api/apiResolverFactory.go | 1 - genesis/process/disabled/feeHandler.go | 5 -- go.mod | 2 +- go.sum | 4 +- .../mock/gasScheduleNotifierMock.go | 5 -- .../testProcessorNodeWithTestWebServer.go | 1 - node/external/timemachine/fee/feeComputer.go | 5 -- .../transactionAPI/apiTransactionArgs.go | 1 - .../transactionAPI/apiTransactionProcessor.go | 1 - .../apiTransactionProcessor_test.go | 3 - node/external/transactionAPI/check.go | 3 - .../transactionAPI/gasUsedAndFeeProcessor.go | 42 -------------- .../gasUsedAndFeeProcessor_test.go | 57 ------------------- node/external/transactionAPI/interface.go | 1 - .../transactionsFeeProcessor.go | 38 ------------- process/interface.go | 1 - testscommon/gasScheduleNotifierMock.go | 10 ---- 18 files changed, 3 insertions(+), 197 deletions(-) diff --git a/common/forking/gasSchedule.go b/common/forking/gasSchedule.go index cac675387be..7da39fed41f 100644 --- a/common/forking/gasSchedule.go +++ b/common/forking/gasSchedule.go @@ -163,26 +163,6 @@ func (g *gasScheduleNotifier) LatestGasSchedule() map[string]map[string]uint64 { return g.lastGasSchedule } -// GasScheduleForEpoch returns the gas schedule for the specific epoch -func (g *gasScheduleNotifier) GasScheduleForEpoch(epoch uint32) (map[string]map[string]uint64, error) { - g.mutNotifier.RLock() - defer g.mutNotifier.RUnlock() - - currentVersion := g.getMatchingVersion(g.currentEpoch) - requestedVersion := g.getMatchingVersion(epoch) - if currentVersion == requestedVersion { - return g.lastGasSchedule, nil - } - - gasSchedule, err := common.LoadGasScheduleConfig(filepath.Join(g.configDir, requestedVersion.FileName)) - if err != nil { - log.Error("could not load the gas schedule", "epoch", requestedVersion.StartEpoch) - return nil, err - } - - return gasSchedule, nil -} - // LatestGasScheduleCopy returns a copy of the latest gas schedule func (g *gasScheduleNotifier) LatestGasScheduleCopy() map[string]map[string]uint64 { g.mutNotifier.RLock() diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index a33fa09b4a8..399ee4b1533 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -244,7 +244,6 @@ func CreateApiResolver(args *ApiResolverArgs) (facade.ApiResolver, error) { TxTypeHandler: txTypeHandler, LogsFacade: logsFacade, DataFieldParser: dataFieldParser, - GasScheduleNotifier: args.GasScheduleNotifier, TxMarshaller: args.CoreComponents.TxMarshalizer(), EnableEpochsHandler: args.CoreComponents.EnableEpochsHandler(), } diff --git a/genesis/process/disabled/feeHandler.go b/genesis/process/disabled/feeHandler.go index 1d4679e859f..f81e7e978eb 100644 --- a/genesis/process/disabled/feeHandler.go +++ b/genesis/process/disabled/feeHandler.go @@ -87,11 +87,6 @@ func (fh *FeeHandler) ComputeMoveBalanceFee(_ data.TransactionWithFeeHandler) *b return big.NewInt(0) } -// ComputeMoveBalanceFeeInEpoch returns 0 -func (fh *FeeHandler) ComputeMoveBalanceFeeInEpoch(_ data.TransactionWithFeeHandler, _ uint32) *big.Int { - return big.NewInt(0) -} - // ComputeFeeForProcessing returns 0 func (fh *FeeHandler) ComputeFeeForProcessing(_ data.TransactionWithFeeHandler, _ uint64) *big.Int { return big.NewInt(0) diff --git a/go.mod b/go.mod index 5a2ac5d99fd..4667bd06e7e 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc + github.com/multiversx/mx-chain-core-go v1.2.21 github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.7.4 github.com/multiversx/mx-chain-logger-go v1.0.15 diff --git a/go.sum b/go.sum index 431460a09e2..11a9bc62556 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc h1:EB25Psgi0GjWJfrNfgvGEMcuoqj63BnFrw0bqsl9Hdc= -github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21 h1:+XVKznPTlUU5EFS1A8chtS8fStW60upRIyF4Pgml19I= +github.com/multiversx/mx-chain-core-go v1.2.21/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= github.com/multiversx/mx-chain-es-indexer-go v1.7.4 h1:SjJk9G9SN8baz0sFIU2jymYCfx3XiikGEB2wW0jwvfw= diff --git a/integrationTests/mock/gasScheduleNotifierMock.go b/integrationTests/mock/gasScheduleNotifierMock.go index ddcff3873fc..6ef6ea2684c 100644 --- a/integrationTests/mock/gasScheduleNotifierMock.go +++ b/integrationTests/mock/gasScheduleNotifierMock.go @@ -28,11 +28,6 @@ func (g *GasScheduleNotifierMock) LatestGasSchedule() map[string]map[string]uint return g.GasSchedule } -// GasScheduleForEpoch - -func (g *GasScheduleNotifierMock) GasScheduleForEpoch(_ uint32) (map[string]map[string]uint64, error) { - return g.GasSchedule, nil -} - // UnRegisterAll - func (g *GasScheduleNotifierMock) UnRegisterAll() { } diff --git a/integrationTests/testProcessorNodeWithTestWebServer.go b/integrationTests/testProcessorNodeWithTestWebServer.go index 8a4d6483970..d533f4c75b1 100644 --- a/integrationTests/testProcessorNodeWithTestWebServer.go +++ b/integrationTests/testProcessorNodeWithTestWebServer.go @@ -237,7 +237,6 @@ func createFacadeComponents(tpn *TestProcessorNode) nodeFacade.ApiResolver { TxTypeHandler: txTypeHandler, LogsFacade: logsFacade, DataFieldParser: dataFieldParser, - GasScheduleNotifier: gasScheduleNotifier, TxMarshaller: &marshallerMock.MarshalizerMock{}, EnableEpochsHandler: tpn.EnableEpochsHandler, } diff --git a/node/external/timemachine/fee/feeComputer.go b/node/external/timemachine/fee/feeComputer.go index 9ad90d2b221..6d19ce05ceb 100644 --- a/node/external/timemachine/fee/feeComputer.go +++ b/node/external/timemachine/fee/feeComputer.go @@ -50,11 +50,6 @@ func (computer *feeComputer) ComputeTransactionFee(tx *transaction.ApiTransactio return computer.economicsInstance.ComputeTxFeeInEpoch(tx.Tx, tx.Epoch) } -// ComputeMoveBalanceFee computes a transaction's move balance fee, at a given epoch -func (computer *feeComputer) ComputeMoveBalanceFee(tx *transaction.ApiTransactionResult) *big.Int { - return computer.economicsInstance.ComputeMoveBalanceFeeInEpoch(tx.Tx, tx.Epoch) -} - // IsInterfaceNil returns true if there is no value under the interface func (computer *feeComputer) IsInterfaceNil() bool { return computer == nil diff --git a/node/external/transactionAPI/apiTransactionArgs.go b/node/external/transactionAPI/apiTransactionArgs.go index 8083a4096cb..1e4099390fd 100644 --- a/node/external/transactionAPI/apiTransactionArgs.go +++ b/node/external/transactionAPI/apiTransactionArgs.go @@ -28,7 +28,6 @@ type ArgAPITransactionProcessor struct { TxTypeHandler process.TxTypeHandler LogsFacade LogsFacade DataFieldParser DataFieldParser - GasScheduleNotifier core.GasScheduleNotifier TxMarshaller marshal.Marshalizer EnableEpochsHandler common.EnableEpochsHandler } diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index 3568175af14..d018a3322ad 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -69,7 +69,6 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti refundDetectorInstance := NewRefundDetector() gasUsedAndFeeProc := newGasUsedAndFeeProcessor( args.FeeComputer, - args.GasScheduleNotifier, args.AddressPubKeyConverter, smartContract.NewArgumentParser(), args.TxMarshaller, diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index 0a36b4b304f..18d524d9c2c 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -61,7 +61,6 @@ func createMockArgAPITransactionProcessor() *ArgAPITransactionProcessor { return &datafield.ResponseParseData{} }, }, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } @@ -482,7 +481,6 @@ func TestNode_GetTransactionWithResultsFromStorage(t *testing.T) { return &datafield.ResponseParseData{} }, }, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } @@ -1053,7 +1051,6 @@ func createAPITransactionProc(t *testing.T, epoch uint32, withDbLookupExt bool) TxTypeHandler: &testscommon.TxTypeHandlerMock{}, LogsFacade: &testscommon.LogsFacadeStub{}, DataFieldParser: dataFieldParser, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } diff --git a/node/external/transactionAPI/check.go b/node/external/transactionAPI/check.go index ce45c38bae4..012aae77618 100644 --- a/node/external/transactionAPI/check.go +++ b/node/external/transactionAPI/check.go @@ -44,9 +44,6 @@ func checkNilArgs(arg *ArgAPITransactionProcessor) error { if check.IfNilReflect(arg.DataFieldParser) { return ErrNilDataFieldParser } - if check.IfNilReflect(arg.GasScheduleNotifier) { - return process.ErrNilGasSchedule - } if check.IfNil(arg.TxMarshaller) { return fmt.Errorf("%w for tx marshaller", process.ErrNilMarshalizer) } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 1ad96c810f9..8951149c983 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -13,7 +13,6 @@ import ( type gasUsedAndFeeProcessor struct { feeComputer feeComputer - gasScheduleNotifier core.GasScheduleNotifier pubKeyConverter core.PubkeyConverter argsParser process.ArgumentsParser marshaller marshal.Marshalizer @@ -22,7 +21,6 @@ type gasUsedAndFeeProcessor struct { func newGasUsedAndFeeProcessor( txFeeCalculator feeComputer, - gasScheduleNotifier core.GasScheduleNotifier, pubKeyConverter core.PubkeyConverter, argsParser process.ArgumentsParser, marshaller marshal.Marshalizer, @@ -30,7 +28,6 @@ func newGasUsedAndFeeProcessor( ) *gasUsedAndFeeProcessor { return &gasUsedAndFeeProcessor{ feeComputer: txFeeCalculator, - gasScheduleNotifier: gasScheduleNotifier, pubKeyConverter: pubKeyConverter, argsParser: argsParser, marshaller: marshaller, @@ -52,21 +49,6 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = tx.InitiallyPaidFee } - // if there is a guardian operation, SetGuardian/GuardAccount/UnGuardAccount - // the pre-configured cost of the operation must be added separately - if gfp.isGuardianOperation(tx) && isFeeFixActive { - gasUsed = gfp.feeComputer.ComputeGasLimit(tx) - guardianOperationCost := gfp.getGuardianOperationCost(tx) - gasUsed += guardianOperationCost - tx.GasUsed = gasUsed - - fee = big.NewInt(0).SetUint64(gasUsed * tx.GasPrice) - tx.Fee = fee.String() - tx.InitiallyPaidFee = fee.String() - - return - } - if tx.IsRelayed && isFeeFixActive { totalFee, isRelayed := gfp.getFeeOfRelayed(tx) if isRelayed { @@ -164,30 +146,6 @@ func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transactio return big.NewInt(0).Add(fee, innerFee), true } -func (gfp *gasUsedAndFeeProcessor) getGuardianOperationCost(tx *transaction.ApiTransactionResult) uint64 { - gasSchedule, err := gfp.gasScheduleNotifier.GasScheduleForEpoch(tx.Epoch) - if err != nil { - return 0 - } - - switch tx.Operation { - case core.BuiltInFunctionSetGuardian: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionSetGuardian] - case core.BuiltInFunctionGuardAccount: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionGuardAccount] - case core.BuiltInFunctionUnGuardAccount: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionUnGuardAccount] - default: - return 0 - } -} - -func (gfp *gasUsedAndFeeProcessor) isGuardianOperation(tx *transaction.ApiTransactionResult) bool { - return tx.Operation == core.BuiltInFunctionSetGuardian || - tx.Operation == core.BuiltInFunctionGuardAccount || - tx.Operation == core.BuiltInFunctionUnGuardAccount -} - func (gfp *gasUsedAndFeeProcessor) prepareTxWithResultsBasedOnLogs( tx *transaction.ApiTransactionResult, hasRefund bool, diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index f6af8464428..d5340e7903c 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -40,7 +40,6 @@ func TestComputeTransactionGasUsedAndFeeMoveBalance(t *testing.T) { gasUsedAndFeeProc := newGasUsedAndFeeProcessor( computer, - &testscommon.GasScheduleNotifierMock{}, pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, @@ -77,7 +76,6 @@ func TestComputeTransactionGasUsedAndFeeLogWithError(t *testing.T) { gasUsedAndFeeProc := newGasUsedAndFeeProcessor( computer, - &testscommon.GasScheduleNotifierMock{}, pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, @@ -127,7 +125,6 @@ func TestComputeTransactionGasUsedAndFeeRelayedTxWithWriteLog(t *testing.T) { gasUsedAndFeeProc := newGasUsedAndFeeProcessor( computer, - &testscommon.GasScheduleNotifierMock{}, pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, @@ -172,7 +169,6 @@ func TestComputeTransactionGasUsedAndFeeTransactionWithScrWithRefund(t *testing. gasUsedAndFeeProc := newGasUsedAndFeeProcessor( computer, - &testscommon.GasScheduleNotifierMock{}, pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, @@ -227,7 +223,6 @@ func TestNFTTransferWithScCall(t *testing.T) { gasUsedAndFeeProc := newGasUsedAndFeeProcessor( computer, - &testscommon.GasScheduleNotifierMock{}, pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, @@ -256,55 +251,3 @@ func TestNFTTransferWithScCall(t *testing.T) { req.Equal(uint64(55_000_000), tx.GasUsed) req.Equal("822250000000000", tx.Fee) } - -func TestComputeAndAttachGasUsedAndFeeSetGuardian(t *testing.T) { - t.Parallel() - - feeComp, err := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { - return flag == common.GasPriceModifierFlag || flag == common.PenalizedTooMuchGasFlag - }, - })) - computer := fee.NewTestFeeComputer(feeComp) - require.NoError(t, err) - - gasSch := &testscommon.GasScheduleNotifierMock{ - GasSchedule: map[string]map[string]uint64{ - common.BuiltInCost: { - core.BuiltInFunctionSetGuardian: 250000, - }, - }, - } - - gasUsedAndFeeProc := newGasUsedAndFeeProcessor( - computer, - gasSch, - pubKeyConverter, - &testscommon.ArgumentParserMock{}, - &testscommon.MarshallerStub{}, - &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { - return flag == common.FixRelayedBaseCostFlag - }, - }, - ) - - sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" - - tx := &transaction.ApiTransactionResult{ - Tx: &transaction.Transaction{ - GasLimit: 475_500, - GasPrice: 1000000000, - SndAddr: silentDecodeAddress(sender), - RcvAddr: silentDecodeAddress(sender), - Data: []byte("SetGuardian@835741dd7018300bb4ed14211f9a9118ea7049572402c3a553deb1141f9c89aa@4d756c7469766572735854435353657276696365"), - }, - GasLimit: 475_500, - Operation: "SetGuardian", - GasPrice: 1000000000, - } - - gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(tx) - require.Equal(t, uint64(475_500), tx.GasUsed) - require.Equal(t, "475500000000000", tx.Fee) -} diff --git a/node/external/transactionAPI/interface.go b/node/external/transactionAPI/interface.go index 77057e1de05..a32cac06184 100644 --- a/node/external/transactionAPI/interface.go +++ b/node/external/transactionAPI/interface.go @@ -12,7 +12,6 @@ type feeComputer interface { ComputeTxFeeBasedOnGasUsed(tx *transaction.ApiTransactionResult, gasUsed uint64) *big.Int ComputeGasLimit(tx *transaction.ApiTransactionResult) uint64 ComputeTransactionFee(tx *transaction.ApiTransactionResult) *big.Int - ComputeMoveBalanceFee(tx *transaction.ApiTransactionResult) *big.Int IsInterfaceNil() bool } diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index 61f87666d2d..cbeaea814be 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -141,20 +141,6 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans feeInfo.SetFee(initialPaidFee) } - res := tep.dataFieldParser.Parse(txHandler.GetData(), txHandler.GetSndAddr(), txHandler.GetRcvAddr(), tep.shardCoordinator.NumberOfShards()) - if tep.isGuardianOperation(res.Operation) && isFeeFixActive { - gasUsed = tep.txFeeCalculator.ComputeGasLimit(txHandler) - guardianOperationCost := tep.getGuardianOperationCost(res.Operation, epoch) - gasUsed += guardianOperationCost - feeInfo.SetGasUsed(gasUsed) - - fee = big.NewInt(0).SetUint64(gasUsed * txHandler.GetGasPrice()) - feeInfo.SetFee(fee) - feeInfo.SetInitialPaidFee(fee) - - return - } - if len(txHandler.GetUserTransactions()) > 0 { tep.prepareRelayedTxV3WithResults(txHashHex, txWithResult) continue @@ -257,30 +243,6 @@ func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transact return big.NewInt(0).Add(fee, innerFee), true } -func (tep *transactionsFeeProcessor) getGuardianOperationCost(operation string, epoch uint32) uint64 { - gasSchedule, err := tep.gasScheduleNotifier.GasScheduleForEpoch(epoch) - if err != nil { - return 0 - } - - switch operation { - case core.BuiltInFunctionSetGuardian: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionSetGuardian] - case core.BuiltInFunctionGuardAccount: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionGuardAccount] - case core.BuiltInFunctionUnGuardAccount: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionUnGuardAccount] - default: - return 0 - } -} - -func (tep *transactionsFeeProcessor) isGuardianOperation(operation string) bool { - return operation == core.BuiltInFunctionSetGuardian || - operation == core.BuiltInFunctionGuardAccount || - operation == core.BuiltInFunctionUnGuardAccount -} - func (tep *transactionsFeeProcessor) prepareRelayedTxV3WithResults(txHashHex string, txWithResults *transactionWithResults) { refundsValue := big.NewInt(0) for _, scrHandler := range txWithResults.scrs { diff --git a/process/interface.go b/process/interface.go index e1c81fa6f96..8e943d0a44e 100644 --- a/process/interface.go +++ b/process/interface.go @@ -680,7 +680,6 @@ type feeHandler interface { MaxGasLimitPerTx() uint64 ComputeGasLimit(tx data.TransactionWithFeeHandler) uint64 ComputeMoveBalanceFee(tx data.TransactionWithFeeHandler) *big.Int - ComputeMoveBalanceFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int ComputeTxFee(tx data.TransactionWithFeeHandler) *big.Int CheckValidityTxValues(tx data.TransactionWithFeeHandler) error ComputeFeeForProcessing(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int diff --git a/testscommon/gasScheduleNotifierMock.go b/testscommon/gasScheduleNotifierMock.go index e7894c25e40..dd0f728cfad 100644 --- a/testscommon/gasScheduleNotifierMock.go +++ b/testscommon/gasScheduleNotifierMock.go @@ -8,7 +8,6 @@ type GasScheduleNotifierMock struct { RegisterNotifyHandlerCalled func(handler core.GasScheduleSubscribeHandler) LatestGasScheduleCalled func() map[string]map[string]uint64 LatestGasScheduleCopyCalled func() map[string]map[string]uint64 - GasScheduleForEpochCalled func(epoch uint32) (map[string]map[string]uint64, error) } // NewGasScheduleNotifierMock - @@ -51,15 +50,6 @@ func (g *GasScheduleNotifierMock) LatestGasScheduleCopy() map[string]map[string] func (g *GasScheduleNotifierMock) UnRegisterAll() { } -// GasScheduleForEpoch - -func (g *GasScheduleNotifierMock) GasScheduleForEpoch(epoch uint32) (map[string]map[string]uint64, error) { - if g.GasScheduleForEpochCalled != nil { - return g.GasScheduleForEpochCalled(epoch) - } - - return g.GasSchedule, nil -} - // IsInterfaceNil - func (g *GasScheduleNotifierMock) IsInterfaceNil() bool { return g == nil From fc273728c0ceeb498b5732b8aaf3b297499e529d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 13 Aug 2024 20:04:39 +0300 Subject: [PATCH 35/99] further reverts --- factory/processing/blockProcessorCreator.go | 1 - outport/process/factory/check_test.go | 1 - outport/process/factory/outportDataProviderFactory.go | 2 -- outport/process/outportDataProvider_test.go | 1 - outport/process/transactionsfee/transactionsFeeProcessor.go | 6 ------ .../transactionsfee/transactionsFeeProcessor_test.go | 6 ------ 6 files changed, 17 deletions(-) diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index f4ee93124a2..93f3e1e95a3 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -1052,7 +1052,6 @@ func (pcf *processComponentsFactory) createOutportDataProvider( MbsStorer: mbsStorer, EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), ExecutionOrderGetter: pcf.txExecutionOrderHandler, - GasScheduleNotifier: pcf.gasSchedule, }) } diff --git a/outport/process/factory/check_test.go b/outport/process/factory/check_test.go index 67b9a91b7dc..513a3c7305b 100644 --- a/outport/process/factory/check_test.go +++ b/outport/process/factory/check_test.go @@ -34,7 +34,6 @@ func createArgOutportDataProviderFactory() ArgOutportDataProviderFactory { MbsStorer: &genericMocks.StorerMock{}, EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ExecutionOrderGetter: &commonMocks.TxExecutionOrderHandlerStub{}, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } } diff --git a/outport/process/factory/outportDataProviderFactory.go b/outport/process/factory/outportDataProviderFactory.go index c57f2a09282..5bb2c698136 100644 --- a/outport/process/factory/outportDataProviderFactory.go +++ b/outport/process/factory/outportDataProviderFactory.go @@ -37,7 +37,6 @@ type ArgOutportDataProviderFactory struct { MbsStorer storage.Storer EnableEpochsHandler common.EnableEpochsHandler ExecutionOrderGetter common.ExecutionOrderGetter - GasScheduleNotifier core.GasScheduleNotifier } // CreateOutportDataProvider will create a new instance of outport.DataProviderOutport @@ -68,7 +67,6 @@ func CreateOutportDataProvider(arg ArgOutportDataProviderFactory) (outport.DataP TxFeeCalculator: arg.EconomicsData, PubKeyConverter: arg.AddressConverter, ArgsParser: smartContract.NewArgumentParser(), - GasScheduleNotifier: arg.GasScheduleNotifier, EnableEpochsHandler: arg.EnableEpochsHandler, }) if err != nil { diff --git a/outport/process/outportDataProvider_test.go b/outport/process/outportDataProvider_test.go index 96527e6404a..ef1422d230a 100644 --- a/outport/process/outportDataProvider_test.go +++ b/outport/process/outportDataProvider_test.go @@ -31,7 +31,6 @@ func createArgOutportDataProvider() ArgOutportDataProvider { ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, TxFeeCalculator: &mock.EconomicsHandlerMock{}, ArgsParser: &testscommon.ArgumentParserMock{}, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), }) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index cbeaea814be..ffad67ee22f 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -27,7 +27,6 @@ type ArgTransactionsFeeProcessor struct { ShardCoordinator sharding.Coordinator TxFeeCalculator FeesProcessorHandler PubKeyConverter core.PubkeyConverter - GasScheduleNotifier core.GasScheduleNotifier ArgsParser process.ArgumentsParser EnableEpochsHandler common.EnableEpochsHandler } @@ -39,7 +38,6 @@ type transactionsFeeProcessor struct { dataFieldParser dataFieldParser log logger.Logger marshaller marshal.Marshalizer - gasScheduleNotifier core.GasScheduleNotifier argsParser process.ArgumentsParser enableEpochsHandler common.EnableEpochsHandler } @@ -66,7 +64,6 @@ func NewTransactionsFeeProcessor(arg ArgTransactionsFeeProcessor) (*transactions log: logger.GetOrCreate(loggerName), dataFieldParser: parser, marshaller: arg.Marshaller, - gasScheduleNotifier: arg.GasScheduleNotifier, argsParser: arg.ArgsParser, enableEpochsHandler: arg.EnableEpochsHandler, }, nil @@ -91,9 +88,6 @@ func checkArg(arg ArgTransactionsFeeProcessor) error { if check.IfNil(arg.ArgsParser) { return process.ErrNilArgumentParser } - if check.IfNil(arg.GasScheduleNotifier) { - return process.ErrNilGasSchedule - } if check.IfNil(arg.EnableEpochsHandler) { return process.ErrNilEnableEpochsHandler } diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index b3bda2cc9c9..6f0e0f94c35 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -30,7 +30,6 @@ func prepareMockArg() ArgTransactionsFeeProcessor { TxFeeCalculator: &mock.EconomicsHandlerMock{}, PubKeyConverter: pubKeyConverter, ArgsParser: &testscommon.ArgumentParserMock{}, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } } @@ -63,11 +62,6 @@ func TestNewTransactionFeeProcessor(t *testing.T) { _, err = NewTransactionsFeeProcessor(arg) require.Equal(t, process.ErrNilArgumentParser, err) - arg = prepareMockArg() - arg.GasScheduleNotifier = nil - _, err = NewTransactionsFeeProcessor(arg) - require.Equal(t, process.ErrNilGasSchedule, err) - arg = prepareMockArg() arg.EnableEpochsHandler = nil _, err = NewTransactionsFeeProcessor(arg) From 894c853d441b7240e7a48ca4273a8472519c4c17 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Aug 2024 09:28:27 +0300 Subject: [PATCH 36/99] debug --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 247a43b09ef..e7d8edc648d 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346 diff --git a/go.sum b/go.sum index f5ec4b8cf9c..a35ee905a8e 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9 h1:eWd7ycVjsozzqfJLp8jMgAni8vu3taF2I/OVUZuyrcM= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346 h1:o13yI3MmkwWshKD5617u9zCdcLFd1v2iBiqAaEpW57k= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 728bc517da15259dd5883daa79a3880cc139ee49 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Aug 2024 10:11:31 +0300 Subject: [PATCH 37/99] backward compatibility --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e7d8edc648d..674b640c67b 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc diff --git a/go.sum b/go.sum index a35ee905a8e..e0970255215 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346 h1:o13yI3MmkwWshKD5617u9zCdcLFd1v2iBiqAaEpW57k= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc h1:WGjf5v8O5NKeAI9oIG+Jb6EkroR3SjIjIHSDXY/msI4= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 215dd458a8566a5bf069af2b5b9f2cd9cc836f2c Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Aug 2024 10:20:23 +0300 Subject: [PATCH 38/99] debug --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 674b640c67b..b79259147e4 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990 diff --git a/go.sum b/go.sum index e0970255215..cc6d790bf62 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc h1:WGjf5v8O5NKeAI9oIG+Jb6EkroR3SjIjIHSDXY/msI4= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990 h1:jb43pkrPsbL4m04OTiDFLR7DtNBx5s61NnTCixgoeYI= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 047464621f15e63366e35614a5d2fd9003e9501e Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Aug 2024 14:16:28 +0300 Subject: [PATCH 39/99] debug delete --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b79259147e4..04e06bec707 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6 diff --git a/go.sum b/go.sum index cc6d790bf62..cd867580cfc 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990 h1:jb43pkrPsbL4m04OTiDFLR7DtNBx5s61NnTCixgoeYI= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6 h1:7q4B9MXAfEWhSSCMPvt5eelxtcit55islP7Yu3MkVwA= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From cab29d2fbe34b15275106991855e97e376de8345 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 14 Aug 2024 18:16:11 +0300 Subject: [PATCH 40/99] switch log level --- process/block/preprocess/transactionsV2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/block/preprocess/transactionsV2.go b/process/block/preprocess/transactionsV2.go index 654ff4231a8..6391987983a 100644 --- a/process/block/preprocess/transactionsV2.go +++ b/process/block/preprocess/transactionsV2.go @@ -218,7 +218,7 @@ func (txs *transactions) processTransaction( } if errors.Is(err, process.ErrFailedTransaction) { - log.Debug("transactions.processTransaction", + log.Trace("transactions.processTransaction", "txHash", txHash, "nonce", tx.Nonce, "value", tx.Value, From ebfc4f7e566daa712c1613a53f677be208d015f6 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Aug 2024 19:08:58 +0300 Subject: [PATCH 41/99] debug and fix --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 04e06bec707..f4f809e4c0b 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3 diff --git a/go.sum b/go.sum index cd867580cfc..c9f247ab27d 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6 h1:7q4B9MXAfEWhSSCMPvt5eelxtcit55islP7Yu3MkVwA= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3 h1:iGyaiwd2koj93cAlqFehZZBHVRTOKD9xzvfBf+MRNB8= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 069ff1d8a20f4e55d1f0f2295d7209d77dc7d1f4 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 15 Aug 2024 09:47:16 +0300 Subject: [PATCH 42/99] integrate newest vm --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f4f809e4c0b..315f9358f6c 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f diff --git a/go.sum b/go.sum index c9f247ab27d..8e75a213f52 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3 h1:iGyaiwd2koj93cAlqFehZZBHVRTOKD9xzvfBf+MRNB8= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f h1:3XBgHHpdLNqTGRr6Muupn8g4Cu7J6/jxjQb4OpklSKo= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 6cec9edf3d3e7380c2f41eb39f6ece5ae9981459 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 19 Aug 2024 09:52:26 +0300 Subject: [PATCH 43/99] fix test after merge --- node/external/transactionAPI/apiTransactionProcessor_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index 204c123decc..e6a7040fe87 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -360,6 +360,8 @@ func TestNode_GetSCRs(t *testing.T) { return &datafield.ResponseParseData{} }, }, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + TxMarshaller: &mock.MarshalizerFake{}, } apiTransactionProc, _ := NewAPITransactionProcessor(args) From 0123471c9682912859ffda012304b067dcea77f4 Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 19 Aug 2024 10:23:55 +0300 Subject: [PATCH 44/99] latest indexer version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c6b99bc0214..49f55d1e0b4 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiversx/mx-chain-communication-go v1.1.0 github.com/multiversx/mx-chain-core-go v1.2.21 github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.4 + github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 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.16 diff --git a/go.sum b/go.sum index d8ed7091831..00b1197adc8 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.21 h1:+XVKznPTlUU5EFS1A8chtS8fStW60u github.com/multiversx/mx-chain-core-go v1.2.21/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.4 h1:SjJk9G9SN8baz0sFIU2jymYCfx3XiikGEB2wW0jwvfw= -github.com/multiversx/mx-chain-es-indexer-go v1.7.4/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 h1:VJOigTM9JbjFdy9ICVhsDfM9YQkFqMigAaQCHaM0iwY= +github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= 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= From f6a7e13e2cad715cc7a44a9ca13f521469d8ca79 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 19 Aug 2024 12:17:24 +0300 Subject: [PATCH 45/99] - new VM version --- go.mod | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 315f9358f6c..85c91c1b534 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 + github.com/multiversx/mx-chain-vm-go v1.5.29-patch2 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 @@ -188,5 +188,3 @@ require ( ) replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 - -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f From 943e43bebd253a77174de531bcf64d060850395d Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 19 Aug 2024 12:20:43 +0300 Subject: [PATCH 46/99] - go mod tidy --- go.sum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index 8e75a213f52..753d3faadb1 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f h1:3XBgHHpdLNqTGRr6Muupn8g4Cu7J6/jxjQb4OpklSKo= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go v1.5.29-patch2 h1:KvTUbtGZmWNr7/b+WT0TlAiXBYtdCvDQoFp8MhWTPPo= +github.com/multiversx/mx-chain-vm-go v1.5.29-patch2/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 290d028e7aeea37da99b725533079c8771667782 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 20 Aug 2024 10:05:10 +0300 Subject: [PATCH 47/99] new VM after merge --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c6b99bc0214..28b3fde7ecd 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240820061342-7527911e28ac github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index d8ed7091831..15a316a964c 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 h1:RlHKl5enbGrleB0Aea9TinZLLymS4WvG0/xAt/iRb6E= github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e h1:BkZtPUAQ9JlATkENydCLxPZ819hjop6laZtmC7Wzqec= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e/go.mod h1:j9FBeftA/BKfn0BbndKV7bNFJAzwCnYZuebsM/sufK0= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240820061342-7527911e28ac h1:hf6BZxtkI0mhXbKnaCKYnD6vSxjLVnfhoy1b634T0TE= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240820061342-7527911e28ac/go.mod h1:j9FBeftA/BKfn0BbndKV7bNFJAzwCnYZuebsM/sufK0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From aa22dd216ed070d23e76f3dde7be08f8a69e9476 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 21 Aug 2024 13:50:20 +0300 Subject: [PATCH 48/99] new VM after merge --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d0ce340fe1e..7f65b32114a 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240820061342-7527911e28ac + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index ad104f86de3..71cb103a90f 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 h1:RlHKl5enbGrleB0Aea9TinZLLymS4WvG0/xAt/iRb6E= github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240820061342-7527911e28ac h1:hf6BZxtkI0mhXbKnaCKYnD6vSxjLVnfhoy1b634T0TE= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240820061342-7527911e28ac/go.mod h1:j9FBeftA/BKfn0BbndKV7bNFJAzwCnYZuebsM/sufK0= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69 h1:HoyZbjYuQLVHJ8UMOkoIyKLA/jq80kbb3Gbqe2AfuPM= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69/go.mod h1:j9FBeftA/BKfn0BbndKV7bNFJAzwCnYZuebsM/sufK0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From d391df9a37aff59444fe0a80b9b2f45cb2bfaf50 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Sat, 24 Aug 2024 15:35:06 +0300 Subject: [PATCH 49/99] update go mod and tests --- go.mod | 4 +- go.sum | 8 +-- .../vm/esdtImprovements_test.go | 58 ++++++++----------- .../vm/txsFee/apiTransactionEvaluator_test.go | 4 +- .../vm/txsFee/asyncCall_multi_test.go | 5 +- integrationTests/vm/txsFee/asyncESDT_test.go | 16 ++--- .../vm/txsFee/esdtLocalBurn_test.go | 2 +- .../vm/txsFee/esdtLocalMint_test.go | 2 +- .../vm/txsFee/esdtMetaDataRecreate_test.go | 6 +- .../vm/txsFee/esdtMetaDataUpdate_test.go | 6 +- .../vm/txsFee/esdtModifyCreator_test.go | 8 ++- .../vm/txsFee/esdtModifyRoyalties_test.go | 8 ++- .../vm/txsFee/esdtSetNewURIs_test.go | 8 ++- integrationTests/vm/txsFee/esdt_test.go | 8 +-- .../vm/txsFee/multiESDTTransfer_test.go | 9 +-- .../vm/txsFee/multiShard/asyncESDT_test.go | 5 +- .../txsFee/multiShard/esdtLiquidity_test.go | 6 +- .../vm/txsFee/multiShard/esdt_test.go | 6 +- .../vm/txsFee/relayedAsyncESDT_test.go | 7 ++- .../vm/txsFee/relayedESDT_test.go | 5 +- integrationTests/vm/txsFee/scCalls_test.go | 2 +- integrationTests/vm/txsFee/utils/utilsESDT.go | 5 +- 22 files changed, 107 insertions(+), 81 deletions(-) diff --git a/go.mod b/go.mod index c6b99bc0214..5f648904813 100644 --- a/go.mod +++ b/go.mod @@ -15,13 +15,13 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.21 + github.com/multiversx/mx-chain-core-go v1.2.22-0.20240823091930-22b700471ada github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.7.4 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240824090826-0159b7bb576f github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 diff --git a/go.sum b/go.sum index d8ed7091831..e6d78cf7129 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.21 h1:+XVKznPTlUU5EFS1A8chtS8fStW60upRIyF4Pgml19I= -github.com/multiversx/mx-chain-core-go v1.2.21/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.22-0.20240823091930-22b700471ada h1:Yi4gpXr/LzpLR2Soca5SNC/NRGnPCrD5FyGKShGLFpE= +github.com/multiversx/mx-chain-core-go v1.2.22-0.20240823091930-22b700471ada/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= github.com/multiversx/mx-chain-es-indexer-go v1.7.4 h1:SjJk9G9SN8baz0sFIU2jymYCfx3XiikGEB2wW0jwvfw= @@ -399,8 +399,8 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 h1:RlHKl5enbGrleB0Aea9TinZLLymS4WvG0/xAt/iRb6E= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240824090826-0159b7bb576f h1:sJupgH9e7xZCHp53COO6eWrdoTUQqaiddnhb9IzUh0A= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240824090826-0159b7bb576f/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e h1:BkZtPUAQ9JlATkENydCLxPZ819hjop6laZtmC7Wzqec= github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e/go.mod h1:j9FBeftA/BKfn0BbndKV7bNFJAzwCnYZuebsM/sufK0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 5ef014f6b65..dbb98384825 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1482,7 +1482,12 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + retrievedMetaData := &esdt.MetaData{} + if bytes.Equal(tokenIDs[i], nftTokenID) { + retrievedMetaData = getMetaDataFromAcc(t, cs, newCreatorAddress.Bytes, tokenIDs[i], shardID) + } else { + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + } require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) } @@ -1695,8 +1700,13 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) + retrievedMetaData := &esdt.MetaData{} shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(newCreatorAddress.Bytes) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + if bytes.Equal(tokenIDs[i], nftTokenID) { + retrievedMetaData = getMetaDataFromAcc(t, cs, newCreatorAddress.Bytes, tokenIDs[i], shardID) + } else { + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + } require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) @@ -2504,7 +2514,8 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) log.Info("Check that token type is Dynamic") @@ -2747,7 +2758,8 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) log.Info("Check that token type is Dynamic") @@ -3789,11 +3801,12 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { err = cs.GenerateBlocks(10) require.Nil(t, err) - log.Info("Step 1. check that the metadata for all tokens is saved on the system account") + log.Info("Step 1. check that the metadata for the Dynamic NFT is saved on the user account") shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) log.Info("Step 1b. Pause all tokens") @@ -3809,34 +3822,13 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { require.Equal(t, "", result.ReturnMessage) require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) - tx = updateTokenIDTx(nonce, addrs[0].Bytes, nftTokenID) - nonce++ - - log.Info("updating token id", "tokenID", nftTokenID) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - log.Info("change to dynamic token") - - tx = changeToDynamicTx(nonce, addrs[0].Bytes, nftTokenID) - nonce++ - - log.Info("updating token id", "tokenID", nftTokenID) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - log.Info("check that the metadata for all tokens is saved on the system account") + log.Info("check that the metadata for the Dynamic NFT is saved on the user account") err = cs.GenerateBlocks(10) require.Nil(t, err) - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) log.Info("transfering token id", "tokenID", nftTokenID) @@ -3846,16 +3838,16 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - log.Info("check that the metaData for the NFT is still on the system account") + log.Info("check that the metaData for the NFT is on the new user account") err = cs.GenerateBlocks(10) require.Nil(t, err) shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, addrs[1].Bytes, nftTokenID, shardID, nftMetaData) checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) - checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, nftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) } func TestChainSimulator_CheckRolesWhichHasToBeSingular(t *testing.T) { diff --git a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go index 8f3894aa319..4c66bf28f52 100644 --- a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go +++ b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go @@ -142,7 +142,7 @@ func TestESDTTransfer(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) tx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100), 0, 0) res, err := testContext.TxCostHandler.ComputeTransactionGasLimit(tx) @@ -170,7 +170,7 @@ func TestAsyncESDTTransfer(t *testing.T) { esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) // deploy 2 contracts ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) diff --git a/integrationTests/vm/txsFee/asyncCall_multi_test.go b/integrationTests/vm/txsFee/asyncCall_multi_test.go index 56a6dc02a26..ef14b5556a3 100644 --- a/integrationTests/vm/txsFee/asyncCall_multi_test.go +++ b/integrationTests/vm/txsFee/asyncCall_multi_test.go @@ -5,6 +5,7 @@ import ( "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/scheduled" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -276,7 +277,7 @@ func deployForwarderAndTestContract( forwarderSCAddress := utils.DoDeploySecond(t, testContext, pathToForwarder, ownerAccount, gasPrice, deployGasLimit, nil, big.NewInt(0)) - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, forwarderSCAddress, egldBalance, esdtToken, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, forwarderSCAddress, egldBalance, esdtToken, 0, esdtBalance, uint32(core.Fungible)) utils.CleanAccumulatedIntermediateTransactions(t, testContext) @@ -514,7 +515,7 @@ func transferESDTAndExecuteCrossShard(t *testing.T, numberOfCallsFromParent int, pathToContract = "testdata/forwarderQueue/forwarder-queue-promises.wasm" forwarderSCAddress := utils.DoDeploySecond(t, forwarderShard, pathToContract, forwarderOwnerAccount, gasPrice, gasLimit, nil, big.NewInt(0)) - utils.CreateAccountWithESDTBalance(t, forwarderShard.Accounts, forwarderSCAddress, egldBalance, esdtToken, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, forwarderShard.Accounts, forwarderSCAddress, egldBalance, esdtToken, 0, esdtBalance, uint32(core.Fungible)) utils.CheckESDTNFTBalance(t, forwarderShard, forwarderSCAddress, esdtToken, 0, esdtBalance) diff --git a/integrationTests/vm/txsFee/asyncESDT_test.go b/integrationTests/vm/txsFee/asyncESDT_test.go index c7c8d088fb9..32869f51ae9 100644 --- a/integrationTests/vm/txsFee/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/asyncESDT_test.go @@ -40,7 +40,7 @@ func TestAsyncESDTCallShouldWork(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance, uint32(core.Fungible)) // deploy 2 contracts ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -96,7 +96,7 @@ func TestAsyncESDTCallSecondScRefusesPayment(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance, uint32(core.Fungible)) // deploy 2 contracts ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -153,7 +153,7 @@ func TestAsyncESDTCallsOutOfGas(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance, uint32(core.Fungible)) // deploy 2 contracts ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -208,7 +208,7 @@ func TestAsyncMultiTransferOnCallback(t *testing.T) { sftBalance := big.NewInt(1000) halfBalance := big.NewInt(500) - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance, uint32(core.SemiFungible)) utils.CheckESDTNFTBalance(t, testContext, ownerAddr, sftTokenID, sftNonce, sftBalance) ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -305,7 +305,7 @@ func TestAsyncMultiTransferOnCallAndOnCallback(t *testing.T) { sftBalance := big.NewInt(1000) halfBalance := big.NewInt(500) - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance, uint32(core.SemiFungible)) utils.CheckESDTNFTBalance(t, testContext, ownerAddr, sftTokenID, sftNonce, sftBalance) ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -408,7 +408,7 @@ func TestSendNFTToContractWith0Function(t *testing.T) { sftNonce := uint64(1) sftBalance := big.NewInt(1000) - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance, uint32(core.SemiFungible)) utils.CheckESDTNFTBalance(t, testContext, ownerAddr, sftTokenID, sftNonce, sftBalance) ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -461,7 +461,7 @@ func TestSendNFTToContractWith0FunctionNonPayable(t *testing.T) { sftNonce := uint64(1) sftBalance := big.NewInt(1000) - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance, uint32(core.SemiFungible)) utils.CheckESDTNFTBalance(t, testContext, ownerAddr, sftTokenID, sftNonce, sftBalance) ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -523,7 +523,7 @@ func TestAsyncESDTCallForThirdContractShouldWork(t *testing.T) { localEsdtBalance := big.NewInt(100000000) esdtTransferValue := big.NewInt(5000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance, uint32(core.Fungible)) // deploy contract ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) diff --git a/integrationTests/vm/txsFee/esdtLocalBurn_test.go b/integrationTests/vm/txsFee/esdtLocalBurn_test.go index 681c7e293b4..77edb13d0e2 100644 --- a/integrationTests/vm/txsFee/esdtLocalBurn_test.go +++ b/integrationTests/vm/txsFee/esdtLocalBurn_test.go @@ -95,7 +95,7 @@ func TestESDTLocalBurnNotAllowedShouldErr(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(40) tx := utils.CreateESDTLocalBurnTx(0, sndAddr, sndAddr, token, big.NewInt(100), gasPrice, gasLimit) diff --git a/integrationTests/vm/txsFee/esdtLocalMint_test.go b/integrationTests/vm/txsFee/esdtLocalMint_test.go index 516402c80a4..62d7bf5decf 100644 --- a/integrationTests/vm/txsFee/esdtLocalMint_test.go +++ b/integrationTests/vm/txsFee/esdtLocalMint_test.go @@ -61,7 +61,7 @@ func TestESDTLocalMintNotAllowedShouldErr(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(40) tx := utils.CreateESDTLocalMintTx(0, sndAddr, sndAddr, token, big.NewInt(100), gasPrice, gasLimit) diff --git a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go index d5778000cbe..e2dc58caf8f 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go @@ -64,7 +64,11 @@ func runEsdtMetaDataRecreateTest(t *testing.T, tokenType string) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) + if tokenType == core.DynamicNFTESDT { + checkMetaData(t, testContext, sndAddr, key, defaultMetaData) + } else { + checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) + } } func esdtMetaDataRecreateTx( diff --git a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go index 4eba58ca178..d8fc6c7bb19 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go @@ -67,7 +67,11 @@ func runEsdtMetaDataUpdateTest(t *testing.T, tokenType string) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) + if tokenType == core.DynamicNFTESDT { + checkMetaData(t, testContext, sndAddr, key, defaultMetaData) + } else { + checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) + } } func esdtMetaDataUpdateTx( diff --git a/integrationTests/vm/txsFee/esdtModifyCreator_test.go b/integrationTests/vm/txsFee/esdtModifyCreator_test.go index 109e6e937e3..d12eb5186af 100644 --- a/integrationTests/vm/txsFee/esdtModifyCreator_test.go +++ b/integrationTests/vm/txsFee/esdtModifyCreator_test.go @@ -8,6 +8,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" dataBlock "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-core-go/data/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -69,7 +70,12 @@ func runEsdtModifyCreatorTest(t *testing.T, tokenType string) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - retrievedMetaData := getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + retrievedMetaData := &esdt.MetaData{} + if tokenType == core.DynamicNFTESDT { + retrievedMetaData = getMetaDataFromAcc(t, testContext, newCreator, key) + } else { + retrievedMetaData = getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + } require.Equal(t, newCreator, retrievedMetaData.Creator) } diff --git a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go index 9d6def6a297..151f1a62866 100644 --- a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go +++ b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go @@ -8,6 +8,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" dataBlock "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-core-go/data/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -63,7 +64,12 @@ func runEsdtModifyRoyaltiesTest(t *testing.T, tokenType string) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - retrievedMetaData := getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + retrievedMetaData := &esdt.MetaData{} + if tokenType == core.DynamicNFTESDT { + retrievedMetaData = getMetaDataFromAcc(t, testContext, creatorAddr, key) + } else { + retrievedMetaData = getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + } require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) } diff --git a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go index f97e9e0e651..7c3500cd641 100644 --- a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go +++ b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go @@ -8,6 +8,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" dataBlock "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-core-go/data/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -64,7 +65,12 @@ func runEsdtSetNewURIsTest(t *testing.T, tokenType string) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - retrievedMetaData := getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + retrievedMetaData := &esdt.MetaData{} + if tokenType == core.DynamicNFTESDT { + retrievedMetaData = getMetaDataFromAcc(t, testContext, sndAddr, key) + } else { + retrievedMetaData = getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + } require.Equal(t, [][]byte{[]byte("newUri1"), []byte("newUri2")}, retrievedMetaData.URIs) } diff --git a/integrationTests/vm/txsFee/esdt_test.go b/integrationTests/vm/txsFee/esdt_test.go index d51848762e8..54cf8b38b71 100644 --- a/integrationTests/vm/txsFee/esdt_test.go +++ b/integrationTests/vm/txsFee/esdt_test.go @@ -32,7 +32,7 @@ func TestESDTTransferShouldWork(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(40) tx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100), gasPrice, gasLimit) @@ -72,7 +72,7 @@ func TestESDTTransferShouldWorkToMuchGasShouldConsumeAllGas(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(1000) tx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100), gasPrice, gasLimit) @@ -112,7 +112,7 @@ func TestESDTTransferInvalidESDTValueShouldConsumeGas(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(1000) tx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100000000+1), gasPrice, gasLimit) @@ -156,7 +156,7 @@ func TestESDTTransferCallBackOnErrorShouldNotGenerateSCRsFurther(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) hexEncodedToken := hex.EncodeToString(token) esdtValueEncoded := hex.EncodeToString(big.NewInt(100).Bytes()) diff --git a/integrationTests/vm/txsFee/multiESDTTransfer_test.go b/integrationTests/vm/txsFee/multiESDTTransfer_test.go index adaf89ad340..b9a4474cf34 100644 --- a/integrationTests/vm/txsFee/multiESDTTransfer_test.go +++ b/integrationTests/vm/txsFee/multiESDTTransfer_test.go @@ -4,6 +4,7 @@ import ( "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -29,9 +30,9 @@ func TestMultiESDTTransferShouldWork(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) secondToken := []byte("second") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), secondToken, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), secondToken, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(4000) tx := utils.CreateMultiTransferTX(0, sndAddr, rcvAddr, gasPrice, gasLimit, &utils.TransferESDTData{ @@ -90,9 +91,9 @@ func TestMultiESDTTransferFailsBecauseOfMaxLimit(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) secondToken := []byte("second") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), secondToken, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), secondToken, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(4000) tx := utils.CreateMultiTransferTX(0, sndAddr, rcvAddr, gasPrice, gasLimit, &utils.TransferESDTData{ diff --git a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go index aa37bc6bf94..5ea878f2b26 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go @@ -5,6 +5,7 @@ import ( "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -46,7 +47,7 @@ func TestAsyncESDTTransferWithSCCallShouldWork(t *testing.T) { token := []byte("miiutoken") egldBalance := big.NewInt(10000000) esdtBalance := big.NewInt(10000000) - utils.CreateAccountWithESDTBalance(t, testContextSender.Accounts, senderAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContextSender.Accounts, senderAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) // create accounts for owners _, _ = vm.CreateAccount(testContextFirstContract.Accounts, firstContractOwner, 0, egldBalance) @@ -162,7 +163,7 @@ func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) { token := []byte("miiutoken") egldBalance := big.NewInt(10000000) esdtBalance := big.NewInt(10000000) - utils.CreateAccountWithESDTBalance(t, testContextSender.Accounts, senderAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContextSender.Accounts, senderAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) // create accounts for owners _, _ = vm.CreateAccount(testContextFirstContract.Accounts, firstContractOwner, 0, egldBalance) diff --git a/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go b/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go index 6d2fe8cfa00..3e863713571 100644 --- a/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go +++ b/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go @@ -35,7 +35,7 @@ func TestSystemAccountLiquidityAfterCrossShardTransferAndBurn(t *testing.T) { _, _ = vm.CreateAccount(sh1Context.Accounts, sh1Addr, 0, big.NewInt(1000000000)) // create the nft and ensure that it exists on the account's trie and the liquidity is set on the system account - utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID, 1, big.NewInt(1)) + utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID, 1, big.NewInt(1), uint32(core.NonFungible)) utils.CheckESDTNFTBalance(t, sh0Context, sh0Addr, tokenID, 1, big.NewInt(1)) utils.CheckESDTNFTBalance(t, sh0Context, core.SystemAccountAddress, tokenID, 1, big.NewInt(1)) @@ -86,7 +86,7 @@ func TestSystemAccountLiquidityAfterNFTWipe(t *testing.T) { defer metaContext.Close() // create the nft and ensure that it exists on the account's trie and the liquidity is set on the system account - utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(10000000000000), tokenID, 1, big.NewInt(1)) + utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(10000000000000), tokenID, 1, big.NewInt(1), uint32(core.NonFungible)) utils.CheckESDTNFTBalance(t, sh0Context, sh0Addr, tokenID, 1, big.NewInt(1)) utils.CheckESDTNFTBalance(t, sh0Context, core.SystemAccountAddress, tokenID, 1, big.NewInt(1)) @@ -136,7 +136,7 @@ func TestSystemAccountLiquidityAfterSFTWipe(t *testing.T) { defer metaContext.Close() // create the nft and ensure that it exists on the account's trie and the liquidity is set on the system account - utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(10000000000000), tokenID, 1, big.NewInt(10)) + utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(10000000000000), tokenID, 1, big.NewInt(10), uint32(core.SemiFungible)) utils.CheckESDTNFTBalance(t, sh0Context, sh0Addr, tokenID, 1, big.NewInt(10)) utils.CheckESDTNFTBalance(t, sh0Context, core.SystemAccountAddress, tokenID, 1, big.NewInt(10)) diff --git a/integrationTests/vm/txsFee/multiShard/esdt_test.go b/integrationTests/vm/txsFee/multiShard/esdt_test.go index 9dd828eb8c1..2e37f2c9948 100644 --- a/integrationTests/vm/txsFee/multiShard/esdt_test.go +++ b/integrationTests/vm/txsFee/multiShard/esdt_test.go @@ -33,7 +33,7 @@ func TestESDTTransferShouldWork(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasPrice := uint64(10) gasLimit := uint64(40) @@ -73,8 +73,8 @@ func TestMultiESDTNFTTransferViaRelayedV2(t *testing.T) { _, _ = vm.CreateAccount(sh1Context.Accounts, relayerSh1, 0, big.NewInt(1000000000)) // create the nfts, add the liquidity to the system accounts and check for balances - utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID1, 1, big.NewInt(1)) - utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID2, 1, big.NewInt(1)) + utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID1, 1, big.NewInt(1), uint32(core.NonFungible)) + utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID2, 1, big.NewInt(1), uint32(core.NonFungible)) sh0Accnt, _ := sh0Context.Accounts.LoadAccount(sh0Addr) sh1Accnt, _ := sh1Context.Accounts.LoadAccount(sh1Addr) diff --git a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go index bb8b05606a7..9958dc2e6b2 100644 --- a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go +++ b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go @@ -5,6 +5,7 @@ import ( "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -34,7 +35,7 @@ func TestRelayedAsyncESDTCallShouldWork(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance, uint32(core.Fungible)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, localEgldBalance) // deploy 2 contracts @@ -96,7 +97,7 @@ func TestRelayedAsyncESDTCall_InvalidCallFirstContract(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance, uint32(core.Fungible)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, localEgldBalance) // deploy 2 contracts @@ -158,7 +159,7 @@ func TestRelayedAsyncESDTCall_InvalidOutOfGas(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance, uint32(core.Fungible)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, localEgldBalance) // deploy 2 contracts diff --git a/integrationTests/vm/txsFee/relayedESDT_test.go b/integrationTests/vm/txsFee/relayedESDT_test.go index 55a7e1bde04..ffe9597f943 100644 --- a/integrationTests/vm/txsFee/relayedESDT_test.go +++ b/integrationTests/vm/txsFee/relayedESDT_test.go @@ -4,6 +4,7 @@ import ( "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -40,7 +41,7 @@ func testRelayedESDTTransferShouldWork( relayerBalance := big.NewInt(10000000) localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance, uint32(core.Fungible)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, relayerBalance) gasLimit := uint64(40) @@ -102,7 +103,7 @@ func testRelayedESTTransferNotEnoughESTValueShouldConsumeGas( relayerBalance := big.NewInt(10000000) localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance, uint32(core.Fungible)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, relayerBalance) gasLimit := uint64(42) diff --git a/integrationTests/vm/txsFee/scCalls_test.go b/integrationTests/vm/txsFee/scCalls_test.go index c17474eb9e3..c98d0960b66 100644 --- a/integrationTests/vm/txsFee/scCalls_test.go +++ b/integrationTests/vm/txsFee/scCalls_test.go @@ -352,7 +352,7 @@ func TestESDTScCallAndGasChangeShouldWork(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, senderBalance, token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, senderBalance, token, 0, localEsdtBalance, uint32(core.Fungible)) txData := txDataBuilder.NewBuilder() valueToSendToSc := int64(1000) diff --git a/integrationTests/vm/txsFee/utils/utilsESDT.go b/integrationTests/vm/txsFee/utils/utilsESDT.go index 68fe255a1ba..99428ecfcf7 100644 --- a/integrationTests/vm/txsFee/utils/utilsESDT.go +++ b/integrationTests/vm/txsFee/utils/utilsESDT.go @@ -27,6 +27,7 @@ func CreateAccountWithESDTBalance( tokenIdentifier []byte, esdtNonce uint64, esdtValue *big.Int, + esdtType uint32, ) { account, err := accnts.LoadAccount(pubKey) require.Nil(t, err) @@ -39,6 +40,7 @@ func CreateAccountWithESDTBalance( require.Nil(t, err) esdtData := &esdt.ESDigitalToken{ + Type: esdtType, Value: esdtValue, Properties: []byte{}, } @@ -92,6 +94,7 @@ func CreateAccountWithNFT( require.Nil(t, err) esdtData := &esdt.ESDigitalToken{ + Type: uint32(core.NonFungible), Value: big.NewInt(1), Properties: []byte{}, TokenMetaData: &esdt.MetaData{ @@ -152,7 +155,7 @@ func CreateAccountWithESDTBalanceAndRoles( esdtValue *big.Int, roles [][]byte, ) { - CreateAccountWithESDTBalance(t, accnts, pubKey, egldValue, tokenIdentifier, esdtNonce, esdtValue) + CreateAccountWithESDTBalance(t, accnts, pubKey, egldValue, tokenIdentifier, esdtNonce, esdtValue, uint32(core.Fungible)) SetESDTRoles(t, accnts, pubKey, tokenIdentifier, roles) } From fc4edd1e1ad678d7a1e77eb7ab9698586877da06 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Sat, 24 Aug 2024 16:05:13 +0300 Subject: [PATCH 50/99] update stub --- testscommon/esdtStorageHandlerStub.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testscommon/esdtStorageHandlerStub.go b/testscommon/esdtStorageHandlerStub.go index b6ff81f2b00..599197e7fca 100644 --- a/testscommon/esdtStorageHandlerStub.go +++ b/testscommon/esdtStorageHandlerStub.go @@ -10,7 +10,7 @@ import ( // EsdtStorageHandlerStub - type EsdtStorageHandlerStub struct { - SaveESDTNFTTokenCalled func(senderAddress []byte, acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken, isCreation bool, isReturnWithError bool) ([]byte, error) + SaveESDTNFTTokenCalled func(senderAddress []byte, acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken, saveArgs vmcommon.NftSaveArgs) ([]byte, error) GetESDTNFTTokenOnSenderCalled func(acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64) (*esdt.ESDigitalToken, error) GetESDTNFTTokenOnDestinationCalled func(acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64) (*esdt.ESDigitalToken, bool, error) GetESDTNFTTokenOnDestinationWithCustomSystemAccountCalled func(accnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, systemAccount vmcommon.UserAccountHandler) (*esdt.ESDigitalToken, bool, error) @@ -40,9 +40,9 @@ func (e *EsdtStorageHandlerStub) GetMetaDataFromSystemAccount(bytes []byte, u ui } // SaveESDTNFTToken - -func (e *EsdtStorageHandlerStub) SaveESDTNFTToken(senderAddress []byte, acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken, isCreation bool, isReturnWithError bool) ([]byte, error) { +func (e *EsdtStorageHandlerStub) SaveESDTNFTToken(senderAddress []byte, acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken, saveArgs vmcommon.NftSaveArgs) ([]byte, error) { if e.SaveESDTNFTTokenCalled != nil { - return e.SaveESDTNFTTokenCalled(senderAddress, acnt, esdtTokenKey, nonce, esdtData, isCreation, isReturnWithError) + return e.SaveESDTNFTTokenCalled(senderAddress, acnt, esdtTokenKey, nonce, esdtData, saveArgs) } return nil, nil From aa637404027f90235b07253691372c9cad644c63 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Mon, 26 Aug 2024 15:07:12 +0300 Subject: [PATCH 51/99] Removed the pull request trigger from the workflow --- .github/workflows/docker-keygenerator.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/docker-keygenerator.yaml b/.github/workflows/docker-keygenerator.yaml index 5e4d9d44a32..c3cca7fc279 100644 --- a/.github/workflows/docker-keygenerator.yaml +++ b/.github/workflows/docker-keygenerator.yaml @@ -2,7 +2,6 @@ name: Build & push keygenerator docker image on: workflow_dispatch: - pull_request: jobs: build-docker-image: @@ -19,7 +18,6 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log into Docker Hub - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -32,5 +30,5 @@ jobs: context: . file: ./docker/keygenerator/Dockerfile platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} + push: true tags: multiversx/chain-keygenerator:latest From 667579e0717c2baae02923e0bad2384c6082e7b8 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 27 Aug 2024 12:20:48 +0300 Subject: [PATCH 52/99] update go mod --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index df04b5af702..603e813c8d4 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240824090826-0159b7bb576f - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240827070828-a7bb8c51a98e + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 890d5c75e54..2eb4ea81617 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240824090826-0159b7bb576f h1:sJupgH9e7xZCHp53COO6eWrdoTUQqaiddnhb9IzUh0A= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240824090826-0159b7bb576f/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69 h1:HoyZbjYuQLVHJ8UMOkoIyKLA/jq80kbb3Gbqe2AfuPM= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69/go.mod h1:j9FBeftA/BKfn0BbndKV7bNFJAzwCnYZuebsM/sufK0= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240827070828-a7bb8c51a98e h1:bM3ftf0/bgyeNs7vEWwXJU/4pIzJ39144jT3v9sDnNQ= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240827070828-a7bb8c51a98e/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191 h1:yTooD6GHLgOlBK74X4u7okJ2qeGAnCo5TrAoyH+PiVY= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191/go.mod h1:v14k+Xd4Rj+wjfU4b6F25SzwqLsU7DiRN/BfQV4qwVU= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From b4b7a2ad38cc62cb385d04fc548ecbcc5aa9ddc0 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Thu, 29 Aug 2024 21:37:36 +0300 Subject: [PATCH 53/99] update go mod --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 603e813c8d4..6568d791977 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240827070828-a7bb8c51a98e - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240829181448-2a52a6d5eb74 + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 2eb4ea81617..de47f0ae1eb 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240827070828-a7bb8c51a98e h1:bM3ftf0/bgyeNs7vEWwXJU/4pIzJ39144jT3v9sDnNQ= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240827070828-a7bb8c51a98e/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191 h1:yTooD6GHLgOlBK74X4u7okJ2qeGAnCo5TrAoyH+PiVY= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191/go.mod h1:v14k+Xd4Rj+wjfU4b6F25SzwqLsU7DiRN/BfQV4qwVU= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240829181448-2a52a6d5eb74 h1:AJWrr+AuSjjHzDFEAWIlkJXL/k/QTN5t+3fbKxbA5iI= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240829181448-2a52a6d5eb74/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c h1:789cSBvz2KNSch5N9QrxZ/1NmWDabMjib46DrymNNDU= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c/go.mod h1:kBt/qUp0G53AvLb3K0OxD5pNHOZuFrzHclF5uLPV9lE= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From dd9dcaf48436b5efd76a37b720eb6f8c96742029 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 30 Aug 2024 13:27:58 +0300 Subject: [PATCH 54/99] update go mod --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 6568d791977..e11bd4e7eb9 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240829181448-2a52a6d5eb74 - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240830102128-33dd73d11361 + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index de47f0ae1eb..a48b6f2e508 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240829181448-2a52a6d5eb74 h1:AJWrr+AuSjjHzDFEAWIlkJXL/k/QTN5t+3fbKxbA5iI= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240829181448-2a52a6d5eb74/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c h1:789cSBvz2KNSch5N9QrxZ/1NmWDabMjib46DrymNNDU= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c/go.mod h1:kBt/qUp0G53AvLb3K0OxD5pNHOZuFrzHclF5uLPV9lE= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240830102128-33dd73d11361 h1:N1CxdRfh+7S0Yywtl3N8LmQDE3ff7wutV58hZvfdnyQ= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240830102128-33dd73d11361/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690 h1:rdTYzHlQY4BCru5/hBn5cobNiUwyoCwmxpjNOFUC17k= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690/go.mod h1:up5NULwRXIPld30uaU1IQulTzW9Bew/L1LTcKBTN8Zc= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From 5934073cbc60080245b32d36e77942ee48561704 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 30 Aug 2024 14:42:51 +0300 Subject: [PATCH 55/99] fixed missing scrs when multiple inner tx fail with the same error, caused by hash collision --- .../relayedTx/relayedTx_test.go | 86 +++++++++++++++++++ process/transaction/export_test.go | 11 ++- process/transaction/shardProcess.go | 45 +++++++--- 3 files changed, 127 insertions(+), 15 deletions(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 97a815549c3..fa2b02b9fe3 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -155,6 +155,92 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. require.True(t, strings.Contains(string(result.Logs.Events[2].Data), "contract is paused")) } +func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorAndInvalidNonces(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + cs := startChainSimulator(t, alterConfigsFuncRelayedV3EarlyActivation) + defer cs.Close() + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(30000)) + relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + receiver, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) + require.NoError(t, err) + + err = cs.GenerateBlocks(1) + require.Nil(t, err) + + // bump sender nonce to 3 + tx0 := generateTransaction(sender.Bytes, 0, sender.Bytes, big.NewInt(0), "", minGasLimit) + tx1 := generateTransaction(sender.Bytes, 1, sender.Bytes, big.NewInt(0), "", minGasLimit) + tx2 := generateTransaction(sender.Bytes, 2, sender.Bytes, big.NewInt(0), "", minGasLimit) + _, err = cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1, tx2}, maxNumOfBlocksToGenerateWhenExecutingTx) + require.Nil(t, err) + + // higher nonce + innerTx1 := generateTransaction(sender.Bytes, 10, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx1.RelayerAddr = relayer.Bytes + + // higher nonce + innerTx2 := generateTransaction(sender.Bytes, 9, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx2.RelayerAddr = relayer.Bytes + + // nonce ok + innerTx3 := generateTransaction(sender.Bytes, 3, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx3.RelayerAddr = relayer.Bytes + + // higher nonce + innerTx4 := generateTransaction(sender.Bytes, 8, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx4.RelayerAddr = relayer.Bytes + + // lower nonce - initial one + innerTx5 := generateTransaction(sender.Bytes, 3, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx5.RelayerAddr = relayer.Bytes + + innerTxs := []*transaction.Transaction{innerTx1, innerTx2, innerTx3, innerTx4, innerTx5} + + // relayer will consume first a move balance for each inner tx, then the specific gas for each inner tx + relayedTxGasLimit := uint64(0) + for _, tx := range innerTxs { + relayedTxGasLimit += minGasLimit + tx.GasLimit + } + relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) + relayedTx.InnerTransactions = innerTxs + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + // 5 scrs, 4 from the failed txs + 1 with success + require.Equal(t, 5, len(result.SmartContractResults)) + scrsMap := make(map[string]int, len(result.SmartContractResults)) + for _, scr := range result.SmartContractResults { + if len(scr.ReturnMessage) == 0 { + scrsMap["success"]++ + } + if strings.Contains(scr.ReturnMessage, process.ErrHigherNonceInTransaction.Error()) { + scrsMap[process.ErrHigherNonceInTransaction.Error()]++ + } + if strings.Contains(scr.ReturnMessage, process.ErrLowerNonceInTransaction.Error()) { + scrsMap[process.ErrLowerNonceInTransaction.Error()]++ + } + } + require.Equal(t, 1, scrsMap["success"]) + require.Equal(t, 3, scrsMap[process.ErrHigherNonceInTransaction.Error()]) + require.Equal(t, 1, scrsMap[process.ErrLowerNonceInTransaction.Error()]) + + // 4 log events from the failed txs + require.Equal(t, 4, len(result.Logs.Events)) + for _, event := range result.Logs.Events { + require.Equal(t, core.SignalErrorOperation, event.Identifier) + } +} + func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") diff --git a/process/transaction/export_test.go b/process/transaction/export_test.go index 07ed7a91896..ef23d5c114f 100644 --- a/process/transaction/export_test.go +++ b/process/transaction/export_test.go @@ -57,7 +57,13 @@ func (txProc *txProcessor) ProcessUserTx( relayedNonce uint64, originalTxHash []byte, ) (vmcommon.ReturnCode, error) { - return txProc.processUserTx(originalTx, userTx, relayedTxValue, relayedNonce, originalTxHash) + return txProc.processUserTx( + originalTx, + userTx, + relayedTxValue, + relayedNonce, + originalTxHash, + nonRelayedV3UserTxIdx) } // ProcessMoveBalanceCostRelayedUserTx calls the un-exported method processMoveBalanceCostRelayedUserTx @@ -87,7 +93,8 @@ func (txProc *txProcessor) ExecuteFailedRelayedTransaction( relayedNonce, originalTx, originalTxHash, - errorMsg) + errorMsg, + nonRelayedV3UserTxIdx) } // CheckMaxGasPrice calls the un-exported method checkMaxGasPrice diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 50fa0c94d21..6d2fbeb80f3 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -31,6 +31,8 @@ var _ process.TransactionProcessor = (*txProcessor)(nil) // for move balance transactions that provide more gas than needed const RefundGasMessage = "refundedGas" +const nonRelayedV3UserTxIdx = -1 + type relayedFees struct { totalFee, remainingFee, relayerFee *big.Int } @@ -647,12 +649,13 @@ func (txProc *txProcessor) finishExecutionOfRelayedTx( tx.Nonce, tx, originalTxHash, - err.Error()) + err.Error(), + nonRelayedV3UserTxIdx) } defer txProc.saveFailedLogsIfNeeded(originalTxHash) - return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce, originalTxHash) + return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce, originalTxHash, nonRelayedV3UserTxIdx) } func (txProc *txProcessor) processTxAtRelayer( @@ -743,8 +746,8 @@ func (txProc *txProcessor) processRelayedTxV3( var innerTxFee *big.Int innerTxsTotalFees := big.NewInt(0) executedUserTxs := make([]*transaction.Transaction, 0) - for _, innerTx := range innerTxs { - innerTxFee, innerTxRetCode, innerTxErr = txProc.processInnerTx(tx, innerTx, originalTxHash) + for innerTxIdx, innerTx := range innerTxs { + innerTxFee, innerTxRetCode, innerTxErr = txProc.processInnerTx(tx, innerTx, originalTxHash, innerTxIdx) innerTxsTotalFees.Add(innerTxsTotalFees, innerTxFee) if innerTxErr != nil || innerTxRetCode != vmcommon.Ok { continue @@ -781,6 +784,7 @@ func (txProc *txProcessor) processInnerTx( tx *transaction.Transaction, innerTx *transaction.Transaction, originalTxHash []byte, + innerTxIdx int, ) (*big.Int, vmcommon.ReturnCode, error) { txFee := txProc.computeInnerTxFee(innerTx) @@ -794,7 +798,8 @@ func (txProc *txProcessor) processInnerTx( tx.Nonce, tx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } if check.IfNil(acntSnd) { @@ -805,7 +810,8 @@ func (txProc *txProcessor) processInnerTx( tx.Nonce, tx, originalTxHash, - process.ErrRelayedTxV3SenderShardMismatch.Error()) + process.ErrRelayedTxV3SenderShardMismatch.Error(), + innerTxIdx) } // TODO: remove adding and then removing the fee at the sender @@ -818,10 +824,11 @@ func (txProc *txProcessor) processInnerTx( tx.Nonce, tx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } - result, err := txProc.processUserTx(tx, innerTx, tx.Value, tx.Nonce, originalTxHash) + result, err := txProc.processUserTx(tx, innerTx, tx.Value, tx.Nonce, originalTxHash, innerTxIdx) return txFee, result, err } @@ -1002,6 +1009,7 @@ func (txProc *txProcessor) processUserTx( relayedTxValue *big.Int, relayedNonce uint64, originalTxHash []byte, + innerTxIdx int, ) (vmcommon.ReturnCode, error) { relayerAdr := originalTx.SndAddr @@ -1018,7 +1026,8 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) @@ -1035,7 +1044,8 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } scrFromTx, err := txProc.makeSCRFromUserTx(userTx, relayerAdr, relayedTxValue, originalTxHash) @@ -1085,7 +1095,8 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } if errors.Is(err, process.ErrInvalidMetaTransaction) || errors.Is(err, process.ErrAccountNotPayable) { @@ -1096,7 +1107,8 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } if errors.Is(err, process.ErrFailedTransaction) { @@ -1174,7 +1186,14 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( originalTx *transaction.Transaction, originalTxHash []byte, errorMsg string, + innerTxIdx int, ) error { + + returnMessage := []byte(errorMsg) + isUserTxOfRelayedV3 := innerTxIdx != nonRelayedV3UserTxIdx + if isUserTxOfRelayedV3 { + returnMessage = []byte(fmt.Sprintf("%s while executing inner tx at index %d", errorMsg, innerTxIdx)) + } scrForRelayer := &smartContractResult.SmartContractResult{ Nonce: relayedNonce, Value: big.NewInt(0).Set(relayedTxValue), @@ -1182,7 +1201,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( SndAddr: userTx.SndAddr, PrevTxHash: originalTxHash, OriginalTxHash: originalTxHash, - ReturnMessage: []byte(errorMsg), + ReturnMessage: returnMessage, } relayerAcnt, err := txProc.getAccountFromAddress(relayerAdr) From 814e4934d227658e58e679cfedecacfe8c2b1227 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 3 Sep 2024 11:18:27 +0300 Subject: [PATCH 56/99] fix docker annotations --- docker/keygenerator/Dockerfile | 2 +- docker/node/Dockerfile | 2 +- docker/seednode/Dockerfile | 2 +- docker/termui/Dockerfile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/keygenerator/Dockerfile b/docker/keygenerator/Dockerfile index a73d7951d42..574f9ea15e5 100644 --- a/docker/keygenerator/Dockerfile +++ b/docker/keygenerator/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.7 as builder +FROM golang:1.20.7 AS builder RUN apt-get update && apt-get install -y WORKDIR /go/mx-chain-go diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile index 2a341a8409b..205733030c1 100644 --- a/docker/node/Dockerfile +++ b/docker/node/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.7 as builder +FROM golang:1.20.7 AS builder RUN apt-get update && apt-get upgrade -y WORKDIR /go/mx-chain-go diff --git a/docker/seednode/Dockerfile b/docker/seednode/Dockerfile index 74cc250c047..0a88e94e2c0 100644 --- a/docker/seednode/Dockerfile +++ b/docker/seednode/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.7 as builder +FROM golang:1.20.7 AS builder RUN apt-get update && apt-get install -y WORKDIR /go/mx-chain-go diff --git a/docker/termui/Dockerfile b/docker/termui/Dockerfile index e22986033eb..22b053b64d4 100644 --- a/docker/termui/Dockerfile +++ b/docker/termui/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.7 as builder +FROM golang:1.20.7 AS builder RUN apt-get update && apt-get install -y WORKDIR /go/mx-chain-go COPY . . From e4a09c614abd96b7e1d0705a65fed058aa51b7b8 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 3 Sep 2024 14:25:32 +0300 Subject: [PATCH 57/99] add testing scenarios and update go mod --- go.mod | 4 +- go.sum | 8 +- .../vm/egldMultiTransfer_test.go | 10 +- .../vm/esdtImprovements_test.go | 597 ++++++++++++++---- .../chainSimulator/vm/esdtTokens_test.go | 4 +- 5 files changed, 503 insertions(+), 120 deletions(-) diff --git a/go.mod b/go.mod index e11bd4e7eb9..92a18248de8 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240830102128-33dd73d11361 - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240903110629-ee357f94b63c + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index a48b6f2e508..21ac2f73c29 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240830102128-33dd73d11361 h1:N1CxdRfh+7S0Yywtl3N8LmQDE3ff7wutV58hZvfdnyQ= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240830102128-33dd73d11361/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690 h1:rdTYzHlQY4BCru5/hBn5cobNiUwyoCwmxpjNOFUC17k= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690/go.mod h1:up5NULwRXIPld30uaU1IQulTzW9Bew/L1LTcKBTN8Zc= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240903110629-ee357f94b63c h1:VLAdXl0NsnMWBuJZUJPxK8qK1AKyEzqSoQ7I8NOj0t4= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240903110629-ee357f94b63c/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d h1:TSObh+pVpKdjBb0eyLHjBRULIZU+v6voSJd2CNprllg= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d/go.mod h1:2x0I5wbWgrVKj7zeVSWITWqdnqmAiuBfsAdrdbAViQE= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 10a10cee5ad..5e9d641f90a 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -141,7 +141,7 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -275,7 +275,7 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -397,7 +397,7 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -519,7 +519,7 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -732,7 +732,7 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index dbb98384825..b1b09764573 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -219,7 +219,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -599,19 +599,20 @@ func updateTokenIDTx(nonce uint64, sndAdr []byte, tokenID []byte) *transaction.T } } -func nftCreateTx( +func esdtNftCreateTx( nonce uint64, sndAdr []byte, tokenID []byte, metaData *txsFee.MetaData, + quantity int64, ) *transaction.Transaction { txDataField := bytes.Join( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity + []byte(hex.EncodeToString(big.NewInt(quantity).Bytes())), // quantity metaData.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + metaData.Royalties, metaData.Hash, metaData.Attributes, metaData.Uris[0], @@ -853,7 +854,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -992,7 +993,7 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1194,7 +1195,7 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1236,35 +1237,7 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) newMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTMetaDataUpdate), - []byte(hex.EncodeToString(tokenIDs[i])), - newMetaData.Nonce, - newMetaData.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - newMetaData.Hash, - newMetaData.Attributes, - newMetaData.Uris[0], - newMetaData.Uris[1], - newMetaData.Uris[2], - }, - []byte("@"), - ) - - tx = &transaction.Transaction{ - Nonce: nonce, - SndAddr: addrs[0].Bytes, - RcvAddr: addrs[0].Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } - + tx = esdtMetaDataUpdateTx(tokenIDs[i], newMetaData, nonce, addrs[0].Bytes) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -1422,7 +1395,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1623,7 +1596,7 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1823,7 +1796,7 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2025,7 +1998,7 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2180,7 +2153,7 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[1].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[1].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -2286,34 +2259,7 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { metaData := txsFee.GetDefaultMetaData() metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - txDataField := bytes.Join( - [][]byte{ - []byte(core.BuiltInFunctionESDTNFTCreate), - []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(2).Bytes())), // quantity - metaData.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - metaData.Hash, - metaData.Attributes, - metaData.Uris[0], - metaData.Uris[1], - metaData.Uris[2], - }, - []byte("@"), - ) - - tx = &transaction.Transaction{ - Nonce: nonce, - SndAddr: addrs[1].Bytes, - RcvAddr: addrs[1].Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + tx = esdtNftCreateTx(nonce, addrs[1].Bytes, tokenID, metaData, 2) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -2374,35 +2320,7 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { sftMetaData2.Hash = []byte(hex.EncodeToString([]byte("hash2"))) sftMetaData2.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) - txDataField = bytes.Join( - [][]byte{ - []byte(core.ESDTMetaDataUpdate), - []byte(hex.EncodeToString(tokenID)), - sftMetaData2.Nonce, - sftMetaData2.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - sftMetaData2.Hash, - sftMetaData2.Attributes, - sftMetaData2.Uris[0], - sftMetaData2.Uris[1], - sftMetaData2.Uris[2], - }, - []byte("@"), - ) - - tx = &transaction.Transaction{ - Nonce: 0, - SndAddr: addrs[0].Bytes, - RcvAddr: addrs[0].Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } - + tx = esdtMetaDataUpdateTx(tokenID, sftMetaData2, 0, addrs[0].Bytes) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -2438,6 +2356,8 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { log.Info("Step 5. check meta data in shard 2 is updated to latest version ") checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shard2ID, sftMetaData2) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData2) + } func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { @@ -2501,7 +2421,7 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2598,7 +2518,7 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2745,7 +2665,7 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2866,7 +2786,7 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, sftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, sftTokenID, nftMetaData, 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3041,7 +2961,7 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, metaTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, metaTokenID, nftMetaData, 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3310,7 +3230,7 @@ func createTokenUpdateTokenIDAndTransfer( } setAddressEsdtRoles(t, cs, 1, walletWithRoles, tokenID, roles) - tx := nftCreateTx(2, originAddress, tokenID, metaData) + tx := esdtNftCreateTx(2, originAddress, tokenID, metaData, 1) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3435,7 +3355,7 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3608,7 +3528,7 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -3790,7 +3710,7 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -3934,3 +3854,466 @@ func TestChainSimulator_CheckRolesWhichHasToBeSingular(t *testing.T) { } } } + +func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) { + t.Parallel() + + baseIssuingCost := "1000" + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + log.Info("Register dynamic metaESDT token") + + metaTicker := []byte("METATICKER") + metaTokenName := []byte("tokenName") + + decimals := big.NewInt(15) + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(metaTokenName)), + []byte(hex.EncodeToString(metaTicker)), + []byte(hex.EncodeToString([]byte("META"))), + []byte(hex.EncodeToString(decimals.Bytes())), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + shard0Nonce := uint64(0) + tx := &transaction.Transaction{ + Nonce: shard0Nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + shard0Nonce++ + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + tokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTAddQuantity), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, shard0Nonce, addrs[0], tokenID, roles) + shard0Nonce++ + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 2) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, metaData) + + log.Info("send metaEsdt cross shard") + + tx = esdtNFTTransferTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("update metaData on shard 0") + + newMetaData := &txsFee.MetaData{} + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData, shard0Nonce, addrs[0].Bytes) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + expectedMetaData := txsFee.GetDefaultMetaData() + expectedMetaData.Nonce = newMetaData.Nonce + expectedMetaData.Name = newMetaData.Name + expectedMetaData.Hash = newMetaData.Hash + expectedMetaData.Attributes = newMetaData.Attributes + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, metaData) + + log.Info("send the update role to shard 2") + + shard0Nonce = transferSpecialRoleToAddr(t, cs, shard0Nonce, tokenID, addrs[0].Bytes, addrs[2].Bytes, []byte(core.ESDTRoleNFTUpdate)) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("update metaData on shard 2") + + newMetaData2 := &txsFee.MetaData{} + newMetaData2.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData2.Uris = [][]byte{[]byte(hex.EncodeToString([]byte("uri5"))), []byte(hex.EncodeToString([]byte("uri6"))), []byte(hex.EncodeToString([]byte("uri7")))} + newMetaData2.Royalties = []byte(hex.EncodeToString(big.NewInt(15).Bytes())) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData2, 0, addrs[2].Bytes) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, metaData) + + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, 2) + require.Equal(t, uint64(0), retrievedMetaData.Nonce) + require.Equal(t, 0, len(retrievedMetaData.Name)) + require.Equal(t, addrs[2].Bytes, retrievedMetaData.Creator) + require.Equal(t, newMetaData2.Royalties, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Royalties)).Bytes()))) + require.Equal(t, 0, len(retrievedMetaData.Hash)) + require.Equal(t, 3, len(retrievedMetaData.URIs)) + for i, uri := range newMetaData2.Uris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, 0, len(retrievedMetaData.Attributes)) + + log.Info("transfer from shard 0 to shard 1 - should merge metaData") + + tx = esdtNFTTransferTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + + log.Info("transfer from shard 1 to shard 2 - should merge metaData") + + tx = setSpecialRoleTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID, [][]byte{[]byte(core.ESDTRoleTransfer)}) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + shard0Nonce++ + + tx = esdtNFTTransferTx(0, addrs[1].Bytes, addrs[2].Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + + latestMetaData := txsFee.GetDefaultMetaData() + latestMetaData.Nonce = expectedMetaData.Nonce + latestMetaData.Name = expectedMetaData.Name + latestMetaData.Royalties = newMetaData2.Royalties + latestMetaData.Hash = expectedMetaData.Hash + latestMetaData.Attributes = expectedMetaData.Attributes + latestMetaData.Uris = newMetaData2.Uris + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 2, latestMetaData) + + log.Info("transfer from shard 2 to shard 0 - should update metaData") + + tx = setSpecialRoleTx(shard0Nonce, addrs[0].Bytes, addrs[2].Bytes, tokenID, [][]byte{[]byte(core.ESDTRoleTransfer)}) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + shard0Nonce++ + + tx = esdtNFTTransferTx(1, addrs[2].Bytes, addrs[0].Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, latestMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 2, latestMetaData) +} + +func unsetSpecialRole( + nonce uint64, + sndAddr []byte, + address []byte, + token []byte, + role []byte, +) *transaction.Transaction { + txDataBytes := [][]byte{ + []byte("unSetSpecialRole"), + []byte(hex.EncodeToString(token)), + []byte(hex.EncodeToString(address)), + []byte(hex.EncodeToString(role)), + } + + txDataField := bytes.Join( + txDataBytes, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: nonce, + SndAddr: sndAddr, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 60_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } +} + +func esdtMetaDataUpdateTx(tokenID []byte, metaData *txsFee.MetaData, nonce uint64, address []byte) *transaction.Transaction { + txData := [][]byte{ + []byte(core.ESDTMetaDataUpdate), + []byte(hex.EncodeToString(tokenID)), + metaData.Nonce, + metaData.Name, + metaData.Royalties, + metaData.Hash, + metaData.Attributes, + } + if len(metaData.Uris) > 0 { + for _, uri := range metaData.Uris { + txData = append(txData, uri) + } + } else { + txData = append(txData, nil) + } + + txDataField := bytes.Join( + txData, + []byte("@"), + ) + + tx := &transaction.Transaction{ + Nonce: nonce, + SndAddr: address, + RcvAddr: address, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + return tx +} + +func transferSpecialRoleToAddr( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + nonce uint64, + tokenID []byte, + sndAddr []byte, + dstAddr []byte, + role []byte, +) uint64 { + tx := unsetSpecialRole(nonce, sndAddr, sndAddr, tokenID, role) + nonce++ + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + tx = setSpecialRoleTx(nonce, sndAddr, dstAddr, tokenID, [][]byte{role}) + nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + return nonce +} + +func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T) { + t.Parallel() + + baseIssuingCost := "1000" + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + log.Info("Register dynamic NFT token") + + ticker := []byte("NFTTICKER") + tokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(tokenName)), + []byte(hex.EncodeToString(ticker)), + []byte(hex.EncodeToString([]byte("NFT"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + shard0Nonce := uint64(0) + tx := &transaction.Transaction{ + Nonce: shard0Nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + shard0Nonce++ + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + tokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, shard0Nonce, addrs[0], tokenID, roles) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 1) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, metaData) + + log.Info("give update role to another account and update metaData") + + shard0Nonce = transferSpecialRoleToAddr(t, cs, shard0Nonce, tokenID, addrs[0].Bytes, addrs[1].Bytes, []byte(core.ESDTRoleNFTUpdate)) + + newMetaData := &txsFee.MetaData{} + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Royalties = []byte(hex.EncodeToString(big.NewInt(15).Bytes())) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData, 0, addrs[1].Bytes) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, metaData) + newMetaData.Nonce = []byte{} + newMetaData.Attributes = []byte{} + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, newMetaData) + + log.Info("transfer nft - should merge metaData") + + tx = esdtNFTTransferTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + mergedMetaData := txsFee.GetDefaultMetaData() + mergedMetaData.Nonce = metaData.Nonce + mergedMetaData.Name = newMetaData.Name + mergedMetaData.Hash = newMetaData.Hash + mergedMetaData.Royalties = newMetaData.Royalties + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, tokenID, 0) + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, mergedMetaData) + + log.Info("transfer nft - should remove metaData from sender") + + tx = setSpecialRoleTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID, [][]byte{[]byte(core.ESDTRoleTransfer)}) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + tx = esdtNFTTransferTx(1, addrs[1].Bytes, addrs[2].Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 2) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, tokenID, 0) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, tokenID, 1) + checkMetaData(t, cs, addrs[2].Bytes, tokenID, 2, mergedMetaData) +} diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index 1000265d8d0..a5505de14ff 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -154,7 +154,7 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -273,7 +273,7 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) From 7c71e3ff4c0dcdb5a92d0bd1caddd2a320d42c28 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 3 Sep 2024 14:44:59 +0300 Subject: [PATCH 58/99] linter fixes --- .../chainSimulator/vm/esdtImprovements_test.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index b1b09764573..8f8417d9b84 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3378,7 +3378,7 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { checkMetaData(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID, esdtMetaData) checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID) - err = cs.GenerateBlocksUntilEpochIsReached(int32(epochForDynamicNFT)) + err = cs.GenerateBlocksUntilEpochIsReached(epochForDynamicNFT) require.Nil(t, err) log.Info("Change to DYNAMIC type") @@ -4054,7 +4054,6 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - shard0Nonce++ tx = esdtNFTTransferTx(1, addrs[2].Bytes, addrs[0].Bytes, tokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -4114,9 +4113,7 @@ func esdtMetaDataUpdateTx(tokenID []byte, metaData *txsFee.MetaData, nonce uint6 metaData.Attributes, } if len(metaData.Uris) > 0 { - for _, uri := range metaData.Uris { - txData = append(txData, uri) - } + txData = append(txData, metaData.Uris...) } else { txData = append(txData, nil) } @@ -4292,7 +4289,6 @@ func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T log.Info("transfer nft - should remove metaData from sender") tx = setSpecialRoleTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID, [][]byte{[]byte(core.ESDTRoleTransfer)}) - shard0Nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) From 506cd9fa48ec334775f05b3b92dc3458fa5a3d24 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 6 Sep 2024 13:22:58 +0300 Subject: [PATCH 59/99] proper fix for gasUsed and fee in case of relayedV3 --- .../transactionAPI/gasUsedAndFeeProcessor.go | 26 +++-- .../transactionsFeeProcessor.go | 15 ++- .../transactionsFeeProcessor_test.go | 103 ++++++++++++++++++ process/economics/economicsData.go | 25 ++++- process/economics/economicsData_test.go | 33 ++++++ 5 files changed, 190 insertions(+), 12 deletions(-) diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 8951149c983..342aa11cce9 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -49,16 +49,16 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = tx.InitiallyPaidFee } - if tx.IsRelayed && isFeeFixActive { - totalFee, isRelayed := gfp.getFeeOfRelayed(tx) - if isRelayed { - tx.Fee = totalFee.String() - tx.InitiallyPaidFee = totalFee.String() - tx.GasUsed = big.NewInt(0).Div(totalFee, big.NewInt(0).SetUint64(tx.GasPrice)).Uint64() - } + initialTotalFee, isRelayed := gfp.getFeeOfRelayed(tx) + if isRelayed && isFeeFixActive { + tx.InitiallyPaidFee = initialTotalFee.String() + tx.Fee = initialTotalFee.String() + tx.GasUsed = big.NewInt(0).Div(initialTotalFee, big.NewInt(0).SetUint64(tx.GasPrice)).Uint64() } hasRefundForSender := false + totalRefunds := big.NewInt(0) + isRelayedV3 := len(tx.InnerTransactions) > 0 for _, scr := range tx.SmartContractResults { if !scr.IsRefund || scr.RcvAddr != tx.Sender { continue @@ -69,7 +69,17 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value) hasRefundForSender = true - break + totalRefunds.Add(totalRefunds, scr.Value) + if !isRelayedV3 { + break + } + } + + if isRelayedV3 { + gasUsed, fee = gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, totalRefunds) + tx.GasUsed = gasUsed + tx.Fee = fee.String() + return } gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index ffad67ee22f..23dcb3fedf1 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -155,6 +155,8 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults) { hasRefund := false + totalRefunds := big.NewInt(0) + isRelayedV3 := len(txWithResults.GetTxHandler().GetUserTransactions()) > 0 for _, scrHandler := range txWithResults.scrs { scr, ok := scrHandler.GetTxHandler().(*smartContractResult.SmartContractResult) if !ok { @@ -167,12 +169,21 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi txWithResults.GetFeeInfo().SetGasUsed(gasUsed) txWithResults.GetFeeInfo().SetFee(fee) hasRefund = true - break + totalRefunds.Add(totalRefunds, scr.Value) + if !isRelayedV3 { + break + } } } - tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) + if isRelayedV3 { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), totalRefunds) + txWithResults.GetFeeInfo().SetGasUsed(gasUsed) + txWithResults.GetFeeInfo().SetFee(fee) + return + } + tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) } func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) (*big.Int, bool) { diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index 6f0e0f94c35..8472ad1551d 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -10,10 +10,13 @@ import ( outportcore "github.com/multiversx/mx-chain-core-go/data/outport" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/outport/mock" "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/economics" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" + "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" logger "github.com/multiversx/mx-chain-logger-go" @@ -597,3 +600,103 @@ func TestMoveBalanceWithSignalError(t *testing.T) { require.Nil(t, err) require.Equal(t, uint64(225_500), initialTx.GetFeeInfo().GetGasUsed()) } + +func TestPutFeeAndGasUsedRelayedTxV3WithRefunds(t *testing.T) { + t.Parallel() + + txHash := []byte("af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa") + scrHash1 := []byte("4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c") + scrWithRefundHash := []byte("94e678f400192eeae3c84b3125c9d45301db619a3ecbf9e7f46266a81a85ef51") + refundValueBig, _ := big.NewInt(0).SetString("299005000000000", 10) + initialTx := &outportcore.TxInfo{ + Transaction: &transaction.Transaction{ + Nonce: 0, + SndAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), + RcvAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), + GasLimit: 99000000, + GasPrice: 1000000000, + Value: big.NewInt(0), + InnerTransactions: []*transaction.Transaction{ + { + Nonce: 0, + SndAddr: []byte("erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg"), + RcvAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), + RelayerAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), + GasLimit: 85000000, + GasPrice: 1000000000, + Data: []byte("createNewDelegationContract@00@00"), + Value: big.NewInt(0), + }, + }, + }, + FeeInfo: &outportcore.FeeInfo{Fee: big.NewInt(0)}, + } + + scr1 := &smartContractResult.SmartContractResult{ + Nonce: 0, + GasPrice: 1000000000, + GasLimit: 84900500, + SndAddr: []byte("erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg"), + RcvAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), + Data: []byte("createNewDelegationContract@00@00"), + PrevTxHash: txHash, + OriginalTxHash: txHash, + } + scrWithRefund := &smartContractResult.SmartContractResult{ + Nonce: 1, + GasPrice: 1000000000, + GasLimit: 0, + Value: refundValueBig, + SndAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), + RcvAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), + PrevTxHash: scrHash1, + OriginalTxHash: txHash, + ReturnMessage: []byte("gas refund for relayer"), + } + + pool := &outportcore.TransactionPool{ + Transactions: map[string]*outportcore.TxInfo{ + hex.EncodeToString(txHash): initialTx, + }, + SmartContractResults: map[string]*outportcore.SCRInfo{ + hex.EncodeToString(scrHash1): { + SmartContractResult: scr1, + FeeInfo: &outportcore.FeeInfo{ + Fee: big.NewInt(0), + }, + }, + hex.EncodeToString(scrWithRefundHash): { + SmartContractResult: scrWithRefund, + FeeInfo: &outportcore.FeeInfo{ + Fee: big.NewInt(0), + }, + }, + }, + } + + enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || + flag == common.RelayedTransactionsV3Flag || + flag == common.FixRelayedBaseCostFlag + }, + } + arg := prepareMockArg() + arg.EnableEpochsHandler = enableEpochsHandler + economicsConfig := testscommon.GetEconomicsConfig() + arg.TxFeeCalculator, _ = economics.NewEconomicsData(economics.ArgsNewEconomicsData{ + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + Economics: &economicsConfig, + EpochNotifier: &epochNotifier.EpochNotifierStub{}, + EnableEpochsHandler: enableEpochsHandler, + }) + txsFeeProc, err := NewTransactionsFeeProcessor(arg) + require.NotNil(t, txsFeeProc) + require.Nil(t, err) + + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) + require.Nil(t, err) + require.Equal(t, big.NewInt(699500000000000), initialTx.GetFeeInfo().GetFee()) + require.Equal(t, uint64(55149500), initialTx.GetFeeInfo().GetGasUsed()) + require.Equal(t, "998505000000000", initialTx.GetFeeInfo().GetInitialPaidFee().String()) +} diff --git a/process/economics/economicsData.go b/process/economics/economicsData.go index a510447dab2..170377e62d3 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -591,8 +591,15 @@ func (ed *economicsData) ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(tx data.T txFee := ed.ComputeTxFeeInEpoch(tx, epoch) if len(tx.GetUserTransactions()) > 0 { - gasUnitsUsed := big.NewInt(0).Div(txFee, big.NewInt(0).SetUint64(tx.GetGasPrice())) - return gasUnitsUsed.Uint64(), txFee + txFeeAfterRefund := txFee.Sub(txFee, refundValue) + + gasPriceForProcessing := ed.GasPriceForProcessingInEpoch(tx, epoch) + gasUnitsRefunded := refundValue.Uint64() / gasPriceForProcessing + + gasUnitsConsideredForInitialFee := ed.computeRelayedTxV3MinGasLimit(tx) + gasUnitsUsed := gasUnitsConsideredForInitialFee - gasUnitsRefunded + + return gasUnitsUsed, txFeeAfterRefund } isPenalizedTooMuchGasFlagEnabled := ed.enableEpochsHandler.IsFlagEnabledInEpoch(common.PenalizedTooMuchGasFlag, epoch) @@ -682,6 +689,20 @@ func (ed *economicsData) ComputeGasLimitBasedOnBalanceInEpoch(tx data.Transactio return totalGasLimit, nil } +func (ed *economicsData) computeRelayedTxV3MinGasLimit(tx data.TransactionWithFeeHandler) uint64 { + relayedTxGasLimit := ed.ComputeGasLimit(tx) + relayedTxMinGasLimit := ed.MinGasLimit() + relayedTxGasLimitDiff := relayedTxGasLimit - relayedTxMinGasLimit // this may be positive if the relayed tx is guarded + + innerTxs := tx.GetUserTransactions() + totalGasLimit := relayedTxGasLimitDiff + relayedTxMinGasLimit*uint64(len(innerTxs)) + for _, innerTx := range innerTxs { + totalGasLimit += innerTx.GetGasLimit() + } + + return totalGasLimit +} + // IsInterfaceNil returns true if there is no value under the interface func (ed *economicsData) IsInterfaceNil() bool { return ed == nil diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index 5fdb8c369c2..f1a66e25dcd 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -1281,6 +1281,39 @@ func TestEconomicsData_ComputeGasUsedAndFeeBasedOnRefundValueSpecialBuiltInTooMu require.Equal(t, expectedFee, fee) } +func TestEconomicsData_ComputeGasUsedAndFeeBasedOnRefundValueRelayedV3(t *testing.T) { + t.Parallel() + + economicData, _ := economics.NewEconomicsData(createArgsForEconomicsDataRealFees()) + tx := &transaction.Transaction{ + GasPrice: 1000000000, + GasLimit: 99000000, + InnerTransactions: []*transaction.Transaction{ + { + GasPrice: 1000000000, + GasLimit: 85000000, + Data: []byte("createNewDelegationContract@00@00"), + }, + { + GasPrice: 1000000000, + GasLimit: 50000, + }, + { + GasPrice: 1000000000, + GasLimit: 50000, + }, + }, + } + + expectedGasUsed := uint64(55349500) + expectedFee, _ := big.NewInt(0).SetString("899500000000000", 10) + + refundValue, _ := big.NewInt(0).SetString("299005000000000", 10) + gasUsed, fee := economicData.ComputeGasUsedAndFeeBasedOnRefundValue(tx, refundValue) + require.Equal(t, expectedGasUsed, gasUsed) + require.Equal(t, expectedFee, fee) +} + func TestEconomicsData_ComputeGasLimitBasedOnBalance(t *testing.T) { t.Parallel() From f3b4b1342f950aea68ccdc2dd520abbfba2ac4d2 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 6 Sep 2024 15:11:50 +0300 Subject: [PATCH 60/99] fixes after review + extra test with multiple refunds --- .../transactionAPI/gasUsedAndFeeProcessor.go | 17 +- .../gasUsedAndFeeProcessor_test.go | 108 ++++++ .../testData/relayedV3WithOneRefund.json | 174 +++++++++ .../scInvokingWithMultipleRefunds.json | 347 ++++++++++++++++++ .../transactionsFeeProcessor.go | 11 +- 5 files changed, 631 insertions(+), 26 deletions(-) create mode 100644 node/external/transactionAPI/testData/relayedV3WithOneRefund.json create mode 100644 node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 342aa11cce9..5f4e2626fca 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -58,28 +58,19 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction hasRefundForSender := false totalRefunds := big.NewInt(0) - isRelayedV3 := len(tx.InnerTransactions) > 0 for _, scr := range tx.SmartContractResults { if !scr.IsRefund || scr.RcvAddr != tx.Sender { continue } - if scr.RcvAddr != tx.Sender { - continue - } - gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value) hasRefundForSender = true totalRefunds.Add(totalRefunds, scr.Value) - if !isRelayedV3 { - break - } } - if isRelayedV3 { + if totalRefunds.Cmp(big.NewInt(0)) > 0 { gasUsed, fee = gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, totalRefunds) tx.GasUsed = gasUsed tx.Fee = fee.String() - return } gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) @@ -182,12 +173,6 @@ func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transactio } } -func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnRefundValue(tx *transaction.ApiTransactionResult, refund *big.Int) { - gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, refund) - tx.GasUsed = gasUsed - tx.Fee = fee.String() -} - func (gfp *gasUsedAndFeeProcessor) isESDTOperationWithSCCall(tx *transaction.ApiTransactionResult) bool { isESDTTransferOperation := tx.Operation == core.BuiltInFunctionESDTTransfer || tx.Operation == core.BuiltInFunctionESDTNFTTransfer || tx.Operation == core.BuiltInFunctionMultiESDTNFTTransfer diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index d5340e7903c..3c8bb6d05cd 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -251,3 +251,111 @@ func TestNFTTransferWithScCall(t *testing.T) { req.Equal(uint64(55_000_000), tx.GasUsed) req.Equal("822250000000000", tx.Fee) } + +func TestComputeAndAttachGasUsedAndFeeTransactionWithMultipleScrWithRefund(t *testing.T) { + t.Parallel() + + feeComp, _ := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || + flag == common.PenalizedTooMuchGasFlag || + flag == common.FixRelayedBaseCostFlag + }, + })) + computer := fee.NewTestFeeComputer(feeComp) + + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + ) + + txWithSRefundSCR := &transaction.ApiTransactionResult{} + err := core.LoadJsonFile(txWithSRefundSCR, "testData/scInvokingWithMultipleRefunds.json") + require.NoError(t, err) + + txWithSRefundSCR.Fee = "" + txWithSRefundSCR.GasUsed = 0 + + snd, _ := pubKeyConverter.Decode(txWithSRefundSCR.Sender) + rcv, _ := pubKeyConverter.Decode(txWithSRefundSCR.Receiver) + val, _ := big.NewInt(0).SetString(txWithSRefundSCR.Value, 10) + txWithSRefundSCR.Tx = &transaction.Transaction{ + Nonce: txWithSRefundSCR.Nonce, + Value: val, + RcvAddr: rcv, + SndAddr: snd, + GasPrice: txWithSRefundSCR.GasPrice, + GasLimit: txWithSRefundSCR.GasLimit, + Data: txWithSRefundSCR.Data, + } + + gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) + require.Equal(t, uint64(20313408), txWithSRefundSCR.GasUsed) + require.Equal(t, "319459080000000", txWithSRefundSCR.Fee) +} + +func TestComputeAndAttachGasUsedAndFeeRelayedV3WithRefund(t *testing.T) { + t.Parallel() + + feeComp, _ := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || + flag == common.PenalizedTooMuchGasFlag || + flag == common.FixRelayedBaseCostFlag + }, + })) + computer := fee.NewTestFeeComputer(feeComp) + + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + ) + + txWithSRefundSCR := &transaction.ApiTransactionResult{} + err := core.LoadJsonFile(txWithSRefundSCR, "testData/relayedV3WithOneRefund.json") + require.NoError(t, err) + + txWithSRefundSCR.Fee = "" + txWithSRefundSCR.GasUsed = 0 + + innerTxs := make([]*transaction.Transaction, 0, len(txWithSRefundSCR.InnerTransactions)) + for _, innerTx := range txWithSRefundSCR.InnerTransactions { + snd, _ := pubKeyConverter.Decode(innerTx.Sender) + rcv, _ := pubKeyConverter.Decode(innerTx.Receiver) + val, _ := big.NewInt(0).SetString(innerTx.Value, 10) + + innerTxs = append(innerTxs, &transaction.Transaction{ + Nonce: innerTx.Nonce, + Value: val, + RcvAddr: rcv, + SndAddr: snd, + GasPrice: innerTx.GasPrice, + GasLimit: innerTx.GasLimit, + Data: innerTx.Data, + }) + } + + snd, _ := pubKeyConverter.Decode(txWithSRefundSCR.Sender) + rcv, _ := pubKeyConverter.Decode(txWithSRefundSCR.Receiver) + val, _ := big.NewInt(0).SetString(txWithSRefundSCR.Value, 10) + txWithSRefundSCR.Tx = &transaction.Transaction{ + Nonce: txWithSRefundSCR.Nonce, + Value: val, + RcvAddr: rcv, + SndAddr: snd, + GasPrice: txWithSRefundSCR.GasPrice, + GasLimit: txWithSRefundSCR.GasLimit, + Data: txWithSRefundSCR.Data, + InnerTransactions: innerTxs, + } + + gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) + require.Equal(t, uint64(55149500), txWithSRefundSCR.GasUsed) + require.Equal(t, "699500000000000", txWithSRefundSCR.Fee) +} diff --git a/node/external/transactionAPI/testData/relayedV3WithOneRefund.json b/node/external/transactionAPI/testData/relayedV3WithOneRefund.json new file mode 100644 index 00000000000..7b29520b9e9 --- /dev/null +++ b/node/external/transactionAPI/testData/relayedV3WithOneRefund.json @@ -0,0 +1,174 @@ +{ + "type": "normal", + "processingTypeOnSource": "RelayedTxV3", + "processingTypeOnDestination": "RelayedTxV3", + "hash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", + "nonce": 0, + "round": 19, + "epoch": 7, + "value": "0", + "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "sender": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "gasPrice": 1000000000, + "gasLimit": 99000000, + "gasUsed": 998505, + "signature": "416a2c25a9ccaabc0f6c55b870f9f028f87cbd617d77fa46ffeb488dbbb7a6e6b54c9baa464580ced73c1d7355a5d529e22d0e2bba3077adbc549bce1d596f0b", + "sourceShard": 1, + "destinationShard": 1, + "blockNonce": 19, + "blockHash": "fa0a0c232f0c1f44f6ba133c3d60f509146ecc845179b0658bcbef8ceded1f6e", + "notarizedAtSourceInMetaNonce": 21, + "NotarizedAtSourceInMetaHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", + "notarizedAtDestinationInMetaNonce": 21, + "notarizedAtDestinationInMetaHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", + "miniblockType": "TxBlock", + "miniblockHash": "b5ed48533fabb058444c6ce1303bf08b4dc11559b938f50a2e0e2dc8722dee20", + "hyperblockNonce": 21, + "hyperblockHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", + "timestamp": 1725611916, + "smartContractResults": [ + { + "hash": "4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c", + "nonce": 0, + "value": 2501000000000000000000, + "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "relayerAddress": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "relayedValue": 0, + "data": "createNewDelegationContract@00@00", + "prevTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", + "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", + "gasLimit": 84900500, + "gasPrice": 1000000000, + "callType": 0, + "logs": { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "identifier": "transferValueOnly", + "topics": [ + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" + ], + "data": "RGVwbG95U21hcnRDb250cmFjdA==", + "additionalData": [ + "RGVwbG95U21hcnRDb250cmFjdA==", + "X2luaXQ=", + "AA==", + "AA==" + ] + }, + { + "address": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "identifier": "delegate", + "topics": [ + "h5RY6SJT9AAA", + "h5RY6SJT9AAA", + "AQ==", + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" + ], + "data": null, + "additionalData": null + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", + "identifier": "transferValueOnly", + "topics": [ + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAB//8=" + ], + "data": "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", + "additionalData": [ + "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", + "c3Rha2U=" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", + "identifier": "SCDeploy", + "topics": [ + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=", + "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=", + "/uYNe6O98aIOSpF57HocNxS4JQ7FILx6+N7MEN3oAQY=" + ], + "data": null, + "additionalData": null + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "identifier": "writeLog", + "topics": [ + "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=" + ], + "data": "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==", + "additionalData": [ + "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==" + ] + } + ] + }, + "operation": "transfer", + "function": "createNewDelegationContract" + }, + { + "hash": "94e678f400192eeae3c84b3125c9d45301db619a3ecbf9e7f46266a81a85ef51", + "nonce": 1, + "value": 299005000000000, + "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "sender": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "prevTxHash": "4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c", + "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "returnMessage": "gas refund for relayer", + "logs": { + "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "events": [ + { + "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "identifier": "completedTxEvent", + "topics": [ + "TFiAHnfFfogpTyEBgUVmLi+xaY/V8aHPe2+B8HP1zWw=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer", + "isRefund": true + } + ], + "status": "success", + "receivers": [ + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6" + ], + "receiversShardIDs": [ + 4294967295 + ], + "operation": "transfer", + "initiallyPaidFee": "998505000000000", + "fee": "998505000000000", + "isRelayed": true, + "chainID": "chain", + "version": 2, + "options": 0, + "innerTransactions": [ + { + "nonce": 0, + "value": "2501000000000000000000", + "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "gasPrice": 1000000000, + "gasLimit": 85000000, + "data": "Y3JlYXRlTmV3RGVsZWdhdGlvbkNvbnRyYWN0QDAwQDAw", + "signature": "610493074d4e3ce0d8dcc5434cc67032f7e4acf3fd9f97525dba4865ba42408df8315824bf7b6268e2fa0d97fc51efe1a32f7928a799064a69d54bf063a19607", + "chainID": "chain", + "version": 2, + "relayer": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze" + } + ] +} \ No newline at end of file diff --git a/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json b/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json new file mode 100644 index 00000000000..b198565d1e8 --- /dev/null +++ b/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json @@ -0,0 +1,347 @@ +{ + "type": "normal", + "processingTypeOnSource": "SCInvoking", + "processingTypeOnDestination": "SCInvoking", + "hash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "nonce": 5720, + "round": 21578404, + "epoch": 1498, + "value": "88000000000000000", + "receiver": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "sender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "gasPrice": 1000000000, + "gasLimit": 45000000, + "gasUsed": 20313408, + "data": "YnV5QDEzMDA5N0A1NjQzNGY0OTRlMmQzMjY0MzQzNDMzNjRAMDFAMDE4NmEw", + "signature": "c3bea1fad86fc321a5016ec2283215b1371dc31a0b6297354bea303267193e3c27ca9589f9899a95e81b4d8cbd4d9fd6d27c765bde004f73efd9c882eb9e2d02", + "sourceShard": 1, + "destinationShard": 2, + "blockNonce": 21569950, + "blockHash": "16981d9bdf3710602366c1ad39c915597755d41aad6b5890fe3ecb7d453e8265", + "notarizedAtSourceInMetaNonce": 21554156, + "NotarizedAtSourceInMetaHash": "3886d224da560e51a1ff57912972bb6793628f5d5231bbafd54edfb81d700081", + "notarizedAtDestinationInMetaNonce": 21554160, + "notarizedAtDestinationInMetaHash": "e0058827df26c4d9ac36748f10a9e0ea56427b4ebfdc4e085bed6ae23eba0a87", + "miniblockType": "TxBlock", + "miniblockHash": "843a4b6fe2ec761ad6a23d5611d26d269c312fc6d1400a524a096102e35e594b", + "hyperblockNonce": 21554160, + "hyperblockHash": "e0058827df26c4d9ac36748f10a9e0ea56427b4ebfdc4e085bed6ae23eba0a87", + "timestamp": 1725588024, + "smartContractResults": [ + { + "hash": "ebc994f2e46037fbf16f3426ab3ea40a43b648620209372bcb158153053fb5f9", + "nonce": 5721, + "value": 246865920000000, + "receiver": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "sender": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "data": "@6f6b", + "prevTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "logs": { + "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "events": [ + { + "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "identifier": "completedTxEvent", + "topics": [ + "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer", + "isRefund": true + }, + { + "hash": "402b39eba60202424565e224ab7121fd49eb8da366bc8b7b5d38496f1ce29f0d", + "nonce": 0, + "value": 2640000000000000, + "receiver": "erd1qqqqqqqqqqqqqpgq8538ku69p97lq4eug75y8d6g6yfwhd7c45qs4zvejt", + "sender": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "data": "depositRoyalties@0000000000000000050073175b6392a2f2661f2fb1fd2552787534433af98638", + "prevTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 5500000, + "gasPrice": 1000000000, + "callType": 0, + "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "operation": "transfer", + "function": "depositRoyalties" + }, + { + "hash": "9912a1b3d3918a79f9c560ff2d81b24b316a89cbefd195325807132319147502", + "nonce": 0, + "value": 84480000000000000, + "receiver": "erd1qtkml3n4lwy5hxdmdfe67nm5jg5v6kqrtsdjt76za35ms4nnvghsjfujaw", + "sender": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "prevTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "logs": { + "address": "erd1qtkml3n4lwy5hxdmdfe67nm5jg5v6kqrtsdjt76za35ms4nnvghsjfujaw", + "events": [ + { + "address": "erd1qtkml3n4lwy5hxdmdfe67nm5jg5v6kqrtsdjt76za35ms4nnvghsjfujaw", + "identifier": "completedTxEvent", + "topics": [ + "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer" + }, + { + "hash": "11c18202b3d117fa3301e8cbc72f6d258d56b70686fa174bffa331079b753b31", + "nonce": 0, + "value": 0, + "receiver": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "sender": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "data": "ESDTNFTTransfer@56434f494e2d326434343364@01@0186a0@08011204000186a022ef020801120d56696c6c6167657220436f696e1a200000000000000000050073175b6392a2f2661f2fb1fd2552787534433af9863820ac022a203e0e25256b5c0a5d5825deb7519eeae0468c2597533db2de10bb560ae317b7f0325068747470733a2f2f697066732e696f2f697066732f6261666b7265696864703577797975706a6174356a6d68726e706c786d3333616570737a67667333656733716c336e776f6268736d72376e747434325068747470733a2f2f697066732e696f2f697066732f6261666b726569636d727763366b6b7472646d6669797a66616f687664357977796f34746f343670776c6b3767363562366d6b74376835697a6f793a71746167733a6769616e74732c6769616e74732076696c6c6167652c6e70632c76696c6c6167657220636f696e3b6d657461646174613a6261666b726569636d727763366b6b7472646d6669797a66616f687664357977796f34746f343670776c6b3767363562366d6b74376835697a6f79", + "prevTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "logs": { + "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "ESDTNFTTransfer", + "topics": [ + "VkNPSU4tMmQ0NDNk", + "AQ==", + "AYag", + "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" + ], + "data": null, + "additionalData": [ + "", + "RVNEVE5GVFRyYW5zZmVy", + "VkNPSU4tMmQ0NDNk", + "AQ==", + "AYag", + "CAESBAABhqAi7wIIARINVmlsbGFnZXIgQ29pbhogAAAAAAAAAAAFAHMXW2OSovJmHy+x/SVSeHU0Qzr5hjggrAIqID4OJSVrXApdWCXet1Ge6uBGjCWXUz2y3hC7VgrjF7fwMlBodHRwczovL2lwZnMuaW8vaXBmcy9iYWZrcmVpaGRwNXd5eXVwamF0NWptaHJucGx4bTMzYWVwc3pnZnMzZWczcWwzbndvYmhzbXI3bnR0NDJQaHR0cHM6Ly9pcGZzLmlvL2lwZnMvYmFma3JlaWNtcndjNmtrdHJkbWZpeXpmYW9odmQ1eXd5bzR0bzQ2cHdsazdnNjViNm1rdDdoNWl6b3k6cXRhZ3M6Z2lhbnRzLGdpYW50cyB2aWxsYWdlLG5wYyx2aWxsYWdlciBjb2luO21ldGFkYXRhOmJhZmtyZWljbXJ3YzZra3RyZG1maXl6ZmFvaHZkNXl3eW80dG80NnB3bGs3ZzY1YjZta3Q3aDVpem95" + ] + }, + { + "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "identifier": "writeLog", + "topics": [ + "AAAAAAAAAAAFANOyiCjWIFISTwfc1Q7TGwgl9g7uFSY=" + ], + "data": "QDZmNmI=", + "additionalData": [ + "QDZmNmI=" + ] + }, + { + "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "identifier": "completedTxEvent", + "topics": [ + "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" + ], + "data": null, + "additionalData": null + } + ] + }, + "tokens": [ + "VCOIN-2d443d-01" + ], + "esdtValues": [ + "100000" + ], + "receivers": [ + "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l" + ], + "receiversShardIDs": [ + 1 + ], + "operation": "ESDTNFTTransfer" + }, + { + "hash": "3a814d0abb4c00c44bc8ba29007c51edc487daa17c7666efc9fad1f5a86d03a2", + "nonce": 1, + "value": 880000000000000, + "receiver": "erd1qqqqqqqqqqqqqpgq8538ku69p97lq4eug75y8d6g6yfwhd7c45qs4zvejt", + "sender": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "data": "deposit", + "prevTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 3500000, + "gasPrice": 1000000000, + "callType": 0, + "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "operation": "transfer", + "function": "deposit" + }, + { + "hash": "b7a2e5cf1ddad2630ccf8c703c9494b9b446e3a25ce362f6ec7c739448e41cbf", + "nonce": 1, + "value": 26131840000000, + "receiver": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "sender": "erd1qqqqqqqqqqqqqpgq8538ku69p97lq4eug75y8d6g6yfwhd7c45qs4zvejt", + "data": "@6f6b", + "prevTxHash": "402b39eba60202424565e224ab7121fd49eb8da366bc8b7b5d38496f1ce29f0d", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "logs": { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "completedTxEvent", + "topics": [ + "QCs566YCAkJFZeIkq3Eh/UnrjaNmvIt7XThJbxzinw0=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer", + "isRefund": true + }, + { + "hash": "40d329ecd05ffa543a41efd216c463f2ec229432d7b5c1c9132af29e406f389d", + "nonce": 2, + "value": 7494280000000, + "receiver": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "sender": "erd1qqqqqqqqqqqqqpgq8538ku69p97lq4eug75y8d6g6yfwhd7c45qs4zvejt", + "data": "@6f6b", + "prevTxHash": "3a814d0abb4c00c44bc8ba29007c51edc487daa17c7666efc9fad1f5a86d03a2", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "logs": { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "completedTxEvent", + "topics": [ + "OoFNCrtMAMRLyLopAHxR7cSH2qF8dmbvyfrR9ahtA6I=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer", + "isRefund": true + } + ], + "logs": { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "buy", + "topics": [ + "YnV5X2V2ZW50", + "VkNPSU4tMmQ0NDNk", + "AQ==", + "EwCX", + "AYag", + "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=", + "zOQWYAA=", + "Au2/xnX7iUuZu2pzr090kijNWANcGyX7QuxpuFZzYi8=", + "RUdMRA==", + "", + "ZtpiOA==", + "", + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", + "aeMS", + "AAAABEVHTEQAAAAAAAAAAAAAAAgBOKOIpDwAAA==" + ], + "data": null, + "additionalData": [ + "" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "transferValueOnly", + "topics": [ + "CWEQ5jUAAA==", + "AAAAAAAAAAAFAD0ie3NFCX3wVzxHqEO3SNES67fYrQE=" + ], + "data": "VHJhbnNmZXJBbmRFeGVjdXRl", + "additionalData": [ + "VHJhbnNmZXJBbmRFeGVjdXRl", + "ZGVwb3NpdFJveWFsdGllcw==", + "AAAAAAAAAAAFAHMXW2OSovJmHy+x/SVSeHU0Qzr5hjg=" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "transferValueOnly", + "topics": [ + "ASwiHMagAAA=", + "Au2/xnX7iUuZu2pzr090kijNWANcGyX7QuxpuFZzYi8=" + ], + "data": "RGlyZWN0Q2FsbA==", + "additionalData": [ + "RGlyZWN0Q2FsbA==", + "" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "ESDTNFTTransfer", + "topics": [ + "VkNPSU4tMmQ0NDNk", + "AQ==", + "AYag", + "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" + ], + "data": "RGlyZWN0Q2FsbA==", + "additionalData": [ + "RGlyZWN0Q2FsbA==", + "RVNEVE5GVFRyYW5zZmVy", + "VkNPSU4tMmQ0NDNk", + "AQ==", + "AYag", + "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "transferValueOnly", + "topics": [ + "AyBa92cAAA==", + "AAAAAAAAAAAFAD0ie3NFCX3wVzxHqEO3SNES67fYrQE=" + ], + "data": "VHJhbnNmZXJBbmRFeGVjdXRl", + "additionalData": [ + "VHJhbnNmZXJBbmRFeGVjdXRl", + "ZGVwb3NpdA==" + ] + } + ] + }, + "status": "success", + "operation": "transfer", + "function": "buy", + "initiallyPaidFee": "566325000000000", + "fee": "319459080000000", + "chainID": "1", + "version": 2, + "options": 0 +} diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index 23dcb3fedf1..ac92ce09790 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -156,7 +156,6 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults) { hasRefund := false totalRefunds := big.NewInt(0) - isRelayedV3 := len(txWithResults.GetTxHandler().GetUserTransactions()) > 0 for _, scrHandler := range txWithResults.scrs { scr, ok := scrHandler.GetTxHandler().(*smartContractResult.SmartContractResult) if !ok { @@ -164,23 +163,15 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi } if isSCRForSenderWithRefund(scr, txHashHex, txWithResults.GetTxHandler()) || isRefundForRelayed(scr, txWithResults.GetTxHandler()) { - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), scr.Value) - - txWithResults.GetFeeInfo().SetGasUsed(gasUsed) - txWithResults.GetFeeInfo().SetFee(fee) hasRefund = true totalRefunds.Add(totalRefunds, scr.Value) - if !isRelayedV3 { - break - } } } - if isRelayedV3 { + if totalRefunds.Cmp(big.NewInt(0)) > 0 { gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), totalRefunds) txWithResults.GetFeeInfo().SetGasUsed(gasUsed) txWithResults.GetFeeInfo().SetFee(fee) - return } tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) From 51990e706e6fda906aaf3e4cc2bd68ecbe1f6268 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 6 Sep 2024 15:12:46 +0300 Subject: [PATCH 61/99] removed test --- .../transactionsFeeProcessor_test.go | 103 ------------------ 1 file changed, 103 deletions(-) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index 8472ad1551d..6f0e0f94c35 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -10,13 +10,10 @@ import ( outportcore "github.com/multiversx/mx-chain-core-go/data/outport" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/outport/mock" "github.com/multiversx/mx-chain-go/process" - "github.com/multiversx/mx-chain-go/process/economics" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" - "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" logger "github.com/multiversx/mx-chain-logger-go" @@ -600,103 +597,3 @@ func TestMoveBalanceWithSignalError(t *testing.T) { require.Nil(t, err) require.Equal(t, uint64(225_500), initialTx.GetFeeInfo().GetGasUsed()) } - -func TestPutFeeAndGasUsedRelayedTxV3WithRefunds(t *testing.T) { - t.Parallel() - - txHash := []byte("af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa") - scrHash1 := []byte("4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c") - scrWithRefundHash := []byte("94e678f400192eeae3c84b3125c9d45301db619a3ecbf9e7f46266a81a85ef51") - refundValueBig, _ := big.NewInt(0).SetString("299005000000000", 10) - initialTx := &outportcore.TxInfo{ - Transaction: &transaction.Transaction{ - Nonce: 0, - SndAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), - RcvAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), - GasLimit: 99000000, - GasPrice: 1000000000, - Value: big.NewInt(0), - InnerTransactions: []*transaction.Transaction{ - { - Nonce: 0, - SndAddr: []byte("erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg"), - RcvAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), - RelayerAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), - GasLimit: 85000000, - GasPrice: 1000000000, - Data: []byte("createNewDelegationContract@00@00"), - Value: big.NewInt(0), - }, - }, - }, - FeeInfo: &outportcore.FeeInfo{Fee: big.NewInt(0)}, - } - - scr1 := &smartContractResult.SmartContractResult{ - Nonce: 0, - GasPrice: 1000000000, - GasLimit: 84900500, - SndAddr: []byte("erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg"), - RcvAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), - Data: []byte("createNewDelegationContract@00@00"), - PrevTxHash: txHash, - OriginalTxHash: txHash, - } - scrWithRefund := &smartContractResult.SmartContractResult{ - Nonce: 1, - GasPrice: 1000000000, - GasLimit: 0, - Value: refundValueBig, - SndAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), - RcvAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), - PrevTxHash: scrHash1, - OriginalTxHash: txHash, - ReturnMessage: []byte("gas refund for relayer"), - } - - pool := &outportcore.TransactionPool{ - Transactions: map[string]*outportcore.TxInfo{ - hex.EncodeToString(txHash): initialTx, - }, - SmartContractResults: map[string]*outportcore.SCRInfo{ - hex.EncodeToString(scrHash1): { - SmartContractResult: scr1, - FeeInfo: &outportcore.FeeInfo{ - Fee: big.NewInt(0), - }, - }, - hex.EncodeToString(scrWithRefundHash): { - SmartContractResult: scrWithRefund, - FeeInfo: &outportcore.FeeInfo{ - Fee: big.NewInt(0), - }, - }, - }, - } - - enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { - return flag == common.GasPriceModifierFlag || - flag == common.RelayedTransactionsV3Flag || - flag == common.FixRelayedBaseCostFlag - }, - } - arg := prepareMockArg() - arg.EnableEpochsHandler = enableEpochsHandler - economicsConfig := testscommon.GetEconomicsConfig() - arg.TxFeeCalculator, _ = economics.NewEconomicsData(economics.ArgsNewEconomicsData{ - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - Economics: &economicsConfig, - EpochNotifier: &epochNotifier.EpochNotifierStub{}, - EnableEpochsHandler: enableEpochsHandler, - }) - txsFeeProc, err := NewTransactionsFeeProcessor(arg) - require.NotNil(t, txsFeeProc) - require.Nil(t, err) - - err = txsFeeProc.PutFeeAndGasUsed(pool, 0) - require.Nil(t, err) - require.Equal(t, big.NewInt(699500000000000), initialTx.GetFeeInfo().GetFee()) - require.Equal(t, uint64(55149500), initialTx.GetFeeInfo().GetGasUsed()) - require.Equal(t, "998505000000000", initialTx.GetFeeInfo().GetInitialPaidFee().String()) -} From 398361a09f24c15fc039f637fb02740a298a2274 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 6 Sep 2024 16:21:12 +0300 Subject: [PATCH 62/99] simplify jsons --- .../testData/relayedV3WithOneRefund.json | 120 +-------- .../scInvokingWithMultipleRefunds.json | 234 +----------------- 2 files changed, 2 insertions(+), 352 deletions(-) diff --git a/node/external/transactionAPI/testData/relayedV3WithOneRefund.json b/node/external/transactionAPI/testData/relayedV3WithOneRefund.json index 7b29520b9e9..c2b0484f877 100644 --- a/node/external/transactionAPI/testData/relayedV3WithOneRefund.json +++ b/node/external/transactionAPI/testData/relayedV3WithOneRefund.json @@ -4,28 +4,12 @@ "processingTypeOnDestination": "RelayedTxV3", "hash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", "nonce": 0, - "round": 19, - "epoch": 7, "value": "0", "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", "sender": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", "gasPrice": 1000000000, "gasLimit": 99000000, "gasUsed": 998505, - "signature": "416a2c25a9ccaabc0f6c55b870f9f028f87cbd617d77fa46ffeb488dbbb7a6e6b54c9baa464580ced73c1d7355a5d529e22d0e2bba3077adbc549bce1d596f0b", - "sourceShard": 1, - "destinationShard": 1, - "blockNonce": 19, - "blockHash": "fa0a0c232f0c1f44f6ba133c3d60f509146ecc845179b0658bcbef8ceded1f6e", - "notarizedAtSourceInMetaNonce": 21, - "NotarizedAtSourceInMetaHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", - "notarizedAtDestinationInMetaNonce": 21, - "notarizedAtDestinationInMetaHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", - "miniblockType": "TxBlock", - "miniblockHash": "b5ed48533fabb058444c6ce1303bf08b4dc11559b938f50a2e0e2dc8722dee20", - "hyperblockNonce": 21, - "hyperblockHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", - "timestamp": 1725611916, "smartContractResults": [ { "hash": "4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c", @@ -33,84 +17,11 @@ "value": 2501000000000000000000, "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", - "relayerAddress": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "relayedValue": 0, "data": "createNewDelegationContract@00@00", "prevTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", "gasLimit": 84900500, - "gasPrice": 1000000000, - "callType": 0, - "logs": { - "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "events": [ - { - "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "identifier": "transferValueOnly", - "topics": [ - "h5RY6SJT9AAA", - "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" - ], - "data": "RGVwbG95U21hcnRDb250cmFjdA==", - "additionalData": [ - "RGVwbG95U21hcnRDb250cmFjdA==", - "X2luaXQ=", - "AA==", - "AA==" - ] - }, - { - "address": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", - "identifier": "delegate", - "topics": [ - "h5RY6SJT9AAA", - "h5RY6SJT9AAA", - "AQ==", - "h5RY6SJT9AAA", - "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" - ], - "data": null, - "additionalData": null - }, - { - "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", - "identifier": "transferValueOnly", - "topics": [ - "h5RY6SJT9AAA", - "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAB//8=" - ], - "data": "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", - "additionalData": [ - "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", - "c3Rha2U=" - ] - }, - { - "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", - "identifier": "SCDeploy", - "topics": [ - "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=", - "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=", - "/uYNe6O98aIOSpF57HocNxS4JQ7FILx6+N7MEN3oAQY=" - ], - "data": null, - "additionalData": null - }, - { - "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "identifier": "writeLog", - "topics": [ - "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=" - ], - "data": "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==", - "additionalData": [ - "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==" - ] - } - ] - }, - "operation": "transfer", - "function": "createNewDelegationContract" + "gasPrice": 1000000000 }, { "hash": "94e678f400192eeae3c84b3125c9d45301db619a3ecbf9e7f46266a81a85ef51", @@ -122,40 +33,11 @@ "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, "returnMessage": "gas refund for relayer", - "logs": { - "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "events": [ - { - "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "identifier": "completedTxEvent", - "topics": [ - "TFiAHnfFfogpTyEBgUVmLi+xaY/V8aHPe2+B8HP1zWw=" - ], - "data": null, - "additionalData": null - } - ] - }, "operation": "transfer", "isRefund": true } ], - "status": "success", - "receivers": [ - "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6" - ], - "receiversShardIDs": [ - 4294967295 - ], - "operation": "transfer", - "initiallyPaidFee": "998505000000000", - "fee": "998505000000000", - "isRelayed": true, - "chainID": "chain", - "version": 2, - "options": 0, "innerTransactions": [ { "nonce": 0, diff --git a/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json b/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json index b198565d1e8..6223da3db9f 100644 --- a/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json +++ b/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json @@ -4,8 +4,6 @@ "processingTypeOnDestination": "SCInvoking", "hash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "nonce": 5720, - "round": 21578404, - "epoch": 1498, "value": "88000000000000000", "receiver": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", "sender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", @@ -13,20 +11,6 @@ "gasLimit": 45000000, "gasUsed": 20313408, "data": "YnV5QDEzMDA5N0A1NjQzNGY0OTRlMmQzMjY0MzQzNDMzNjRAMDFAMDE4NmEw", - "signature": "c3bea1fad86fc321a5016ec2283215b1371dc31a0b6297354bea303267193e3c27ca9589f9899a95e81b4d8cbd4d9fd6d27c765bde004f73efd9c882eb9e2d02", - "sourceShard": 1, - "destinationShard": 2, - "blockNonce": 21569950, - "blockHash": "16981d9bdf3710602366c1ad39c915597755d41aad6b5890fe3ecb7d453e8265", - "notarizedAtSourceInMetaNonce": 21554156, - "NotarizedAtSourceInMetaHash": "3886d224da560e51a1ff57912972bb6793628f5d5231bbafd54edfb81d700081", - "notarizedAtDestinationInMetaNonce": 21554160, - "notarizedAtDestinationInMetaHash": "e0058827df26c4d9ac36748f10a9e0ea56427b4ebfdc4e085bed6ae23eba0a87", - "miniblockType": "TxBlock", - "miniblockHash": "843a4b6fe2ec761ad6a23d5611d26d269c312fc6d1400a524a096102e35e594b", - "hyperblockNonce": 21554160, - "hyperblockHash": "e0058827df26c4d9ac36748f10a9e0ea56427b4ebfdc4e085bed6ae23eba0a87", - "timestamp": 1725588024, "smartContractResults": [ { "hash": "ebc994f2e46037fbf16f3426ab3ea40a43b648620209372bcb158153053fb5f9", @@ -39,21 +23,6 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, - "logs": { - "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "events": [ - { - "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "identifier": "completedTxEvent", - "topics": [ - "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" - ], - "data": null, - "additionalData": null - } - ] - }, "operation": "transfer", "isRefund": true }, @@ -68,7 +37,6 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 5500000, "gasPrice": 1000000000, - "callType": 0, "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", "operation": "transfer", "function": "depositRoyalties" @@ -83,22 +51,7 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "logs": { - "address": "erd1qtkml3n4lwy5hxdmdfe67nm5jg5v6kqrtsdjt76za35ms4nnvghsjfujaw", - "events": [ - { - "address": "erd1qtkml3n4lwy5hxdmdfe67nm5jg5v6kqrtsdjt76za35ms4nnvghsjfujaw", - "identifier": "completedTxEvent", - "topics": [ - "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" - ], - "data": null, - "additionalData": null - } - ] - }, "operation": "transfer" }, { @@ -112,64 +65,7 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "logs": { - "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "events": [ - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "ESDTNFTTransfer", - "topics": [ - "VkNPSU4tMmQ0NDNk", - "AQ==", - "AYag", - "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" - ], - "data": null, - "additionalData": [ - "", - "RVNEVE5GVFRyYW5zZmVy", - "VkNPSU4tMmQ0NDNk", - "AQ==", - "AYag", - "CAESBAABhqAi7wIIARINVmlsbGFnZXIgQ29pbhogAAAAAAAAAAAFAHMXW2OSovJmHy+x/SVSeHU0Qzr5hjggrAIqID4OJSVrXApdWCXet1Ge6uBGjCWXUz2y3hC7VgrjF7fwMlBodHRwczovL2lwZnMuaW8vaXBmcy9iYWZrcmVpaGRwNXd5eXVwamF0NWptaHJucGx4bTMzYWVwc3pnZnMzZWczcWwzbndvYmhzbXI3bnR0NDJQaHR0cHM6Ly9pcGZzLmlvL2lwZnMvYmFma3JlaWNtcndjNmtrdHJkbWZpeXpmYW9odmQ1eXd5bzR0bzQ2cHdsazdnNjViNm1rdDdoNWl6b3k6cXRhZ3M6Z2lhbnRzLGdpYW50cyB2aWxsYWdlLG5wYyx2aWxsYWdlciBjb2luO21ldGFkYXRhOmJhZmtyZWljbXJ3YzZra3RyZG1maXl6ZmFvaHZkNXl3eW80dG80NnB3bGs3ZzY1YjZta3Q3aDVpem95" - ] - }, - { - "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "identifier": "writeLog", - "topics": [ - "AAAAAAAAAAAFANOyiCjWIFISTwfc1Q7TGwgl9g7uFSY=" - ], - "data": "QDZmNmI=", - "additionalData": [ - "QDZmNmI=" - ] - }, - { - "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "identifier": "completedTxEvent", - "topics": [ - "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" - ], - "data": null, - "additionalData": null - } - ] - }, - "tokens": [ - "VCOIN-2d443d-01" - ], - "esdtValues": [ - "100000" - ], - "receivers": [ - "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l" - ], - "receiversShardIDs": [ - 1 - ], "operation": "ESDTNFTTransfer" }, { @@ -183,7 +79,6 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 3500000, "gasPrice": 1000000000, - "callType": 0, "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", "operation": "transfer", "function": "deposit" @@ -199,21 +94,6 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, - "logs": { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "events": [ - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "completedTxEvent", - "topics": [ - "QCs566YCAkJFZeIkq3Eh/UnrjaNmvIt7XThJbxzinw0=" - ], - "data": null, - "additionalData": null - } - ] - }, "operation": "transfer", "isRefund": true }, @@ -228,120 +108,8 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, - "logs": { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "events": [ - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "completedTxEvent", - "topics": [ - "OoFNCrtMAMRLyLopAHxR7cSH2qF8dmbvyfrR9ahtA6I=" - ], - "data": null, - "additionalData": null - } - ] - }, "operation": "transfer", "isRefund": true } - ], - "logs": { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "events": [ - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "buy", - "topics": [ - "YnV5X2V2ZW50", - "VkNPSU4tMmQ0NDNk", - "AQ==", - "EwCX", - "AYag", - "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=", - "zOQWYAA=", - "Au2/xnX7iUuZu2pzr090kijNWANcGyX7QuxpuFZzYi8=", - "RUdMRA==", - "", - "ZtpiOA==", - "", - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", - "aeMS", - "AAAABEVHTEQAAAAAAAAAAAAAAAgBOKOIpDwAAA==" - ], - "data": null, - "additionalData": [ - "" - ] - }, - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "transferValueOnly", - "topics": [ - "CWEQ5jUAAA==", - "AAAAAAAAAAAFAD0ie3NFCX3wVzxHqEO3SNES67fYrQE=" - ], - "data": "VHJhbnNmZXJBbmRFeGVjdXRl", - "additionalData": [ - "VHJhbnNmZXJBbmRFeGVjdXRl", - "ZGVwb3NpdFJveWFsdGllcw==", - "AAAAAAAAAAAFAHMXW2OSovJmHy+x/SVSeHU0Qzr5hjg=" - ] - }, - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "transferValueOnly", - "topics": [ - "ASwiHMagAAA=", - "Au2/xnX7iUuZu2pzr090kijNWANcGyX7QuxpuFZzYi8=" - ], - "data": "RGlyZWN0Q2FsbA==", - "additionalData": [ - "RGlyZWN0Q2FsbA==", - "" - ] - }, - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "ESDTNFTTransfer", - "topics": [ - "VkNPSU4tMmQ0NDNk", - "AQ==", - "AYag", - "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" - ], - "data": "RGlyZWN0Q2FsbA==", - "additionalData": [ - "RGlyZWN0Q2FsbA==", - "RVNEVE5GVFRyYW5zZmVy", - "VkNPSU4tMmQ0NDNk", - "AQ==", - "AYag", - "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" - ] - }, - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "transferValueOnly", - "topics": [ - "AyBa92cAAA==", - "AAAAAAAAAAAFAD0ie3NFCX3wVzxHqEO3SNES67fYrQE=" - ], - "data": "VHJhbnNmZXJBbmRFeGVjdXRl", - "additionalData": [ - "VHJhbnNmZXJBbmRFeGVjdXRl", - "ZGVwb3NpdA==" - ] - } - ] - }, - "status": "success", - "operation": "transfer", - "function": "buy", - "initiallyPaidFee": "566325000000000", - "fee": "319459080000000", - "chainID": "1", - "version": 2, - "options": 0 + ] } From 0378c6dfd7900cfb1d7b5b7a2191cfce168713e7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 9 Sep 2024 11:32:05 +0300 Subject: [PATCH 63/99] updated deps to tags --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 92a18248de8..857521f3966 100644 --- a/go.mod +++ b/go.mod @@ -15,14 +15,14 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.22-0.20240823091930-22b700471ada + github.com/multiversx/mx-chain-core-go v1.2.22 github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 + github.com/multiversx/mx-chain-es-indexer-go v1.7.8 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240903110629-ee357f94b63c - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d + github.com/multiversx/mx-chain-vm-common-go v1.5.14 + github.com/multiversx/mx-chain-vm-go v1.5.32 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 21ac2f73c29..5eb00724155 100644 --- a/go.sum +++ b/go.sum @@ -387,22 +387,22 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.22-0.20240823091930-22b700471ada h1:Yi4gpXr/LzpLR2Soca5SNC/NRGnPCrD5FyGKShGLFpE= -github.com/multiversx/mx-chain-core-go v1.2.22-0.20240823091930-22b700471ada/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.22 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pTF333gWPpd+FNk= +github.com/multiversx/mx-chain-core-go v1.2.22/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 h1:VJOigTM9JbjFdy9ICVhsDfM9YQkFqMigAaQCHaM0iwY= -github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.8 h1:ZDKTXkQhQ7lLi6huVrBTUssVEqCvaCxGH4Y52GapboQ= +github.com/multiversx/mx-chain-es-indexer-go v1.7.8/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240903110629-ee357f94b63c h1:VLAdXl0NsnMWBuJZUJPxK8qK1AKyEzqSoQ7I8NOj0t4= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240903110629-ee357f94b63c/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d h1:TSObh+pVpKdjBb0eyLHjBRULIZU+v6voSJd2CNprllg= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d/go.mod h1:2x0I5wbWgrVKj7zeVSWITWqdnqmAiuBfsAdrdbAViQE= +github.com/multiversx/mx-chain-vm-common-go v1.5.14 h1:QauClmsZVKnShhvAVkXndO4j25q361SPvt9dqdx1qlM= +github.com/multiversx/mx-chain-vm-common-go v1.5.14/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.32 h1:bEHKmXhjo2aHsx+cFDtKRV7/uq0yBip47gj9Xrl/B84= +github.com/multiversx/mx-chain-vm-go v1.5.32/go.mod h1:yjOCetRG0wFXm+IWGyioipdR959TYoR+FRdAGVq8xXw= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From 0e3adbbb2a81955a82e87f83f10d0705e3f83916 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 11 Sep 2024 10:41:06 +0300 Subject: [PATCH 64/99] proper fix for fee/initially paid fee for relayed after fix --- .../transactionAPI/gasUsedAndFeeProcessor.go | 7 +++++- .../transactionsFeeProcessor.go | 22 +++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 5f4e2626fca..7f957f50ece 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -50,7 +50,8 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction } initialTotalFee, isRelayed := gfp.getFeeOfRelayed(tx) - if isRelayed && isFeeFixActive { + isRelayedAfterFix := isRelayed && isFeeFixActive + if isRelayedAfterFix { tx.InitiallyPaidFee = initialTotalFee.String() tx.Fee = initialTotalFee.String() tx.GasUsed = big.NewInt(0).Div(initialTotalFee, big.NewInt(0).SetUint64(tx.GasPrice)).Uint64() @@ -73,6 +74,10 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = fee.String() } + if isRelayedAfterFix { + return + } + gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) } diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index ac92ce09790..dccf0366b23 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -140,20 +140,20 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans continue } - if isRelayedTx(txWithResult) && isFeeFixActive { - totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) - if isRelayed { - feeInfo.SetFee(totalFee) - feeInfo.SetInitialPaidFee(totalFee) - feeInfo.SetGasUsed(big.NewInt(0).Div(totalFee, big.NewInt(0).SetUint64(txHandler.GetGasPrice())).Uint64()) - } + totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) + isRelayedAfterFix := isRelayed && isFeeFixActive + if isRelayedAfterFix { + feeInfo.SetFee(totalFee) + feeInfo.SetInitialPaidFee(totalFee) + feeInfo.SetGasUsed(big.NewInt(0).Div(totalFee, big.NewInt(0).SetUint64(txHandler.GetGasPrice())).Uint64()) + } - tep.prepareTxWithResults(txHashHex, txWithResult) + tep.prepareTxWithResults(txHashHex, txWithResult, isRelayedAfterFix) } } -func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults) { +func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults, isRelayedAfterFix bool) { hasRefund := false totalRefunds := big.NewInt(0) for _, scrHandler := range txWithResults.scrs { @@ -174,6 +174,10 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi txWithResults.GetFeeInfo().SetFee(fee) } + if isRelayedAfterFix { + return + } + tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) } From cfc8c78746bc60c8ed919c3f7b08788714dc5040 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 11 Sep 2024 13:11:10 +0300 Subject: [PATCH 65/99] added unittest --- .../gasUsedAndFeeProcessor_test.go | 50 +++++++++++++++ .../testData/failedRelayedV1.json | 61 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 node/external/transactionAPI/testData/failedRelayedV1.json diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 3c8bb6d05cd..7e4011e0f2c 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -7,10 +7,12 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/pubkeyConverter" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/node/external/timemachine/fee" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/economics" + "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" @@ -359,3 +361,51 @@ func TestComputeAndAttachGasUsedAndFeeRelayedV3WithRefund(t *testing.T) { require.Equal(t, uint64(55149500), txWithSRefundSCR.GasUsed) require.Equal(t, "699500000000000", txWithSRefundSCR.Fee) } + +func TestComputeAndAttachGasUsedAndFeeFailedRelayedV1(t *testing.T) { + t.Parallel() + + enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || + flag == common.PenalizedTooMuchGasFlag || + flag == common.FixRelayedBaseCostFlag + }, + } + feeComp, _ := fee.NewFeeComputer(createEconomicsData(enableEpochsHandler)) + computer := fee.NewTestFeeComputer(feeComp) + + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + pubKeyConverter, + smartContract.NewArgumentParser(), + &marshal.JsonMarshalizer{}, + enableEpochsHandler, + ) + + txWithSRefundSCR := &transaction.ApiTransactionResult{} + err := core.LoadJsonFile(txWithSRefundSCR, "testData/failedRelayedV1.json") + require.NoError(t, err) + + snd, _ := pubKeyConverter.Decode(txWithSRefundSCR.Sender) + rcv, _ := pubKeyConverter.Decode(txWithSRefundSCR.Receiver) + val, _ := big.NewInt(0).SetString(txWithSRefundSCR.Value, 10) + txWithSRefundSCR.Tx = &transaction.Transaction{ + Nonce: txWithSRefundSCR.Nonce, + Value: val, + RcvAddr: rcv, + SndAddr: snd, + GasPrice: txWithSRefundSCR.GasPrice, + GasLimit: txWithSRefundSCR.GasLimit, + Data: txWithSRefundSCR.Data, + } + + txWithSRefundSCR.InitiallyPaidFee = "" + txWithSRefundSCR.Fee = "" + txWithSRefundSCR.GasUsed = 0 + + gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) + require.Equal(t, uint64(1274230), txWithSRefundSCR.GasUsed) + require.Equal(t, "1274230000000000", txWithSRefundSCR.Fee) + require.Equal(t, "1274230000000000", txWithSRefundSCR.InitiallyPaidFee) +} diff --git a/node/external/transactionAPI/testData/failedRelayedV1.json b/node/external/transactionAPI/testData/failedRelayedV1.json new file mode 100644 index 00000000000..5f1a72c8c33 --- /dev/null +++ b/node/external/transactionAPI/testData/failedRelayedV1.json @@ -0,0 +1,61 @@ +{ + "type": "normal", + "processingTypeOnSource": "RelayedTx", + "processingTypeOnDestination": "RelayedTx", + "hash": "efe3e8fa273fc2db4d559185e9729f7bbf17f617e28424b6a6533fb193caf561", + "nonce": 125, + "value": "0", + "receiver": "erd1x9hax7mdqux0nak9ahxrc2g75h5ckpfs4ssr8l7tkxscaa293x6q8ffd4e", + "sender": "erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6", + "gasPrice": 1000000000, + "gasLimit": 6148000, + "gasUsed": 6148000, + "data": "cmVsYXllZFR4QDdiMjI2ZTZmNmU2MzY1MjIzYTM0MzcyYzIyNzM2NTZlNjQ2NTcyMjIzYTIyNGQ1NzJmNTQ2NTMyMzA0ODQ0NTA2ZTMyNzg2NTMzNGQ1MDQzNmI2NTcwNjU2ZDRjNDI1NDQzNzM0OTQ0NTAyZjc5Mzc0NzY4NmE3NjU2NDY2OTYyNTEzZDIyMmMyMjcyNjU2MzY1Njk3NjY1NzIyMjNhMjI0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDY0MTQ0MzU1MzM3NTg2MjUwNzk1NTQzNzU3NzRiNDk1MTM0NmUzNzMxNTE3OTZmNGE1ODM1NzM1NDQyNzI2NzNkMjIyYzIyNzY2MTZjNzU2NTIyM2EzMTMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDJjMjI2NzYxNzM1MDcyNjk2MzY1MjIzYTMxMzAzMDMwMzAzMDMwMzAzMDMwMmMyMjY3NjE3MzRjNjk2ZDY5NzQyMjNhMzUzMDMwMzAzMDMwMzAyYzIyNjQ2MTc0NjEyMjNhMjI1OTU3NTI2YjUxNDQ0MTc4NTE0NDQxNzk1MTQ0NDE3YTUxNDQ0MTMwNTE0NDQxMzEyMjJjMjI3MzY5Njc2ZTYxNzQ3NTcyNjUyMjNhMjI3NjRjNjQ2ZDMyMmY0ZTQ0NTQ0NDc3MzgzMTMxNTEzMDYyNzgyYjU4NGI1MTc4NTA0NTJmNzY0OTU3NDM2ODRlNzI2OTU1NmE3ODcyNzAyZjU5Mzg1MDRlNzI0ZDQ1NmM2NTQ3NmUzNTMxNTM3NjUyNTk2NDQ3MzQ2ZjQ3NTc3MjQ5Njk0MzQ4Mzk2YTMxNzY0ZjRiNmY1OTJmNDg1NTUyNjE0ZTQxNDg0MjUxM2QzZDIyMmMyMjYzNjg2MTY5NmU0OTQ0MjIzYTIyNTY0MTNkM2QyMjJjMjI3NjY1NzI3MzY5NmY2ZTIyM2EzMjdk", + "sourceShard": 0, + "destinationShard": 0, + "logs": { + "address": "erd1qqqqqqqqqqqqqpgq8efw6ak0e9q2as9zzr38aa2r9gy4lxcnq6uqpefzvu", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgq8efw6ak0e9q2as9zzr38aa2r9gy4lxcnq6uqpefzvu", + "identifier": "signalError", + "topics": [ + "MW/Te20HDPn2xe3MPCkepemLBTCsIDP/y7GhjvVFibQ=", + "ZnVuY3Rpb24gZG9lcyBub3QgYWNjZXB0IEVHTEQgcGF5bWVudA==" + ], + "data": "QDY1Nzg2NTYzNzU3NDY5NmY2ZTIwNjY2MTY5NmM2NTY0", + "additionalData": [ + "QDY1Nzg2NTYzNzU3NDY5NmY2ZTIwNjY2MTY5NmM2NTY0" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqpgq8efw6ak0e9q2as9zzr38aa2r9gy4lxcnq6uqpefzvu", + "identifier": "signalError", + "topics": [ + "XPSryD5QxTCdgH/D9naYh1mh4wEAG8mgJlgE9Cr4Brg=", + "ZnVuY3Rpb24gZG9lcyBub3QgYWNjZXB0IEVHTEQgcGF5bWVudA==" + ], + "data": null, + "additionalData": [ + "" + ] + }, + { + "address": "erd1x9hax7mdqux0nak9ahxrc2g75h5ckpfs4ssr8l7tkxscaa293x6q8ffd4e", + "identifier": "internalVMErrors", + "topics": [ + "AAAAAAAAAAAFAD5S7XbPyUCuwKIQ4n71QyoJX5sTBrg=", + "YWRk" + ], + "data": "CglydW50aW1lLmdvOjg1NiBbZXhlY3V0aW9uIGZhaWxlZF0gW2FkZF0KCXJ1bnRpbWUuZ286ODU2IFtleGVjdXRpb24gZmFpbGVkXSBbYWRkXQoJcnVudGltZS5nbzo4NTMgW2Z1bmN0aW9uIGRvZXMgbm90IGFjY2VwdCBFR0xEIHBheW1lbnRd", + "additionalData": [ + "CglydW50aW1lLmdvOjg1NiBbZXhlY3V0aW9uIGZhaWxlZF0gW2FkZF0KCXJ1bnRpbWUuZ286ODU2IFtleGVjdXRpb24gZmFpbGVkXSBbYWRkXQoJcnVudGltZS5nbzo4NTMgW2Z1bmN0aW9uIGRvZXMgbm90IGFjY2VwdCBFR0xEIHBheW1lbnRd" + ] + } + ] + }, + "status": "success", + "operation": "transfer", + "function": "add", + "isRelayed": true +} \ No newline at end of file From 1f2d5930888ca7c98ff7ad052d9c765ad382c9ca Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 11 Sep 2024 13:13:17 +0300 Subject: [PATCH 66/99] new line at the end of newly added test json --- node/external/transactionAPI/testData/failedRelayedV1.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/node/external/transactionAPI/testData/failedRelayedV1.json b/node/external/transactionAPI/testData/failedRelayedV1.json index 5f1a72c8c33..e2b1be88bee 100644 --- a/node/external/transactionAPI/testData/failedRelayedV1.json +++ b/node/external/transactionAPI/testData/failedRelayedV1.json @@ -9,7 +9,6 @@ "sender": "erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6", "gasPrice": 1000000000, "gasLimit": 6148000, - "gasUsed": 6148000, "data": "cmVsYXllZFR4QDdiMjI2ZTZmNmU2MzY1MjIzYTM0MzcyYzIyNzM2NTZlNjQ2NTcyMjIzYTIyNGQ1NzJmNTQ2NTMyMzA0ODQ0NTA2ZTMyNzg2NTMzNGQ1MDQzNmI2NTcwNjU2ZDRjNDI1NDQzNzM0OTQ0NTAyZjc5Mzc0NzY4NmE3NjU2NDY2OTYyNTEzZDIyMmMyMjcyNjU2MzY1Njk3NjY1NzIyMjNhMjI0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDY0MTQ0MzU1MzM3NTg2MjUwNzk1NTQzNzU3NzRiNDk1MTM0NmUzNzMxNTE3OTZmNGE1ODM1NzM1NDQyNzI2NzNkMjIyYzIyNzY2MTZjNzU2NTIyM2EzMTMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDJjMjI2NzYxNzM1MDcyNjk2MzY1MjIzYTMxMzAzMDMwMzAzMDMwMzAzMDMwMmMyMjY3NjE3MzRjNjk2ZDY5NzQyMjNhMzUzMDMwMzAzMDMwMzAyYzIyNjQ2MTc0NjEyMjNhMjI1OTU3NTI2YjUxNDQ0MTc4NTE0NDQxNzk1MTQ0NDE3YTUxNDQ0MTMwNTE0NDQxMzEyMjJjMjI3MzY5Njc2ZTYxNzQ3NTcyNjUyMjNhMjI3NjRjNjQ2ZDMyMmY0ZTQ0NTQ0NDc3MzgzMTMxNTEzMDYyNzgyYjU4NGI1MTc4NTA0NTJmNzY0OTU3NDM2ODRlNzI2OTU1NmE3ODcyNzAyZjU5Mzg1MDRlNzI0ZDQ1NmM2NTQ3NmUzNTMxNTM3NjUyNTk2NDQ3MzQ2ZjQ3NTc3MjQ5Njk0MzQ4Mzk2YTMxNzY0ZjRiNmY1OTJmNDg1NTUyNjE0ZTQxNDg0MjUxM2QzZDIyMmMyMjYzNjg2MTY5NmU0OTQ0MjIzYTIyNTY0MTNkM2QyMjJjMjI3NjY1NzI3MzY5NmY2ZTIyM2EzMjdk", "sourceShard": 0, "destinationShard": 0, @@ -58,4 +57,4 @@ "operation": "transfer", "function": "add", "isRelayed": true -} \ No newline at end of file +} From 7becc67db2e307548cb0ebaf144d2141758b22fe Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 11 Sep 2024 13:40:56 +0300 Subject: [PATCH 67/99] added missing epoch for inner tx --- node/external/transactionAPI/gasUsedAndFeeProcessor.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 7f957f50ece..530b6b81b3d 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -125,7 +125,8 @@ func (gfp *gasUsedAndFeeProcessor) handleRelayedV1(args [][]byte, tx *transactio fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ - Tx: innerTx, + Tx: innerTx, + Epoch: tx.Epoch, }) return big.NewInt(0).Add(fee, innerFee), true @@ -146,7 +147,8 @@ func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transactio fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ - Tx: innerTx, + Tx: innerTx, + Epoch: tx.Epoch, }) return big.NewInt(0).Add(fee, innerFee), true From e37b5c29f7b8702edf63d1d0e6d3804e92dbb09b Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Thu, 12 Sep 2024 14:55:08 +0300 Subject: [PATCH 68/99] update go mod and refactor some tests --- go.mod | 4 +- go.sum | 8 +- .../vm/esdtImprovements_test.go | 73 ++++++++++++++++++- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 857521f3966..f7148271aeb 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.14 - github.com/multiversx/mx-chain-vm-go v1.5.32 + github.com/multiversx/mx-chain-vm-common-go v1.5.15-0.20240912084229-e96c462e523d + github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 5eb00724155..b899383ae66 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.14 h1:QauClmsZVKnShhvAVkXndO4j25q361SPvt9dqdx1qlM= -github.com/multiversx/mx-chain-vm-common-go v1.5.14/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.32 h1:bEHKmXhjo2aHsx+cFDtKRV7/uq0yBip47gj9Xrl/B84= -github.com/multiversx/mx-chain-vm-go v1.5.32/go.mod h1:yjOCetRG0wFXm+IWGyioipdR959TYoR+FRdAGVq8xXw= +github.com/multiversx/mx-chain-vm-common-go v1.5.15-0.20240912084229-e96c462e523d h1:R/4JLgd6voLZPieHhHCh3uTztlSym0iDI8fkMpN4JAE= +github.com/multiversx/mx-chain-vm-common-go v1.5.15-0.20240912084229-e96c462e523d/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2 h1:p8pHfq+VhdKUp4oSP0QEjUkjAVLpXlCXnM4eS1vsGoo= +github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2/go.mod h1:3LmdbQOb+Fy3UqF9DtQ9j/RITetee9CHbEm+PV+JrC4= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 8f8417d9b84..10fdc804257 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -401,6 +401,18 @@ func checkMetaData( require.Equal(t, expectedMetaData.Attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) } +func checkReservedField( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + addressBytes []byte, + tokenID []byte, + shardID uint32, + expectedReservedField []byte, +) { + esdtData := getESDTDataFromAcc(t, cs, addressBytes, tokenID, shardID) + require.Equal(t, expectedReservedField, esdtData.Reserved) +} + func checkMetaDataNotInAcc( t *testing.T, cs testsChainSimulator.ChainSimulator, @@ -3861,7 +3873,7 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - + marshaller := cs.GetNodeHandler(0).GetCoreComponents().InternalMarshalizer() addrs := createAddresses(t, cs, true) log.Info("Register dynamic metaESDT token") @@ -3930,6 +3942,7 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, metaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, shardID, []byte{1}) log.Info("send metaEsdt cross shard") @@ -3964,8 +3977,19 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) expectedMetaData.Hash = newMetaData.Hash expectedMetaData.Attributes = newMetaData.Attributes + round := cs.GetNodeHandler(0).GetChainHandler().GetCurrentBlockHeader().GetRound() + reserved := &esdt.MetaDataVersion{ + Name: round, + Creator: round, + Hash: round, + Attributes: round, + } + firstVersion, _ := marshaller.Marshal(reserved) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, firstVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, metaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, []byte{1}) log.Info("send the update role to shard 2") @@ -3988,7 +4012,9 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) require.Equal(t, "success", txResult.Status.String()) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, firstVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, metaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, []byte{1}) retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, 2) require.Equal(t, uint64(0), retrievedMetaData.Nonce) @@ -4002,6 +4028,15 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) } require.Equal(t, 0, len(retrievedMetaData.Attributes)) + round2 := cs.GetNodeHandler(2).GetChainHandler().GetCurrentBlockHeader().GetRound() + reserved = &esdt.MetaDataVersion{ + URIs: round2, + Creator: round2, + Royalties: round2, + } + secondVersion, _ := cs.GetNodeHandler(shardID).GetCoreComponents().InternalMarshalizer().Marshal(reserved) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 2, secondVersion) + log.Info("transfer from shard 0 to shard 1 - should merge metaData") tx = esdtNFTTransferTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) @@ -4015,7 +4050,9 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) require.Nil(t, err) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, firstVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, firstVersion) log.Info("transfer from shard 1 to shard 2 - should merge metaData") @@ -4036,7 +4073,9 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) require.Nil(t, err) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, firstVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, firstVersion) latestMetaData := txsFee.GetDefaultMetaData() latestMetaData.Nonce = expectedMetaData.Nonce @@ -4047,6 +4086,17 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) latestMetaData.Uris = newMetaData2.Uris checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 2, latestMetaData) + reserved = &esdt.MetaDataVersion{ + Name: round, + Creator: round2, + Royalties: round2, + Hash: round, + URIs: round2, + Attributes: round, + } + thirdVersion, _ := cs.GetNodeHandler(shardID).GetCoreComponents().InternalMarshalizer().Marshal(reserved) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 2, thirdVersion) + log.Info("transfer from shard 2 to shard 0 - should update metaData") tx = setSpecialRoleTx(shard0Nonce, addrs[0].Bytes, addrs[2].Bytes, tokenID, [][]byte{[]byte(core.ESDTRoleTransfer)}) @@ -4065,8 +4115,29 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) require.Nil(t, err) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, latestMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, thirdVersion) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, firstVersion) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 2, latestMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 2, thirdVersion) + + log.Info("transfer from shard 1 to shard 0 - liquidity should be updated") + + tx = esdtNFTTransferTx(1, addrs[1].Bytes, addrs[0].Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, latestMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, thirdVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, firstVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 2, latestMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 2, thirdVersion) } func unsetSpecialRole( From 3ec3288f3c6f9c257309a201897842ed0514dc1d Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Thu, 12 Sep 2024 15:10:00 +0300 Subject: [PATCH 69/99] change github workflow --- .../build_and_run_chain_simulator_and_execute_system_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index 00c329dd3fa..f766ccddbf5 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -179,7 +179,7 @@ jobs: - name: Upload test report if: always() - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: pytest-report-${{ github.run_id }} path: reports/report.html From 4e58b182b7d88dd55e736ea058a944974e4472fc Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 12 Sep 2024 16:19:52 +0300 Subject: [PATCH 70/99] new indexer version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f7148271aeb..bd9b064e48c 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiversx/mx-chain-communication-go v1.1.0 github.com/multiversx/mx-chain-core-go v1.2.22 github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.8 + github.com/multiversx/mx-chain-es-indexer-go v1.7.9-0.20240912110120-3287bbe713da 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.16 diff --git a/go.sum b/go.sum index b899383ae66..5a11bafdc94 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.22 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pT github.com/multiversx/mx-chain-core-go v1.2.22/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.8 h1:ZDKTXkQhQ7lLi6huVrBTUssVEqCvaCxGH4Y52GapboQ= -github.com/multiversx/mx-chain-es-indexer-go v1.7.8/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.9-0.20240912110120-3287bbe713da h1:Dk0UXrr4rwMblSnsXWERKiqi1Jwa+bWIrLn7J03ixZU= +github.com/multiversx/mx-chain-es-indexer-go v1.7.9-0.20240912110120-3287bbe713da/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= 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= From 82658db527c77c3790d33d06a9c41310944ac0a5 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 17 Sep 2024 14:53:03 +0300 Subject: [PATCH 71/99] updated deps to tags --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index bd9b064e48c..99629511184 100644 --- a/go.mod +++ b/go.mod @@ -17,12 +17,12 @@ require ( github.com/multiversx/mx-chain-communication-go v1.1.0 github.com/multiversx/mx-chain-core-go v1.2.22 github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.9-0.20240912110120-3287bbe713da + github.com/multiversx/mx-chain-es-indexer-go v1.7.9 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.15-0.20240912084229-e96c462e523d - github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2 + github.com/multiversx/mx-chain-vm-common-go v1.5.15 + github.com/multiversx/mx-chain-vm-go v1.5.33 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 5a11bafdc94..c9deff299f6 100644 --- a/go.sum +++ b/go.sum @@ -391,18 +391,18 @@ github.com/multiversx/mx-chain-core-go v1.2.22 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pT github.com/multiversx/mx-chain-core-go v1.2.22/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.9-0.20240912110120-3287bbe713da h1:Dk0UXrr4rwMblSnsXWERKiqi1Jwa+bWIrLn7J03ixZU= -github.com/multiversx/mx-chain-es-indexer-go v1.7.9-0.20240912110120-3287bbe713da/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.9 h1:rWq9phJu8GG6TtoJ5cL+MmhyReWCEyqBE5ymXUvudCg= +github.com/multiversx/mx-chain-es-indexer-go v1.7.9/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.15-0.20240912084229-e96c462e523d h1:R/4JLgd6voLZPieHhHCh3uTztlSym0iDI8fkMpN4JAE= -github.com/multiversx/mx-chain-vm-common-go v1.5.15-0.20240912084229-e96c462e523d/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2 h1:p8pHfq+VhdKUp4oSP0QEjUkjAVLpXlCXnM4eS1vsGoo= -github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2/go.mod h1:3LmdbQOb+Fy3UqF9DtQ9j/RITetee9CHbEm+PV+JrC4= +github.com/multiversx/mx-chain-vm-common-go v1.5.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= +github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.33 h1:KM/qNf6xpg0rgLI4BwQRdleeFqLwI2QC3ZJpV/EIrzg= +github.com/multiversx/mx-chain-vm-go v1.5.33/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From 7173c623b909b3b5299a4294c8e13e16c42ddcfe Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 17 Sep 2024 14:02:26 +0000 Subject: [PATCH 72/99] errors for invalid signatures in crypto hooks; update vm version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 99629511184..39983f02e15 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.15 - github.com/multiversx/mx-chain-vm-go v1.5.33 + github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index c9deff299f6..35e134237be 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= github.com/multiversx/mx-chain-vm-common-go v1.5.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.33 h1:KM/qNf6xpg0rgLI4BwQRdleeFqLwI2QC3ZJpV/EIrzg= -github.com/multiversx/mx-chain-vm-go v1.5.33/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4 h1:Isk9b3npbJlfSzlTxiF8eZxt/sGJggkn6OhAt0P6YEs= +github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From e140ea3a733266f5f6755711de9c64d6e4a61f32 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 18 Sep 2024 13:42:46 +0300 Subject: [PATCH 73/99] new vm go tag --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 39983f02e15..b7041989903 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.15 - github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4 + github.com/multiversx/mx-chain-vm-go v1.5.34 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 35e134237be..7a40bc97102 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= github.com/multiversx/mx-chain-vm-common-go v1.5.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4 h1:Isk9b3npbJlfSzlTxiF8eZxt/sGJggkn6OhAt0P6YEs= -github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-go v1.5.34 h1:SPFMdO6E7sUYiFpZ41wtNOGfukR7Xqp6z5RA4sTSX9c= +github.com/multiversx/mx-chain-vm-go v1.5.34/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From a6d2fabb7a000eedc0f6fe39875f7d32a90f6381 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 18 Sep 2024 14:53:52 +0300 Subject: [PATCH 74/99] newer vm go tag --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b7041989903..ea003f03a1f 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.15 - github.com/multiversx/mx-chain-vm-go v1.5.34 + github.com/multiversx/mx-chain-vm-go v1.5.35 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 7a40bc97102..b0f8c511822 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= github.com/multiversx/mx-chain-vm-common-go v1.5.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.34 h1:SPFMdO6E7sUYiFpZ41wtNOGfukR7Xqp6z5RA4sTSX9c= -github.com/multiversx/mx-chain-vm-go v1.5.34/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-go v1.5.35 h1:UP6jjtI4L8beY5kYvqeNNtgn7CR4SM8XlHVtIYsQxS0= +github.com/multiversx/mx-chain-vm-go v1.5.35/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From cd5c81e107b13a044e3e6e49560e66e875f2a297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 23 Sep 2024 14:41:23 +0300 Subject: [PATCH 75/99] Optimize GH workflows. --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/build_and_test_macos.yml | 48 ++++++++++++++++++++++ .github/workflows/create_release.yml | 6 +-- .github/workflows/docker-keygenerator.yaml | 4 +- .github/workflows/golangci-lint.yml | 1 + 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/build_and_test_macos.yml diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index d552db889c7..efb1c939339 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -9,7 +9,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] + runs-on: [ubuntu-latest] runs-on: ${{ matrix.runs-on }} name: Build steps: diff --git a/.github/workflows/build_and_test_macos.yml b/.github/workflows/build_and_test_macos.yml new file mode 100644 index 00000000000..114a3bcd2b8 --- /dev/null +++ b/.github/workflows/build_and_test_macos.yml @@ -0,0 +1,48 @@ +name: Build and smoke test (MacOS) + +on: + pull_request: + branches: [master] + workflow_dispatch: + +jobs: + build: + strategy: + matrix: + runs-on: [macos-latest] + runs-on: ${{ matrix.runs-on }} + name: Build + steps: + - name: Set up Go 1.20.7 + uses: actions/setup-go@v3 + with: + go-version: 1.20.7 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + + - name: Get dependencies + run: | + go get -v -t -d ./... + if [ -f Gopkg.toml ]; then + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh + dep ensure + fi + + - name: Build + run: | + cd ${GITHUB_WORKSPACE}/cmd/node && go build . + cd ${GITHUB_WORKSPACE}/cmd/seednode && go build . + cd ${GITHUB_WORKSPACE}/cmd/keygenerator && go build . + cd ${GITHUB_WORKSPACE}/cmd/logviewer && go build . + cd ${GITHUB_WORKSPACE}/cmd/termui && go build . + + # On GitHub, we only run the short tests, and we only run them for some OS/ARCH combinations. + - name: Run tests + run: | + GOOS=$(go env GOOS) + + if [[ "$GOOS" == darwin ]]; then + go test -short -v ./... + fi diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index fe74d301325..bac2bab26b7 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -15,7 +15,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] + runs-on: [ubuntu-latest] runs-on: ${{ matrix.runs-on }} name: Build steps: @@ -129,7 +129,7 @@ jobs: zip -r -j ${ARCHIVE} ${BUILD_DIR} - name: Save artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ env.ARCHIVE }} path: ${{ env.ARCHIVE }} @@ -145,7 +145,7 @@ jobs: # https://docs.github.com/en/free-pro-team@latest/actions/guides/storing-workflow-data-as-artifacts#downloading-or-deleting-artifacts # A directory for each artifact is created using its name - name: Download all workflow run artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: path: assets diff --git a/.github/workflows/docker-keygenerator.yaml b/.github/workflows/docker-keygenerator.yaml index 5e4d9d44a32..c3cca7fc279 100644 --- a/.github/workflows/docker-keygenerator.yaml +++ b/.github/workflows/docker-keygenerator.yaml @@ -2,7 +2,6 @@ name: Build & push keygenerator docker image on: workflow_dispatch: - pull_request: jobs: build-docker-image: @@ -19,7 +18,6 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log into Docker Hub - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -32,5 +30,5 @@ jobs: context: . file: ./docker/keygenerator/Dockerfile platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} + push: true tags: multiversx/chain-keygenerator:latest diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 611fadc3d08..1cc46af26c8 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -5,6 +5,7 @@ on: - master pull_request: branches: [ master, feat/*, rc/* ] + workflow_dispatch: permissions: contents: read From 75156ecd26c8eafc977804ffe34bcf57e0cc0f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 23 Sep 2024 14:56:43 +0300 Subject: [PATCH 76/99] Simplification. --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/build_and_test_macos.yml | 48 ---------------------- 2 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 .github/workflows/build_and_test_macos.yml diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index efb1c939339..8f8985811cc 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -9,7 +9,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest] + runs-on: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.runs-on }} name: Build steps: diff --git a/.github/workflows/build_and_test_macos.yml b/.github/workflows/build_and_test_macos.yml deleted file mode 100644 index 114a3bcd2b8..00000000000 --- a/.github/workflows/build_and_test_macos.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Build and smoke test (MacOS) - -on: - pull_request: - branches: [master] - workflow_dispatch: - -jobs: - build: - strategy: - matrix: - runs-on: [macos-latest] - runs-on: ${{ matrix.runs-on }} - name: Build - steps: - - name: Set up Go 1.20.7 - uses: actions/setup-go@v3 - with: - go-version: 1.20.7 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v3 - - - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi - - - name: Build - run: | - cd ${GITHUB_WORKSPACE}/cmd/node && go build . - cd ${GITHUB_WORKSPACE}/cmd/seednode && go build . - cd ${GITHUB_WORKSPACE}/cmd/keygenerator && go build . - cd ${GITHUB_WORKSPACE}/cmd/logviewer && go build . - cd ${GITHUB_WORKSPACE}/cmd/termui && go build . - - # On GitHub, we only run the short tests, and we only run them for some OS/ARCH combinations. - - name: Run tests - run: | - GOOS=$(go env GOOS) - - if [[ "$GOOS" == darwin ]]; then - go test -short -v ./... - fi From 965682c1749bdfdbe35e06b82f16e5688b6197e6 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 23 Sep 2024 16:03:30 +0300 Subject: [PATCH 77/99] update vm common version and add integration tests --- go.mod | 4 +- go.sum | 8 +- .../vm/esdtImprovements_test.go | 117 +++++++++++++++++- 3 files changed, 121 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index ea003f03a1f..9668440bbf5 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.15 - github.com/multiversx/mx-chain-vm-go v1.5.35 + github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923123831-e44cdaa3a9ba + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index b0f8c511822..164339f5b75 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= -github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.35 h1:UP6jjtI4L8beY5kYvqeNNtgn7CR4SM8XlHVtIYsQxS0= -github.com/multiversx/mx-chain-vm-go v1.5.35/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923123831-e44cdaa3a9ba h1:UGKkWK2JJx09NG0b6Dv/BOrkptv7f9M5MNMY+X1yyvg= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923123831-e44cdaa3a9ba/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313 h1:O9XppzM+i/l553T2XpiPKMvIhdX9aOe0ze9S3Fpptkw= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313/go.mod h1:VIxYqss+koXj6qfy2c3geluFAZd2BC70YGv8MQlzAKU= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 10fdc804257..ed810c0150c 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -4017,7 +4017,7 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, []byte{1}) retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, 2) - require.Equal(t, uint64(0), retrievedMetaData.Nonce) + require.Equal(t, uint64(1), retrievedMetaData.Nonce) require.Equal(t, 0, len(retrievedMetaData.Name)) require.Equal(t, addrs[2].Bytes, retrievedMetaData.Creator) require.Equal(t, newMetaData2.Royalties, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Royalties)).Bytes()))) @@ -4330,7 +4330,6 @@ func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, metaData) - newMetaData.Nonce = []byte{} newMetaData.Attributes = []byte{} checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, newMetaData) @@ -4384,3 +4383,117 @@ func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, tokenID, 1) checkMetaData(t, cs, addrs[2].Bytes, tokenID, 2, mergedMetaData) } + +func TestChainSimulator_dynamicNFT_changeMetaDataForOneNFTShouldNotChangeOtherNonces(t *testing.T) { + t.Parallel() + + baseIssuingCost := "1000" + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + log.Info("Register dynamic NFT token") + + ticker := []byte("NFTTICKER") + tokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(tokenName)), + []byte(hex.EncodeToString(ticker)), + []byte(hex.EncodeToString([]byte("NFT"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + shard0Nonce := uint64(0) + tx := &transaction.Transaction{ + Nonce: shard0Nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + shard0Nonce++ + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + tokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, shard0Nonce, addrs[0], tokenID, roles) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 1) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(2).Bytes())) + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 1) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("give update role to another account and update metaData for nonce 2") + + shard0Nonce = transferSpecialRoleToAddr(t, cs, shard0Nonce, tokenID, addrs[0].Bytes, addrs[1].Bytes, []byte(core.ESDTRoleNFTUpdate)) + + newMetaData := &txsFee.MetaData{} + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(2).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Royalties = []byte(hex.EncodeToString(big.NewInt(15).Bytes())) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData, 0, addrs[1].Bytes) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + log.Info("transfer nft with nonce 1 - should not merge metaData") + + tx = esdtNFTTransferTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, metaData) +} From 61a1de9ae3058ff432d9ebb6d366d7c4a5e77e0f Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 23 Sep 2024 16:15:20 +0300 Subject: [PATCH 78/99] fix linter issue --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index ed810c0150c..e26b35c9a3a 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -4483,7 +4483,6 @@ func TestChainSimulator_dynamicNFT_changeMetaDataForOneNFTShouldNotChangeOtherNo log.Info("transfer nft with nonce 1 - should not merge metaData") tx = esdtNFTTransferTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) - shard0Nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) From 7c480fa3240343b9377cc5ebba29ac9442eb212b Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 23 Sep 2024 16:43:49 +0300 Subject: [PATCH 79/99] update go mod --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 9668440bbf5..8d4d271b7dd 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923123831-e44cdaa3a9ba - github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313 + github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 164339f5b75..b963afb82df 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923123831-e44cdaa3a9ba h1:UGKkWK2JJx09NG0b6Dv/BOrkptv7f9M5MNMY+X1yyvg= -github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923123831-e44cdaa3a9ba/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313 h1:O9XppzM+i/l553T2XpiPKMvIhdX9aOe0ze9S3Fpptkw= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313/go.mod h1:VIxYqss+koXj6qfy2c3geluFAZd2BC70YGv8MQlzAKU= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab h1:EcurAXYDlfnXtwPDz8tBBdbnh+ntsK6Dw77DL1/tVdI= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd h1:2vJk299/KQbtTE/dUmwFW8dkn0RTru0F7EqFqSyMneQ= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From 023dcb59390ed8420b70518767e1074332c523ce Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Mon, 23 Sep 2024 13:59:32 +0000 Subject: [PATCH 80/99] upgrade wasmer executor version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ea003f03a1f..f495ebcc9d3 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.15 - github.com/multiversx/mx-chain-vm-go v1.5.35 + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index b0f8c511822..0f06273f7b6 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= github.com/multiversx/mx-chain-vm-common-go v1.5.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.35 h1:UP6jjtI4L8beY5kYvqeNNtgn7CR4SM8XlHVtIYsQxS0= -github.com/multiversx/mx-chain-vm-go v1.5.35/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d h1:AZzDVIr5o12ZRRObHwneLlEiAUQhsrhr/x/hFMCxYeM= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From c69930e50f4c9c27123ab94a49e5c48d500fa10a Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 24 Sep 2024 14:19:45 +0000 Subject: [PATCH 81/99] update vm version --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index f495ebcc9d3..cc2c5233096 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.15 - github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d + github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 0f06273f7b6..788adc85758 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= -github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d h1:AZzDVIr5o12ZRRObHwneLlEiAUQhsrhr/x/hFMCxYeM= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab h1:EcurAXYDlfnXtwPDz8tBBdbnh+ntsK6Dw77DL1/tVdI= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5 h1:daWLWs7Ei99rpdScJlEUOjGfUItS2OAUJkDJux6BOBo= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From 87bda6fcddab7030ebad8b1ba469f662ad869e2f Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Wed, 25 Sep 2024 09:21:28 +0000 Subject: [PATCH 82/99] upgrade wasmer executor version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cc2c5233096..560cb07cdc8 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab - github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5 + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 788adc85758..b9c62be4605 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab h1:EcurAXYDlfnXtwPDz8tBBdbnh+ntsK6Dw77DL1/tVdI= github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5 h1:daWLWs7Ei99rpdScJlEUOjGfUItS2OAUJkDJux6BOBo= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3 h1:XxCQ6pHf6py8jUlg7BR8JaSPB92yj4/TK/HTLw6Bmg4= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From fa5fc0b6a66168804fb9d19fcf2b174015e65777 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Thu, 26 Sep 2024 08:42:19 +0000 Subject: [PATCH 83/99] upgrade wasmer executor version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 560cb07cdc8..f81cdfd8451 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab - github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3 + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240926083101-d10ec7c4e3f5 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index b9c62be4605..fd1a8286ebe 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab h1:EcurAXYDlfnXtwPDz8tBBdbnh+ntsK6Dw77DL1/tVdI= github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3 h1:XxCQ6pHf6py8jUlg7BR8JaSPB92yj4/TK/HTLw6Bmg4= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240926083101-d10ec7c4e3f5 h1:aVzZYR0Bro1na2MIeOcLmcAlel5IHcu5aap1VLT5w40= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240926083101-d10ec7c4e3f5/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From 7b855cd18da9f341d1c83b2e22872534570b6288 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 27 Sep 2024 15:31:24 +0300 Subject: [PATCH 84/99] updated mx-chain-vm-go to latest rc/v1.7.next1 --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 8d4d271b7dd..d2b76ce9593 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( 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.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab - github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd + 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 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index b963afb82df..0b789eb79b2 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab h1:EcurAXYDlfnXtwPDz8tBBdbnh+ntsK6Dw77DL1/tVdI= -github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd h1:2vJk299/KQbtTE/dUmwFW8dkn0RTru0F7EqFqSyMneQ= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= +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= +github.com/multiversx/mx-chain-vm-go v1.5.37/go.mod h1:nzLrWeXvfxCIiwj5uNBZq3d7stkXyeY+Fktfr4tTaiY= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From 4f16b0a52b5c7e65226f3794a8f1d4b03f4d9359 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 7 Oct 2024 12:35:19 +0300 Subject: [PATCH 85/99] add more integration tests --- .../vm/esdtImprovements_test.go | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index e26b35c9a3a..e0f23f1ce8c 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -4496,3 +4496,223 @@ func TestChainSimulator_dynamicNFT_changeMetaDataForOneNFTShouldNotChangeOtherNo metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, metaData) } + +func TestChainSimulator_dynamicNFT_updateBeforeCreateOnSameAccountShouldOverwrite(t *testing.T) { + t.Parallel() + + baseIssuingCost := "1000" + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + log.Info("Register dynamic NFT token") + + ticker := []byte("NFTTICKER") + tokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(tokenName)), + []byte(hex.EncodeToString(ticker)), + []byte(hex.EncodeToString([]byte("NFT"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + shard0Nonce := uint64(0) + tx := &transaction.Transaction{ + Nonce: shard0Nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + shard0Nonce++ + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + tokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, shard0Nonce, addrs[0], tokenID, roles) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("update meta data for a token that is not yet created") + + newMetaData := &txsFee.MetaData{} + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Royalties = []byte(hex.EncodeToString(big.NewInt(15).Bytes())) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData, shard0Nonce, addrs[0].Bytes) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + newMetaData.Attributes = []byte{} + newMetaData.Uris = [][]byte{} + checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, newMetaData) + + log.Info("create nft with the same nonce - should overwrite the metadata") + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 1) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, metaData) +} + +func TestChainSimulator_dynamicNFT_updateBeforeCreateOnDifferentAccountsShouldMergeMetaDataWhenTransferred(t *testing.T) { + t.Parallel() + + baseIssuingCost := "1000" + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + log.Info("Register dynamic NFT token") + + ticker := []byte("NFTTICKER") + tokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(tokenName)), + []byte(hex.EncodeToString(ticker)), + []byte(hex.EncodeToString([]byte("NFT"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + shard0Nonce := uint64(0) + tx := &transaction.Transaction{ + Nonce: shard0Nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + shard0Nonce++ + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + tokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, shard0Nonce, addrs[0], tokenID, roles) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("transfer update role to another address") + + shard0Nonce = transferSpecialRoleToAddr(t, cs, shard0Nonce, tokenID, addrs[0].Bytes, addrs[1].Bytes, []byte(core.ESDTRoleNFTUpdate)) + + log.Info("update meta data for a token that is not yet created") + + newMetaData := &txsFee.MetaData{} + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Royalties = []byte(hex.EncodeToString(big.NewInt(15).Bytes())) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData, 0, addrs[1].Bytes) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, tokenID, 0) + newMetaData.Attributes = []byte{} + newMetaData.Uris = [][]byte{} + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, newMetaData) + + log.Info("create nft with the same nonce on different account") + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 1) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, metaData) + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, newMetaData) + + log.Info("transfer dynamic NFT to the updated account") + + tx = esdtNFTTransferTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, tokenID, 0) + newMetaData.Attributes = metaData.Attributes + newMetaData.Uris = metaData.Uris + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, newMetaData) +} From 7005551274cc1b9d461e7ff86cd0fa5b374a2c60 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 18 Oct 2024 19:00:04 +0300 Subject: [PATCH 86/99] reverted relayed v3 --- api/groups/transactionGroup.go | 128 +--- api/groups/transactionGroup_test.go | 62 -- cmd/node/config/enableEpochs.toml | 7 +- common/constants.go | 4 - common/enablers/enableEpochsHandler.go | 6 - common/enablers/enableEpochsHandler_test.go | 11 +- config/epochConfig.go | 1 - config/tomlConfig_test.go | 16 +- .../epochStartInterceptorsContainerFactory.go | 2 - errors/errors.go | 3 - factory/interface.go | 1 - factory/mock/processComponentsStub.go | 6 - factory/processing/blockProcessorCreator.go | 146 ++--- .../processing/blockProcessorCreator_test.go | 2 - factory/processing/export_test.go | 6 +- factory/processing/processComponents.go | 24 +- .../processing/processComponentsHandler.go | 15 - .../processComponentsHandler_test.go | 2 - .../txSimulatorProcessComponents.go | 142 ++-- .../txSimulatorProcessComponents_test.go | 7 +- genesis/process/disabled/feeHandler.go | 5 - genesis/process/metaGenesisBlockCreator.go | 51 +- genesis/process/shardGenesisBlockCreator.go | 91 ++- go.mod | 4 +- go.sum | 8 +- .../relayedTx/relayedTx_test.go | 587 +---------------- .../mock/processComponentsStub.go | 6 - .../multiShard/relayedTx/common.go | 81 +-- .../multiShard/relayedTx/relayedTx_test.go | 4 - integrationTests/testHeartbeatNode.go | 2 - integrationTests/testInitializer.go | 21 +- integrationTests/testProcessorNode.go | 180 +++-- .../testProcessorNodeWithTestWebServer.go | 1 - integrationTests/vm/testInitializer.go | 225 +++---- integrationTests/vm/wasm/utils.go | 54 +- .../vm/wasm/wasmvm/wasmVM_test.go | 37 +- .../components/processComponents.go | 7 - .../components/processComponents_test.go | 1 - node/external/dtos.go | 35 +- .../transactionAPI/gasUsedAndFeeProcessor.go | 31 +- .../gasUsedAndFeeProcessor_test.go | 67 +- .../testData/relayedV3WithOneRefund.json | 56 -- node/external/transactionAPI/unmarshaller.go | 131 +--- node/metrics/metrics.go | 1 - node/metrics/metrics_test.go | 14 +- node/node.go | 36 +- node/node_test.go | 33 +- .../transactionsFeeProcessor.go | 47 +- process/block/preprocess/gasComputation.go | 2 +- process/constants.go | 4 - process/coordinator/transactionType.go | 9 - process/coordinator/transactionType_test.go | 26 - process/disabled/failedTxLogsAccumulator.go | 33 - process/disabled/relayedTxV3Processor.go | 23 - process/economics/economicsData.go | 98 --- process/economics/economicsData_test.go | 133 ---- process/errors.go | 45 -- process/factory/interceptorscontainer/args.go | 1 - .../metaInterceptorsContainerFactory.go | 1 - .../metaInterceptorsContainerFactory_test.go | 2 - .../shardInterceptorsContainerFactory.go | 1 - .../shardInterceptorsContainerFactory_test.go | 2 - .../factory/argInterceptedDataFactory.go | 1 - .../interceptedMetaHeaderDataFactory_test.go | 2 - .../factory/interceptedTxDataFactory.go | 4 - process/interface.go | 16 - .../processProxy/processProxy.go | 47 +- .../processProxy/processProxy_test.go | 8 +- .../processProxy/testProcessProxy.go | 47 +- process/smartContract/process_test.go | 12 +- .../smartContract/processorV2/processV2.go | 86 ++- .../smartContract/processorV2/process_test.go | 31 +- process/smartContract/scrCommon/common.go | 47 +- process/transaction/export_test.go | 6 +- process/transaction/interceptedTransaction.go | 83 +-- .../interceptedTransaction_test.go | 368 +---------- process/transaction/relayedTxV3Processor.go | 112 ---- .../transaction/relayedTxV3Processor_test.go | 249 ------- process/transaction/shardProcess.go | 327 ++-------- process/transaction/shardProcess_test.go | 613 +----------------- .../transactionEvaluator.go | 2 +- .../transactionLog/failedTxLogsAccumulator.go | 109 ---- .../failedTxLogsAccumulator_test.go | 168 ----- sharding/mock/enableEpochsHandlerMock.go | 15 - testscommon/components/default.go | 4 +- .../economicsDataHandlerStub.go | 19 - .../economicsmocks/economicsHandlerMock.go | 19 - .../failedTxLogsAccumulatorMock.go | 41 -- .../processMocks/relayedTxV3ProcessorMock.go | 23 - update/factory/exportHandlerFactory.go | 2 - update/factory/fullSyncInterceptors.go | 2 - 91 files changed, 808 insertions(+), 4442 deletions(-) delete mode 100644 node/external/transactionAPI/testData/relayedV3WithOneRefund.json delete mode 100644 process/disabled/failedTxLogsAccumulator.go delete mode 100644 process/disabled/relayedTxV3Processor.go delete mode 100644 process/transaction/relayedTxV3Processor.go delete mode 100644 process/transaction/relayedTxV3Processor_test.go delete mode 100644 process/transactionLog/failedTxLogsAccumulator.go delete mode 100644 process/transactionLog/failedTxLogsAccumulator_test.go delete mode 100644 testscommon/processMocks/failedTxLogsAccumulatorMock.go delete mode 100644 testscommon/processMocks/relayedTxV3ProcessorMock.go diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index 83eb97136b8..f35969ed701 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -197,23 +197,7 @@ func (tg *transactionGroup) simulateTransaction(c *gin.Context) { return } - innerTxs, err := tg.extractInnerTransactions(ftx.InnerTransactions) - if err != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return - } - - if len(innerTxs) == 0 { - innerTxs = nil - } - tx, txHash, err := tg.createTransaction(&ftx, innerTxs) + tx, txHash, err := tg.createTransaction(&ftx) if err != nil { c.JSON( http.StatusBadRequest, @@ -283,23 +267,7 @@ func (tg *transactionGroup) sendTransaction(c *gin.Context) { return } - innerTxs, err := tg.extractInnerTransactions(ftx.InnerTransactions) - if err != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return - } - - if len(innerTxs) == 0 { - innerTxs = nil - } - tx, txHash, err := tg.createTransaction(&ftx, innerTxs) + tx, txHash, err := tg.createTransaction(&ftx) if err != nil { c.JSON( http.StatusBadRequest, @@ -378,23 +346,7 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) { var start time.Time txsHashes := make(map[int]string) for idx, receivedTx := range ftxs { - innerTxs, errExtractInnerTransactions := tg.extractInnerTransactions(receivedTx.InnerTransactions) - if errExtractInnerTransactions != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), - Code: shared.ReturnCodeInternalError, - }, - ) - return - } - - if len(innerTxs) == 0 { - innerTxs = nil - } - tx, txHash, err = tg.createTransaction(&receivedTx, innerTxs) + tx, txHash, err = tg.createTransaction(&receivedTx) if err != nil { continue } @@ -556,23 +508,7 @@ func (tg *transactionGroup) computeTransactionGasLimit(c *gin.Context) { return } - innerTxs, errExtractInnerTransactions := tg.extractInnerTransactions(ftx.InnerTransactions) - if errExtractInnerTransactions != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errExtractInnerTransactions.Error()), - Code: shared.ReturnCodeInternalError, - }, - ) - return - } - - if len(innerTxs) == 0 { - innerTxs = nil - } - tx, _, err := tg.createTransaction(&ftx, innerTxs) + tx, _, err := tg.createTransaction(&ftx) if err != nil { c.JSON( http.StatusInternalServerError, @@ -782,25 +718,23 @@ func (tg *transactionGroup) getTransactionsPoolNonceGapsForSender(sender string, ) } -func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction, innerTxs []*transaction.Transaction) (*transaction.Transaction, []byte, error) { +func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction) (*transaction.Transaction, []byte, error) { txArgs := &external.ArgsCreateTransaction{ - Nonce: receivedTx.Nonce, - Value: receivedTx.Value, - Receiver: receivedTx.Receiver, - ReceiverUsername: receivedTx.ReceiverUsername, - Sender: receivedTx.Sender, - SenderUsername: receivedTx.SenderUsername, - GasPrice: receivedTx.GasPrice, - GasLimit: receivedTx.GasLimit, - DataField: receivedTx.Data, - SignatureHex: receivedTx.Signature, - ChainID: receivedTx.ChainID, - Version: receivedTx.Version, - Options: receivedTx.Options, - Guardian: receivedTx.GuardianAddr, - GuardianSigHex: receivedTx.GuardianSignature, - Relayer: receivedTx.Relayer, - InnerTransactions: innerTxs, + Nonce: receivedTx.Nonce, + Value: receivedTx.Value, + Receiver: receivedTx.Receiver, + ReceiverUsername: receivedTx.ReceiverUsername, + Sender: receivedTx.Sender, + SenderUsername: receivedTx.SenderUsername, + GasPrice: receivedTx.GasPrice, + GasLimit: receivedTx.GasLimit, + DataField: receivedTx.Data, + SignatureHex: receivedTx.Signature, + ChainID: receivedTx.ChainID, + Version: receivedTx.Version, + Options: receivedTx.Options, + Guardian: receivedTx.GuardianAddr, + GuardianSigHex: receivedTx.GuardianSignature, } start := time.Now() tx, txHash, err := tg.getFacade().CreateTransaction(txArgs) @@ -906,28 +840,6 @@ func (tg *transactionGroup) getFacade() transactionFacadeHandler { return tg.facade } -func (tg *transactionGroup) extractInnerTransactions( - innerTransactions []*transaction.FrontendTransaction, -) ([]*transaction.Transaction, error) { - innerTxs := make([]*transaction.Transaction, 0, len(innerTransactions)) - if len(innerTransactions) != 0 { - for _, innerTx := range innerTransactions { - if len(innerTx.InnerTransactions) != 0 { - return innerTxs, errors.ErrRecursiveRelayedTxIsNotAllowed - } - - newInnerTx, _, err := tg.createTransaction(innerTx, nil) - if err != nil { - return innerTxs, err - } - - innerTxs = append(innerTxs, newInnerTx) - } - } - - return innerTxs, nil -} - // UpdateFacade will update the facade func (tg *transactionGroup) UpdateFacade(newFacade interface{}) error { if newFacade == nil { diff --git a/api/groups/transactionGroup_test.go b/api/groups/transactionGroup_test.go index e517f51f8bd..9f603412ae0 100644 --- a/api/groups/transactionGroup_test.go +++ b/api/groups/transactionGroup_test.go @@ -312,7 +312,6 @@ func TestTransactionGroup_sendTransaction(t *testing.T) { expectedErr, ) }) - t.Run("recursive relayed v3 should error", testRecursiveRelayedV3("/transaction/send")) t.Run("should work", func(t *testing.T) { t.Parallel() @@ -591,7 +590,6 @@ func TestTransactionGroup_computeTransactionGasLimit(t *testing.T) { expectedErr, ) }) - t.Run("recursive relayed v3 should error", testRecursiveRelayedV3("/transaction/cost")) t.Run("should work", func(t *testing.T) { t.Parallel() @@ -712,7 +710,6 @@ func TestTransactionGroup_simulateTransaction(t *testing.T) { expectedErr, ) }) - t.Run("recursive relayed v3 should error", testRecursiveRelayedV3("/transaction/simulate")) t.Run("should work", func(t *testing.T) { t.Parallel() @@ -1201,62 +1198,3 @@ func getTransactionRoutesConfig() config.ApiRoutesConfig { }, } } - -func testRecursiveRelayedV3(url string) func(t *testing.T) { - return func(t *testing.T) { - t.Parallel() - - facade := &mock.FacadeStub{ - CreateTransactionHandler: func(txArgs *external.ArgsCreateTransaction) (*dataTx.Transaction, []byte, error) { - txHash, _ := hex.DecodeString(hexTxHash) - return nil, txHash, nil - }, - SendBulkTransactionsHandler: func(txs []*dataTx.Transaction) (u uint64, err error) { - return 1, nil - }, - ValidateTransactionHandler: func(tx *dataTx.Transaction) error { - return nil - }, - } - - userTx1 := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s"}`, - nonce, - sender, - receiver, - value, - signature, - ) - userTx2 := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransactions":[%s]}`, - nonce, - sender, - receiver, - value, - signature, - userTx1, - ) - tx := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransactions":[%s]}`, - nonce, - sender, - receiver, - value, - signature, - userTx2, - ) - - transactionGroup, err := groups.NewTransactionGroup(facade) - require.NoError(t, err) - - ws := startWebServer(transactionGroup, "transaction", getTransactionRoutesConfig()) - - req, _ := http.NewRequest("POST", url, bytes.NewBuffer([]byte(tx))) - resp := httptest.NewRecorder() - ws.ServeHTTP(resp, req) - - txResp := shared.GenericAPIResponse{} - loadResponse(resp.Body, &txResp) - - assert.Equal(t, http.StatusBadRequest, resp.Code) - assert.True(t, strings.Contains(txResp.Error, apiErrors.ErrRecursiveRelayedTxIsNotAllowed.Error())) - assert.Empty(t, txResp.Data) - } -} diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 7f41c21468a..9ca2083a352 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -324,17 +324,14 @@ # UnjailCleanupEnableEpoch represents the epoch when the cleanup of the unjailed nodes is enabled UnJailCleanupEnableEpoch = 4 - # RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions V3 will be enabled - RelayedTransactionsV3EnableEpoch = 7 - # FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled - FixRelayedBaseCostEnableEpoch = 7 + FixRelayedBaseCostEnableEpoch = 4 # MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 9999999 # FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled - FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 7 + FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 4 # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ diff --git a/common/constants.go b/common/constants.go index cbcd0caa6c8..2b56d2f388b 100644 --- a/common/constants.go +++ b/common/constants.go @@ -495,9 +495,6 @@ const ( // MetricRelayedTransactionsV2EnableEpoch represents the epoch when the relayed transactions v2 is enabled MetricRelayedTransactionsV2EnableEpoch = "erd_relayed_transactions_v2_enable_epoch" - // MetricRelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions v3 is enabled - MetricRelayedTransactionsV3EnableEpoch = "erd_relayed_transactions_v3_enable_epoch" - // MetricFixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost is enabled MetricFixRelayedBaseCostEnableEpoch = "erd_fix_relayed_base_cost_enable_epoch" @@ -1234,7 +1231,6 @@ const ( EGLDInESDTMultiTransferFlag core.EnableEpochFlag = "EGLDInESDTMultiTransferFlag" CryptoOpcodesV2Flag core.EnableEpochFlag = "CryptoOpcodesV2Flag" UnJailCleanupFlag core.EnableEpochFlag = "UnJailCleanupFlag" - RelayedTransactionsV3Flag core.EnableEpochFlag = "RelayedTransactionsV3Flag" FixRelayedBaseCostFlag core.EnableEpochFlag = "FixRelayedBaseCostFlag" MultiESDTNFTTransferAndExecuteByUserFlag core.EnableEpochFlag = "MultiESDTNFTTransferAndExecuteByUserFlag" FixRelayedMoveBalanceToNonPayableSCFlag core.EnableEpochFlag = "FixRelayedMoveBalanceToNonPayableSCFlag" diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index cba4bb4fb4a..65cc7762796 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -762,12 +762,6 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.UnJailCleanupEnableEpoch, }, - common.RelayedTransactionsV3Flag: { - isActiveInEpoch: func(epoch uint32) bool { - return epoch >= handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch - }, - activationEpoch: handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch, - }, common.FixRelayedBaseCostFlag: { isActiveInEpoch: func(epoch uint32) bool { return epoch >= handler.enableEpochsConfig.FixRelayedBaseCostEnableEpoch diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index b7d8f27692d..d0f9191055e 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -119,11 +119,10 @@ func createEnableEpochsConfig() config.EnableEpochs { DynamicESDTEnableEpoch: 102, EGLDInMultiTransferEnableEpoch: 103, CryptoOpcodesV2EnableEpoch: 104, - RelayedTransactionsV3EnableEpoch: 105, - FixRelayedBaseCostEnableEpoch: 106, - MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 107, - FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 108, - UseGasBoundedShouldFailExecutionEnableEpoch: 110, + FixRelayedBaseCostEnableEpoch: 105, + MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 106, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107, + UseGasBoundedShouldFailExecutionEnableEpoch: 108, } } @@ -324,7 +323,6 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) { require.True(t, handler.IsFlagEnabled(common.StakingV4StartedFlag)) require.True(t, handler.IsFlagEnabled(common.AlwaysMergeContextsInEEIFlag)) require.True(t, handler.IsFlagEnabled(common.DynamicESDTFlag)) - require.True(t, handler.IsFlagEnabled(common.RelayedTransactionsV3Flag)) require.True(t, handler.IsFlagEnabled(common.FixRelayedBaseCostFlag)) require.True(t, handler.IsFlagEnabled(common.FixRelayedMoveBalanceToNonPayableSCFlag)) } @@ -447,7 +445,6 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.DynamicESDTEnableEpoch, handler.GetActivationEpoch(common.DynamicESDTFlag)) require.Equal(t, cfg.EGLDInMultiTransferEnableEpoch, handler.GetActivationEpoch(common.EGLDInESDTMultiTransferFlag)) require.Equal(t, cfg.CryptoOpcodesV2EnableEpoch, handler.GetActivationEpoch(common.CryptoOpcodesV2Flag)) - require.Equal(t, cfg.RelayedTransactionsV3EnableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV3Flag)) require.Equal(t, cfg.FixRelayedBaseCostEnableEpoch, handler.GetActivationEpoch(common.FixRelayedBaseCostFlag)) require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.MultiESDTNFTTransferAndExecuteByUserFlag)) require.Equal(t, cfg.FixRelayedMoveBalanceToNonPayableSCEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceToNonPayableSCFlag)) diff --git a/config/epochConfig.go b/config/epochConfig.go index e24c302b7d0..a7fd67c680a 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -119,7 +119,6 @@ type EnableEpochs struct { EGLDInMultiTransferEnableEpoch uint32 CryptoOpcodesV2EnableEpoch uint32 UnJailCleanupEnableEpoch uint32 - RelayedTransactionsV3EnableEpoch uint32 FixRelayedBaseCostEnableEpoch uint32 MultiESDTNFTTransferAndExecuteByUserEnableEpoch uint32 FixRelayedMoveBalanceToNonPayableSCEnableEpoch uint32 diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index f331917c5d0..e7095b0b096 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -875,17 +875,14 @@ func TestEnableEpochConfig(t *testing.T) { # CryptoOpcodesV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled CryptoOpcodesV2EnableEpoch = 98 - # RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions V3 will be enabled - RelayedTransactionsV3EnableEpoch = 99 - # FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled - FixRelayedBaseCostEnableEpoch = 100 + FixRelayedBaseCostEnableEpoch = 99 # MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled - MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 101 + MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 100 # FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled - FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 102 + FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 101 # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ @@ -1004,10 +1001,9 @@ func TestEnableEpochConfig(t *testing.T) { DynamicESDTEnableEpoch: 96, EGLDInMultiTransferEnableEpoch: 97, CryptoOpcodesV2EnableEpoch: 98, - RelayedTransactionsV3EnableEpoch: 99, - FixRelayedBaseCostEnableEpoch: 100, - MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 101, - FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 102, + FixRelayedBaseCostEnableEpoch: 99, + MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 100, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 101, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go b/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go index 0ebf8417d7b..d659989896b 100644 --- a/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go +++ b/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go @@ -14,7 +14,6 @@ import ( disabledFactory "github.com/multiversx/mx-chain-go/factory/disabled" disabledGenesis "github.com/multiversx/mx-chain-go/genesis/process/disabled" "github.com/multiversx/mx-chain-go/process" - processDisabled "github.com/multiversx/mx-chain-go/process/disabled" "github.com/multiversx/mx-chain-go/process/factory/interceptorscontainer" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/storage/cache" @@ -109,7 +108,6 @@ func NewEpochStartInterceptorsContainer(args ArgsEpochStartInterceptorContainer) FullArchivePeerShardMapper: fullArchivePeerShardMapper, HardforkTrigger: hardforkTrigger, NodeOperationMode: args.NodeOperationMode, - RelayedTxV3Processor: processDisabled.NewRelayedTxV3Processor(), } interceptorsContainerFactory, err := interceptorscontainer.NewMetaInterceptorsContainerFactory(containerFactoryArgs) diff --git a/errors/errors.go b/errors/errors.go index b1edc990afc..dd475327876 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -598,6 +598,3 @@ var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker") // ErrNilEpochSystemSCProcessor defines the error for setting a nil EpochSystemSCProcessor var ErrNilEpochSystemSCProcessor = errors.New("nil epoch system SC processor") - -// ErrNilRelayedTxV3Processor signals that a nil relayed tx v3 processor has been provided -var ErrNilRelayedTxV3Processor = errors.New("nil relayed tx v3 processor") diff --git a/factory/interface.go b/factory/interface.go index ec92f478992..0f1c237d0d9 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -311,7 +311,6 @@ type ProcessComponentsHolder interface { ReceiptsRepository() ReceiptsRepository SentSignaturesTracker() process.SentSignaturesTracker EpochSystemSCProcessor() process.EpochStartSystemSCProcessor - RelayedTxV3Processor() process.RelayedTxV3Processor IsInterfaceNil() bool } diff --git a/factory/mock/processComponentsStub.go b/factory/mock/processComponentsStub.go index 4a52413b7cd..32bbfaf2df3 100644 --- a/factory/mock/processComponentsStub.go +++ b/factory/mock/processComponentsStub.go @@ -58,7 +58,6 @@ type ProcessComponentsMock struct { ReceiptsRepositoryInternal factory.ReceiptsRepository SentSignaturesTrackerInternal process.SentSignaturesTracker EpochSystemSCProcessorInternal process.EpochStartSystemSCProcessor - RelayedTxV3ProcessorField process.RelayedTxV3Processor } // Create - @@ -291,11 +290,6 @@ func (pcm *ProcessComponentsMock) EpochSystemSCProcessor() process.EpochStartSys return pcm.EpochSystemSCProcessorInternal } -// RelayedTxV3Processor - -func (pcm *ProcessComponentsMock) RelayedTxV3Processor() process.RelayedTxV3Processor { - return pcm.RelayedTxV3ProcessorField -} - // IsInterfaceNil - func (pcm *ProcessComponentsMock) IsInterfaceNil() bool { return pcm == nil diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index c48a777f01c..0721efc6a23 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -38,7 +38,6 @@ import ( "github.com/multiversx/mx-chain-go/process/smartContract/scrCommon" "github.com/multiversx/mx-chain-go/process/throttle" "github.com/multiversx/mx-chain-go/process/transaction" - "github.com/multiversx/mx-chain-go/process/transactionLog" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/state/syncer" "github.com/multiversx/mx-chain-go/storage/txcache" @@ -70,7 +69,6 @@ func (pcf *processComponentsFactory) newBlockProcessor( blockCutoffProcessingHandler cutoff.BlockProcessingCutoffHandler, missingTrieNodesNotifier common.MissingTrieNodesNotifier, sentSignaturesTracker process.SentSignaturesTracker, - relayedTxV3Processor process.RelayedTxV3Processor, ) (*blockProcessorAndVmFactories, error) { shardCoordinator := pcf.bootstrapComponents.ShardCoordinator() if shardCoordinator.SelfId() < shardCoordinator.NumberOfShards() { @@ -89,7 +87,6 @@ func (pcf *processComponentsFactory) newBlockProcessor( blockCutoffProcessingHandler, missingTrieNodesNotifier, sentSignaturesTracker, - relayedTxV3Processor, ) } if shardCoordinator.SelfId() == core.MetachainShardId { @@ -131,7 +128,6 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( blockProcessingCutoffHandler cutoff.BlockProcessingCutoffHandler, missingTrieNodesNotifier common.MissingTrieNodesNotifier, sentSignaturesTracker process.SentSignaturesTracker, - relayedTxV3Processor process.RelayedTxV3Processor, ) (*blockProcessorAndVmFactories, error) { argsParser := smartContract.NewArgumentParser() @@ -233,11 +229,6 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( return nil, err } - err = pcf.coreData.EconomicsData().SetTxTypeHandler(txTypeHandler) - if err != nil { - return nil, err - } - gasHandler, err := preprocess.NewGasComputation( pcf.coreData.EconomicsData(), txTypeHandler, @@ -247,32 +238,30 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( return nil, err } - failedTxLogsAccumulator := transactionLog.NewFailedTxLogsAccumulator() txFeeHandler := postprocess.NewFeeAccumulator() argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: argsParser, - Hasher: pcf.coreData.Hasher(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - AccountsDB: pcf.state.AccountsAdapter(), - BlockChainHook: vmFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScrForwarder: scForwarder, - TxFeeHandler: txFeeHandler, - EconomicsFee: pcf.coreData.EconomicsData(), - GasHandler: gasHandler, - GasSchedule: pcf.gasSchedule, - TxLogsProcessor: pcf.txLogsProcessor, - TxTypeHandler: txTypeHandler, - IsGenesisProcessing: false, - BadTxForwarder: badTxInterim, - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: wasmVMChangeLocker, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + VmContainer: vmContainer, + ArgsParser: argsParser, + Hasher: pcf.coreData.Hasher(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + AccountsDB: pcf.state.AccountsAdapter(), + BlockChainHook: vmFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScrForwarder: scForwarder, + TxFeeHandler: txFeeHandler, + EconomicsFee: pcf.coreData.EconomicsData(), + GasHandler: gasHandler, + GasSchedule: pcf.gasSchedule, + TxLogsProcessor: pcf.txLogsProcessor, + TxTypeHandler: txTypeHandler, + IsGenesisProcessing: false, + BadTxForwarder: badTxInterim, + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: wasmVMChangeLocker, } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewScProcessor, pcf.epochNotifier) @@ -290,27 +279,25 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( } argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: pcf.state.AccountsAdapter(), - Hasher: pcf.coreData.Hasher(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - SignMarshalizer: pcf.coreData.TxMarshalizer(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScProcessor: scProcessorProxy, - TxFeeHandler: txFeeHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: pcf.coreData.EconomicsData(), - ReceiptForwarder: receiptTxInterim, - BadTxForwarder: badTxInterim, - ArgsParser: argsParser, - ScrForwarder: scForwarder, - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), - TxVersionChecker: pcf.coreData.TxVersionChecker(), - TxLogsProcessor: pcf.txLogsProcessor, - RelayedTxV3Processor: relayedTxV3Processor, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + Accounts: pcf.state.AccountsAdapter(), + Hasher: pcf.coreData.Hasher(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + SignMarshalizer: pcf.coreData.TxMarshalizer(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScProcessor: scProcessorProxy, + TxFeeHandler: txFeeHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: pcf.coreData.EconomicsData(), + ReceiptForwarder: receiptTxInterim, + BadTxForwarder: badTxInterim, + ArgsParser: argsParser, + ScrForwarder: scForwarder, + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), + TxVersionChecker: pcf.coreData.TxVersionChecker(), + TxLogsProcessor: pcf.txLogsProcessor, } transactionProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { @@ -570,11 +557,6 @@ func (pcf *processComponentsFactory) newMetaBlockProcessor( return nil, err } - err = pcf.coreData.EconomicsData().SetTxTypeHandler(txTypeHandler) - if err != nil { - return nil, err - } - gasHandler, err := preprocess.NewGasComputation( pcf.coreData.EconomicsData(), txTypeHandler, @@ -584,33 +566,31 @@ func (pcf *processComponentsFactory) newMetaBlockProcessor( return nil, err } - failedTxLogsAccumulator := transactionLog.NewFailedTxLogsAccumulator() txFeeHandler := postprocess.NewFeeAccumulator() enableEpochs := pcf.epochConfig.EnableEpochs argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: argsParser, - Hasher: pcf.coreData.Hasher(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - AccountsDB: pcf.state.AccountsAdapter(), - BlockChainHook: vmFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScrForwarder: scForwarder, - TxFeeHandler: txFeeHandler, - EconomicsFee: pcf.coreData.EconomicsData(), - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: pcf.gasSchedule, - TxLogsProcessor: pcf.txLogsProcessor, - IsGenesisProcessing: false, - BadTxForwarder: badTxForwarder, - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: wasmVMChangeLocker, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + VmContainer: vmContainer, + ArgsParser: argsParser, + Hasher: pcf.coreData.Hasher(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + AccountsDB: pcf.state.AccountsAdapter(), + BlockChainHook: vmFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScrForwarder: scForwarder, + TxFeeHandler: txFeeHandler, + EconomicsFee: pcf.coreData.EconomicsData(), + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: pcf.gasSchedule, + TxLogsProcessor: pcf.txLogsProcessor, + IsGenesisProcessing: false, + BadTxForwarder: badTxForwarder, + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: wasmVMChangeLocker, } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewScProcessor, pcf.epochNotifier) diff --git a/factory/processing/blockProcessorCreator_test.go b/factory/processing/blockProcessorCreator_test.go index 4fb8f8c5d7d..099fec4a82d 100644 --- a/factory/processing/blockProcessorCreator_test.go +++ b/factory/processing/blockProcessorCreator_test.go @@ -57,7 +57,6 @@ func Test_newBlockProcessorCreatorForShard(t *testing.T) { &testscommon.BlockProcessingCutoffStub{}, &testscommon.MissingTrieNodesNotifierStub{}, &testscommon.SentSignatureTrackerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) require.NoError(t, err) @@ -185,7 +184,6 @@ func Test_newBlockProcessorCreatorForMeta(t *testing.T) { &testscommon.BlockProcessingCutoffStub{}, &testscommon.MissingTrieNodesNotifierStub{}, &testscommon.SentSignatureTrackerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) require.NoError(t, err) diff --git a/factory/processing/export_test.go b/factory/processing/export_test.go index c82f01b3f6f..76e84d75fee 100644 --- a/factory/processing/export_test.go +++ b/factory/processing/export_test.go @@ -25,7 +25,6 @@ func (pcf *processComponentsFactory) NewBlockProcessor( blockProcessingCutoff cutoff.BlockProcessingCutoffHandler, missingTrieNodesNotifier common.MissingTrieNodesNotifier, sentSignaturesTracker process.SentSignaturesTracker, - relayedV3TxProcessor process.RelayedTxV3Processor, ) (process.BlockProcessor, process.EpochStartSystemSCProcessor, error) { blockProcessorComponents, err := pcf.newBlockProcessor( requestHandler, @@ -43,7 +42,6 @@ func (pcf *processComponentsFactory) NewBlockProcessor( blockProcessingCutoff, missingTrieNodesNotifier, sentSignaturesTracker, - relayedV3TxProcessor, ) if err != nil { return nil, nil, err @@ -53,6 +51,6 @@ func (pcf *processComponentsFactory) NewBlockProcessor( } // CreateAPITransactionEvaluator - -func (pcf *processComponentsFactory) CreateAPITransactionEvaluator(relayedV3TxProcessor process.RelayedTxV3Processor) (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) { - return pcf.createAPITransactionEvaluator(relayedV3TxProcessor) +func (pcf *processComponentsFactory) CreateAPITransactionEvaluator() (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) { + return pcf.createAPITransactionEvaluator() } diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 6f711a502ae..482343bbadf 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -62,7 +62,6 @@ import ( "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/process/sync" "github.com/multiversx/mx-chain-go/process/track" - "github.com/multiversx/mx-chain-go/process/transaction" "github.com/multiversx/mx-chain-go/process/transactionLog" "github.com/multiversx/mx-chain-go/process/txsSender" "github.com/multiversx/mx-chain-go/redundancy" @@ -134,7 +133,6 @@ type processComponents struct { receiptsRepository mainFactory.ReceiptsRepository sentSignaturesTracker process.SentSignaturesTracker epochSystemSCProcessor process.EpochStartSystemSCProcessor - relayedTxV3Processor process.RelayedTxV3Processor } // ProcessComponentsFactoryArgs holds the arguments needed to create a process components factory @@ -517,16 +515,6 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { return nil, err } - argsRelayedTxV3Processor := transaction.ArgRelayedTxV3Processor{ - EconomicsFee: pcf.coreData.EconomicsData(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - MaxTransactionsAllowed: pcf.config.RelayedTransactionConfig.MaxTransactionsAllowed, - } - relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(argsRelayedTxV3Processor) - if err != nil { - return nil, err - } - interceptorContainerFactory, blackListHandler, err := pcf.newInterceptorContainerFactory( headerSigVerifier, pcf.bootstrapComponents.HeaderIntegrityVerifier(), @@ -536,7 +524,6 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { mainPeerShardMapper, fullArchivePeerShardMapper, hardforkTrigger, - relayedTxV3Processor, ) if err != nil { return nil, err @@ -633,7 +620,6 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { blockCutoffProcessingHandler, pcf.state.MissingTrieNodesNotifier(), sentSignaturesTracker, - relayedTxV3Processor, ) if err != nil { return nil, err @@ -723,7 +709,7 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { return nil, err } - apiTransactionEvaluator, vmFactoryForTxSimulate, err := pcf.createAPITransactionEvaluator(relayedTxV3Processor) + apiTransactionEvaluator, vmFactoryForTxSimulate, err := pcf.createAPITransactionEvaluator() if err != nil { return nil, fmt.Errorf("%w when assembling components for the transactions simulator processor", err) } @@ -776,7 +762,6 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { accountsParser: pcf.accountsParser, receiptsRepository: receiptsRepository, sentSignaturesTracker: sentSignaturesTracker, - relayedTxV3Processor: relayedTxV3Processor, }, nil } @@ -1508,7 +1493,6 @@ func (pcf *processComponentsFactory) newInterceptorContainerFactory( mainPeerShardMapper *networksharding.PeerShardMapper, fullArchivePeerShardMapper *networksharding.PeerShardMapper, hardforkTrigger factory.HardforkTrigger, - relayedTxV3Processor process.RelayedTxV3Processor, ) (process.InterceptorsContainerFactory, process.TimeCacher, error) { nodeOperationMode := common.NormalOperation if pcf.prefConfigs.Preferences.FullArchive { @@ -1527,7 +1511,6 @@ func (pcf *processComponentsFactory) newInterceptorContainerFactory( fullArchivePeerShardMapper, hardforkTrigger, nodeOperationMode, - relayedTxV3Processor, ) } if shardCoordinator.SelfId() == core.MetachainShardId { @@ -1541,7 +1524,6 @@ func (pcf *processComponentsFactory) newInterceptorContainerFactory( fullArchivePeerShardMapper, hardforkTrigger, nodeOperationMode, - relayedTxV3Processor, ) } @@ -1681,7 +1663,6 @@ func (pcf *processComponentsFactory) newShardInterceptorContainerFactory( fullArchivePeerShardMapper *networksharding.PeerShardMapper, hardforkTrigger factory.HardforkTrigger, nodeOperationMode common.NodeOperation, - relayedTxV3Processor process.RelayedTxV3Processor, ) (process.InterceptorsContainerFactory, process.TimeCacher, error) { headerBlackList := cache.NewTimeCache(timeSpanForBadHeaders) shardInterceptorsContainerFactoryArgs := interceptorscontainer.CommonInterceptorsContainerFactoryArgs{ @@ -1715,7 +1696,6 @@ func (pcf *processComponentsFactory) newShardInterceptorContainerFactory( FullArchivePeerShardMapper: fullArchivePeerShardMapper, HardforkTrigger: hardforkTrigger, NodeOperationMode: nodeOperationMode, - RelayedTxV3Processor: relayedTxV3Processor, } interceptorContainerFactory, err := interceptorscontainer.NewShardInterceptorsContainerFactory(shardInterceptorsContainerFactoryArgs) @@ -1736,7 +1716,6 @@ func (pcf *processComponentsFactory) newMetaInterceptorContainerFactory( fullArchivePeerShardMapper *networksharding.PeerShardMapper, hardforkTrigger factory.HardforkTrigger, nodeOperationMode common.NodeOperation, - relayedTxV3Processor process.RelayedTxV3Processor, ) (process.InterceptorsContainerFactory, process.TimeCacher, error) { headerBlackList := cache.NewTimeCache(timeSpanForBadHeaders) metaInterceptorsContainerFactoryArgs := interceptorscontainer.CommonInterceptorsContainerFactoryArgs{ @@ -1770,7 +1749,6 @@ func (pcf *processComponentsFactory) newMetaInterceptorContainerFactory( FullArchivePeerShardMapper: fullArchivePeerShardMapper, HardforkTrigger: hardforkTrigger, NodeOperationMode: nodeOperationMode, - RelayedTxV3Processor: relayedTxV3Processor, } interceptorContainerFactory, err := interceptorscontainer.NewMetaInterceptorsContainerFactory(metaInterceptorsContainerFactoryArgs) diff --git a/factory/processing/processComponentsHandler.go b/factory/processing/processComponentsHandler.go index 94f21a5b8f2..28b3c4b0eed 100644 --- a/factory/processing/processComponentsHandler.go +++ b/factory/processing/processComponentsHandler.go @@ -180,9 +180,6 @@ func (m *managedProcessComponents) CheckSubcomponents() error { if check.IfNil(m.processComponents.epochSystemSCProcessor) { return errors.ErrNilEpochSystemSCProcessor } - if check.IfNil(m.processComponents.relayedTxV3Processor) { - return errors.ErrNilRelayedTxV3Processor - } return nil } @@ -691,18 +688,6 @@ func (m *managedProcessComponents) EpochSystemSCProcessor() process.EpochStartSy return m.processComponents.epochSystemSCProcessor } -// RelayedTxV3Processor returns the relayed tx v3 processor -func (m *managedProcessComponents) RelayedTxV3Processor() process.RelayedTxV3Processor { - m.mutProcessComponents.RLock() - defer m.mutProcessComponents.RUnlock() - - if m.processComponents == nil { - return nil - } - - return m.processComponents.relayedTxV3Processor -} - // IsInterfaceNil returns true if the interface is nil func (m *managedProcessComponents) IsInterfaceNil() bool { return m == nil diff --git a/factory/processing/processComponentsHandler_test.go b/factory/processing/processComponentsHandler_test.go index c999d25b041..2aec3cb8c6e 100644 --- a/factory/processing/processComponentsHandler_test.go +++ b/factory/processing/processComponentsHandler_test.go @@ -94,7 +94,6 @@ func TestManagedProcessComponents_Create(t *testing.T) { require.True(t, check.IfNil(managedProcessComponents.FullArchiveInterceptorsContainer())) require.True(t, check.IfNil(managedProcessComponents.SentSignaturesTracker())) require.True(t, check.IfNil(managedProcessComponents.EpochSystemSCProcessor())) - require.True(t, check.IfNil(managedProcessComponents.RelayedTxV3Processor())) err := managedProcessComponents.Create() require.NoError(t, err) @@ -140,7 +139,6 @@ func TestManagedProcessComponents_Create(t *testing.T) { require.False(t, check.IfNil(managedProcessComponents.FullArchiveInterceptorsContainer())) require.False(t, check.IfNil(managedProcessComponents.SentSignaturesTracker())) require.False(t, check.IfNil(managedProcessComponents.EpochSystemSCProcessor())) - require.False(t, check.IfNil(managedProcessComponents.RelayedTxV3Processor())) require.Equal(t, factory.ProcessComponentsName, managedProcessComponents.String()) }) diff --git a/factory/processing/txSimulatorProcessComponents.go b/factory/processing/txSimulatorProcessComponents.go index 21fe2ddc073..257a46af1a5 100644 --- a/factory/processing/txSimulatorProcessComponents.go +++ b/factory/processing/txSimulatorProcessComponents.go @@ -27,7 +27,7 @@ import ( datafield "github.com/multiversx/mx-chain-vm-common-go/parsers/dataField" ) -func (pcf *processComponentsFactory) createAPITransactionEvaluator(relayedTxV3Processor process.RelayedTxV3Processor) (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) { +func (pcf *processComponentsFactory) createAPITransactionEvaluator() (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) { simulationAccountsDB, err := transactionEvaluator.NewSimulationAccountsDB(pcf.state.AccountsAdapterAPI()) if err != nil { return nil, nil, err @@ -47,7 +47,7 @@ func (pcf *processComponentsFactory) createAPITransactionEvaluator(relayedTxV3Pr return nil, nil, err } - txSimulatorProcessorArgs, vmContainerFactory, txTypeHandler, err := pcf.createArgsTxSimulatorProcessor(simulationAccountsDB, vmOutputCacher, txLogsProcessor, relayedTxV3Processor) + txSimulatorProcessorArgs, vmContainerFactory, txTypeHandler, err := pcf.createArgsTxSimulatorProcessor(simulationAccountsDB, vmOutputCacher, txLogsProcessor) if err != nil { return nil, nil, err } @@ -89,13 +89,12 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessor( accountsAdapter state.AccountsAdapter, vmOutputCacher storage.Cacher, txLogsProcessor process.TransactionLogProcessor, - relayedTxV3Processor process.RelayedTxV3Processor, ) (transactionEvaluator.ArgsTxSimulator, process.VirtualMachinesContainerFactory, process.TxTypeHandler, error) { shardID := pcf.bootstrapComponents.ShardCoordinator().SelfId() if shardID == core.MetachainShardId { return pcf.createArgsTxSimulatorProcessorForMeta(accountsAdapter, vmOutputCacher, txLogsProcessor) } else { - return pcf.createArgsTxSimulatorProcessorShard(accountsAdapter, vmOutputCacher, txLogsProcessor, relayedTxV3Processor) + return pcf.createArgsTxSimulatorProcessorShard(accountsAdapter, vmOutputCacher, txLogsProcessor) } } @@ -173,32 +172,29 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorForMeta( return args, nil, nil, err } - failedTxLogsAccumulator := transactionLog.NewFailedTxLogsAccumulator() - scProcArgs := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: smartContract.NewArgumentParser(), - Hasher: pcf.coreData.Hasher(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - AccountsDB: accountsAdapter, - BlockChainHook: vmContainerFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScrForwarder: scForwarder, - TxFeeHandler: &processDisabled.FeeHandler{}, - EconomicsFee: pcf.coreData.EconomicsData(), - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: pcf.gasSchedule, - TxLogsProcessor: txLogsProcessor, - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - BadTxForwarder: badTxInterim, - VMOutputCacher: vmOutputCacher, - WasmVMChangeLocker: pcf.coreData.WasmVMChangeLocker(), - IsGenesisProcessing: false, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + VmContainer: vmContainer, + ArgsParser: smartContract.NewArgumentParser(), + Hasher: pcf.coreData.Hasher(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + AccountsDB: accountsAdapter, + BlockChainHook: vmContainerFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScrForwarder: scForwarder, + TxFeeHandler: &processDisabled.FeeHandler{}, + EconomicsFee: pcf.coreData.EconomicsData(), + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: pcf.gasSchedule, + TxLogsProcessor: txLogsProcessor, + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + BadTxForwarder: badTxInterim, + VMOutputCacher: vmOutputCacher, + WasmVMChangeLocker: pcf.coreData.WasmVMChangeLocker(), + IsGenesisProcessing: false, } scProcessor, err := smartContract.NewSmartContractProcessor(scProcArgs) @@ -253,7 +249,6 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard( accountsAdapter state.AccountsAdapter, vmOutputCacher storage.Cacher, txLogsProcessor process.TransactionLogProcessor, - relayedTxV3Processor process.RelayedTxV3Processor, ) (transactionEvaluator.ArgsTxSimulator, process.VirtualMachinesContainerFactory, process.TxTypeHandler, error) { args := transactionEvaluator.ArgsTxSimulator{} @@ -351,32 +346,29 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard( argsParser := smartContract.NewArgumentParser() - failedTxLogsAccumulator := transactionLog.NewFailedTxLogsAccumulator() - scProcArgs := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: argsParser, - Hasher: pcf.coreData.Hasher(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - AccountsDB: accountsAdapter, - BlockChainHook: vmContainerFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScrForwarder: scForwarder, - TxFeeHandler: &processDisabled.FeeHandler{}, - EconomicsFee: pcf.coreData.EconomicsData(), - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: pcf.gasSchedule, - TxLogsProcessor: txLogsProcessor, - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - BadTxForwarder: badTxInterim, - VMOutputCacher: vmOutputCacher, - WasmVMChangeLocker: pcf.coreData.WasmVMChangeLocker(), - IsGenesisProcessing: false, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + VmContainer: vmContainer, + ArgsParser: argsParser, + Hasher: pcf.coreData.Hasher(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + AccountsDB: accountsAdapter, + BlockChainHook: vmContainerFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScrForwarder: scForwarder, + TxFeeHandler: &processDisabled.FeeHandler{}, + EconomicsFee: pcf.coreData.EconomicsData(), + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: pcf.gasSchedule, + TxLogsProcessor: txLogsProcessor, + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + BadTxForwarder: badTxInterim, + VMOutputCacher: vmOutputCacher, + WasmVMChangeLocker: pcf.coreData.WasmVMChangeLocker(), + IsGenesisProcessing: false, } scProcessor, err := smartContract.NewSmartContractProcessor(scProcArgs) @@ -385,27 +377,25 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard( } argsTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: accountsAdapter, - Hasher: pcf.coreData.Hasher(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - SignMarshalizer: pcf.coreData.TxMarshalizer(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScProcessor: scProcessor, - TxFeeHandler: txFeeHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: pcf.coreData.EconomicsData(), - ReceiptForwarder: receiptTxInterim, - BadTxForwarder: badTxInterim, - ArgsParser: argsParser, - ScrForwarder: scForwarder, - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - TxVersionChecker: pcf.coreData.TxVersionChecker(), - GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), - TxLogsProcessor: txLogsProcessor, - RelayedTxV3Processor: relayedTxV3Processor, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + Accounts: accountsAdapter, + Hasher: pcf.coreData.Hasher(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + SignMarshalizer: pcf.coreData.TxMarshalizer(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScProcessor: scProcessor, + TxFeeHandler: txFeeHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: pcf.coreData.EconomicsData(), + ReceiptForwarder: receiptTxInterim, + BadTxForwarder: badTxInterim, + ArgsParser: argsParser, + ScrForwarder: scForwarder, + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + TxVersionChecker: pcf.coreData.TxVersionChecker(), + GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), + TxLogsProcessor: txLogsProcessor, } txProcessor, err := transaction.NewTxProcessor(argsTxProcessor) diff --git a/factory/processing/txSimulatorProcessComponents_test.go b/factory/processing/txSimulatorProcessComponents_test.go index 37944768bfe..aad848600d8 100644 --- a/factory/processing/txSimulatorProcessComponents_test.go +++ b/factory/processing/txSimulatorProcessComponents_test.go @@ -8,7 +8,6 @@ import ( "github.com/multiversx/mx-chain-go/factory/processing" "github.com/multiversx/mx-chain-go/process/mock" "github.com/multiversx/mx-chain-go/testscommon/components" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/stretchr/testify/assert" ) @@ -27,7 +26,7 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { processArgs.Config.VMOutputCacher.Type = "invalid" pcf, _ := processing.NewProcessComponentsFactory(processArgs) - apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator(&processMocks.RelayedTxV3ProcessorMock{}) + apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator() assert.NotNil(t, err) assert.True(t, check.IfNil(apiTransactionEvaluator)) assert.True(t, check.IfNil(vmContainerFactory)) @@ -37,7 +36,7 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { processArgs := components.GetProcessComponentsFactoryArgs(shardCoordinatorForShardID2) pcf, _ := processing.NewProcessComponentsFactory(processArgs) - apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator(&processMocks.RelayedTxV3ProcessorMock{}) + apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator() assert.Nil(t, err) assert.False(t, check.IfNil(apiTransactionEvaluator)) assert.False(t, check.IfNil(vmContainerFactory)) @@ -46,7 +45,7 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { processArgs := components.GetProcessComponentsFactoryArgs(shardCoordinatorForMetachain) pcf, _ := processing.NewProcessComponentsFactory(processArgs) - apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator(&processMocks.RelayedTxV3ProcessorMock{}) + apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator() assert.Nil(t, err) assert.False(t, check.IfNil(apiTransactionEvaluator)) assert.False(t, check.IfNil(vmContainerFactory)) diff --git a/genesis/process/disabled/feeHandler.go b/genesis/process/disabled/feeHandler.go index f81e7e978eb..1fc34bbc2b5 100644 --- a/genesis/process/disabled/feeHandler.go +++ b/genesis/process/disabled/feeHandler.go @@ -183,11 +183,6 @@ func (fh *FeeHandler) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.TransactionWithF return big.NewInt(0) } -// ComputeRelayedTxFees returns 0 and 0 -func (fh *FeeHandler) ComputeRelayedTxFees(_ data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { - return big.NewInt(0), big.NewInt(0), nil -} - // IsInterfaceNil returns true if there is no value under the interface func (fh *FeeHandler) IsInterfaceNil() bool { return fh == nil diff --git a/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index 78546562736..f695c274b42 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -28,7 +28,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/coordinator" - disabledProcess "github.com/multiversx/mx-chain-go/process/disabled" "github.com/multiversx/mx-chain-go/process/factory" "github.com/multiversx/mx-chain-go/process/factory/metachain" disabledGuardian "github.com/multiversx/mx-chain-go/process/guardian/disabled" @@ -431,11 +430,6 @@ func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, enableEpoc return nil, err } - err = arg.Core.EconomicsData().SetTxTypeHandler(txTypeHandler) - if err != nil { - return nil, err - } - gasHandler, err := preprocess.NewGasComputation(arg.Economics, txTypeHandler, enableEpochsHandler) if err != nil { return nil, err @@ -443,29 +437,28 @@ func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, enableEpoc argsParser := smartContract.NewArgumentParser() argsNewSCProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: argsParser, - Hasher: arg.Core.Hasher(), - Marshalizer: arg.Core.InternalMarshalizer(), - AccountsDB: arg.Accounts, - BlockChainHook: virtualMachineFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncs, - PubkeyConv: arg.Core.AddressPubKeyConverter(), - ShardCoordinator: arg.ShardCoordinator, - ScrForwarder: scForwarder, - TxFeeHandler: genesisFeeHandler, - EconomicsFee: genesisFeeHandler, - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: arg.GasSchedule, - TxLogsProcessor: arg.TxLogsProcessor, - BadTxForwarder: badTxForwarder, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - IsGenesisProcessing: true, - WasmVMChangeLocker: &sync.RWMutex{}, // local Locker as to not interfere with the rest of the components - VMOutputCacher: txcache.NewDisabledCache(), - FailedTxLogsAccumulator: disabledProcess.NewFailedTxLogsAccumulator(), + VmContainer: vmContainer, + ArgsParser: argsParser, + Hasher: arg.Core.Hasher(), + Marshalizer: arg.Core.InternalMarshalizer(), + AccountsDB: arg.Accounts, + BlockChainHook: virtualMachineFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncs, + PubkeyConv: arg.Core.AddressPubKeyConverter(), + ShardCoordinator: arg.ShardCoordinator, + ScrForwarder: scForwarder, + TxFeeHandler: genesisFeeHandler, + EconomicsFee: genesisFeeHandler, + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: arg.GasSchedule, + TxLogsProcessor: arg.TxLogsProcessor, + BadTxForwarder: badTxForwarder, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + IsGenesisProcessing: true, + WasmVMChangeLocker: &sync.RWMutex{}, // local Locker as to not interfere with the rest of the components + VMOutputCacher: txcache.NewDisabledCache(), } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewSCProcessor, epochNotifier) diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index b44ed14c207..2347632d2d5 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -24,7 +24,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/coordinator" - processDisabled "github.com/multiversx/mx-chain-go/process/disabled" "github.com/multiversx/mx-chain-go/process/factory/shard" disabledGuardian "github.com/multiversx/mx-chain-go/process/guardian/disabled" "github.com/multiversx/mx-chain-go/process/receipts" @@ -501,40 +500,34 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo return nil, err } - err = arg.Core.EconomicsData().SetTxTypeHandler(txTypeHandler) - if err != nil { - return nil, err - } - gasHandler, err := preprocess.NewGasComputation(arg.Economics, txTypeHandler, enableEpochsHandler) if err != nil { return nil, err } argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: smartContract.NewArgumentParser(), - Hasher: arg.Core.Hasher(), - Marshalizer: arg.Core.InternalMarshalizer(), - AccountsDB: arg.Accounts, - BlockChainHook: vmFactoryImpl.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: arg.Core.AddressPubKeyConverter(), - ShardCoordinator: arg.ShardCoordinator, - ScrForwarder: scForwarder, - TxFeeHandler: genesisFeeHandler, - EconomicsFee: genesisFeeHandler, - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: arg.GasSchedule, - TxLogsProcessor: arg.TxLogsProcessor, - BadTxForwarder: badTxInterim, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - IsGenesisProcessing: true, - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: genesisWasmVMLocker, - FailedTxLogsAccumulator: processDisabled.NewFailedTxLogsAccumulator(), + VmContainer: vmContainer, + ArgsParser: smartContract.NewArgumentParser(), + Hasher: arg.Core.Hasher(), + Marshalizer: arg.Core.InternalMarshalizer(), + AccountsDB: arg.Accounts, + BlockChainHook: vmFactoryImpl.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: arg.Core.AddressPubKeyConverter(), + ShardCoordinator: arg.ShardCoordinator, + ScrForwarder: scForwarder, + TxFeeHandler: genesisFeeHandler, + EconomicsFee: genesisFeeHandler, + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: arg.GasSchedule, + TxLogsProcessor: arg.TxLogsProcessor, + BadTxForwarder: badTxInterim, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + IsGenesisProcessing: true, + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: genesisWasmVMLocker, } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewScProcessor, epochNotifier) @@ -552,27 +545,25 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo } argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: arg.Accounts, - Hasher: arg.Core.Hasher(), - PubkeyConv: arg.Core.AddressPubKeyConverter(), - Marshalizer: arg.Core.InternalMarshalizer(), - SignMarshalizer: arg.Core.TxMarshalizer(), - ShardCoordinator: arg.ShardCoordinator, - ScProcessor: scProcessorProxy, - TxFeeHandler: genesisFeeHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: genesisFeeHandler, - ReceiptForwarder: receiptTxInterim, - BadTxForwarder: badTxInterim, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: scForwarder, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - TxVersionChecker: arg.Core.TxVersionChecker(), - GuardianChecker: disabledGuardian.NewDisabledGuardedAccountHandler(), - TxLogsProcessor: arg.TxLogsProcessor, - RelayedTxV3Processor: processDisabled.NewRelayedTxV3Processor(), - FailedTxLogsAccumulator: processDisabled.NewFailedTxLogsAccumulator(), + Accounts: arg.Accounts, + Hasher: arg.Core.Hasher(), + PubkeyConv: arg.Core.AddressPubKeyConverter(), + Marshalizer: arg.Core.InternalMarshalizer(), + SignMarshalizer: arg.Core.TxMarshalizer(), + ShardCoordinator: arg.ShardCoordinator, + ScProcessor: scProcessorProxy, + TxFeeHandler: genesisFeeHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: genesisFeeHandler, + ReceiptForwarder: receiptTxInterim, + BadTxForwarder: badTxInterim, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: scForwarder, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + TxVersionChecker: arg.Core.TxVersionChecker(), + GuardianChecker: disabledGuardian.NewDisabledGuardedAccountHandler(), + TxLogsProcessor: arg.TxLogsProcessor, } transactionProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { diff --git a/go.mod b/go.mod index d2b76ce9593..8718f3e9d10 100644 --- a/go.mod +++ b/go.mod @@ -15,9 +15,9 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.22 + github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.9 + github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6 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.16 diff --git a/go.sum b/go.sum index 0b789eb79b2..232f91ed5a7 100644 --- a/go.sum +++ b/go.sum @@ -387,12 +387,12 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.22 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pTF333gWPpd+FNk= -github.com/multiversx/mx-chain-core-go v1.2.22/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c h1:hPCfMSj2vd9xNkARNxB1b3b9k8taFb+Xfja+WK97jno= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.9 h1:rWq9phJu8GG6TtoJ5cL+MmhyReWCEyqBE5ymXUvudCg= -github.com/multiversx/mx-chain-es-indexer-go v1.7.9/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6 h1:2F5WyCIvFVs4CONd9kJxibY1NIfJLYFAwqNJvC31qNA= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6/go.mod h1:AJew7KVcICVyVDlXpDQzvjcSnKs0aCYl7eXnJwg+15E= github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= 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= diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index fa2b02b9fe3..f7c0f74649b 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -4,7 +4,6 @@ import ( "encoding/hex" "encoding/json" "math/big" - "strconv" "strings" "testing" "time" @@ -18,9 +17,6 @@ import ( "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" - chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" - "github.com/multiversx/mx-chain-go/process" - "github.com/multiversx/mx-chain-go/sharding" "github.com/stretchr/testify/require" ) @@ -28,8 +24,6 @@ const ( defaultPathToInitialConfig = "../../../cmd/node/config/" minGasPrice = 1_000_000_000 minGasLimit = 50_000 - guardAccountCost = 250_000 - extraGasLimitForGuarded = minGasLimit gasPerDataByte = 1_500 txVersion = 2 mockTxSignature = "sig" @@ -38,383 +32,9 @@ const ( ) var ( - oneEGLD = big.NewInt(1000000000000000000) - alterConfigsFuncRelayedV3EarlyActivation = func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 - cfg.EpochConfig.EnableEpochs.FixRelayedBaseCostEnableEpoch = 1 - } + oneEGLD = big.NewInt(1000000000000000000) ) -func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - cs := startChainSimulator(t, alterConfigsFuncRelayedV3EarlyActivation) - defer cs.Close() - - initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(30000)) - relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - receiver, err := cs.GenerateAndMintWalletAddress(1, big.NewInt(0)) - require.NoError(t, err) - - err = cs.GenerateBlocks(1) - require.Nil(t, err) - - innerTx := generateTransaction(sender.Bytes, 0, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx.RelayerAddr = relayer.Bytes - - sender2, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - receiver2, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) - require.NoError(t, err) - - err = cs.GenerateBlocks(1) - require.Nil(t, err) - - innerTx2 := generateTransaction(sender2.Bytes, 0, receiver2.Bytes, oneEGLD, "", minGasLimit) - innerTx2.RelayerAddr = relayer.Bytes - - pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() - - // innerTx3Failure should fail due to less gas limit - // deploy a wrapper contract - owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - err = cs.GenerateBlocks(1) - require.Nil(t, err) - - scCode := wasm.GetSCCode("testData/egld-esdt-swap.wasm") - params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, hex.EncodeToString([]byte("WEGLD"))} - txDataDeploy := strings.Join(params, "@") - deployTx := generateTransaction(owner.Bytes, 0, make([]byte, 32), big.NewInt(0), txDataDeploy, 600000000) - - result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - scAddress := result.Logs.Events[0].Address - scAddressBytes, _ := pkConv.Decode(scAddress) - - // try a wrap transaction which will fail as the contract is paused - txDataWrap := "wrapEgld" - gasLimit := 2300000 - innerTx3Failure := generateTransaction(owner.Bytes, 1, scAddressBytes, big.NewInt(1), txDataWrap, uint64(gasLimit)) - innerTx3Failure.RelayerAddr = relayer.Bytes - - innerTx3 := generateTransaction(sender.Bytes, 1, receiver2.Bytes, oneEGLD, "", minGasLimit) - innerTx3.RelayerAddr = relayer.Bytes - - innerTxs := []*transaction.Transaction{innerTx, innerTx2, innerTx3Failure, innerTx3} - - // relayer will consume first a move balance for each inner tx, then the specific gas for each inner tx - relayedTxGasLimit := uint64(0) - for _, tx := range innerTxs { - relayedTxGasLimit += minGasLimit + tx.GasLimit - } - relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) - relayedTx.InnerTransactions = innerTxs - - result, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - // generate few more blocks for the cross shard scrs to be done - err = cs.GenerateBlocks(maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - economicsData := cs.GetNodeHandler(0).GetCoreComponents().EconomicsData() - relayerMoveBalanceFee := economicsData.ComputeMoveBalanceFee(relayedTx) - expectedRelayerFee := big.NewInt(0).Mul(relayerMoveBalanceFee, big.NewInt(int64(len(relayedTx.InnerTransactions)))) - for _, tx := range innerTxs { - expectedRelayerFee.Add(expectedRelayerFee, economicsData.ComputeTxFee(tx)) - } - checkBalance(t, cs, relayer, big.NewInt(0).Sub(initialBalance, expectedRelayerFee)) - - checkBalance(t, cs, sender, big.NewInt(0).Sub(initialBalance, big.NewInt(0).Mul(oneEGLD, big.NewInt(2)))) - - checkBalance(t, cs, sender2, big.NewInt(0).Sub(initialBalance, oneEGLD)) - - checkBalance(t, cs, receiver, oneEGLD) - - checkBalance(t, cs, receiver2, big.NewInt(0).Mul(oneEGLD, big.NewInt(2))) - - // check SCRs - shardC := cs.GetNodeHandler(0).GetShardCoordinator() - for _, scr := range result.SmartContractResults { - checkSCRSucceeded(t, cs, pkConv, shardC, scr) - } - - // 3 log events from the failed sc call - require.Equal(t, 3, len(result.Logs.Events)) - require.True(t, strings.Contains(string(result.Logs.Events[2].Data), "contract is paused")) -} - -func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorAndInvalidNonces(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - cs := startChainSimulator(t, alterConfigsFuncRelayedV3EarlyActivation) - defer cs.Close() - - initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(30000)) - relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - receiver, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) - require.NoError(t, err) - - err = cs.GenerateBlocks(1) - require.Nil(t, err) - - // bump sender nonce to 3 - tx0 := generateTransaction(sender.Bytes, 0, sender.Bytes, big.NewInt(0), "", minGasLimit) - tx1 := generateTransaction(sender.Bytes, 1, sender.Bytes, big.NewInt(0), "", minGasLimit) - tx2 := generateTransaction(sender.Bytes, 2, sender.Bytes, big.NewInt(0), "", minGasLimit) - _, err = cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1, tx2}, maxNumOfBlocksToGenerateWhenExecutingTx) - require.Nil(t, err) - - // higher nonce - innerTx1 := generateTransaction(sender.Bytes, 10, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx1.RelayerAddr = relayer.Bytes - - // higher nonce - innerTx2 := generateTransaction(sender.Bytes, 9, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx2.RelayerAddr = relayer.Bytes - - // nonce ok - innerTx3 := generateTransaction(sender.Bytes, 3, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx3.RelayerAddr = relayer.Bytes - - // higher nonce - innerTx4 := generateTransaction(sender.Bytes, 8, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx4.RelayerAddr = relayer.Bytes - - // lower nonce - initial one - innerTx5 := generateTransaction(sender.Bytes, 3, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx5.RelayerAddr = relayer.Bytes - - innerTxs := []*transaction.Transaction{innerTx1, innerTx2, innerTx3, innerTx4, innerTx5} - - // relayer will consume first a move balance for each inner tx, then the specific gas for each inner tx - relayedTxGasLimit := uint64(0) - for _, tx := range innerTxs { - relayedTxGasLimit += minGasLimit + tx.GasLimit - } - relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) - relayedTx.InnerTransactions = innerTxs - - result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - // 5 scrs, 4 from the failed txs + 1 with success - require.Equal(t, 5, len(result.SmartContractResults)) - scrsMap := make(map[string]int, len(result.SmartContractResults)) - for _, scr := range result.SmartContractResults { - if len(scr.ReturnMessage) == 0 { - scrsMap["success"]++ - } - if strings.Contains(scr.ReturnMessage, process.ErrHigherNonceInTransaction.Error()) { - scrsMap[process.ErrHigherNonceInTransaction.Error()]++ - } - if strings.Contains(scr.ReturnMessage, process.ErrLowerNonceInTransaction.Error()) { - scrsMap[process.ErrLowerNonceInTransaction.Error()]++ - } - } - require.Equal(t, 1, scrsMap["success"]) - require.Equal(t, 3, scrsMap[process.ErrHigherNonceInTransaction.Error()]) - require.Equal(t, 1, scrsMap[process.ErrLowerNonceInTransaction.Error()]) - - // 4 log events from the failed txs - require.Equal(t, 4, len(result.Logs.Events)) - for _, event := range result.Logs.Events { - require.Equal(t, core.SignalErrorOperation, event.Identifier) - } -} - -func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - cs := startChainSimulator(t, alterConfigsFuncRelayedV3EarlyActivation) - defer cs.Close() - - initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) - relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() - shardC := cs.GetNodeHandler(0).GetShardCoordinator() - - // deploy adder contract - owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - err = cs.GenerateBlocks(1) - require.Nil(t, err) - - ownerNonce := uint64(0) - scAddressBytes := deployAdder(t, cs, owner, ownerNonce) - scShard := shardC.ComputeId(scAddressBytes) - scShardNodeHandler := cs.GetNodeHandler(scShard) - - // 1st inner tx, successful add 1 - ownerNonce++ - txDataAdd := "add@" + hex.EncodeToString(big.NewInt(1).Bytes()) - innerTx1 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), txDataAdd, 5000000) - innerTx1.RelayerAddr = relayer.Bytes - - // 2nd inner tx, successful add 1 - ownerNonce++ - innerTx2 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), txDataAdd, 5000000) - innerTx2.RelayerAddr = relayer.Bytes - - // 3rd inner tx, wrong number of parameters - ownerNonce++ - innerTx3 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), "add", 5000000) - innerTx3.RelayerAddr = relayer.Bytes - - // 4th inner tx, successful add 1 - ownerNonce++ - innerTx4 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), txDataAdd, 5000000) - innerTx4.RelayerAddr = relayer.Bytes - - // 5th inner tx, invalid function - ownerNonce++ - innerTx5 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), "substract", 5000000) - innerTx5.RelayerAddr = relayer.Bytes - - // 6th inner tx, successful add 1 - ownerNonce++ - innerTx6 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), txDataAdd, 5000000) - innerTx6.RelayerAddr = relayer.Bytes - - // 7th inner tx, not enough gas - ownerNonce++ - innerTx7 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), txDataAdd, 100000) - innerTx7.RelayerAddr = relayer.Bytes - - innerTxs := []*transaction.Transaction{innerTx1, innerTx2, innerTx3, innerTx4, innerTx5, innerTx6, innerTx7} - - relayedTxGasLimit := uint64(0) - for _, tx := range innerTxs { - relayedTxGasLimit += minGasLimit + tx.GasLimit - } - relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) - relayedTx.InnerTransactions = innerTxs - - result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - checkSum(t, scShardNodeHandler, scAddressBytes, owner.Bytes, 4) - - // 8 scrs, 4 from the succeeded txs + 4 with refunded gas to relayer - require.Equal(t, 8, len(result.SmartContractResults)) - for _, scr := range result.SmartContractResults { - if strings.Contains(scr.ReturnMessage, "gas refund for relayer") { - continue - } - - checkSCRSucceeded(t, cs, pkConv, shardC, scr) - } - - // 6 events, 3 with signalError + 3 with the actual errors - require.Equal(t, 6, len(result.Logs.Events)) - expectedLogEvents := map[int]string{ - 1: "[wrong number of arguments]", - 3: "[invalid function (not found)] [substract]", - 5: "[not enough gas] [add]", - } - for idx, logEvent := range result.Logs.Events { - if logEvent.Identifier == "signalError" { - continue - } - - expectedLogEvent := expectedLogEvents[idx] - require.True(t, strings.Contains(string(logEvent.Data), expectedLogEvent)) - } -} - -func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInnerMoveBalanceToNonPayableSC(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - cs := startChainSimulator(t, func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 - cfg.EpochConfig.EnableEpochs.FixRelayedBaseCostEnableEpoch = 1 - cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 1 - }) - defer cs.Close() - - initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) - relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() - - // deploy adder contract - owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - err = cs.GenerateBlocks(1) - require.Nil(t, err) - - ownerNonce := uint64(0) - scCode := wasm.GetSCCode("testData/adder.wasm") - params := []string{scCode, wasm.VMTypeHex, "0000", "00"} - txDataDeploy := strings.Join(params, "@") - deployTx := generateTransaction(owner.Bytes, ownerNonce, make([]byte, 32), big.NewInt(0), txDataDeploy, 100000000) - - result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - scAddress := result.Logs.Events[0].Address - scAddressBytes, _ := pkConv.Decode(scAddress) - - balanceRelayerBefore := getBalance(t, cs, relayer) - balanceOwnerBefore := getBalance(t, cs, owner) - - // move balance to non-payable contract should only consume fees and sender's nonce - ownerNonce++ - innerTx1 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, oneEGLD, "", 50000) - innerTx1.RelayerAddr = relayer.Bytes - - // move balance to meta contract should only consume fees and sender's nonce - ownerNonce++ - innerTx2 := generateTransaction(owner.Bytes, ownerNonce, core.ESDTSCAddress, oneEGLD, "", 50000) - innerTx2.RelayerAddr = relayer.Bytes - - innerTxs := []*transaction.Transaction{innerTx1, innerTx2} - - relayedTxGasLimit := uint64(0) - for _, tx := range innerTxs { - relayedTxGasLimit += minGasLimit + tx.GasLimit - } - relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) - relayedTx.InnerTransactions = innerTxs - - _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - balanceRelayerAfter := getBalance(t, cs, relayer) - balanceOwnerAfter := getBalance(t, cs, owner) - consumedRelayedFee := core.SafeMul(relayedTxGasLimit, minGasPrice) - expectedBalanceRelayerAfter := big.NewInt(0).Sub(balanceRelayerBefore, consumedRelayedFee) - require.Equal(t, balanceOwnerBefore.String(), balanceOwnerAfter.String()) - require.Equal(t, expectedBalanceRelayerAfter.String(), balanceRelayerAfter.String()) -} - func TestFixRelayedMoveBalanceWithChainSimulator(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -594,131 +214,6 @@ func testFixRelayedMoveBalanceWithChainSimulatorMoveBalance( } } -func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInnerNotExecutable(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - cs := startChainSimulator(t, alterConfigsFuncRelayedV3EarlyActivation) - defer cs.Close() - - initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) - relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - sender2, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - guardian, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - err = cs.GenerateBlocks(1) - require.Nil(t, err) - - // Set guardian for sender - senderNonce := uint64(0) - setGuardianTxData := "SetGuardian@" + hex.EncodeToString(guardian.Bytes) + "@" + hex.EncodeToString([]byte("uuid")) - setGuardianGasLimit := minGasLimit + 1500*len(setGuardianTxData) + guardAccountCost - setGuardianTx := generateTransaction(sender.Bytes, senderNonce, sender.Bytes, big.NewInt(0), setGuardianTxData, uint64(setGuardianGasLimit)) - _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(setGuardianTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - // fast-forward until the guardian becomes active - err = cs.GenerateBlocks(roundsPerEpoch * 20) - require.NoError(t, err) - - // guard account - senderNonce++ - guardAccountTxData := "GuardAccount" - guardAccountGasLimit := minGasLimit + 1500*len(guardAccountTxData) + guardAccountCost - guardAccountTx := generateTransaction(sender.Bytes, senderNonce, sender.Bytes, big.NewInt(0), guardAccountTxData, uint64(guardAccountGasLimit)) - _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(guardAccountTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - receiver, err := cs.GenerateAndMintWalletAddress(1, big.NewInt(0)) - require.NoError(t, err) - - // move balance inner transaction non-executable due to guardian mismatch - senderNonce++ - innerTx := generateTransaction(sender.Bytes, senderNonce, receiver.Bytes, oneEGLD, "", minGasLimit+extraGasLimitForGuarded) - innerTx.RelayerAddr = relayer.Bytes - innerTx.GuardianAddr = sender.Bytes // this is not the real guardian - innerTx.GuardianSignature = []byte(mockTxSignature) - innerTx.Options = 2 - - // move balance inner transaction non-executable due to higher nonce - nonceTooHigh := uint64(100) - innerTx2 := generateTransaction(sender2.Bytes, nonceTooHigh, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx2.RelayerAddr = relayer.Bytes - - innerTxs := []*transaction.Transaction{innerTx, innerTx2} - - // relayer will consume first a move balance for each inner tx, then the specific gas for each inner tx - relayedTxGasLimit := uint64(0) - for _, tx := range innerTxs { - relayedTxGasLimit += minGasLimit + tx.GasLimit - } - relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) - relayedTx.InnerTransactions = innerTxs - - result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - // generate few more blocks for the cross shard scrs to be done - err = cs.GenerateBlocks(maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - // check the inner tx failed with the desired error - require.Equal(t, 2, len(result.SmartContractResults)) - require.True(t, strings.Contains(result.SmartContractResults[0].ReturnMessage, process.ErrTransactionNotExecutable.Error())) - require.True(t, strings.Contains(result.SmartContractResults[0].ReturnMessage, process.ErrTransactionAndAccountGuardianMismatch.Error())) - require.True(t, strings.Contains(result.SmartContractResults[1].ReturnMessage, process.ErrHigherNonceInTransaction.Error())) - - // check events - require.Equal(t, 2, len(result.Logs.Events)) - for _, event := range result.Logs.Events { - require.Equal(t, core.SignalErrorOperation, event.Identifier) - } - - // compute expected consumed fee for relayer - expectedConsumedGasForGuardedInnerTx := minGasLimit + minGasLimit + extraGasLimitForGuarded // invalid guardian - expectedConsumedGasForHigherNonceInnerTx := minGasLimit + minGasLimit // higher nonce - expectedConsumeGas := expectedConsumedGasForGuardedInnerTx + expectedConsumedGasForHigherNonceInnerTx - expectedRelayerFee := core.SafeMul(uint64(expectedConsumeGas), minGasPrice) - checkBalance(t, cs, relayer, big.NewInt(0).Sub(initialBalance, expectedRelayerFee)) - - checkBalance(t, cs, receiver, big.NewInt(0)) - - relayerBalanceBeforeSuccessfullAttempt := getBalance(t, cs, relayer) - - // generate a valid guarded move balance inner tx - // senderNonce would be the same, as previous failed tx didn't increase it(expected) - innerTx = generateTransaction(sender.Bytes, senderNonce, receiver.Bytes, oneEGLD, "", minGasLimit+extraGasLimitForGuarded) - innerTx.RelayerAddr = relayer.Bytes - innerTx.GuardianAddr = guardian.Bytes - innerTx.GuardianSignature = []byte(mockTxSignature) - innerTx.Options = 2 - - innerTxs = []*transaction.Transaction{innerTx} - relayedTx = generateTransaction(relayer.Bytes, 1, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) - relayedTx.InnerTransactions = innerTxs - - _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - // generate few more blocks for the cross shard scrs to be done - err = cs.GenerateBlocks(maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - expectedRelayerFee = core.SafeMul(uint64(expectedConsumedGasForGuardedInnerTx), minGasPrice) - checkBalance(t, cs, relayer, big.NewInt(0).Sub(relayerBalanceBeforeSuccessfullAttempt, expectedRelayerFee)) - - checkBalance(t, cs, receiver, oneEGLD) -} - func TestRelayedTransactionFeeField(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -726,8 +221,6 @@ func TestRelayedTransactionFeeField(t *testing.T) { cs := startChainSimulator(t, func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.RelayedTransactionsEnableEpoch = 1 - cfg.EpochConfig.EnableEpochs.RelayedTransactionsV2EnableEpoch = 1 - cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 cfg.EpochConfig.EnableEpochs.FixRelayedBaseCostEnableEpoch = 1 }) defer cs.Close() @@ -757,22 +250,6 @@ func TestRelayedTransactionFeeField(t *testing.T) { result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) require.NoError(t, err) - expectedFee := core.SafeMul(uint64(gasLimit), minGasPrice) - require.Equal(t, expectedFee.String(), result.Fee) - require.Equal(t, expectedFee.String(), result.InitiallyPaidFee) - require.Equal(t, uint64(gasLimit), result.GasUsed) - }) - t.Run("relayed v3", func(t *testing.T) { - innerTx := generateTransaction(sender.Bytes, 1, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx.RelayerAddr = relayer.Bytes - - gasLimit := minGasLimit + int(innerTx.GasLimit) - relayedTx := generateTransaction(relayer.Bytes, 1, relayer.Bytes, big.NewInt(0), "", uint64(gasLimit)) - relayedTx.InnerTransactions = []*transaction.Transaction{innerTx} - - result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - expectedFee := core.SafeMul(uint64(gasLimit), minGasPrice) require.Equal(t, expectedFee.String(), result.Fee) require.Equal(t, expectedFee.String(), result.InitiallyPaidFee) @@ -829,58 +306,6 @@ func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *bi } } -func checkSum( - t *testing.T, - nodeHandler chainSimulatorProcess.NodeHandler, - scAddress []byte, - callerAddress []byte, - expectedSum int, -) { - scQuery := &process.SCQuery{ - ScAddress: scAddress, - FuncName: "getSum", - CallerAddr: callerAddress, - CallValue: big.NewInt(0), - } - result, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(scQuery) - require.Nil(t, err) - require.Equal(t, "ok", result.ReturnCode) - - sum, err := strconv.Atoi(hex.EncodeToString(result.ReturnData[0])) - require.NoError(t, err) - - require.Equal(t, expectedSum, sum) -} - -func checkSCRSucceeded( - t *testing.T, - cs testsChainSimulator.ChainSimulator, - pkConv core.PubkeyConverter, - shardC sharding.Coordinator, - scr *transaction.ApiSmartContractResult, -) { - addr, err := pkConv.Decode(scr.RcvAddr) - require.NoError(t, err) - - senderShard := shardC.ComputeId(addr) - tx, err := cs.GetNodeHandler(senderShard).GetFacadeHandler().GetTransaction(scr.Hash, true) - require.NoError(t, err) - require.Equal(t, transaction.TxStatusSuccess, tx.Status) - - if tx.ReturnMessage == core.GasRefundForRelayerMessage { - return - } - - require.GreaterOrEqual(t, len(tx.Logs.Events), 1) - for _, event := range tx.Logs.Events { - if event.Identifier == core.WriteLogIdentifier { - continue - } - - require.Equal(t, core.CompletedTxEventIdentifier, event.Identifier) - } -} - func getBalance( t *testing.T, cs testsChainSimulator.ChainSimulator, @@ -895,16 +320,6 @@ func getBalance( return balance } -func checkBalance( - t *testing.T, - cs testsChainSimulator.ChainSimulator, - address dtos.WalletAddress, - expectedBalance *big.Int, -) { - balance := getBalance(t, cs, address) - require.Equal(t, expectedBalance.String(), balance.String()) -} - func deployAdder( t *testing.T, cs testsChainSimulator.ChainSimulator, diff --git a/integrationTests/mock/processComponentsStub.go b/integrationTests/mock/processComponentsStub.go index 04dad00a52c..11d4f4ce69d 100644 --- a/integrationTests/mock/processComponentsStub.go +++ b/integrationTests/mock/processComponentsStub.go @@ -61,7 +61,6 @@ type ProcessComponentsStub struct { ESDTDataStorageHandlerForAPIInternal vmcommon.ESDTNFTStorageHandler SentSignaturesTrackerInternal process.SentSignaturesTracker EpochSystemSCProcessorInternal process.EpochStartSystemSCProcessor - RelayedTxV3ProcessorField process.RelayedTxV3Processor } // Create - @@ -303,11 +302,6 @@ func (pcs *ProcessComponentsStub) EpochSystemSCProcessor() process.EpochStartSys return pcs.EpochSystemSCProcessorInternal } -// RelayedTxV3Processor - -func (pcs *ProcessComponentsStub) RelayedTxV3Processor() process.RelayedTxV3Processor { - return pcs.RelayedTxV3ProcessorField -} - // IsInterfaceNil - func (pcs *ProcessComponentsStub) IsInterfaceNil() bool { return pcs == nil diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 6815d12802e..54d99ff869d 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -19,7 +19,6 @@ func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.T initialVal := big.NewInt(10000000000) epochsConfig := integrationTests.GetDefaultEnableEpochsConfig() if !relayedV3Test { - epochsConfig.RelayedTransactionsV3EnableEpoch = integrationTests.UnreachableEpoch epochsConfig.FixRelayedBaseCostEnableEpoch = integrationTests.UnreachableEpoch epochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch = integrationTests.UnreachableEpoch } @@ -90,7 +89,7 @@ func CreateAndSendRelayedAndUserTx( ) (*transaction.Transaction, *transaction.Transaction) { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) - userTx := createUserTx(player, rcvAddr, value, gasLimit, txData, nil) + userTx := createUserTx(player, rcvAddr, value, gasLimit, txData) relayedTx := createRelayedTx(txDispatcherNode.EconomicsData, relayer, userTx) _, err := txDispatcherNode.SendTransaction(relayedTx) @@ -113,7 +112,7 @@ func CreateAndSendRelayedAndUserTxV2( ) (*transaction.Transaction, *transaction.Transaction) { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) - userTx := createUserTx(player, rcvAddr, value, 0, txData, nil) + userTx := createUserTx(player, rcvAddr, value, 0, txData) relayedTx := createRelayedTxV2(txDispatcherNode.EconomicsData, relayer, userTx, gasLimit) _, err := txDispatcherNode.SendTransaction(relayedTx) @@ -124,48 +123,23 @@ func CreateAndSendRelayedAndUserTxV2( return relayedTx, userTx } -// CreateAndSendRelayedAndUserTxV3 will create and send a relayed user transaction for relayed v3 -func CreateAndSendRelayedAndUserTxV3( - nodes []*integrationTests.TestProcessorNode, - relayer *integrationTests.TestWalletAccount, - player *integrationTests.TestWalletAccount, - rcvAddr []byte, - value *big.Int, - gasLimit uint64, - txData []byte, -) (*transaction.Transaction, *transaction.Transaction) { - txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) - - userTx := createUserTx(player, rcvAddr, value, gasLimit, txData, relayer.Address) - relayedTx := createRelayedTxV3(txDispatcherNode.EconomicsData, relayer, userTx) - - _, err := txDispatcherNode.SendTransaction(relayedTx) - if err != nil { - fmt.Println(err.Error()) - } - - return relayedTx, userTx -} - func createUserTx( player *integrationTests.TestWalletAccount, rcvAddr []byte, value *big.Int, gasLimit uint64, txData []byte, - relayerAddress []byte, ) *transaction.Transaction { tx := &transaction.Transaction{ - Nonce: player.Nonce, - Value: big.NewInt(0).Set(value), - RcvAddr: rcvAddr, - SndAddr: player.Address, - GasPrice: integrationTests.MinTxGasPrice, - GasLimit: gasLimit, - Data: txData, - ChainID: integrationTests.ChainID, - Version: integrationTests.MinTransactionVersion, - RelayerAddr: relayerAddress, + Nonce: player.Nonce, + Value: big.NewInt(0).Set(value), + RcvAddr: rcvAddr, + SndAddr: player.Address, + GasPrice: integrationTests.MinTxGasPrice, + GasLimit: gasLimit, + Data: txData, + ChainID: integrationTests.ChainID, + Version: integrationTests.MinTransactionVersion, } txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) tx.Signature, _ = player.SingleSigner.Sign(player.SkTxSign, txBuff) @@ -238,37 +212,6 @@ func createRelayedTxV2( return tx } -func createRelayedTxV3( - economicsFee process.FeeHandler, - relayer *integrationTests.TestWalletAccount, - userTx *transaction.Transaction, -) *transaction.Transaction { - tx := &transaction.Transaction{ - Nonce: relayer.Nonce, - Value: big.NewInt(0), - RcvAddr: relayer.Address, - SndAddr: relayer.Address, - GasPrice: integrationTests.MinTxGasPrice, - Data: []byte(""), - ChainID: userTx.ChainID, - Version: userTx.Version, - InnerTransactions: []*transaction.Transaction{userTx}, - } - gasLimit := economicsFee.ComputeGasLimit(tx) - tx.GasLimit = userTx.GasLimit + gasLimit - - txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) - tx.Signature, _ = relayer.SingleSigner.Sign(relayer.SkTxSign, txBuff) - relayer.Nonce++ - - relayer.Balance.Sub(relayer.Balance, tx.Value) - - txFee := economicsFee.ComputeTxFee(tx) - relayer.Balance.Sub(relayer.Balance, txFee) - - return tx -} - func createAndSendSimpleTransaction( nodes []*integrationTests.TestProcessorNode, player *integrationTests.TestWalletAccount, @@ -279,7 +222,7 @@ func createAndSendSimpleTransaction( ) { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, player.Address) - userTx := createUserTx(player, rcvAddr, value, gasLimit, txData, nil) + userTx := createUserTx(player, rcvAddr, value, gasLimit, txData) _, err := txDispatcherNode.SendTransaction(userTx) if err != nil { fmt.Println(err.Error()) diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index d9ea772d7ba..87a54633953 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -33,24 +33,20 @@ type createAndSendRelayedAndUserTxFuncType = func( func TestRelayedTransactionInMultiShardEnvironmentWithNormalTx(t *testing.T) { t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTx, false)) - t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTxV3, true)) } func TestRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(t *testing.T) { t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTx, false)) t.Run("relayed v2", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTxV2, false)) - t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTxV3, true)) } func TestRelayedTransactionInMultiShardEnvironmentWithESDTTX(t *testing.T) { t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTx, false)) t.Run("relayed v2", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTxV2, false)) - t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTxV3, true)) } func TestRelayedTransactionInMultiShardEnvironmentWithAttestationContract(t *testing.T) { t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithAttestationContract(CreateAndSendRelayedAndUserTx, false)) - t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithAttestationContract(CreateAndSendRelayedAndUserTxV3, true)) } func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( diff --git a/integrationTests/testHeartbeatNode.go b/integrationTests/testHeartbeatNode.go index 43b2ac576a0..1ba488b9e12 100644 --- a/integrationTests/testHeartbeatNode.go +++ b/integrationTests/testHeartbeatNode.go @@ -54,7 +54,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/genesisMocks" "github.com/multiversx/mx-chain-go/testscommon/nodeTypeProviderMock" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" trieMock "github.com/multiversx/mx-chain-go/testscommon/trie" vic "github.com/multiversx/mx-chain-go/testscommon/validatorInfoCacher" @@ -627,7 +626,6 @@ func (thn *TestHeartbeatNode) initInterceptors() { SignaturesHandler: &processMock.SignaturesHandlerStub{}, HeartbeatExpiryTimespanInSec: thn.heartbeatExpiryTimespanInSec, PeerID: thn.MainMessenger.ID(), - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } thn.createPeerAuthInterceptor(argsFactory) diff --git a/integrationTests/testInitializer.go b/integrationTests/testInitializer.go index 06dc1a24866..a7c6cdac3c3 100644 --- a/integrationTests/testInitializer.go +++ b/integrationTests/testInitializer.go @@ -69,7 +69,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/stakingcommon" testStorage "github.com/multiversx/mx-chain-go/testscommon/state" statusHandlerMock "github.com/multiversx/mx-chain-go/testscommon/statusHandler" @@ -1056,17 +1055,15 @@ func CreateSimpleTxProcessor(accnts state.AccountsAdapter) process.TransactionPr return fee }, }, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, } txProcessor, _ := txProc.NewTxProcessor(argsNewTxProcessor) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index cf76e1582d0..dc828291384 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -114,7 +114,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/mainFactoryMocks" "github.com/multiversx/mx-chain-go/testscommon/outport" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" "github.com/multiversx/mx-chain-go/testscommon/stakingcommon" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -1288,12 +1287,6 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { cryptoComponents.BlKeyGen = tpn.OwnAccount.KeygenBlockSign cryptoComponents.TxKeyGen = tpn.OwnAccount.KeygenTxSign - relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ - EconomicsFee: tpn.EconomicsData, - ShardCoordinator: tpn.ShardCoordinator, - MaxTransactionsAllowed: 10, - }) - if tpn.ShardCoordinator.SelfId() == core.MetachainShardId { argsEpochStart := &metachain.ArgsNewMetaEpochStartTrigger{ GenesisTime: tpn.RoundHandler.TimeStamp(), @@ -1346,7 +1339,6 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { FullArchivePeerShardMapper: tpn.FullArchivePeerShardMapper, HardforkTrigger: tpn.HardforkTrigger, NodeOperationMode: tpn.NodeOperationMode, - RelayedTxV3Processor: relayedV3TxProcessor, } interceptorContainerFactory, _ := interceptorscontainer.NewMetaInterceptorsContainerFactory(metaInterceptorContainerFactoryArgs) @@ -1415,7 +1407,6 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { FullArchivePeerShardMapper: tpn.FullArchivePeerShardMapper, HardforkTrigger: tpn.HardforkTrigger, NodeOperationMode: tpn.NodeOperationMode, - RelayedTxV3Processor: relayedV3TxProcessor, } interceptorContainerFactory, _ := interceptorscontainer.NewShardInterceptorsContainerFactory(shardIntereptorContainerFactoryArgs) @@ -1696,66 +1687,56 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u EnableEpochsHandler: tpn.EnableEpochsHandler, } txTypeHandler, _ := coordinator.NewTxTypeHandler(argsTxTypeHandler) - _ = tpn.EconomicsData.SetTxTypeHandler(txTypeHandler) tpn.GasHandler, _ = preprocess.NewGasComputation(tpn.EconomicsData, txTypeHandler, tpn.EnableEpochsHandler) badBlocksHandler, _ := tpn.InterimProcContainer.Get(dataBlock.InvalidBlock) argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: tpn.VMContainer, - ArgsParser: tpn.ArgsParser, - Hasher: TestHasher, - Marshalizer: TestMarshalizer, - AccountsDB: tpn.AccntState, - BlockChainHook: vmFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: TestAddressPubkeyConverter, - ShardCoordinator: tpn.ShardCoordinator, - ScrForwarder: tpn.ScrForwarder, - TxFeeHandler: tpn.FeeAccumulator, - EconomicsFee: tpn.EconomicsData, - TxTypeHandler: txTypeHandler, - GasHandler: tpn.GasHandler, - GasSchedule: gasSchedule, - TxLogsProcessor: tpn.TransactionLogProcessor, - BadTxForwarder: badBlocksHandler, - EnableRoundsHandler: tpn.EnableRoundsHandler, - EnableEpochsHandler: tpn.EnableEpochsHandler, - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: tpn.WasmVMChangeLocker, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + VmContainer: tpn.VMContainer, + ArgsParser: tpn.ArgsParser, + Hasher: TestHasher, + Marshalizer: TestMarshalizer, + AccountsDB: tpn.AccntState, + BlockChainHook: vmFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: TestAddressPubkeyConverter, + ShardCoordinator: tpn.ShardCoordinator, + ScrForwarder: tpn.ScrForwarder, + TxFeeHandler: tpn.FeeAccumulator, + EconomicsFee: tpn.EconomicsData, + TxTypeHandler: txTypeHandler, + GasHandler: tpn.GasHandler, + GasSchedule: gasSchedule, + TxLogsProcessor: tpn.TransactionLogProcessor, + BadTxForwarder: badBlocksHandler, + EnableRoundsHandler: tpn.EnableRoundsHandler, + EnableEpochsHandler: tpn.EnableEpochsHandler, + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: tpn.WasmVMChangeLocker, } tpn.ScProcessor, _ = processProxy.NewTestSmartContractProcessorProxy(argsNewScProcessor, tpn.EpochNotifier) - relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ - EconomicsFee: tpn.EconomicsData, - ShardCoordinator: tpn.ShardCoordinator, - MaxTransactionsAllowed: 10, - }) - receiptsHandler, _ := tpn.InterimProcContainer.Get(dataBlock.ReceiptBlock) argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: tpn.AccntState, - Hasher: TestHasher, - PubkeyConv: TestAddressPubkeyConverter, - Marshalizer: TestMarshalizer, - SignMarshalizer: TestTxSignMarshalizer, - ShardCoordinator: tpn.ShardCoordinator, - ScProcessor: tpn.ScProcessor, - TxFeeHandler: tpn.FeeAccumulator, - TxTypeHandler: txTypeHandler, - EconomicsFee: tpn.EconomicsData, - ReceiptForwarder: receiptsHandler, - BadTxForwarder: badBlocksHandler, - ArgsParser: tpn.ArgsParser, - ScrForwarder: tpn.ScrForwarder, - EnableRoundsHandler: tpn.EnableRoundsHandler, - EnableEpochsHandler: tpn.EnableEpochsHandler, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - TxLogsProcessor: tpn.TransactionLogProcessor, - RelayedTxV3Processor: relayedV3TxProcessor, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + Accounts: tpn.AccntState, + Hasher: TestHasher, + PubkeyConv: TestAddressPubkeyConverter, + Marshalizer: TestMarshalizer, + SignMarshalizer: TestTxSignMarshalizer, + ShardCoordinator: tpn.ShardCoordinator, + ScProcessor: tpn.ScProcessor, + TxFeeHandler: tpn.FeeAccumulator, + TxTypeHandler: txTypeHandler, + EconomicsFee: tpn.EconomicsData, + ReceiptForwarder: receiptsHandler, + BadTxForwarder: badBlocksHandler, + ArgsParser: tpn.ArgsParser, + ScrForwarder: tpn.ScrForwarder, + EnableRoundsHandler: tpn.EnableRoundsHandler, + EnableEpochsHandler: tpn.EnableEpochsHandler, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + TxLogsProcessor: tpn.TransactionLogProcessor, } tpn.TxProcessor, _ = transaction.NewTxProcessor(argsNewTxProcessor) scheduledSCRsStorer, _ := tpn.Storage.GetStorer(dataRetriever.ScheduledSCRsUnit) @@ -1986,32 +1967,30 @@ func (tpn *TestProcessorNode) initMetaInnerProcessors(gasMap map[string]map[stri EnableEpochsHandler: tpn.EnableEpochsHandler, } txTypeHandler, _ := coordinator.NewTxTypeHandler(argsTxTypeHandler) - _ = tpn.EconomicsData.SetTxTypeHandler(txTypeHandler) tpn.GasHandler, _ = preprocess.NewGasComputation(tpn.EconomicsData, txTypeHandler, tpn.EnableEpochsHandler) badBlocksHandler, _ := tpn.InterimProcContainer.Get(dataBlock.InvalidBlock) argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: tpn.VMContainer, - ArgsParser: tpn.ArgsParser, - Hasher: TestHasher, - Marshalizer: TestMarshalizer, - AccountsDB: tpn.AccntState, - BlockChainHook: vmFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: TestAddressPubkeyConverter, - ShardCoordinator: tpn.ShardCoordinator, - ScrForwarder: tpn.ScrForwarder, - TxFeeHandler: tpn.FeeAccumulator, - EconomicsFee: tpn.EconomicsData, - TxTypeHandler: txTypeHandler, - GasHandler: tpn.GasHandler, - GasSchedule: gasSchedule, - TxLogsProcessor: tpn.TransactionLogProcessor, - BadTxForwarder: badBlocksHandler, - EnableRoundsHandler: tpn.EnableRoundsHandler, - EnableEpochsHandler: tpn.EnableEpochsHandler, - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: tpn.WasmVMChangeLocker, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + VmContainer: tpn.VMContainer, + ArgsParser: tpn.ArgsParser, + Hasher: TestHasher, + Marshalizer: TestMarshalizer, + AccountsDB: tpn.AccntState, + BlockChainHook: vmFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: TestAddressPubkeyConverter, + ShardCoordinator: tpn.ShardCoordinator, + ScrForwarder: tpn.ScrForwarder, + TxFeeHandler: tpn.FeeAccumulator, + EconomicsFee: tpn.EconomicsData, + TxTypeHandler: txTypeHandler, + GasHandler: tpn.GasHandler, + GasSchedule: gasSchedule, + TxLogsProcessor: tpn.TransactionLogProcessor, + BadTxForwarder: badBlocksHandler, + EnableRoundsHandler: tpn.EnableRoundsHandler, + EnableEpochsHandler: tpn.EnableEpochsHandler, + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: tpn.WasmVMChangeLocker, } tpn.ScProcessor, _ = processProxy.NewTestSmartContractProcessorProxy(argsNewScProcessor, tpn.EpochNotifier) @@ -2614,22 +2593,21 @@ func (tpn *TestProcessorNode) SendTransaction(tx *dataTransaction.Transaction) ( guardianAddress = TestAddressPubkeyConverter.SilentEncode(tx.GuardianAddr, log) } createTxArgs := &external.ArgsCreateTransaction{ - Nonce: tx.Nonce, - Value: tx.Value.String(), - Receiver: encodedRcvAddr, - ReceiverUsername: nil, - Sender: encodedSndAddr, - SenderUsername: nil, - GasPrice: tx.GasPrice, - GasLimit: tx.GasLimit, - DataField: tx.Data, - SignatureHex: hex.EncodeToString(tx.Signature), - ChainID: string(tx.ChainID), - Version: tx.Version, - Options: tx.Options, - Guardian: guardianAddress, - GuardianSigHex: hex.EncodeToString(tx.GuardianSignature), - InnerTransactions: tx.InnerTransactions, + Nonce: tx.Nonce, + Value: tx.Value.String(), + Receiver: encodedRcvAddr, + ReceiverUsername: nil, + Sender: encodedSndAddr, + SenderUsername: nil, + GasPrice: tx.GasPrice, + GasLimit: tx.GasLimit, + DataField: tx.Data, + SignatureHex: hex.EncodeToString(tx.Signature), + ChainID: string(tx.ChainID), + Version: tx.Version, + Options: tx.Options, + Guardian: guardianAddress, + GuardianSigHex: hex.EncodeToString(tx.GuardianSignature), } tx, txHash, err := tpn.Node.CreateTransaction(createTxArgs) if err != nil { @@ -3275,7 +3253,6 @@ func CreateEnableEpochsConfig() config.EnableEpochs { MiniBlockPartialExecutionEnableEpoch: UnreachableEpoch, RefactorPeersMiniBlocksEnableEpoch: UnreachableEpoch, SCProcessorV2EnableEpoch: UnreachableEpoch, - RelayedTransactionsV3EnableEpoch: UnreachableEpoch, FixRelayedBaseCostEnableEpoch: UnreachableEpoch, FixRelayedMoveBalanceToNonPayableSCEnableEpoch: UnreachableEpoch, } @@ -3363,11 +3340,6 @@ func GetDefaultProcessComponents() *mock.ProcessComponentsStub { CurrentEpochProviderInternal: &testscommon.CurrentEpochProviderStub{}, HistoryRepositoryInternal: &dblookupextMock.HistoryRepositoryStub{}, HardforkTriggerField: &testscommon.HardforkTriggerStub{}, - RelayedTxV3ProcessorField: &processMocks.RelayedTxV3ProcessorMock{ - CheckRelayedTxCalled: func(tx *dataTransaction.Transaction) error { - return nil - }, - }, } } diff --git a/integrationTests/testProcessorNodeWithTestWebServer.go b/integrationTests/testProcessorNodeWithTestWebServer.go index d533f4c75b1..b4e2490b900 100644 --- a/integrationTests/testProcessorNodeWithTestWebServer.go +++ b/integrationTests/testProcessorNodeWithTestWebServer.go @@ -163,7 +163,6 @@ func createFacadeComponents(tpn *TestProcessorNode) nodeFacade.ApiResolver { } txTypeHandler, err := coordinator.NewTxTypeHandler(argsTxTypeHandler) log.LogIfError(err) - _ = tpn.EconomicsData.SetTxTypeHandler(txTypeHandler) argsDataFieldParser := &datafield.ArgsOperationDataFieldParser{ AddressLength: TestAddressPubkeyConverter.Len(), diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index c701007ca00..c6e33ddc21a 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -62,7 +62,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/genesisMocks" "github.com/multiversx/mx-chain-go/testscommon/integrationtests" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/testscommon/txDataBuilder" @@ -141,9 +140,8 @@ type VMTestContext struct { ContractOwner VMTestAccount Contract VMTestAccount - TxCostHandler external.TransactionEvaluator - TxsLogsProcessor process.TransactionLogProcessor - FailedTxLogsAccumulator process.FailedTxLogsAccumulator + TxCostHandler external.TransactionEvaluator + TxsLogsProcessor process.TransactionLogProcessor } // Close - @@ -443,7 +441,6 @@ func CreateTxProcessorWithOneSCExecutorMockVM( if err != nil { return nil, err } - _ = economicsData.SetTxTypeHandler(txTypeHandler) argsNewSCProcessor := scrCommon.ArgsNewSmartContractProcessor{ VmContainer: vmContainer, @@ -463,13 +460,12 @@ func CreateTxProcessorWithOneSCExecutorMockVM( GasHandler: &testscommon.GasHandlerStub{ SetGasRefundedCalled: func(gasRefunded uint64, hash []byte) {}, }, - GasSchedule: gasScheduleNotifier, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - EnableEpochsHandler: enableEpochsHandler, - EnableRoundsHandler: enableRoundsHandler, - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: wasmVMChangeLocker, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + GasSchedule: gasScheduleNotifier, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + EnableEpochsHandler: enableEpochsHandler, + EnableRoundsHandler: enableRoundsHandler, + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: wasmVMChangeLocker, } scProcessor, _ := processProxy.NewTestSmartContractProcessorProxy(argsNewSCProcessor, genericEpochNotifier) @@ -480,27 +476,25 @@ func CreateTxProcessorWithOneSCExecutorMockVM( } argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: accnts, - Hasher: integrationtests.TestHasher, - PubkeyConv: pubkeyConv, - Marshalizer: integrationtests.TestMarshalizer, - SignMarshalizer: integrationtests.TestMarshalizer, - ShardCoordinator: mock.NewMultiShardsCoordinatorMock(2), - ScProcessor: scProcessor, - TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, - TxTypeHandler: txTypeHandler, - EconomicsFee: economicsData, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), - GuardianChecker: guardedAccountHandler, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + Accounts: accnts, + Hasher: integrationtests.TestHasher, + PubkeyConv: pubkeyConv, + Marshalizer: integrationtests.TestMarshalizer, + SignMarshalizer: integrationtests.TestMarshalizer, + ShardCoordinator: mock.NewMultiShardsCoordinatorMock(2), + ScProcessor: scProcessor, + TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, + TxTypeHandler: txTypeHandler, + EconomicsFee: economicsData, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), + GuardianChecker: guardedAccountHandler, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, } return transaction.NewTxProcessor(argsNewTxProcessor) @@ -810,13 +804,12 @@ func CreateVMConfigWithVersion(version string) *config.VirtualMachineConfig { // ResultsCreateTxProcessor is the struct that will hold all needed processor instances type ResultsCreateTxProcessor struct { - TxProc process.TransactionProcessor - SCProc scrCommon.TestSmartContractProcessor - IntermediateTxProc process.IntermediateTransactionHandler - EconomicsHandler process.EconomicsDataHandler - CostHandler external.TransactionEvaluator - TxLogProc process.TransactionLogProcessor - FailedTxLogsAccumulator process.FailedTxLogsAccumulator + TxProc process.TransactionProcessor + SCProc scrCommon.TestSmartContractProcessor + IntermediateTxProc process.IntermediateTransactionHandler + EconomicsHandler process.EconomicsDataHandler + CostHandler external.TransactionEvaluator + TxLogProc process.TransactionLogProcessor } // CreateTxProcessorWithOneSCExecutorWithVMs - @@ -861,7 +854,6 @@ func CreateTxProcessorWithOneSCExecutorWithVMs( if err != nil { return nil, err } - _ = economicsData.SetTxTypeHandler(txTypeHandler) gasComp, err := preprocess.NewGasComputation(economicsData, txTypeHandler, enableEpochsHandler) if err != nil { @@ -873,58 +865,53 @@ func CreateTxProcessorWithOneSCExecutorWithVMs( Marshalizer: integrationtests.TestMarshalizer, }) - failedLogsAcc := transactionLog.NewFailedTxLogsAccumulator() - intermediateTxHandler := &mock.IntermediateTransactionHandlerMock{} argsNewSCProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: smartContract.NewArgumentParser(), - Hasher: integrationtests.TestHasher, - Marshalizer: integrationtests.TestMarshalizer, - AccountsDB: accnts, - BlockChainHook: blockChainHook, - BuiltInFunctions: blockChainHook.GetBuiltinFunctionsContainer(), - PubkeyConv: pubkeyConv, - ShardCoordinator: shardCoordinator, - ScrForwarder: intermediateTxHandler, - BadTxForwarder: intermediateTxHandler, - TxFeeHandler: feeAccumulator, - EconomicsFee: economicsData, - TxTypeHandler: txTypeHandler, - GasHandler: gasComp, - GasSchedule: mock.NewGasScheduleNotifierMock(gasSchedule), - TxLogsProcessor: logProc, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - WasmVMChangeLocker: wasmVMChangeLocker, - VMOutputCacher: txcache.NewDisabledCache(), - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + VmContainer: vmContainer, + ArgsParser: smartContract.NewArgumentParser(), + Hasher: integrationtests.TestHasher, + Marshalizer: integrationtests.TestMarshalizer, + AccountsDB: accnts, + BlockChainHook: blockChainHook, + BuiltInFunctions: blockChainHook.GetBuiltinFunctionsContainer(), + PubkeyConv: pubkeyConv, + ShardCoordinator: shardCoordinator, + ScrForwarder: intermediateTxHandler, + BadTxForwarder: intermediateTxHandler, + TxFeeHandler: feeAccumulator, + EconomicsFee: economicsData, + TxTypeHandler: txTypeHandler, + GasHandler: gasComp, + GasSchedule: mock.NewGasScheduleNotifierMock(gasSchedule), + TxLogsProcessor: logProc, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + WasmVMChangeLocker: wasmVMChangeLocker, + VMOutputCacher: txcache.NewDisabledCache(), } scProcessorProxy, _ := processProxy.NewTestSmartContractProcessorProxy(argsNewSCProcessor, epochNotifierInstance) argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: accnts, - Hasher: integrationtests.TestHasher, - PubkeyConv: pubkeyConv, - Marshalizer: integrationtests.TestMarshalizer, - SignMarshalizer: integrationtests.TestMarshalizer, - ShardCoordinator: shardCoordinator, - ScProcessor: scProcessorProxy, - TxFeeHandler: feeAccumulator, - TxTypeHandler: txTypeHandler, - EconomicsFee: economicsData, - ReceiptForwarder: intermediateTxHandler, - BadTxForwarder: intermediateTxHandler, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: intermediateTxHandler, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), - GuardianChecker: guardianChecker, - TxLogsProcessor: logProc, - FailedTxLogsAccumulator: failedLogsAcc, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + Accounts: accnts, + Hasher: integrationtests.TestHasher, + PubkeyConv: pubkeyConv, + Marshalizer: integrationtests.TestMarshalizer, + SignMarshalizer: integrationtests.TestMarshalizer, + ShardCoordinator: shardCoordinator, + ScProcessor: scProcessorProxy, + TxFeeHandler: feeAccumulator, + TxTypeHandler: txTypeHandler, + EconomicsFee: economicsData, + ReceiptForwarder: intermediateTxHandler, + BadTxForwarder: intermediateTxHandler, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: intermediateTxHandler, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), + GuardianChecker: guardianChecker, + TxLogsProcessor: logProc, } txProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { @@ -1331,24 +1318,23 @@ func CreatePreparedTxProcessorWithVMConfigWithShardCoordinatorDBAndGasAndRoundCo } return &VMTestContext{ - TxProcessor: res.TxProc, - ScProcessor: res.SCProc, - Accounts: accounts, - BlockchainHook: blockchainHook, - VMContainer: vmContainer, - TxFeeHandler: feeAccumulator, - ScForwarder: res.IntermediateTxProc, - ShardCoordinator: shardCoordinator, - EconomicsData: res.EconomicsHandler, - TxCostHandler: res.CostHandler, - TxsLogsProcessor: res.TxLogProc, - FailedTxLogsAccumulator: res.FailedTxLogsAccumulator, - GasSchedule: gasScheduleNotifier, - EpochNotifier: epochNotifierInstance, - EnableEpochsHandler: enableEpochsHandler, - ChainHandler: chainHandler, - Marshalizer: integrationtests.TestMarshalizer, - GuardedAccountsHandler: guardedAccountHandler, + TxProcessor: res.TxProc, + ScProcessor: res.SCProc, + Accounts: accounts, + BlockchainHook: blockchainHook, + VMContainer: vmContainer, + TxFeeHandler: feeAccumulator, + ScForwarder: res.IntermediateTxProc, + ShardCoordinator: shardCoordinator, + EconomicsData: res.EconomicsHandler, + TxCostHandler: res.CostHandler, + TxsLogsProcessor: res.TxLogProc, + GasSchedule: gasScheduleNotifier, + EpochNotifier: epochNotifierInstance, + EnableEpochsHandler: enableEpochsHandler, + ChainHandler: chainHandler, + Marshalizer: integrationtests.TestMarshalizer, + GuardedAccountsHandler: guardedAccountHandler, }, nil } @@ -1945,22 +1931,21 @@ func CreatePreparedTxProcessorWithVMsMultiShardRoundVMConfig( } return &VMTestContext{ - TxProcessor: res.TxProc, - ScProcessor: res.SCProc, - Accounts: accounts, - BlockchainHook: blockchainHook, - VMContainer: vmContainer, - TxFeeHandler: feeAccumulator, - ShardCoordinator: shardCoordinator, - ScForwarder: res.IntermediateTxProc, - EconomicsData: res.EconomicsHandler, - Marshalizer: integrationtests.TestMarshalizer, - TxsLogsProcessor: res.TxLogProc, - FailedTxLogsAccumulator: res.FailedTxLogsAccumulator, - EpochNotifier: epochNotifierInstance, - EnableEpochsHandler: enableEpochsHandler, - ChainHandler: chainHandler, - GuardedAccountsHandler: guardedAccountHandler, + TxProcessor: res.TxProc, + ScProcessor: res.SCProc, + Accounts: accounts, + BlockchainHook: blockchainHook, + VMContainer: vmContainer, + TxFeeHandler: feeAccumulator, + ShardCoordinator: shardCoordinator, + ScForwarder: res.IntermediateTxProc, + EconomicsData: res.EconomicsHandler, + Marshalizer: integrationtests.TestMarshalizer, + TxsLogsProcessor: res.TxLogProc, + EpochNotifier: epochNotifierInstance, + EnableEpochsHandler: enableEpochsHandler, + ChainHandler: chainHandler, + GuardedAccountsHandler: guardedAccountHandler, }, nil } diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index 7ec28bb8f45..bfe7b4b7ca9 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -53,7 +53,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/integrationtests" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts/defaults" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -392,40 +391,37 @@ func (context *TestContext) initTxProcessorWithOneSCExecutorWithVMs() { GasHandler: &testscommon.GasHandlerStub{ SetGasRefundedCalled: func(gasRefunded uint64, hash []byte) {}, }, - GasSchedule: mock.NewGasScheduleNotifierMock(gasSchedule), - TxLogsProcessor: context.TxLogsProcessor, - EnableRoundsHandler: context.EnableRoundsHandler, - EnableEpochsHandler: context.EnableEpochsHandler, - WasmVMChangeLocker: context.WasmVMChangeLocker, - VMOutputCacher: txcache.NewDisabledCache(), - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + GasSchedule: mock.NewGasScheduleNotifierMock(gasSchedule), + TxLogsProcessor: context.TxLogsProcessor, + EnableRoundsHandler: context.EnableRoundsHandler, + EnableEpochsHandler: context.EnableEpochsHandler, + WasmVMChangeLocker: context.WasmVMChangeLocker, + VMOutputCacher: txcache.NewDisabledCache(), } context.ScProcessor, err = processProxy.NewTestSmartContractProcessorProxy(argsNewSCProcessor, context.EpochNotifier) require.Nil(context.T, err) argsNewTxProcessor := processTransaction.ArgsNewTxProcessor{ - Accounts: context.Accounts, - Hasher: hasher, - PubkeyConv: pkConverter, - Marshalizer: marshalizer, - SignMarshalizer: marshalizer, - ShardCoordinator: oneShardCoordinator, - ScProcessor: context.ScProcessor, - TxFeeHandler: context.UnsignexTxHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: context.EconomicsFee, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: context.EnableRoundsHandler, - EnableEpochsHandler: context.EnableEpochsHandler, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxLogsProcessor: context.TxLogsProcessor, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + Accounts: context.Accounts, + Hasher: hasher, + PubkeyConv: pkConverter, + Marshalizer: marshalizer, + SignMarshalizer: marshalizer, + ShardCoordinator: oneShardCoordinator, + ScProcessor: context.ScProcessor, + TxFeeHandler: context.UnsignexTxHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: context.EconomicsFee, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: context.EnableRoundsHandler, + EnableEpochsHandler: context.EnableEpochsHandler, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxLogsProcessor: context.TxLogsProcessor, } context.TxProcessor, err = processTransaction.NewTxProcessor(argsNewTxProcessor) diff --git a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go index 9ad6a861235..2957aa42add 100644 --- a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go +++ b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go @@ -31,7 +31,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/integrationtests" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" logger "github.com/multiversx/mx-chain-logger-go" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" @@ -630,25 +629,23 @@ func TestExecuteTransactionAndTimeToProcessChange(t *testing.T) { _, _ = vm.CreateAccount(accnts, ownerAddressBytes, ownerNonce, ownerBalance) argsNewTxProcessor := processTransaction.ArgsNewTxProcessor{ - Accounts: accnts, - Hasher: testHasher, - PubkeyConv: pubkeyConv, - Marshalizer: testMarshalizer, - SignMarshalizer: testMarshalizer, - ShardCoordinator: shardCoordinator, - ScProcessor: &testscommon.SCProcessorMock{}, - TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, - TxTypeHandler: txTypeHandler, - EconomicsFee: &economicsmocks.EconomicsHandlerStub{}, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + Accounts: accnts, + Hasher: testHasher, + PubkeyConv: pubkeyConv, + Marshalizer: testMarshalizer, + SignMarshalizer: testMarshalizer, + ShardCoordinator: shardCoordinator, + ScProcessor: &testscommon.SCProcessorMock{}, + TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, + TxTypeHandler: txTypeHandler, + EconomicsFee: &economicsmocks.EconomicsHandlerStub{}, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, } txProc, _ := processTransaction.NewTxProcessor(argsNewTxProcessor) diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 6e00d776784..cbd119fa517 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -100,7 +100,6 @@ type processComponentsHolder struct { accountsParser genesis.AccountsParser sentSignatureTracker process.SentSignaturesTracker epochStartSystemSCProcessor process.EpochStartSystemSCProcessor - relayedTxV3Processor process.RelayedTxV3Processor managedProcessComponentsCloser io.Closer } @@ -284,7 +283,6 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen accountsParser: managedProcessComponents.AccountsParser(), sentSignatureTracker: managedProcessComponents.SentSignaturesTracker(), epochStartSystemSCProcessor: managedProcessComponents.EpochSystemSCProcessor(), - relayedTxV3Processor: managedProcessComponents.RelayedTxV3Processor(), managedProcessComponentsCloser: managedProcessComponents, } @@ -525,11 +523,6 @@ func (p *processComponentsHolder) EpochSystemSCProcessor() process.EpochStartSys return p.epochStartSystemSCProcessor } -// RelayedTxV3Processor returns the relayed tx v3 processor -func (p *processComponentsHolder) RelayedTxV3Processor() process.RelayedTxV3Processor { - return p.relayedTxV3Processor -} - // Close will call the Close methods on all inner components func (p *processComponentsHolder) Close() error { return p.managedProcessComponentsCloser.Close() diff --git a/node/chainSimulator/components/processComponents_test.go b/node/chainSimulator/components/processComponents_test.go index 93b6a7689a3..a8cb2f053e7 100644 --- a/node/chainSimulator/components/processComponents_test.go +++ b/node/chainSimulator/components/processComponents_test.go @@ -408,7 +408,6 @@ func TestProcessComponentsHolder_Getters(t *testing.T) { require.NotNil(t, comp.AccountsParser()) require.NotNil(t, comp.ReceiptsRepository()) require.NotNil(t, comp.EpochSystemSCProcessor()) - require.NotNil(t, comp.RelayedTxV3Processor()) require.Nil(t, comp.CheckSubcomponents()) require.Empty(t, comp.String()) diff --git a/node/external/dtos.go b/node/external/dtos.go index 12a6b153c46..ad8d073967b 100644 --- a/node/external/dtos.go +++ b/node/external/dtos.go @@ -1,24 +1,21 @@ package external -import "github.com/multiversx/mx-chain-core-go/data/transaction" - // ArgsCreateTransaction defines arguments for creating a transaction type ArgsCreateTransaction struct { - Nonce uint64 - Value string - Receiver string - ReceiverUsername []byte - Sender string - SenderUsername []byte - GasPrice uint64 - GasLimit uint64 - DataField []byte - SignatureHex string - ChainID string - Version uint32 - Options uint32 - Guardian string - GuardianSigHex string - Relayer string - InnerTransactions []*transaction.Transaction + Nonce uint64 + Value string + Receiver string + ReceiverUsername []byte + Sender string + SenderUsername []byte + GasPrice uint64 + GasLimit uint64 + DataField []byte + SignatureHex string + ChainID string + Version uint32 + Options uint32 + Guardian string + GuardianSigHex string + Relayer string } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 530b6b81b3d..ab5c77fee40 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -58,24 +58,17 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction } hasRefundForSender := false - totalRefunds := big.NewInt(0) for _, scr := range tx.SmartContractResults { if !scr.IsRefund || scr.RcvAddr != tx.Sender { continue } + if scr.RcvAddr != tx.Sender { + continue + } + gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value) hasRefundForSender = true - totalRefunds.Add(totalRefunds, scr.Value) - } - - if totalRefunds.Cmp(big.NewInt(0)) > 0 { - gasUsed, fee = gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, totalRefunds) - tx.GasUsed = gasUsed - tx.Fee = fee.String() - } - - if isRelayedAfterFix { - return + break } gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) @@ -86,10 +79,6 @@ func (gfp *gasUsedAndFeeProcessor) getFeeOfRelayed(tx *transaction.ApiTransactio return nil, false } - if len(tx.InnerTransactions) > 0 { - return gfp.feeComputer.ComputeTransactionFee(tx), true - } - if len(tx.Data) == 0 { return nil, false } @@ -180,6 +169,16 @@ func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transactio } } +func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnRefundValue(tx *transaction.ApiTransactionResult, refund *big.Int) { + + gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, refund) + + tx.GasUsed = gasUsed + + tx.Fee = fee.String() + +} + func (gfp *gasUsedAndFeeProcessor) isESDTOperationWithSCCall(tx *transaction.ApiTransactionResult) bool { isESDTTransferOperation := tx.Operation == core.BuiltInFunctionESDTTransfer || tx.Operation == core.BuiltInFunctionESDTNFTTransfer || tx.Operation == core.BuiltInFunctionMultiESDTNFTTransfer diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 7e4011e0f2c..c6abd9278d6 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -299,69 +299,6 @@ func TestComputeAndAttachGasUsedAndFeeTransactionWithMultipleScrWithRefund(t *te require.Equal(t, "319459080000000", txWithSRefundSCR.Fee) } -func TestComputeAndAttachGasUsedAndFeeRelayedV3WithRefund(t *testing.T) { - t.Parallel() - - feeComp, _ := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { - return flag == common.GasPriceModifierFlag || - flag == common.PenalizedTooMuchGasFlag || - flag == common.FixRelayedBaseCostFlag - }, - })) - computer := fee.NewTestFeeComputer(feeComp) - - gasUsedAndFeeProc := newGasUsedAndFeeProcessor( - computer, - pubKeyConverter, - &testscommon.ArgumentParserMock{}, - &testscommon.MarshallerStub{}, - enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), - ) - - txWithSRefundSCR := &transaction.ApiTransactionResult{} - err := core.LoadJsonFile(txWithSRefundSCR, "testData/relayedV3WithOneRefund.json") - require.NoError(t, err) - - txWithSRefundSCR.Fee = "" - txWithSRefundSCR.GasUsed = 0 - - innerTxs := make([]*transaction.Transaction, 0, len(txWithSRefundSCR.InnerTransactions)) - for _, innerTx := range txWithSRefundSCR.InnerTransactions { - snd, _ := pubKeyConverter.Decode(innerTx.Sender) - rcv, _ := pubKeyConverter.Decode(innerTx.Receiver) - val, _ := big.NewInt(0).SetString(innerTx.Value, 10) - - innerTxs = append(innerTxs, &transaction.Transaction{ - Nonce: innerTx.Nonce, - Value: val, - RcvAddr: rcv, - SndAddr: snd, - GasPrice: innerTx.GasPrice, - GasLimit: innerTx.GasLimit, - Data: innerTx.Data, - }) - } - - snd, _ := pubKeyConverter.Decode(txWithSRefundSCR.Sender) - rcv, _ := pubKeyConverter.Decode(txWithSRefundSCR.Receiver) - val, _ := big.NewInt(0).SetString(txWithSRefundSCR.Value, 10) - txWithSRefundSCR.Tx = &transaction.Transaction{ - Nonce: txWithSRefundSCR.Nonce, - Value: val, - RcvAddr: rcv, - SndAddr: snd, - GasPrice: txWithSRefundSCR.GasPrice, - GasLimit: txWithSRefundSCR.GasLimit, - Data: txWithSRefundSCR.Data, - InnerTransactions: innerTxs, - } - - gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) - require.Equal(t, uint64(55149500), txWithSRefundSCR.GasUsed) - require.Equal(t, "699500000000000", txWithSRefundSCR.Fee) -} - func TestComputeAndAttachGasUsedAndFeeFailedRelayedV1(t *testing.T) { t.Parallel() @@ -405,7 +342,7 @@ func TestComputeAndAttachGasUsedAndFeeFailedRelayedV1(t *testing.T) { txWithSRefundSCR.GasUsed = 0 gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) - require.Equal(t, uint64(1274230), txWithSRefundSCR.GasUsed) - require.Equal(t, "1274230000000000", txWithSRefundSCR.Fee) + require.Equal(t, uint64(6148000), txWithSRefundSCR.GasUsed) + require.Equal(t, "1198000000000000", txWithSRefundSCR.Fee) require.Equal(t, "1274230000000000", txWithSRefundSCR.InitiallyPaidFee) } diff --git a/node/external/transactionAPI/testData/relayedV3WithOneRefund.json b/node/external/transactionAPI/testData/relayedV3WithOneRefund.json deleted file mode 100644 index c2b0484f877..00000000000 --- a/node/external/transactionAPI/testData/relayedV3WithOneRefund.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "type": "normal", - "processingTypeOnSource": "RelayedTxV3", - "processingTypeOnDestination": "RelayedTxV3", - "hash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", - "nonce": 0, - "value": "0", - "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "sender": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "gasPrice": 1000000000, - "gasLimit": 99000000, - "gasUsed": 998505, - "smartContractResults": [ - { - "hash": "4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c", - "nonce": 0, - "value": 2501000000000000000000, - "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", - "data": "createNewDelegationContract@00@00", - "prevTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", - "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", - "gasLimit": 84900500, - "gasPrice": 1000000000 - }, - { - "hash": "94e678f400192eeae3c84b3125c9d45301db619a3ecbf9e7f46266a81a85ef51", - "nonce": 1, - "value": 299005000000000, - "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "sender": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "prevTxHash": "4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c", - "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", - "gasLimit": 0, - "gasPrice": 1000000000, - "returnMessage": "gas refund for relayer", - "operation": "transfer", - "isRefund": true - } - ], - "innerTransactions": [ - { - "nonce": 0, - "value": "2501000000000000000000", - "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", - "gasPrice": 1000000000, - "gasLimit": 85000000, - "data": "Y3JlYXRlTmV3RGVsZWdhdGlvbkNvbnRyYWN0QDAwQDAw", - "signature": "610493074d4e3ce0d8dcc5434cc67032f7e4acf3fd9f97525dba4865ba42408df8315824bf7b6268e2fa0d97fc51efe1a32f7928a799064a69d54bf063a19607", - "chainID": "chain", - "version": 2, - "relayer": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze" - } - ] -} \ No newline at end of file diff --git a/node/external/transactionAPI/unmarshaller.go b/node/external/transactionAPI/unmarshaller.go index bc997cdf042..c9526217f4f 100644 --- a/node/external/transactionAPI/unmarshaller.go +++ b/node/external/transactionAPI/unmarshaller.go @@ -13,8 +13,6 @@ import ( "github.com/multiversx/mx-chain-go/sharding" ) -const operationTransfer = "transfer" - type txUnmarshaller struct { shardCoordinator sharding.Coordinator addressPubKeyConverter core.PubkeyConverter @@ -88,25 +86,8 @@ func (tu *txUnmarshaller) unmarshalTransaction(txBytes []byte, txType transactio } apiTx = tu.prepareUnsignedTx(&tx) } - - isRelayedV3 := len(apiTx.InnerTransactions) > 0 - if isRelayedV3 { - apiTx.Operation = operationTransfer - for _, innerTx := range apiTx.InnerTransactions { - apiTx.Receivers = append(apiTx.Receivers, innerTx.Receiver) - - rcvBytes, errDecode := tu.addressPubKeyConverter.Decode(innerTx.Receiver) - if errDecode != nil { - log.Warn("bech32PubkeyConverter.Decode() failed while decoding innerTx.Receiver", "error", errDecode) - continue - } - - apiTx.ReceiversShardIDs = append(apiTx.ReceiversShardIDs, tu.shardCoordinator.ComputeId(rcvBytes)) - } - - apiTx.IsRelayed = true - - return apiTx, nil + if err != nil { + return nil, err } res := tu.dataFieldParser.Parse(apiTx.Data, apiTx.Tx.GetSndAddr(), apiTx.Tx.GetRcvAddr(), tu.shardCoordinator.NumberOfShards()) @@ -130,22 +111,21 @@ func (tu *txUnmarshaller) prepareNormalTx(tx *transaction.Transaction) *transact senderAddress := tu.addressPubKeyConverter.SilentEncode(tx.SndAddr, log) apiTx := &transaction.ApiTransactionResult{ - Tx: tx, - Type: string(transaction.TxTypeNormal), - Nonce: tx.Nonce, - Value: tx.Value.String(), - Receiver: receiverAddress, - ReceiverUsername: tx.RcvUserName, - Sender: senderAddress, - SenderUsername: tx.SndUserName, - GasPrice: tx.GasPrice, - GasLimit: tx.GasLimit, - Data: tx.Data, - Signature: hex.EncodeToString(tx.Signature), - Options: tx.Options, - Version: tx.Version, - ChainID: string(tx.ChainID), - InnerTransactions: tu.prepareInnerTxs(tx), + Tx: tx, + Type: string(transaction.TxTypeNormal), + Nonce: tx.Nonce, + Value: tx.Value.String(), + Receiver: receiverAddress, + ReceiverUsername: tx.RcvUserName, + Sender: senderAddress, + SenderUsername: tx.SndUserName, + GasPrice: tx.GasPrice, + GasLimit: tx.GasLimit, + Data: tx.Data, + Signature: hex.EncodeToString(tx.Signature), + Options: tx.Options, + Version: tx.Version, + ChainID: string(tx.ChainID), } if len(tx.GuardianAddr) > 0 { @@ -153,72 +133,29 @@ func (tu *txUnmarshaller) prepareNormalTx(tx *transaction.Transaction) *transact apiTx.GuardianSignature = hex.EncodeToString(tx.GuardianSignature) } - if len(tx.RelayerAddr) > 0 { - apiTx.RelayerAddress = tu.addressPubKeyConverter.SilentEncode(tx.RelayerAddr, log) - } - return apiTx } -func (tu *txUnmarshaller) prepareInnerTxs(tx *transaction.Transaction) []*transaction.FrontendTransaction { - if len(tx.InnerTransactions) == 0 { - return nil - } - - innerTxs := make([]*transaction.FrontendTransaction, 0, len(tx.InnerTransactions)) - for _, innerTx := range tx.InnerTransactions { - frontEndTx := &transaction.FrontendTransaction{ - Nonce: innerTx.Nonce, - Value: innerTx.Value.String(), - Receiver: tu.addressPubKeyConverter.SilentEncode(innerTx.RcvAddr, log), - Sender: tu.addressPubKeyConverter.SilentEncode(innerTx.SndAddr, log), - SenderUsername: innerTx.SndUserName, - ReceiverUsername: innerTx.RcvUserName, - GasPrice: innerTx.GasPrice, - GasLimit: innerTx.GasLimit, - Data: innerTx.Data, - Signature: hex.EncodeToString(innerTx.Signature), - ChainID: string(innerTx.ChainID), - Version: innerTx.Version, - Options: innerTx.Options, - } - - if len(innerTx.GuardianAddr) > 0 { - frontEndTx.GuardianAddr = tu.addressPubKeyConverter.SilentEncode(innerTx.GuardianAddr, log) - frontEndTx.GuardianSignature = hex.EncodeToString(innerTx.GuardianSignature) - } - - if len(innerTx.RelayerAddr) > 0 { - frontEndTx.Relayer = tu.addressPubKeyConverter.SilentEncode(innerTx.RelayerAddr, log) - } - - innerTxs = append(innerTxs, frontEndTx) - } - - return innerTxs -} - func (tu *txUnmarshaller) prepareInvalidTx(tx *transaction.Transaction) *transaction.ApiTransactionResult { receiverAddress := tu.addressPubKeyConverter.SilentEncode(tx.RcvAddr, log) senderAddress := tu.addressPubKeyConverter.SilentEncode(tx.SndAddr, log) apiTx := &transaction.ApiTransactionResult{ - Tx: tx, - Type: string(transaction.TxTypeInvalid), - Nonce: tx.Nonce, - Value: tx.Value.String(), - Receiver: receiverAddress, - ReceiverUsername: tx.RcvUserName, - Sender: senderAddress, - SenderUsername: tx.SndUserName, - GasPrice: tx.GasPrice, - GasLimit: tx.GasLimit, - Data: tx.Data, - Signature: hex.EncodeToString(tx.Signature), - Options: tx.Options, - Version: tx.Version, - ChainID: string(tx.ChainID), - InnerTransactions: tu.prepareInnerTxs(tx), + Tx: tx, + Type: string(transaction.TxTypeInvalid), + Nonce: tx.Nonce, + Value: tx.Value.String(), + Receiver: receiverAddress, + ReceiverUsername: tx.RcvUserName, + Sender: senderAddress, + SenderUsername: tx.SndUserName, + GasPrice: tx.GasPrice, + GasLimit: tx.GasLimit, + Data: tx.Data, + Signature: hex.EncodeToString(tx.Signature), + Options: tx.Options, + Version: tx.Version, + ChainID: string(tx.ChainID), } if len(tx.GuardianAddr) > 0 { @@ -226,10 +163,6 @@ func (tu *txUnmarshaller) prepareInvalidTx(tx *transaction.Transaction) *transac apiTx.GuardianSignature = hex.EncodeToString(tx.GuardianSignature) } - if len(tx.RelayerAddr) > 0 { - apiTx.RelayerAddress = tu.addressPubKeyConverter.SilentEncode(tx.RelayerAddr, log) - } - return apiTx } diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index bc84198eca5..7d828d26394 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -121,7 +121,6 @@ func InitConfigMetrics( appStatusHandler.SetUInt64Value(common.MetricReturnDataToLastTransferEnableEpoch, uint64(enableEpochs.ReturnDataToLastTransferEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricSenderInOutTransferEnableEpoch, uint64(enableEpochs.SenderInOutTransferEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricRelayedTransactionsV2EnableEpoch, uint64(enableEpochs.RelayedTransactionsV2EnableEpoch)) - appStatusHandler.SetUInt64Value(common.MetricRelayedTransactionsV3EnableEpoch, uint64(enableEpochs.RelayedTransactionsV3EnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricFixRelayedBaseCostEnableEpoch, uint64(enableEpochs.FixRelayedBaseCostEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricUnbondTokensV2EnableEpoch, uint64(enableEpochs.UnbondTokensV2EnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricSaveJailedAlwaysEnableEpoch, uint64(enableEpochs.SaveJailedAlwaysEnableEpoch)) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index bec9f099923..1aa3bd7be2e 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -208,10 +208,9 @@ func TestInitConfigMetrics(t *testing.T) { EGLDInMultiTransferEnableEpoch: 101, CryptoOpcodesV2EnableEpoch: 102, ScToScLogEventEnableEpoch: 103, - RelayedTransactionsV3EnableEpoch: 104, - FixRelayedBaseCostEnableEpoch: 105, - MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 106, - FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107, + FixRelayedBaseCostEnableEpoch: 104, + MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 105, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 106, MaxNodesChangeEnableEpoch: []config.MaxNodesChangeConfig{ { EpochEnable: 0, @@ -330,10 +329,9 @@ func TestInitConfigMetrics(t *testing.T) { "erd_egld_in_multi_transfer_enable_epoch": uint32(101), "erd_crypto_opcodes_v2_enable_epoch": uint32(102), "erd_set_sc_to_sc_log_event_enable_epoch": uint32(103), - "erd_relayed_transactions_v3_enable_epoch": uint32(104), - "erd_fix_relayed_base_cost_enable_epoch": uint32(105), - "erd_multi_esdt_transfer_execute_by_user_enable_epoch": uint32(106), - "erd_fix_relayed_move_balance_to_non_payable_sc_enable_epoch": uint32(107), + "erd_fix_relayed_base_cost_enable_epoch": uint32(104), + "erd_multi_esdt_transfer_execute_by_user_enable_epoch": uint32(105), + "erd_fix_relayed_move_balance_to_non_payable_sc_enable_epoch": uint32(106), "erd_max_nodes_change_enable_epoch": nil, "erd_total_supply": "12345", "erd_hysteresis": "0.100000", diff --git a/node/node.go b/node/node.go index 7331b9d44ca..a652e80be60 100644 --- a/node/node.go +++ b/node/node.go @@ -798,8 +798,6 @@ func (n *Node) commonTransactionValidation( enableSignWithTxHash, n.coreComponents.TxSignHasher(), n.coreComponents.TxVersionChecker(), - n.coreComponents.EnableEpochsHandler(), - n.processComponents.RelayedTxV3Processor(), ) if err != nil { return nil, nil, err @@ -893,20 +891,19 @@ func (n *Node) CreateTransaction(txArgs *external.ArgsCreateTransaction) (*trans } tx := &transaction.Transaction{ - Nonce: txArgs.Nonce, - Value: valAsBigInt, - RcvAddr: receiverAddress, - RcvUserName: txArgs.ReceiverUsername, - SndAddr: senderAddress, - SndUserName: txArgs.SenderUsername, - GasPrice: txArgs.GasPrice, - GasLimit: txArgs.GasLimit, - Data: txArgs.DataField, - Signature: signatureBytes, - ChainID: []byte(txArgs.ChainID), - Version: txArgs.Version, - Options: txArgs.Options, - InnerTransactions: txArgs.InnerTransactions, + Nonce: txArgs.Nonce, + Value: valAsBigInt, + RcvAddr: receiverAddress, + RcvUserName: txArgs.ReceiverUsername, + SndAddr: senderAddress, + SndUserName: txArgs.SenderUsername, + GasPrice: txArgs.GasPrice, + GasLimit: txArgs.GasLimit, + Data: txArgs.DataField, + Signature: signatureBytes, + ChainID: []byte(txArgs.ChainID), + Version: txArgs.Version, + Options: txArgs.Options, } if len(txArgs.Guardian) > 0 { @@ -916,13 +913,6 @@ func (n *Node) CreateTransaction(txArgs *external.ArgsCreateTransaction) (*trans } } - if len(txArgs.Relayer) > 0 { - tx.RelayerAddr, err = addrPubKeyConverter.Decode(txArgs.Relayer) - if err != nil { - return nil, nil, errors.New("could not create relayer address from provided param") - } - } - var txHash []byte txHash, err = core.CalculateHash(n.coreComponents.InternalMarshalizer(), n.coreComponents.Hasher(), tx) if err != nil { diff --git a/node/node_test.go b/node/node_test.go index b584dc2370b..319890a5d0d 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -61,7 +61,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/mainFactoryMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" "github.com/multiversx/mx-chain-go/testscommon/stakingcommon" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -1851,22 +1850,21 @@ func TestGenerateTransaction_CorrectParamsShouldNotError(t *testing.T) { func getDefaultTransactionArgs() *external.ArgsCreateTransaction { return &external.ArgsCreateTransaction{ - Nonce: uint64(0), - Value: new(big.Int).SetInt64(10).String(), - Receiver: "rcv", - ReceiverUsername: []byte("rcvrUsername"), - Sender: "snd", - SenderUsername: []byte("sndrUsername"), - GasPrice: uint64(10), - GasLimit: uint64(20), - DataField: []byte("-"), - SignatureHex: hex.EncodeToString(bytes.Repeat([]byte{0}, 10)), - ChainID: "chainID", - Version: 1, - Options: 0, - Guardian: "", - GuardianSigHex: "", - InnerTransactions: nil, + Nonce: uint64(0), + Value: new(big.Int).SetInt64(10).String(), + Receiver: "rcv", + ReceiverUsername: []byte("rcvrUsername"), + Sender: "snd", + SenderUsername: []byte("sndrUsername"), + GasPrice: uint64(10), + GasLimit: uint64(20), + DataField: []byte("-"), + SignatureHex: hex.EncodeToString(bytes.Repeat([]byte{0}, 10)), + ChainID: "chainID", + Version: 1, + Options: 0, + Guardian: "", + GuardianSigHex: "", } } @@ -5297,7 +5295,6 @@ func getDefaultProcessComponents() *factoryMock.ProcessComponentsMock { TxsSenderHandlerField: &txsSenderMock.TxsSenderHandlerMock{}, ScheduledTxsExecutionHandlerInternal: &testscommon.ScheduledTxsExecutionStub{}, HistoryRepositoryInternal: &dblookupext.HistoryRepositoryStub{}, - RelayedTxV3ProcessorField: &processMocks.RelayedTxV3ProcessorMock{}, } } diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index dccf0366b23..e0d56acbde3 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -135,11 +135,6 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans feeInfo.SetFee(initialPaidFee) } - if len(txHandler.GetUserTransactions()) > 0 { - tep.prepareRelayedTxV3WithResults(txHashHex, txWithResult) - continue - } - totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) isRelayedAfterFix := isRelayed && isFeeFixActive if isRelayedAfterFix { @@ -155,7 +150,6 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults, isRelayedAfterFix bool) { hasRefund := false - totalRefunds := big.NewInt(0) for _, scrHandler := range txWithResults.scrs { scr, ok := scrHandler.GetTxHandler().(*smartContractResult.SmartContractResult) if !ok { @@ -163,21 +157,15 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi } if isSCRForSenderWithRefund(scr, txHashHex, txWithResults.GetTxHandler()) || isRefundForRelayed(scr, txWithResults.GetTxHandler()) { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), scr.Value) + + txWithResults.GetFeeInfo().SetGasUsed(gasUsed) + txWithResults.GetFeeInfo().SetFee(fee) hasRefund = true - totalRefunds.Add(totalRefunds, scr.Value) + break } } - if totalRefunds.Cmp(big.NewInt(0)) > 0 { - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), totalRefunds) - txWithResults.GetFeeInfo().SetGasUsed(gasUsed) - txWithResults.GetFeeInfo().SetFee(fee) - } - - if isRelayedAfterFix { - return - } - tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) } @@ -243,31 +231,6 @@ func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transact return big.NewInt(0).Add(fee, innerFee), true } -func (tep *transactionsFeeProcessor) prepareRelayedTxV3WithResults(txHashHex string, txWithResults *transactionWithResults) { - refundsValue := big.NewInt(0) - for _, scrHandler := range txWithResults.scrs { - scr, ok := scrHandler.GetTxHandler().(*smartContractResult.SmartContractResult) - if !ok { - continue - } - - if !isRefundForRelayed(scr, txWithResults.GetTxHandler()) { - continue - } - - refundsValue.Add(refundsValue, scr.Value) - } - - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), refundsValue) - - txWithResults.GetFeeInfo().SetGasUsed(gasUsed) - txWithResults.GetFeeInfo().SetFee(fee) - - hasRefunds := refundsValue.Cmp(big.NewInt(0)) == 1 - tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefunds) - -} - func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( txHashHex string, txWithResults *transactionWithResults, diff --git a/process/block/preprocess/gasComputation.go b/process/block/preprocess/gasComputation.go index 9888917b7f3..628c6de455f 100644 --- a/process/block/preprocess/gasComputation.go +++ b/process/block/preprocess/gasComputation.go @@ -426,7 +426,7 @@ func (gc *gasComputation) computeGasProvidedByTxV1( } func (gc *gasComputation) isRelayedTx(txType process.TransactionType) bool { - return txType == process.RelayedTx || txType == process.RelayedTxV2 || txType == process.RelayedTxV3 + return txType == process.RelayedTx || txType == process.RelayedTxV2 } // IsInterfaceNil returns true if there is no value under the interface diff --git a/process/constants.go b/process/constants.go index 44101f50b7c..f75e7b882ee 100644 --- a/process/constants.go +++ b/process/constants.go @@ -36,8 +36,6 @@ const ( RelayedTx // RelayedTxV2 defines the ID of a slim relayed transaction version RelayedTxV2 - // RelayedTxV3 defines the ID of a relayed v3 transaction - RelayedTxV3 // RewardTx defines ID of a reward transaction RewardTx // InvalidTransaction defines unknown transaction type @@ -58,8 +56,6 @@ func (transactionType TransactionType) String() string { return "RelayedTx" case RelayedTxV2: return "RelayedTxV2" - case RelayedTxV3: - return "RelayedTxV3" case RewardTx: return "RewardTx" case InvalidTransaction: diff --git a/process/coordinator/transactionType.go b/process/coordinator/transactionType.go index d754da2c34d..32081a1ac0e 100644 --- a/process/coordinator/transactionType.go +++ b/process/coordinator/transactionType.go @@ -90,11 +90,6 @@ func (tth *txTypeHandler) ComputeTransactionType(tx data.TransactionHandler) (pr } return process.InvalidTransaction, process.InvalidTransaction } - - if tth.isRelayedTransactionV3(tx) { - return process.RelayedTxV3, process.RelayedTxV3 - } - if len(tx.GetData()) == 0 { return process.MoveBalance, process.MoveBalance } @@ -195,10 +190,6 @@ func (tth *txTypeHandler) isRelayedTransactionV2(functionName string) bool { return functionName == core.RelayedTransactionV2 } -func (tth *txTypeHandler) isRelayedTransactionV3(tx data.TransactionHandler) bool { - return len(tx.GetUserTransactions()) != 0 -} - func (tth *txTypeHandler) isDestAddressEmpty(tx data.TransactionHandler) bool { isEmptyAddress := bytes.Equal(tx.GetRcvAddr(), make([]byte, tth.pubkeyConv.Len())) return isEmptyAddress diff --git a/process/coordinator/transactionType_test.go b/process/coordinator/transactionType_test.go index 9739075d847..918b6069212 100644 --- a/process/coordinator/transactionType_test.go +++ b/process/coordinator/transactionType_test.go @@ -466,32 +466,6 @@ func TestTxTypeHandler_ComputeTransactionTypeRelayedV2Func(t *testing.T) { assert.Equal(t, process.RelayedTxV2, txTypeCross) } -func TestTxTypeHandler_ComputeTransactionTypeRelayedV3(t *testing.T) { - t.Parallel() - - tx := &transaction.Transaction{} - tx.Nonce = 0 - tx.SndAddr = []byte("000") - tx.RcvAddr = []byte("001") - tx.Value = big.NewInt(45) - tx.InnerTransactions = []*transaction.Transaction{{Nonce: 1}} - - arg := createMockArguments() - arg.PubkeyConverter = &testscommon.PubkeyConverterStub{ - LenCalled: func() int { - return len(tx.RcvAddr) - }, - } - tth, err := NewTxTypeHandler(arg) - - assert.NotNil(t, tth) - assert.Nil(t, err) - - txTypeIn, txTypeCross := tth.ComputeTransactionType(tx) - assert.Equal(t, process.RelayedTxV3, txTypeIn) - assert.Equal(t, process.RelayedTxV3, txTypeCross) -} - func TestTxTypeHandler_ComputeTransactionTypeForSCRCallBack(t *testing.T) { t.Parallel() diff --git a/process/disabled/failedTxLogsAccumulator.go b/process/disabled/failedTxLogsAccumulator.go deleted file mode 100644 index 3bd3f01cd69..00000000000 --- a/process/disabled/failedTxLogsAccumulator.go +++ /dev/null @@ -1,33 +0,0 @@ -package disabled - -import ( - "github.com/multiversx/mx-chain-core-go/data" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" -) - -type failedTxLogsAccumulator struct { -} - -// NewFailedTxLogsAccumulator returns a new instance of disabled failedTxLogsAccumulator -func NewFailedTxLogsAccumulator() *failedTxLogsAccumulator { - return &failedTxLogsAccumulator{} -} - -// GetLogs returns false as it is disabled -func (accumulator *failedTxLogsAccumulator) GetLogs(_ []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) { - return nil, nil, false -} - -// SaveLogs returns nil as it is disabled -func (accumulator *failedTxLogsAccumulator) SaveLogs(_ []byte, _ data.TransactionHandler, _ []*vmcommon.LogEntry) error { - return nil -} - -// Remove does nothing as it is disabled -func (accumulator *failedTxLogsAccumulator) Remove(_ []byte) { -} - -// IsInterfaceNil returns true if there is no value under the interface -func (accumulator *failedTxLogsAccumulator) IsInterfaceNil() bool { - return accumulator == nil -} diff --git a/process/disabled/relayedTxV3Processor.go b/process/disabled/relayedTxV3Processor.go deleted file mode 100644 index ddabd2753c8..00000000000 --- a/process/disabled/relayedTxV3Processor.go +++ /dev/null @@ -1,23 +0,0 @@ -package disabled - -import ( - "github.com/multiversx/mx-chain-core-go/data/transaction" -) - -type relayedTxV3Processor struct { -} - -// NewRelayedTxV3Processor returns a new instance of disabled relayedTxV3Processor -func NewRelayedTxV3Processor() *relayedTxV3Processor { - return &relayedTxV3Processor{} -} - -// CheckRelayedTx returns nil as it is disabled -func (proc *relayedTxV3Processor) CheckRelayedTx(_ *transaction.Transaction) error { - return nil -} - -// IsInterfaceNil returns true if there is no value under the interface -func (proc *relayedTxV3Processor) IsInterfaceNil() bool { - return proc == nil -} diff --git a/process/economics/economicsData.go b/process/economics/economicsData.go index 170377e62d3..5b7ce045237 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -13,7 +13,6 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/process" - "github.com/multiversx/mx-chain-go/process/disabled" "github.com/multiversx/mx-chain-go/statusHandler" logger "github.com/multiversx/mx-chain-logger-go" ) @@ -35,8 +34,6 @@ type economicsData struct { statusHandler core.AppStatusHandler enableEpochsHandler common.EnableEpochsHandler txVersionHandler process.TxVersionCheckerHandler - txTypeHandler process.TxTypeHandler - mutTxTypeHandler sync.RWMutex mut sync.RWMutex } @@ -78,7 +75,6 @@ func NewEconomicsData(args ArgsNewEconomicsData) (*economicsData, error) { statusHandler: statusHandler.NewNilStatusHandler(), enableEpochsHandler: args.EnableEpochsHandler, txVersionHandler: args.TxVersionChecker, - txTypeHandler: disabled.NewTxTypeHandler(), } ed.yearSettings = make(map[uint32]*config.YearSetting) @@ -141,19 +137,6 @@ func (ed *economicsData) SetStatusHandler(statusHandler core.AppStatusHandler) e return ed.rewardsConfigHandler.setStatusHandler(statusHandler) } -// SetTxTypeHandler sets the provided tx type handler -func (ed *economicsData) SetTxTypeHandler(txTypeHandler process.TxTypeHandler) error { - if check.IfNil(txTypeHandler) { - return process.ErrNilTxTypeHandler - } - - ed.mutTxTypeHandler.Lock() - ed.txTypeHandler = txTypeHandler - ed.mutTxTypeHandler.Unlock() - - return nil -} - // LeaderPercentage returns leader reward percentage func (ed *economicsData) LeaderPercentage() float64 { currentEpoch := ed.enableEpochsHandler.GetCurrentEpoch() @@ -302,11 +285,6 @@ func (ed *economicsData) ComputeTxFee(tx data.TransactionWithFeeHandler) *big.In // ComputeTxFeeInEpoch computes the provided transaction's fee in a specific epoch func (ed *economicsData) ComputeTxFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int { - if len(tx.GetUserTransactions()) > 0 { - _, totalFee, _ := ed.ComputeRelayedTxFees(tx) - return totalFee - } - if ed.enableEpochsHandler.IsFlagEnabledInEpoch(common.GasPriceModifierFlag, epoch) { if isSmartContractResult(tx) { return ed.ComputeFeeForProcessingInEpoch(tx, tx.GetGasLimit(), epoch) @@ -330,56 +308,6 @@ func (ed *economicsData) ComputeTxFeeInEpoch(tx data.TransactionWithFeeHandler, return ed.ComputeMoveBalanceFeeInEpoch(tx, epoch) } -// ComputeRelayedTxFees returns the both the total fee for the entire relayed tx and the relayed only fee -func (ed *economicsData) ComputeRelayedTxFees(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { - innerTxs := tx.GetUserTransactions() - if len(innerTxs) == 0 { - return big.NewInt(0), big.NewInt(0), process.ErrEmptyInnerTransactions - } - - feesForInnerTxs := ed.getTotalFeesRequiredForInnerTxs(innerTxs) - - relayerUnguardedMoveBalanceFee := core.SafeMul(ed.GasPriceForMove(tx), ed.MinGasLimit()) - relayerTotalMoveBalanceFee := ed.ComputeMoveBalanceFee(tx) - relayerMoveBalanceFeeDiff := big.NewInt(0).Sub(relayerTotalMoveBalanceFee, relayerUnguardedMoveBalanceFee) - - relayerFee := big.NewInt(0).Mul(relayerUnguardedMoveBalanceFee, big.NewInt(int64(len(innerTxs)))) - relayerFee.Add(relayerFee, relayerMoveBalanceFeeDiff) // add the difference in case of guarded relayed tx - - totalFee := big.NewInt(0).Add(relayerFee, feesForInnerTxs) - - return relayerFee, totalFee, nil -} - -func (ed *economicsData) getTotalFeesRequiredForInnerTxs(innerTxs []data.TransactionHandler) *big.Int { - totalFees := big.NewInt(0) - for _, innerTx := range innerTxs { - if ed.isMoveBalance(innerTx) { - innerTxFee := ed.ComputeMoveBalanceFee(innerTx) - totalFees.Add(totalFees, innerTxFee) - - continue - } - - gasToUse := innerTx.GetGasLimit() - ed.ComputeGasLimit(innerTx) - moveBalanceUserFee := ed.ComputeMoveBalanceFee(innerTx) - processingUserFee := ed.ComputeFeeForProcessing(innerTx, gasToUse) - innerTxFee := big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) - - totalFees.Add(totalFees, innerTxFee) - } - - return totalFees -} - -func (ed *economicsData) isMoveBalance(tx data.TransactionHandler) bool { - ed.mutTxTypeHandler.RLock() - _, dstTxType := ed.txTypeHandler.ComputeTransactionType(tx) - ed.mutTxTypeHandler.RUnlock() - - return dstTxType == process.MoveBalance -} - // SplitTxGasInCategories returns the gas split per categories func (ed *economicsData) SplitTxGasInCategories(tx data.TransactionWithFeeHandler) (gasLimitMove, gasLimitProcess uint64) { currentEpoch := ed.enableEpochsHandler.GetCurrentEpoch() @@ -590,18 +518,6 @@ func (ed *economicsData) ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(tx data.T txFee := ed.ComputeTxFeeInEpoch(tx, epoch) - if len(tx.GetUserTransactions()) > 0 { - txFeeAfterRefund := txFee.Sub(txFee, refundValue) - - gasPriceForProcessing := ed.GasPriceForProcessingInEpoch(tx, epoch) - gasUnitsRefunded := refundValue.Uint64() / gasPriceForProcessing - - gasUnitsConsideredForInitialFee := ed.computeRelayedTxV3MinGasLimit(tx) - gasUnitsUsed := gasUnitsConsideredForInitialFee - gasUnitsRefunded - - return gasUnitsUsed, txFeeAfterRefund - } - isPenalizedTooMuchGasFlagEnabled := ed.enableEpochsHandler.IsFlagEnabledInEpoch(common.PenalizedTooMuchGasFlag, epoch) isGasPriceModifierFlagEnabled := ed.enableEpochsHandler.IsFlagEnabledInEpoch(common.GasPriceModifierFlag, epoch) flagCorrectTxFee := !isPenalizedTooMuchGasFlagEnabled && !isGasPriceModifierFlagEnabled @@ -689,20 +605,6 @@ func (ed *economicsData) ComputeGasLimitBasedOnBalanceInEpoch(tx data.Transactio return totalGasLimit, nil } -func (ed *economicsData) computeRelayedTxV3MinGasLimit(tx data.TransactionWithFeeHandler) uint64 { - relayedTxGasLimit := ed.ComputeGasLimit(tx) - relayedTxMinGasLimit := ed.MinGasLimit() - relayedTxGasLimitDiff := relayedTxGasLimit - relayedTxMinGasLimit // this may be positive if the relayed tx is guarded - - innerTxs := tx.GetUserTransactions() - totalGasLimit := relayedTxGasLimitDiff + relayedTxMinGasLimit*uint64(len(innerTxs)) - for _, innerTx := range innerTxs { - totalGasLimit += innerTx.GetGasLimit() - } - - return totalGasLimit -} - // IsInterfaceNil returns true if there is no value under the interface func (ed *economicsData) IsInterfaceNil() bool { return ed == nil diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index f1a66e25dcd..1f2c913a826 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" @@ -1281,39 +1280,6 @@ func TestEconomicsData_ComputeGasUsedAndFeeBasedOnRefundValueSpecialBuiltInTooMu require.Equal(t, expectedFee, fee) } -func TestEconomicsData_ComputeGasUsedAndFeeBasedOnRefundValueRelayedV3(t *testing.T) { - t.Parallel() - - economicData, _ := economics.NewEconomicsData(createArgsForEconomicsDataRealFees()) - tx := &transaction.Transaction{ - GasPrice: 1000000000, - GasLimit: 99000000, - InnerTransactions: []*transaction.Transaction{ - { - GasPrice: 1000000000, - GasLimit: 85000000, - Data: []byte("createNewDelegationContract@00@00"), - }, - { - GasPrice: 1000000000, - GasLimit: 50000, - }, - { - GasPrice: 1000000000, - GasLimit: 50000, - }, - }, - } - - expectedGasUsed := uint64(55349500) - expectedFee, _ := big.NewInt(0).SetString("899500000000000", 10) - - refundValue, _ := big.NewInt(0).SetString("299005000000000", 10) - gasUsed, fee := economicData.ComputeGasUsedAndFeeBasedOnRefundValue(tx, refundValue) - require.Equal(t, expectedGasUsed, gasUsed) - require.Equal(t, expectedFee, fee) -} - func TestEconomicsData_ComputeGasLimitBasedOnBalance(t *testing.T) { t.Parallel() @@ -1655,102 +1621,3 @@ func TestEconomicsData_RewardsTopUpFactor(t *testing.T) { value := economicsData.RewardsTopUpFactor() assert.Equal(t, topUpFactor, value) } - -func TestEconomicsData_ComputeRelayedTxFees(t *testing.T) { - t.Parallel() - - args := createArgsForEconomicsData(1) - minGasLimit, _ := strconv.Atoi(args.Economics.FeeSettings.GasLimitSettings[0].MinGasLimit) - tx := &transaction.Transaction{ - Nonce: 0, - Value: big.NewInt(0), - RcvAddr: []byte("rel"), - SndAddr: []byte("rel"), - GasPrice: 1, - GasLimit: uint64(minGasLimit) * 4, - InnerTransactions: []*transaction.Transaction{ - { - Nonce: 0, - Value: big.NewInt(1), - RcvAddr: []byte("rcv1"), - SndAddr: []byte("snd1"), - GasPrice: 1, - GasLimit: uint64(minGasLimit), - RelayerAddr: []byte("rel"), - }, - { - Nonce: 0, - Value: big.NewInt(1), - RcvAddr: []byte("rcv1"), - SndAddr: []byte("snd2"), - GasPrice: 1, - GasLimit: uint64(minGasLimit), - RelayerAddr: []byte("rel"), - }, - }, - } - t.Run("empty inner txs should error", func(t *testing.T) { - t.Parallel() - - economicsData, _ := economics.NewEconomicsData(args) - - txCopy := *tx - txCopy.InnerTransactions = []*transaction.Transaction{} - relayerFee, totalFee, err := economicsData.ComputeRelayedTxFees(&txCopy) - require.Equal(t, process.ErrEmptyInnerTransactions, err) - require.Equal(t, big.NewInt(0), relayerFee) - require.Equal(t, big.NewInt(0), totalFee) - }) - t.Run("should work unguarded", func(t *testing.T) { - t.Parallel() - - economicsData, _ := economics.NewEconomicsData(args) - - _ = economicsData.SetTxTypeHandler(&testscommon.TxTypeHandlerMock{ - ComputeTransactionTypeCalled: func(tx data.TransactionHandler) (process.TransactionType, process.TransactionType) { - return process.MoveBalance, process.MoveBalance - }, - }) - - relayerFee, totalFee, err := economicsData.ComputeRelayedTxFees(tx) - require.NoError(t, err) - expectedRelayerFee := big.NewInt(int64(2 * uint64(minGasLimit) * tx.GetGasPrice())) // 2 move balance - require.Equal(t, expectedRelayerFee, relayerFee) - require.Equal(t, big.NewInt(int64(tx.GetGasLimit()*tx.GetGasPrice())), totalFee) - }) - t.Run("should work guarded", func(t *testing.T) { - t.Parallel() - - argsLocal := createArgsForEconomicsData(1) - argsLocal.TxVersionChecker = &testscommon.TxVersionCheckerStub{ - IsGuardedTransactionCalled: func(tx *transaction.Transaction) bool { - return len(tx.InnerTransactions) > 0 // only the relayed tx is guarded - }, - } - economicsData, _ := economics.NewEconomicsData(argsLocal) - - extraGasLimitGuardedTx, _ := strconv.Atoi(argsLocal.Economics.FeeSettings.GasLimitSettings[0].ExtraGasLimitGuardedTx) - - txCopy := *tx - txCopy.GasLimit += uint64(extraGasLimitGuardedTx) - relayerFee, totalFee, err := economicsData.ComputeRelayedTxFees(&txCopy) - require.NoError(t, err) - expectedRelayerFee := big.NewInt(int64(2*uint64(minGasLimit)*txCopy.GetGasPrice() + uint64(extraGasLimitGuardedTx)*txCopy.GetGasPrice())) // 2 move balance - require.Equal(t, expectedRelayerFee, relayerFee) - require.Equal(t, big.NewInt(int64(txCopy.GetGasLimit()*txCopy.GetGasPrice())), totalFee) - }) -} - -func TestEconomicsData_SetTxTypeHandler(t *testing.T) { - t.Parallel() - - args := createArgsForEconomicsData(1) - economicsData, _ := economics.NewEconomicsData(args) - assert.NotNil(t, economicsData) - - err := economicsData.SetTxTypeHandler(nil) - require.Equal(t, process.ErrNilTxTypeHandler, err) - - err = economicsData.SetTxTypeHandler(&testscommon.TxTypeHandlerMock{}) - require.NoError(t, err) -} diff --git a/process/errors.go b/process/errors.go index a4e426691bd..83e8095dcb3 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1229,48 +1229,3 @@ var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker") // ErrTransferAndExecuteByUserAddressesAreNil signals that transfer and execute by user addresses are nil var ErrTransferAndExecuteByUserAddressesAreNil = errors.New("transfer and execute by user addresses are nil") - -// ErrRelayedV3GasPriceMismatch signals that relayed v3 gas price is not equal with inner tx -var ErrRelayedV3GasPriceMismatch = errors.New("relayed tx v3 gas price mismatch") - -// ErrRelayedTxV3SenderDoesNotMatchReceiver signals that the sender of relayed tx v3 does not match the receiver -var ErrRelayedTxV3SenderDoesNotMatchReceiver = errors.New("relayed tx v3 sender does not match receiver") - -// ErrRelayedTxV3Disabled signals that the v3 version of relayed tx is disabled -var ErrRelayedTxV3Disabled = errors.New("relayed tx v3 is disabled") - -// ErrRelayedTxV3ZeroVal signals that the v3 version of relayed tx should be created with 0 as value -var ErrRelayedTxV3ZeroVal = errors.New("relayed tx v3 value should be 0") - -// ErrRelayedTxV3RelayerMismatch signals that the relayer address of the inner tx does not match the real relayer -var ErrRelayedTxV3RelayerMismatch = errors.New("relayed tx v3 relayer mismatch") - -// ErrRelayedTxV3GasLimitMismatch signals that relayed tx v3 gas limit is higher than user tx gas limit -var ErrRelayedTxV3GasLimitMismatch = errors.New("relayed tx v3 gas limit mismatch") - -// ErrNilRelayedTxV3Processor signals that a nil relayed tx v3 processor has been provided -var ErrNilRelayedTxV3Processor = errors.New("nil relayed tx v3 processor") - -// ErrRelayedTxV3SenderShardMismatch signals that the sender from inner transaction is from a different shard than relayer -var ErrRelayedTxV3SenderShardMismatch = errors.New("sender shard mismatch") - -// ErrNilRelayerAccount signals that a nil relayer accouont has been provided -var ErrNilRelayerAccount = errors.New("nil relayer account") - -// ErrRelayedTxV3TooManyInnerTransactions signals that too many inner transactions were provided -var ErrRelayedTxV3TooManyInnerTransactions = errors.New("too many inner transactions") - -// ErrConsumedFeesMismatch signals that the fees consumed from relayer do not match the inner transactions fees -var ErrConsumedFeesMismatch = errors.New("consumed fees mismatch") - -// ErrRelayedTxV3InvalidDataField signals that the data field is invalid -var ErrRelayedTxV3InvalidDataField = errors.New("invalid data field") - -// ErrMultipleRelayedTxTypesIsNotAllowed signals that multiple types of relayed tx is not allowed -var ErrMultipleRelayedTxTypesIsNotAllowed = errors.New("multiple relayed tx types is not allowed") - -// ErrNilFailedTxLogsAccumulator signals that a nil failed transaction logs accumulator has been provided -var ErrNilFailedTxLogsAccumulator = errors.New("nil failed transaction logs accumulator") - -// ErrEmptyInnerTransactions signals that the inner transactions slice is empty -var ErrEmptyInnerTransactions = errors.New("empty inner transactions") diff --git a/process/factory/interceptorscontainer/args.go b/process/factory/interceptorscontainer/args.go index 0d224b031ad..294e66290b3 100644 --- a/process/factory/interceptorscontainer/args.go +++ b/process/factory/interceptorscontainer/args.go @@ -43,5 +43,4 @@ type CommonInterceptorsContainerFactoryArgs struct { FullArchivePeerShardMapper process.PeerShardMapper HardforkTrigger heartbeat.HardforkTrigger NodeOperationMode common.NodeOperation - RelayedTxV3Processor process.RelayedTxV3Processor } diff --git a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory.go b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory.go index 31a4344b771..38d3e460bce 100644 --- a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory.go +++ b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory.go @@ -99,7 +99,6 @@ func NewMetaInterceptorsContainerFactory( SignaturesHandler: args.SignaturesHandler, HeartbeatExpiryTimespanInSec: args.HeartbeatExpiryTimespanInSec, PeerID: args.MainMessenger.ID(), - RelayedTxV3Processor: args.RelayedTxV3Processor, } base := &baseInterceptorsContainerFactory{ diff --git a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go index b9124001264..fe853c32662 100644 --- a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go +++ b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go @@ -18,7 +18,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/p2pmocks" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -708,6 +707,5 @@ func getArgumentsMeta( FullArchivePeerShardMapper: &p2pmocks.NetworkShardingCollectorStub{}, HardforkTrigger: &testscommon.HardforkTriggerStub{}, NodeOperationMode: common.NormalOperation, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } } diff --git a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory.go b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory.go index 26224fbc152..beef288c54c 100644 --- a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory.go +++ b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory.go @@ -98,7 +98,6 @@ func NewShardInterceptorsContainerFactory( SignaturesHandler: args.SignaturesHandler, HeartbeatExpiryTimespanInSec: args.HeartbeatExpiryTimespanInSec, PeerID: args.MainMessenger.ID(), - RelayedTxV3Processor: args.RelayedTxV3Processor, } base := &baseInterceptorsContainerFactory{ diff --git a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go index f802562ae35..677876311e9 100644 --- a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go +++ b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go @@ -22,7 +22,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -733,6 +732,5 @@ func getArgumentsShard( MainPeerShardMapper: &p2pmocks.NetworkShardingCollectorStub{}, FullArchivePeerShardMapper: &p2pmocks.NetworkShardingCollectorStub{}, HardforkTrigger: &testscommon.HardforkTriggerStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } } diff --git a/process/interceptors/factory/argInterceptedDataFactory.go b/process/interceptors/factory/argInterceptedDataFactory.go index 36ab4968375..37701a92f7a 100644 --- a/process/interceptors/factory/argInterceptedDataFactory.go +++ b/process/interceptors/factory/argInterceptedDataFactory.go @@ -57,5 +57,4 @@ type ArgInterceptedDataFactory struct { SignaturesHandler process.SignaturesHandler HeartbeatExpiryTimespanInSec int64 PeerID core.PeerID - RelayedTxV3Processor process.RelayedTxV3Processor } diff --git a/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go b/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go index d2ecc63e59d..e46692e6614 100644 --- a/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go +++ b/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go @@ -20,7 +20,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" - testProcessMocks "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" "github.com/stretchr/testify/assert" ) @@ -107,7 +106,6 @@ func createMockArgument( SignaturesHandler: &processMocks.SignaturesHandlerStub{}, HeartbeatExpiryTimespanInSec: 30, PeerID: "pid", - RelayedTxV3Processor: &testProcessMocks.RelayedTxV3ProcessorMock{}, } } diff --git a/process/interceptors/factory/interceptedTxDataFactory.go b/process/interceptors/factory/interceptedTxDataFactory.go index e2dc86e599c..563997c5066 100644 --- a/process/interceptors/factory/interceptedTxDataFactory.go +++ b/process/interceptors/factory/interceptedTxDataFactory.go @@ -31,7 +31,6 @@ type interceptedTxDataFactory struct { txSignHasher hashing.Hasher txVersionChecker process.TxVersionCheckerHandler enableEpochsHandler common.EnableEpochsHandler - relayedTxV3Processor process.RelayedTxV3Processor } // NewInterceptedTxDataFactory creates an instance of interceptedTxDataFactory @@ -108,7 +107,6 @@ func NewInterceptedTxDataFactory(argument *ArgInterceptedDataFactory) (*intercep txSignHasher: argument.CoreComponents.TxSignHasher(), txVersionChecker: argument.CoreComponents.TxVersionChecker(), enableEpochsHandler: argument.CoreComponents.EnableEpochsHandler(), - relayedTxV3Processor: argument.RelayedTxV3Processor, } return itdf, nil @@ -132,8 +130,6 @@ func (itdf *interceptedTxDataFactory) Create(buff []byte) (process.InterceptedDa itdf.enableEpochsHandler.IsFlagEnabled(common.TransactionSignedWithTxHashFlag), itdf.txSignHasher, itdf.txVersionChecker, - itdf.enableEpochsHandler, - itdf.relayedTxV3Processor, ) } diff --git a/process/interface.go b/process/interface.go index 8e943d0a44e..747103f26ca 100644 --- a/process/interface.go +++ b/process/interface.go @@ -699,7 +699,6 @@ type feeHandler interface { ComputeGasLimitInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) uint64 ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(tx data.TransactionWithFeeHandler, refundValue *big.Int, epoch uint32) (uint64, *big.Int) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int - ComputeRelayedTxFees(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) } // TxGasHandler handles a transaction gas and gas cost @@ -726,7 +725,6 @@ type EconomicsDataHandler interface { rewardsHandler feeHandler SetStatusHandler(statusHandler core.AppStatusHandler) error - SetTxTypeHandler(txTypeHandler TxTypeHandler) error IsInterfaceNil() bool } @@ -1361,17 +1359,3 @@ type SentSignaturesTracker interface { ResetCountersForManagedBlockSigner(signerPk []byte) IsInterfaceNil() bool } - -// RelayedTxV3Processor defines a component able to check and process relayed transactions v3 -type RelayedTxV3Processor interface { - CheckRelayedTx(tx *transaction.Transaction) error - IsInterfaceNil() bool -} - -// FailedTxLogsAccumulator defines a component able to accumulate logs during a relayed tx execution -type FailedTxLogsAccumulator interface { - GetLogs(txHash []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) - SaveLogs(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error - Remove(txHash []byte) - IsInterfaceNil() bool -} diff --git a/process/smartContract/processProxy/processProxy.go b/process/smartContract/processProxy/processProxy.go index a36a5fbd4f4..c64db4791a4 100644 --- a/process/smartContract/processProxy/processProxy.go +++ b/process/smartContract/processProxy/processProxy.go @@ -50,30 +50,29 @@ func NewSmartContractProcessorProxy(args scrCommon.ArgsNewSmartContractProcessor proxy := &scProcessorProxy{ args: scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: args.VmContainer, - ArgsParser: args.ArgsParser, - Hasher: args.Hasher, - Marshalizer: args.Marshalizer, - AccountsDB: args.AccountsDB, - BlockChainHook: args.BlockChainHook, - BuiltInFunctions: args.BuiltInFunctions, - PubkeyConv: args.PubkeyConv, - ShardCoordinator: args.ShardCoordinator, - ScrForwarder: args.ScrForwarder, - TxFeeHandler: args.TxFeeHandler, - EconomicsFee: args.EconomicsFee, - TxTypeHandler: args.TxTypeHandler, - GasHandler: args.GasHandler, - GasSchedule: args.GasSchedule, - TxLogsProcessor: args.TxLogsProcessor, - BadTxForwarder: args.BadTxForwarder, - EnableRoundsHandler: args.EnableRoundsHandler, - EnableEpochsHandler: args.EnableEpochsHandler, - EnableEpochs: args.EnableEpochs, - VMOutputCacher: args.VMOutputCacher, - WasmVMChangeLocker: args.WasmVMChangeLocker, - IsGenesisProcessing: args.IsGenesisProcessing, - FailedTxLogsAccumulator: args.FailedTxLogsAccumulator, + VmContainer: args.VmContainer, + ArgsParser: args.ArgsParser, + Hasher: args.Hasher, + Marshalizer: args.Marshalizer, + AccountsDB: args.AccountsDB, + BlockChainHook: args.BlockChainHook, + BuiltInFunctions: args.BuiltInFunctions, + PubkeyConv: args.PubkeyConv, + ShardCoordinator: args.ShardCoordinator, + ScrForwarder: args.ScrForwarder, + TxFeeHandler: args.TxFeeHandler, + EconomicsFee: args.EconomicsFee, + TxTypeHandler: args.TxTypeHandler, + GasHandler: args.GasHandler, + GasSchedule: args.GasSchedule, + TxLogsProcessor: args.TxLogsProcessor, + BadTxForwarder: args.BadTxForwarder, + EnableRoundsHandler: args.EnableRoundsHandler, + EnableEpochsHandler: args.EnableEpochsHandler, + EnableEpochs: args.EnableEpochs, + VMOutputCacher: args.VMOutputCacher, + WasmVMChangeLocker: args.WasmVMChangeLocker, + IsGenesisProcessing: args.IsGenesisProcessing, }, } if check.IfNil(epochNotifier) { diff --git a/process/smartContract/processProxy/processProxy_test.go b/process/smartContract/processProxy/processProxy_test.go index 98a56fd0f30..d153615600f 100644 --- a/process/smartContract/processProxy/processProxy_test.go +++ b/process/smartContract/processProxy/processProxy_test.go @@ -23,7 +23,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" epochNotifierMock "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" @@ -77,10 +76,9 @@ func createMockSmartContractProcessorArguments() scrCommon.ArgsNewSmartContractP return flag == common.SCDeployFlag }, }, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - WasmVMChangeLocker: &sync.RWMutex{}, - VMOutputCacher: txcache.NewDisabledCache(), - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + WasmVMChangeLocker: &sync.RWMutex{}, + VMOutputCacher: txcache.NewDisabledCache(), } } diff --git a/process/smartContract/processProxy/testProcessProxy.go b/process/smartContract/processProxy/testProcessProxy.go index 65e5d525565..5d5d96ee0d2 100644 --- a/process/smartContract/processProxy/testProcessProxy.go +++ b/process/smartContract/processProxy/testProcessProxy.go @@ -28,30 +28,29 @@ type scProcessorTestProxy struct { func NewTestSmartContractProcessorProxy(args scrCommon.ArgsNewSmartContractProcessor, epochNotifier vmcommon.EpochNotifier) (*scProcessorTestProxy, error) { scProcessorTestProxy := &scProcessorTestProxy{ args: scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: args.VmContainer, - ArgsParser: args.ArgsParser, - Hasher: args.Hasher, - Marshalizer: args.Marshalizer, - AccountsDB: args.AccountsDB, - BlockChainHook: args.BlockChainHook, - BuiltInFunctions: args.BuiltInFunctions, - PubkeyConv: args.PubkeyConv, - ShardCoordinator: args.ShardCoordinator, - ScrForwarder: args.ScrForwarder, - TxFeeHandler: args.TxFeeHandler, - EconomicsFee: args.EconomicsFee, - TxTypeHandler: args.TxTypeHandler, - GasHandler: args.GasHandler, - GasSchedule: args.GasSchedule, - TxLogsProcessor: args.TxLogsProcessor, - BadTxForwarder: args.BadTxForwarder, - EnableRoundsHandler: args.EnableRoundsHandler, - EnableEpochsHandler: args.EnableEpochsHandler, - EnableEpochs: args.EnableEpochs, - VMOutputCacher: args.VMOutputCacher, - WasmVMChangeLocker: args.WasmVMChangeLocker, - IsGenesisProcessing: args.IsGenesisProcessing, - FailedTxLogsAccumulator: args.FailedTxLogsAccumulator, + VmContainer: args.VmContainer, + ArgsParser: args.ArgsParser, + Hasher: args.Hasher, + Marshalizer: args.Marshalizer, + AccountsDB: args.AccountsDB, + BlockChainHook: args.BlockChainHook, + BuiltInFunctions: args.BuiltInFunctions, + PubkeyConv: args.PubkeyConv, + ShardCoordinator: args.ShardCoordinator, + ScrForwarder: args.ScrForwarder, + TxFeeHandler: args.TxFeeHandler, + EconomicsFee: args.EconomicsFee, + TxTypeHandler: args.TxTypeHandler, + GasHandler: args.GasHandler, + GasSchedule: args.GasSchedule, + TxLogsProcessor: args.TxLogsProcessor, + BadTxForwarder: args.BadTxForwarder, + EnableRoundsHandler: args.EnableRoundsHandler, + EnableEpochsHandler: args.EnableEpochsHandler, + EnableEpochs: args.EnableEpochs, + VMOutputCacher: args.VMOutputCacher, + WasmVMChangeLocker: args.WasmVMChangeLocker, + IsGenesisProcessing: args.IsGenesisProcessing, }, } diff --git a/process/smartContract/process_test.go b/process/smartContract/process_test.go index 29c1e082be3..bc8caf169f3 100644 --- a/process/smartContract/process_test.go +++ b/process/smartContract/process_test.go @@ -39,7 +39,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" "github.com/multiversx/mx-chain-go/testscommon/trie" "github.com/multiversx/mx-chain-go/testscommon/vmcommonMocks" @@ -116,12 +115,11 @@ func createMockSmartContractProcessorArguments() scrCommon.ArgsNewSmartContractP GasHandler: &testscommon.GasHandlerStub{ SetGasRefundedCalled: func(gasRefunded uint64, hash []byte) {}, }, - GasSchedule: testscommon.NewGasScheduleNotifierMock(gasSchedule), - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.SCDeployFlag), - WasmVMChangeLocker: &sync.RWMutex{}, - VMOutputCacher: txcache.NewDisabledCache(), - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + GasSchedule: testscommon.NewGasScheduleNotifierMock(gasSchedule), + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.SCDeployFlag), + WasmVMChangeLocker: &sync.RWMutex{}, + VMOutputCacher: txcache.NewDisabledCache(), } } diff --git a/process/smartContract/processorV2/processV2.go b/process/smartContract/processorV2/processV2.go index dafa4f9712f..5f6c02b7d09 100644 --- a/process/smartContract/processorV2/processV2.go +++ b/process/smartContract/processorV2/processV2.go @@ -81,14 +81,13 @@ type scProcessor struct { txTypeHandler process.TxTypeHandler gasHandler process.GasHandler - builtInGasCosts map[string]uint64 - persistPerByte uint64 - storePerByte uint64 - mutGasLock sync.RWMutex - txLogsProcessor process.TransactionLogProcessor - failedTxLogsAccumulator process.FailedTxLogsAccumulator - vmOutputCacher storage.Cacher - isGenesisProcessing bool + builtInGasCosts map[string]uint64 + persistPerByte uint64 + storePerByte uint64 + mutGasLock sync.RWMutex + txLogsProcessor process.TransactionLogProcessor + vmOutputCacher storage.Cacher + isGenesisProcessing bool executableCheckers map[string]scrCommon.ExecutableChecker mutExecutableCheckers sync.RWMutex @@ -162,9 +161,6 @@ func NewSmartContractProcessorV2(args scrCommon.ArgsNewSmartContractProcessor) ( if check.IfNil(args.TxLogsProcessor) { return nil, process.ErrNilTxLogsProcessor } - if check.IfNil(args.FailedTxLogsAccumulator) { - return nil, process.ErrNilFailedTxLogsAccumulator - } if check.IfNil(args.EnableEpochsHandler) { return nil, process.ErrNilEnableEpochsHandler } @@ -188,31 +184,30 @@ func NewSmartContractProcessorV2(args scrCommon.ArgsNewSmartContractProcessor) ( builtInFuncCost := args.GasSchedule.LatestGasSchedule()[common.BuiltInCost] baseOperationCost := args.GasSchedule.LatestGasSchedule()[common.BaseOperationCost] sc := &scProcessor{ - vmContainer: args.VmContainer, - argsParser: args.ArgsParser, - hasher: args.Hasher, - marshalizer: args.Marshalizer, - accounts: args.AccountsDB, - blockChainHook: args.BlockChainHook, - pubkeyConv: args.PubkeyConv, - shardCoordinator: args.ShardCoordinator, - scrForwarder: args.ScrForwarder, - txFeeHandler: args.TxFeeHandler, - economicsFee: args.EconomicsFee, - txTypeHandler: args.TxTypeHandler, - gasHandler: args.GasHandler, - builtInGasCosts: builtInFuncCost, - txLogsProcessor: args.TxLogsProcessor, - failedTxLogsAccumulator: args.FailedTxLogsAccumulator, - badTxForwarder: args.BadTxForwarder, - builtInFunctions: args.BuiltInFunctions, - isGenesisProcessing: args.IsGenesisProcessing, - arwenChangeLocker: args.WasmVMChangeLocker, - vmOutputCacher: args.VMOutputCacher, - enableEpochsHandler: args.EnableEpochsHandler, - storePerByte: baseOperationCost["StorePerByte"], - persistPerByte: baseOperationCost["PersistPerByte"], - executableCheckers: scrCommon.CreateExecutableCheckersMap(args.BuiltInFunctions), + vmContainer: args.VmContainer, + argsParser: args.ArgsParser, + hasher: args.Hasher, + marshalizer: args.Marshalizer, + accounts: args.AccountsDB, + blockChainHook: args.BlockChainHook, + pubkeyConv: args.PubkeyConv, + shardCoordinator: args.ShardCoordinator, + scrForwarder: args.ScrForwarder, + txFeeHandler: args.TxFeeHandler, + economicsFee: args.EconomicsFee, + txTypeHandler: args.TxTypeHandler, + gasHandler: args.GasHandler, + builtInGasCosts: builtInFuncCost, + txLogsProcessor: args.TxLogsProcessor, + badTxForwarder: args.BadTxForwarder, + builtInFunctions: args.BuiltInFunctions, + isGenesisProcessing: args.IsGenesisProcessing, + arwenChangeLocker: args.WasmVMChangeLocker, + vmOutputCacher: args.VMOutputCacher, + enableEpochsHandler: args.EnableEpochsHandler, + storePerByte: baseOperationCost["StorePerByte"], + persistPerByte: baseOperationCost["PersistPerByte"], + executableCheckers: scrCommon.CreateExecutableCheckersMap(args.BuiltInFunctions), } sc.esdtTransferParser, err = parsers.NewESDTTransferParser(args.Marshalizer) @@ -1412,19 +1407,19 @@ func (sc *scProcessor) isCrossShardESDTTransfer(sender []byte, receiver []byte, func (sc *scProcessor) getOriginalTxHashIfIntraShardRelayedSCR( tx data.TransactionHandler, txHash []byte, -) ([]byte, bool) { +) []byte { relayedSCR, isRelayed := isRelayedTx(tx) if !isRelayed { - return txHash, isRelayed + return txHash } sndShardID := sc.shardCoordinator.ComputeId(relayedSCR.SndAddr) rcvShardID := sc.shardCoordinator.ComputeId(relayedSCR.RcvAddr) if sndShardID != rcvShardID { - return txHash, isRelayed + return txHash } - return relayedSCR.OriginalTxHash, isRelayed + return relayedSCR.OriginalTxHash } // ProcessIfError creates a smart contract result, consumes the gas and returns the value to the user @@ -1514,15 +1509,10 @@ func (sc *scProcessor) processIfErrorWithAddedLogs(acntSnd state.UserAccountHand processIfErrorLogs = append(processIfErrorLogs, failureContext.logs...) } - logsTxHash, isRelayed := sc.getOriginalTxHashIfIntraShardRelayedSCR(tx, failureContext.txHash) - var ignorableError error - if isRelayed { - ignorableError = sc.failedTxLogsAccumulator.SaveLogs(logsTxHash, tx, processIfErrorLogs) - } else { - ignorableError = sc.txLogsProcessor.SaveLog(logsTxHash, tx, processIfErrorLogs) - } + logsTxHash := sc.getOriginalTxHashIfIntraShardRelayedSCR(tx, failureContext.txHash) + ignorableError := sc.txLogsProcessor.SaveLog(logsTxHash, tx, processIfErrorLogs) if ignorableError != nil { - log.Debug("scProcessor.ProcessIfError() save log", "error", ignorableError.Error(), "isRelayed", isRelayed) + log.Debug("scProcessor.ProcessIfError() save log", "error", ignorableError.Error()) } txType, _ := sc.txTypeHandler.ComputeTransactionType(tx) diff --git a/process/smartContract/processorV2/process_test.go b/process/smartContract/processorV2/process_test.go index 8722991d0a7..905c18a033d 100644 --- a/process/smartContract/processorV2/process_test.go +++ b/process/smartContract/processorV2/process_test.go @@ -43,7 +43,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" testsCommonStorage "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/testscommon/vmcommonMocks" @@ -131,10 +130,9 @@ func createMockSmartContractProcessorArguments() scrCommon.ArgsNewSmartContractP return flag == common.SCDeployFlag }, }, - GasSchedule: testscommon.NewGasScheduleNotifierMock(gasSchedule), - WasmVMChangeLocker: &sync.RWMutex{}, - VMOutputCacher: txcache.NewDisabledCache(), - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + GasSchedule: testscommon.NewGasScheduleNotifierMock(gasSchedule), + WasmVMChangeLocker: &sync.RWMutex{}, + VMOutputCacher: txcache.NewDisabledCache(), } } @@ -337,17 +335,6 @@ func TestNewSmartContractProcessor_NilTxLogsProcessorShouldErr(t *testing.T) { require.Equal(t, process.ErrNilTxLogsProcessor, err) } -func TestNewSmartContractProcessor_NilFailedTxLogsAccumulatorShouldErr(t *testing.T) { - t.Parallel() - - arguments := createMockSmartContractProcessorArguments() - arguments.FailedTxLogsAccumulator = nil - sc, err := NewSmartContractProcessorV2(arguments) - - require.Nil(t, sc) - require.Equal(t, process.ErrNilFailedTxLogsAccumulator, err) -} - func TestNewSmartContractProcessor_NilBadTxForwarderShouldErr(t *testing.T) { t.Parallel() @@ -3345,8 +3332,8 @@ func TestScProcessor_ProcessRelayedSCRValueBackToRelayer(t *testing.T) { }, } wasSaveLogsCalled := false - arguments.FailedTxLogsAccumulator = &processMocks.FailedTxLogsAccumulatorMock{ - SaveLogsCalled: func(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { + arguments.TxLogsProcessor = &mock.TxLogsProcessorStub{ + SaveLogCalled: func(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { wasSaveLogsCalled = true return nil }, @@ -4083,20 +4070,18 @@ func TestProcessGetOriginalTxHashForRelayedIntraShard(t *testing.T) { scr := &smartContractResult.SmartContractResult{Value: big.NewInt(1), SndAddr: bytes.Repeat([]byte{1}, 32)} scrHash := []byte("hash") - logHash, isRelayed := sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) + logHash := sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) assert.Equal(t, scrHash, logHash) - assert.False(t, isRelayed) scr.OriginalTxHash = []byte("originalHash") scr.RelayerAddr = bytes.Repeat([]byte{1}, 32) scr.SndAddr = bytes.Repeat([]byte{1}, 32) scr.RcvAddr = bytes.Repeat([]byte{1}, 32) - logHash, isRelayed = sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) + logHash = sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) assert.Equal(t, scr.OriginalTxHash, logHash) - assert.True(t, isRelayed) scr.RcvAddr = bytes.Repeat([]byte{2}, 32) - logHash, _ = sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) + logHash = sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) assert.Equal(t, scrHash, logHash) } diff --git a/process/smartContract/scrCommon/common.go b/process/smartContract/scrCommon/common.go index 07efc6cfd59..8cd8efd6484 100644 --- a/process/smartContract/scrCommon/common.go +++ b/process/smartContract/scrCommon/common.go @@ -32,30 +32,29 @@ type ExecutableChecker interface { // ArgsNewSmartContractProcessor defines the arguments needed for new smart contract processor type ArgsNewSmartContractProcessor struct { - VmContainer process.VirtualMachinesContainer - ArgsParser process.ArgumentsParser - Hasher hashing.Hasher - Marshalizer marshal.Marshalizer - AccountsDB state.AccountsAdapter - BlockChainHook process.BlockChainHookHandler - BuiltInFunctions vmcommon.BuiltInFunctionContainer - PubkeyConv core.PubkeyConverter - ShardCoordinator sharding.Coordinator - ScrForwarder process.IntermediateTransactionHandler - TxFeeHandler process.TransactionFeeHandler - EconomicsFee process.FeeHandler - TxTypeHandler process.TxTypeHandler - GasHandler process.GasHandler - GasSchedule core.GasScheduleNotifier - TxLogsProcessor process.TransactionLogProcessor - FailedTxLogsAccumulator process.FailedTxLogsAccumulator - BadTxForwarder process.IntermediateTransactionHandler - EnableRoundsHandler process.EnableRoundsHandler - EnableEpochsHandler common.EnableEpochsHandler - EnableEpochs config.EnableEpochs - VMOutputCacher storage.Cacher - WasmVMChangeLocker common.Locker - IsGenesisProcessing bool + VmContainer process.VirtualMachinesContainer + ArgsParser process.ArgumentsParser + Hasher hashing.Hasher + Marshalizer marshal.Marshalizer + AccountsDB state.AccountsAdapter + BlockChainHook process.BlockChainHookHandler + BuiltInFunctions vmcommon.BuiltInFunctionContainer + PubkeyConv core.PubkeyConverter + ShardCoordinator sharding.Coordinator + ScrForwarder process.IntermediateTransactionHandler + TxFeeHandler process.TransactionFeeHandler + EconomicsFee process.FeeHandler + TxTypeHandler process.TxTypeHandler + GasHandler process.GasHandler + GasSchedule core.GasScheduleNotifier + TxLogsProcessor process.TransactionLogProcessor + BadTxForwarder process.IntermediateTransactionHandler + EnableRoundsHandler process.EnableRoundsHandler + EnableEpochsHandler common.EnableEpochsHandler + EnableEpochs config.EnableEpochs + VMOutputCacher storage.Cacher + WasmVMChangeLocker common.Locker + IsGenesisProcessing bool } // FindVMByScAddress is exported for use in all version of scr processors diff --git a/process/transaction/export_test.go b/process/transaction/export_test.go index ef23d5c114f..cd657c3991d 100644 --- a/process/transaction/export_test.go +++ b/process/transaction/export_test.go @@ -62,8 +62,7 @@ func (txProc *txProcessor) ProcessUserTx( userTx, relayedTxValue, relayedNonce, - originalTxHash, - nonRelayedV3UserTxIdx) + originalTxHash) } // ProcessMoveBalanceCostRelayedUserTx calls the un-exported method processMoveBalanceCostRelayedUserTx @@ -93,8 +92,7 @@ func (txProc *txProcessor) ExecuteFailedRelayedTransaction( relayedNonce, originalTx, originalTxHash, - errorMsg, - nonRelayedV3UserTxIdx) + errorMsg) } // CheckMaxGasPrice calls the un-exported method checkMaxGasPrice diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index 831afdcbcbc..75b9a65ae7c 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -13,7 +13,6 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-crypto-go" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" logger "github.com/multiversx/mx-chain-logger-go" @@ -43,8 +42,6 @@ type InterceptedTransaction struct { sndShard uint32 isForCurrentShard bool enableSignedTxWithHash bool - enableEpochsHandler common.EnableEpochsHandler - relayedTxV3Processor process.RelayedTxV3Processor } // NewInterceptedTransaction returns a new instance of InterceptedTransaction @@ -64,8 +61,6 @@ func NewInterceptedTransaction( enableSignedTxWithHash bool, txSignHasher hashing.Hasher, txVersionChecker process.TxVersionCheckerHandler, - enableEpochsHandler common.EnableEpochsHandler, - relayedTxV3Processor process.RelayedTxV3Processor, ) (*InterceptedTransaction, error) { if txBuff == nil { @@ -110,12 +105,6 @@ func NewInterceptedTransaction( if check.IfNil(txVersionChecker) { return nil, process.ErrNilTransactionVersionChecker } - if check.IfNil(enableEpochsHandler) { - return nil, process.ErrNilEnableEpochsHandler - } - if check.IfNil(relayedTxV3Processor) { - return nil, process.ErrNilRelayedTxV3Processor - } tx, err := createTx(protoMarshalizer, txBuff) if err != nil { @@ -138,8 +127,6 @@ func NewInterceptedTransaction( enableSignedTxWithHash: enableSignedTxWithHash, txVersionChecker: txVersionChecker, txSignHasher: txSignHasher, - enableEpochsHandler: enableEpochsHandler, - relayedTxV3Processor: relayedTxV3Processor, } err = inTx.processFields(txBuff) @@ -212,26 +199,13 @@ func (inTx *InterceptedTransaction) CheckValidity() error { return err } - err = inTx.verifyIfRelayedTxV3(inTx.tx) - if err != nil { - return err - } - - if len(inTx.tx.RelayerAddr) > 0 { - return fmt.Errorf("%w, relayer address found on transaction", process.ErrWrongTransaction) - } - inTx.whiteListerVerifiedTxs.Add([][]byte{inTx.Hash()}) } return nil } -func (inTx *InterceptedTransaction) checkRecursiveRelayed(userTxData []byte, innerTxs []*transaction.Transaction) error { - if isRelayedV3(innerTxs) { - return process.ErrRecursiveRelayedTxIsNotAllowed - } - +func (inTx *InterceptedTransaction) checkRecursiveRelayed(userTxData []byte) error { funcName, _, err := inTx.argsParser.ParseCallData(string(userTxData)) if err != nil { return nil @@ -249,46 +223,6 @@ func isRelayedTx(funcName string) bool { core.RelayedTransactionV2 == funcName } -func isRelayedV3(innerTxs []*transaction.Transaction) bool { - return len(innerTxs) > 0 -} - -func (inTx *InterceptedTransaction) verifyIfRelayedTxV3(tx *transaction.Transaction) error { - if len(tx.InnerTransactions) == 0 { - return nil - } - if !inTx.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsV3Flag) { - return process.ErrRelayedTxV3Disabled - } - err := inTx.relayedTxV3Processor.CheckRelayedTx(tx) - if err != nil { - return err - } - - funcName, _, err := inTx.argsParser.ParseCallData(string(tx.Data)) - if err == nil && isRelayedTx(funcName) { - return process.ErrMultipleRelayedTxTypesIsNotAllowed - } - - return inTx.verifyInnerTransactions(tx) -} - -func (inTx *InterceptedTransaction) verifyInnerTransactions(tx *transaction.Transaction) error { - for _, innerTx := range tx.InnerTransactions { - err := inTx.integrity(innerTx) - if err != nil { - return fmt.Errorf("inner transaction: %w", err) - } - - err = inTx.verifyUserTx(innerTx) - if err != nil { - return fmt.Errorf("inner transaction: %w", err) - } - } - - return nil -} - func (inTx *InterceptedTransaction) verifyIfRelayedTxV2(tx *transaction.Transaction) error { funcName, userTxArgs, err := inTx.argsParser.ParseCallData(string(tx.Data)) if err != nil { @@ -298,10 +232,6 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTxV2(tx *transaction.Transact return nil } - if len(tx.InnerTransactions) > 0 { - return process.ErrMultipleRelayedTxTypesIsNotAllowed - } - userTx, err := createRelayedV2(tx, userTxArgs) if err != nil { return err @@ -323,10 +253,6 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTx(tx *transaction.Transactio return process.ErrInvalidArguments } - if len(tx.InnerTransactions) > 0 { - return process.ErrMultipleRelayedTxTypesIsNotAllowed - } - userTx, err := createTx(inTx.signMarshalizer, userTxArgs[0]) if err != nil { return fmt.Errorf("inner transaction: %w", err) @@ -346,7 +272,7 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTx(tx *transaction.Transactio func (inTx *InterceptedTransaction) verifyUserTx(userTx *transaction.Transaction) error { // recursive relayed transactions are not allowed - err := inTx.checkRecursiveRelayed(userTx.Data, userTx.InnerTransactions) + err := inTx.checkRecursiveRelayed(userTx.Data) if err != nil { return fmt.Errorf("inner transaction: %w", err) } @@ -537,11 +463,6 @@ func (inTx *InterceptedTransaction) Fee() *big.Int { return inTx.feeHandler.ComputeTxFee(inTx.tx) } -// RelayerAddress returns the relayer address from transaction -func (inTx *InterceptedTransaction) RelayerAddress() []byte { - return inTx.tx.RelayerAddr -} - // Type returns the type of this intercepted data func (inTx *InterceptedTransaction) Type() string { return "intercepted tx" diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index 44d416194ab..f35ce467d13 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -15,7 +15,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data" dataTransaction "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/process" "github.com/multiversx/mx-chain-go/process/interceptors" "github.com/multiversx/mx-chain-go/process/mock" @@ -23,10 +22,8 @@ import ( "github.com/multiversx/mx-chain-go/process/transaction" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" - "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" logger "github.com/multiversx/mx-chain-logger-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -37,10 +34,8 @@ var errSignerMockVerifySigFails = errors.New("errSignerMockVerifySigFails") var senderShard = uint32(2) var recvShard = uint32(3) -var relayerShard = senderShard var senderAddress = []byte("12345678901234567890123456789012") var recvAddress = []byte("23456789012345678901234567890123") -var relayerAddress = []byte("34567890123456789012345678901234") var sigBad = []byte("bad-signature") var sigOk = []byte("signature") @@ -95,9 +90,6 @@ func createInterceptedTxWithTxFeeHandlerAndVersionChecker(tx *dataTransaction.Tr if bytes.Equal(address, recvAddress) { return recvShard } - if bytes.Equal(address, relayerAddress) { - return relayerShard - } return shardCoordinator.CurrentShard } @@ -122,8 +114,6 @@ func createInterceptedTxWithTxFeeHandlerAndVersionChecker(tx *dataTransaction.Tr false, &hashingMocks.HasherMock{}, txVerChecker, - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) } @@ -143,9 +133,6 @@ func createInterceptedTxFromPlainTx(tx *dataTransaction.Transaction, txFeeHandle if bytes.Equal(address, recvAddress) { return recvShard } - if bytes.Equal(address, relayerAddress) { - return relayerShard - } return shardCoordinator.CurrentShard } @@ -170,8 +157,6 @@ func createInterceptedTxFromPlainTx(tx *dataTransaction.Transaction, txFeeHandle false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) } @@ -191,23 +176,10 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction if bytes.Equal(address, recvAddress) { return recvShard } - if bytes.Equal(address, relayerAddress) { - return relayerShard - } return shardCoordinator.CurrentShard } - txFeeHandler := createFreeTxFeeHandler() - relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ - EconomicsFee: txFeeHandler, - ShardCoordinator: shardCoordinator, - MaxTransactionsAllowed: 10, - }) - if err != nil { - return nil, err - } - return transaction.NewInterceptedTransaction( txBuff, marshalizer, @@ -221,15 +193,13 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction }, }, shardCoordinator, - txFeeHandler, + createFreeTxFeeHandler(), &testscommon.WhiteListHandlerStub{}, smartContract.NewArgumentParser(), tx.ChainID, false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(tx.Version), - enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag), - relayedTxV3Processor, ) } @@ -254,8 +224,6 @@ func TestNewInterceptedTransaction_NilBufferShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -281,8 +249,6 @@ func TestNewInterceptedTransaction_NilArgsParser(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -308,8 +274,6 @@ func TestNewInterceptedTransaction_NilVersionChecker(t *testing.T) { false, &hashingMocks.HasherMock{}, nil, - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -335,8 +299,6 @@ func TestNewInterceptedTransaction_NilMarshalizerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -362,8 +324,6 @@ func TestNewInterceptedTransaction_NilSignMarshalizerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -389,8 +349,6 @@ func TestNewInterceptedTransaction_NilHasherShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -416,8 +374,6 @@ func TestNewInterceptedTransaction_NilKeyGenShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -443,8 +399,6 @@ func TestNewInterceptedTransaction_NilSignerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -470,8 +424,6 @@ func TestNewInterceptedTransaction_NilPubkeyConverterShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -497,8 +449,6 @@ func TestNewInterceptedTransaction_NilCoordinatorShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -524,8 +474,6 @@ func TestNewInterceptedTransaction_NilFeeHandlerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -551,8 +499,6 @@ func TestNewInterceptedTransaction_NilWhiteListerVerifiedTxsShouldErr(t *testing false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -578,8 +524,6 @@ func TestNewInterceptedTransaction_InvalidChainIDShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -605,68 +549,12 @@ func TestNewInterceptedTransaction_NilTxSignHasherShouldErr(t *testing.T) { false, nil, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) assert.Equal(t, process.ErrNilHasher, err) } -func TestNewInterceptedTransaction_NilEnableEpochsHandlerShouldErr(t *testing.T) { - t.Parallel() - - txi, err := transaction.NewInterceptedTransaction( - make([]byte, 0), - &mock.MarshalizerMock{}, - &mock.MarshalizerMock{}, - &hashingMocks.HasherMock{}, - &mock.SingleSignKeyGenMock{}, - &mock.SignerMock{}, - createMockPubKeyConverter(), - mock.NewOneShardCoordinatorMock(), - &economicsmocks.EconomicsHandlerStub{}, - &testscommon.WhiteListHandlerStub{}, - &testscommon.ArgumentParserMock{}, - []byte("chainID"), - false, - &hashingMocks.HasherMock{}, - versioning.NewTxVersionChecker(1), - nil, - &processMocks.RelayedTxV3ProcessorMock{}, - ) - - assert.Nil(t, txi) - assert.Equal(t, process.ErrNilEnableEpochsHandler, err) -} - -func TestNewInterceptedTransaction_NilRelayedV3ProcessorShouldErr(t *testing.T) { - t.Parallel() - - txi, err := transaction.NewInterceptedTransaction( - make([]byte, 0), - &mock.MarshalizerMock{}, - &mock.MarshalizerMock{}, - &hashingMocks.HasherMock{}, - &mock.SingleSignKeyGenMock{}, - &mock.SignerMock{}, - createMockPubKeyConverter(), - mock.NewOneShardCoordinatorMock(), - &economicsmocks.EconomicsHandlerStub{}, - &testscommon.WhiteListHandlerStub{}, - &testscommon.ArgumentParserMock{}, - []byte("chainID"), - false, - &hashingMocks.HasherMock{}, - versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - nil, - ) - - assert.Nil(t, txi) - assert.Equal(t, process.ErrNilRelayedTxV3Processor, err) -} - func TestNewInterceptedTransaction_UnmarshalingTxFailsShouldErr(t *testing.T) { t.Parallel() @@ -692,8 +580,6 @@ func TestNewInterceptedTransaction_UnmarshalingTxFailsShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -1110,32 +996,6 @@ func TestInterceptedTransaction_CheckValidityOkValsShouldWork(t *testing.T) { assert.Nil(t, err) } -func TestInterceptedTransaction_CheckValidityRelayerAddressShouldError(t *testing.T) { - t.Parallel() - - minTxVersion := uint32(1) - chainID := []byte("chain") - tx := &dataTransaction.Transaction{ - Nonce: 1, - Value: big.NewInt(2), - Data: []byte("data"), - GasLimit: 3, - GasPrice: 4, - RcvAddr: recvAddress, - SndAddr: senderAddress, - Signature: sigOk, - ChainID: chainID, - Version: minTxVersion, - RelayerAddr: []byte("45678901234567890123456789012345"), - } - txi, _ := createInterceptedTxFromPlainTx(tx, createFreeTxFeeHandler(), chainID, minTxVersion) - - err := txi.CheckValidity() - - assert.True(t, errors.Is(err, process.ErrWrongTransaction)) - assert.True(t, strings.Contains(err.Error(), "relayer address found on transaction")) -} - func TestInterceptedTransaction_CheckValiditySignedWithHashButNotEnabled(t *testing.T) { t.Parallel() @@ -1190,8 +1050,6 @@ func TestInterceptedTransaction_CheckValiditySignedWithHashButNotEnabled(t *test false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) err := txi.CheckValidity() @@ -1252,8 +1110,6 @@ func TestInterceptedTransaction_CheckValiditySignedWithHashShouldWork(t *testing true, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) err := txi.CheckValidity() @@ -1339,8 +1195,6 @@ func TestInterceptedTransaction_ScTxDeployRecvShardIdShouldBeSendersShardId(t *t false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, err) @@ -1421,31 +1275,6 @@ func TestInterceptedTransaction_GetSenderAddress(t *testing.T) { assert.NotNil(t, result) } -func TestInterceptedTransaction_GetRelayerAddress(t *testing.T) { - t.Parallel() - - relayerAddr := []byte("34567890123456789012345678901234") - minTxVersion := uint32(1) - chainID := []byte("chain") - tx := &dataTransaction.Transaction{ - Nonce: 0, - Value: big.NewInt(2), - Data: []byte("data"), - GasLimit: 3, - GasPrice: 4, - RcvAddr: recvAddress, - SndAddr: senderAddress, - Signature: sigOk, - ChainID: chainID, - Version: minTxVersion, - RelayerAddr: relayerAddr, - } - - txi, _ := createInterceptedTxFromPlainTx(tx, createFreeTxFeeHandler(), chainID, minTxVersion) - result := txi.RelayerAddress() - assert.Equal(t, relayerAddr, result) -} - func TestInterceptedTransaction_CheckValiditySecondTimeDoesNotVerifySig(t *testing.T) { t.Parallel() @@ -1505,8 +1334,6 @@ func TestInterceptedTransaction_CheckValiditySecondTimeDoesNotVerifySig(t *testi false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) require.Nil(t, err) @@ -1602,14 +1429,6 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTx(t *testing.T) { err = txi.CheckValidity() assert.True(t, strings.Contains(err.Error(), process.ErrRecursiveRelayedTxIsNotAllowed.Error())) assert.Contains(t, err.Error(), "inner transaction") - - userTx.Data = []byte("") - userTxData, _ = marshalizer.Marshal(userTx) - tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxData)) - tx.InnerTransactions = []*dataTransaction.Transaction{{Nonce: 100}} - txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) - err = txi.CheckValidity() - assert.True(t, strings.Contains(err.Error(), process.ErrMultipleRelayedTxTypesIsNotAllowed.Error())) } func TestInterceptedTransaction_CheckValidityOfRelayedTxV2(t *testing.T) { @@ -1673,16 +1492,6 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV2(t *testing.T) { assert.True(t, strings.Contains(err.Error(), process.ErrRecursiveRelayedTxIsNotAllowed.Error())) assert.Contains(t, err.Error(), "inner transaction") - userTx.Data = []byte("") - marshalizer := &mock.MarshalizerMock{} - userTxData, _ := marshalizer.Marshal(userTx) - tx.Data = []byte(core.RelayedTransactionV2 + "@" + hex.EncodeToString(userTxData)) - tx.InnerTransactions = []*dataTransaction.Transaction{{Nonce: 100}} - txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) - err = txi.CheckValidity() - assert.True(t, strings.Contains(err.Error(), process.ErrMultipleRelayedTxTypesIsNotAllowed.Error())) - - tx.InnerTransactions = nil userTx.Signature = sigOk userTx.SndAddr = []byte("otherAddress") tx.Data = []byte(core.RelayedTransactionV2 + "@" + hex.EncodeToString(userTx.RcvAddr) + "@" + hex.EncodeToString(big.NewInt(0).SetUint64(userTx.Nonce).Bytes()) + "@" + hex.EncodeToString(userTx.Data) + "@" + hex.EncodeToString(userTx.Signature)) @@ -1691,177 +1500,6 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV2(t *testing.T) { assert.Nil(t, err) } -func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { - t.Parallel() - - minTxVersion := uint32(1) - chainID := []byte("chain") - innerTx := &dataTransaction.Transaction{ - Nonce: 1, - Value: big.NewInt(2), - Data: []byte("data inner tx 1"), - GasLimit: 3, - GasPrice: 4, - RcvAddr: recvAddress, - SndAddr: senderAddress, - Signature: sigOk, - ChainID: chainID, - Version: minTxVersion, - RelayerAddr: relayerAddress, - } - - tx := &dataTransaction.Transaction{ - Nonce: 1, - Value: big.NewInt(0), - GasLimit: 10, - GasPrice: 4, - RcvAddr: relayerAddress, - SndAddr: relayerAddress, - Signature: sigOk, - ChainID: chainID, - Version: minTxVersion, - InnerTransactions: []*dataTransaction.Transaction{innerTx}, - } - - t.Run("should work", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.Nil(t, err) - }) - t.Run("inner txs on inner tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - innerTxCopy.InnerTransactions = []*dataTransaction.Transaction{{}} - txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.Equal(t, process.ErrRecursiveRelayedTxIsNotAllowed, err) - }) - t.Run("different relayer on inner tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - innerTxCopy.RelayerAddr = recvAddress - txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.Equal(t, process.ErrRelayedTxV3RelayerMismatch, err) - }) - t.Run("different sender than receiver should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - txCopy.RcvAddr = recvAddress - txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.Equal(t, process.ErrRelayedTxV3SenderDoesNotMatchReceiver, err) - }) - t.Run("empty signature on inner tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - innerTxCopy.Signature = nil - txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.NotNil(t, err) - }) - t.Run("bad signature on inner tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - innerTxCopy.Signature = sigBad - txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.NotNil(t, err) - }) - t.Run("inner tx on inner tx(recursive) should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - innerTx2 := &dataTransaction.Transaction{ - Nonce: 2, - Value: big.NewInt(3), - Data: []byte(""), - GasLimit: 3, - GasPrice: 4, - RcvAddr: recvAddress, - SndAddr: senderAddress, - Signature: sigOk, - ChainID: chainID, - Version: minTxVersion, - } - innerTxCopy.InnerTransactions = []*dataTransaction.Transaction{innerTx2} - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.NotNil(t, err) - }) - t.Run("relayed v3 not enabled yet should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - marshalizer := &mock.MarshalizerMock{} - txBuff, _ := marshalizer.Marshal(&txCopy) - txi, _ := transaction.NewInterceptedTransaction( - txBuff, - marshalizer, - marshalizer, - &hashingMocks.HasherMock{}, - createKeyGenMock(), - createDummySigner(), - &testscommon.PubkeyConverterStub{ - LenCalled: func() int { - return 32 - }, - }, - mock.NewMultipleShardsCoordinatorMock(), - createFreeTxFeeHandler(), - &testscommon.WhiteListHandlerStub{}, - &testscommon.ArgumentParserMock{}, - txCopy.ChainID, - false, - &hashingMocks.HasherMock{}, - versioning.NewTxVersionChecker(0), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, - ) - - assert.NotNil(t, txi) - err := txi.CheckValidity() - assert.Equal(t, process.ErrRelayedTxV3Disabled, err) - }) - t.Run("inner txs + relayed v2 should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - marshaller := &marshallerMock.MarshalizerMock{} - userTxData, _ := marshaller.Marshal(innerTxCopy) - txCopy.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxData)) - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.Equal(t, process.ErrMultipleRelayedTxTypesIsNotAllowed, err) - }) -} - // ------- IsInterfaceNil func TestInterceptedTransaction_IsInterfaceNil(t *testing.T) { t.Parallel() @@ -1991,8 +1629,6 @@ func TestInterceptedTransaction_Fee(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(0), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Equal(t, big.NewInt(0), txin.Fee()) @@ -2036,8 +1672,6 @@ func TestInterceptedTransaction_String(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(0), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) expectedFormat := fmt.Sprintf( diff --git a/process/transaction/relayedTxV3Processor.go b/process/transaction/relayedTxV3Processor.go deleted file mode 100644 index 1c25ad46214..00000000000 --- a/process/transaction/relayedTxV3Processor.go +++ /dev/null @@ -1,112 +0,0 @@ -package transaction - -import ( - "bytes" - "fmt" - "math/big" - - "github.com/multiversx/mx-chain-core-go/core/check" - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-go/process" - "github.com/multiversx/mx-chain-go/sharding" -) - -const minTransactionsAllowed = 1 - -// ArgRelayedTxV3Processor is the DTO used to create a new instance of relayedTxV3Processor -type ArgRelayedTxV3Processor struct { - EconomicsFee process.FeeHandler - ShardCoordinator sharding.Coordinator - MaxTransactionsAllowed int -} - -type relayedTxV3Processor struct { - economicsFee process.FeeHandler - shardCoordinator sharding.Coordinator - maxTransactionsAllowed int -} - -// NewRelayedTxV3Processor returns a new instance of relayedTxV3Processor -func NewRelayedTxV3Processor(args ArgRelayedTxV3Processor) (*relayedTxV3Processor, error) { - err := checkArgs(args) - if err != nil { - return nil, err - } - return &relayedTxV3Processor{ - economicsFee: args.EconomicsFee, - shardCoordinator: args.ShardCoordinator, - maxTransactionsAllowed: args.MaxTransactionsAllowed, - }, nil -} - -func checkArgs(args ArgRelayedTxV3Processor) error { - if check.IfNil(args.EconomicsFee) { - return process.ErrNilEconomicsFeeHandler - } - if check.IfNil(args.ShardCoordinator) { - return process.ErrNilShardCoordinator - } - if args.MaxTransactionsAllowed < minTransactionsAllowed { - return fmt.Errorf("%w for MaxTransactionsAllowed, provided %d, min expected %d", process.ErrInvalidValue, args.MaxTransactionsAllowed, minTransactionsAllowed) - } - - return nil -} - -// CheckRelayedTx checks the relayed transaction and its inner transactions -func (proc *relayedTxV3Processor) CheckRelayedTx(tx *transaction.Transaction) error { - if len(tx.InnerTransactions) > proc.maxTransactionsAllowed { - return process.ErrRelayedTxV3TooManyInnerTransactions - } - if tx.GetValue().Cmp(big.NewInt(0)) != 0 { - return process.ErrRelayedTxV3ZeroVal - } - if !bytes.Equal(tx.RcvAddr, tx.SndAddr) { - return process.ErrRelayedTxV3SenderDoesNotMatchReceiver - } - if tx.GasLimit < proc.computeRelayedTxMinGasLimit(tx) { - return process.ErrRelayedTxV3GasLimitMismatch - } - if len(tx.Data) > 0 { - return process.ErrRelayedTxV3InvalidDataField - } - - innerTxs := tx.InnerTransactions - for _, innerTx := range innerTxs { - if !bytes.Equal(innerTx.RelayerAddr, tx.SndAddr) { - return process.ErrRelayedTxV3RelayerMismatch - } - if tx.GasPrice != innerTx.GasPrice { - return process.ErrRelayedV3GasPriceMismatch - } - if len(innerTx.InnerTransactions) > 0 { - return process.ErrRecursiveRelayedTxIsNotAllowed - } - - senderShard := proc.shardCoordinator.ComputeId(innerTx.SndAddr) - relayerShard := proc.shardCoordinator.ComputeId(innerTx.RelayerAddr) - if senderShard != relayerShard { - return process.ErrRelayedTxV3SenderShardMismatch - } - } - - return nil -} - -func (proc *relayedTxV3Processor) computeRelayedTxMinGasLimit(tx *transaction.Transaction) uint64 { - relayedTxGasLimit := proc.economicsFee.ComputeGasLimit(tx) - relayedTxMinGasLimit := proc.economicsFee.MinGasLimit() - relayedTxGasLimitDiff := relayedTxGasLimit - relayedTxMinGasLimit // this may be positive if the relayed tx is guarded - - totalGasLimit := relayedTxGasLimitDiff + relayedTxMinGasLimit*uint64(len(tx.InnerTransactions)) - for _, innerTx := range tx.InnerTransactions { - totalGasLimit += innerTx.GasLimit - } - - return totalGasLimit -} - -// IsInterfaceNil returns true if there is no value under the interface -func (proc *relayedTxV3Processor) IsInterfaceNil() bool { - return proc == nil -} diff --git a/process/transaction/relayedTxV3Processor_test.go b/process/transaction/relayedTxV3Processor_test.go deleted file mode 100644 index 7f6495ebd92..00000000000 --- a/process/transaction/relayedTxV3Processor_test.go +++ /dev/null @@ -1,249 +0,0 @@ -package transaction_test - -import ( - "bytes" - "errors" - "math/big" - "strings" - "testing" - - "github.com/multiversx/mx-chain-core-go/data" - coreTransaction "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-go/process" - "github.com/multiversx/mx-chain-go/process/transaction" - "github.com/multiversx/mx-chain-go/testscommon" - "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" - "github.com/stretchr/testify/require" -) - -const minGasLimit = uint64(1) - -func getDefaultTx() *coreTransaction.Transaction { - return &coreTransaction.Transaction{ - Nonce: 0, - Value: big.NewInt(0), - RcvAddr: []byte("rel"), - SndAddr: []byte("rel"), - GasPrice: 1, - GasLimit: minGasLimit * 4, - InnerTransactions: []*coreTransaction.Transaction{ - { - Nonce: 0, - Value: big.NewInt(1), - RcvAddr: []byte("rcv1"), - SndAddr: []byte("snd1"), - GasPrice: 1, - GasLimit: minGasLimit, - RelayerAddr: []byte("rel"), - }, - { - Nonce: 0, - Value: big.NewInt(1), - RcvAddr: []byte("rcv1"), - SndAddr: []byte("snd2"), - GasPrice: 1, - GasLimit: minGasLimit, - RelayerAddr: []byte("rel"), - }, - }, - } -} - -func createMockArgRelayedTxV3Processor() transaction.ArgRelayedTxV3Processor { - return transaction.ArgRelayedTxV3Processor{ - EconomicsFee: &economicsmocks.EconomicsHandlerStub{}, - ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, - MaxTransactionsAllowed: 10, - } -} - -func TestNewRelayedTxV3Processor(t *testing.T) { - t.Parallel() - - t.Run("nil economics fee should error", func(t *testing.T) { - t.Parallel() - - args := createMockArgRelayedTxV3Processor() - args.EconomicsFee = nil - proc, err := transaction.NewRelayedTxV3Processor(args) - require.Nil(t, proc) - require.Equal(t, process.ErrNilEconomicsFeeHandler, err) - }) - t.Run("nil shard coordinator should error", func(t *testing.T) { - t.Parallel() - - args := createMockArgRelayedTxV3Processor() - args.ShardCoordinator = nil - proc, err := transaction.NewRelayedTxV3Processor(args) - require.Nil(t, proc) - require.Equal(t, process.ErrNilShardCoordinator, err) - }) - t.Run("invalid max transactions allowed should error", func(t *testing.T) { - t.Parallel() - - args := createMockArgRelayedTxV3Processor() - args.MaxTransactionsAllowed = 0 - proc, err := transaction.NewRelayedTxV3Processor(args) - require.Nil(t, proc) - require.True(t, errors.Is(err, process.ErrInvalidValue)) - require.True(t, strings.Contains(err.Error(), "MaxTransactionsAllowed")) - }) - t.Run("should work", func(t *testing.T) { - t.Parallel() - - proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) - require.NoError(t, err) - require.NotNil(t, proc) - }) -} - -func TestRelayedTxV3Processor_IsInterfaceNil(t *testing.T) { - t.Parallel() - - args := createMockArgRelayedTxV3Processor() - args.EconomicsFee = nil - proc, _ := transaction.NewRelayedTxV3Processor(args) - require.True(t, proc.IsInterfaceNil()) - - proc, _ = transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) - require.False(t, proc.IsInterfaceNil()) -} - -func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { - t.Parallel() - - t.Run("invalid num of inner txs should error", func(t *testing.T) { - t.Parallel() - - tx := getDefaultTx() - args := createMockArgRelayedTxV3Processor() - args.MaxTransactionsAllowed = len(tx.InnerTransactions) - 1 - proc, err := transaction.NewRelayedTxV3Processor(args) - require.NoError(t, err) - - tx.Value = big.NewInt(1) - - err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrRelayedTxV3TooManyInnerTransactions, err) - }) - t.Run("value on relayed tx should error", func(t *testing.T) { - t.Parallel() - - proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) - require.NoError(t, err) - - tx := getDefaultTx() - tx.Value = big.NewInt(1) - - err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrRelayedTxV3ZeroVal, err) - }) - t.Run("relayed tx not to self should error", func(t *testing.T) { - t.Parallel() - - proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) - require.NoError(t, err) - - tx := getDefaultTx() - tx.RcvAddr = []byte("another rcv") - - err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrRelayedTxV3SenderDoesNotMatchReceiver, err) - }) - t.Run("invalid gas limit should error", func(t *testing.T) { - t.Parallel() - - args := createMockArgRelayedTxV3Processor() - args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ - ComputeGasLimitCalled: func(tx data.TransactionWithFeeHandler) uint64 { - return minGasLimit - }, - } - proc, err := transaction.NewRelayedTxV3Processor(args) - require.NoError(t, err) - - tx := getDefaultTx() - tx.GasLimit = minGasLimit - - err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrRelayedTxV3GasLimitMismatch, err) - }) - t.Run("data field not empty should error", func(t *testing.T) { - t.Parallel() - - proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) - require.NoError(t, err) - - tx := getDefaultTx() - tx.Data = []byte("dummy") - - err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrRelayedTxV3InvalidDataField, err) - }) - t.Run("inner txs on inner should error", func(t *testing.T) { - t.Parallel() - - proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) - require.NoError(t, err) - - tx := getDefaultTx() - tx.InnerTransactions[0].InnerTransactions = []*coreTransaction.Transaction{{}} - - err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrRecursiveRelayedTxIsNotAllowed, err) - }) - t.Run("relayer mismatch on inner should error", func(t *testing.T) { - t.Parallel() - - proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) - require.NoError(t, err) - - tx := getDefaultTx() - tx.InnerTransactions[0].RelayerAddr = []byte("another relayer") - - err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrRelayedTxV3RelayerMismatch, err) - }) - t.Run("gas price mismatch on inner should error", func(t *testing.T) { - t.Parallel() - - proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) - require.NoError(t, err) - - tx := getDefaultTx() - tx.InnerTransactions[0].GasPrice = tx.GasPrice + 1 - - err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrRelayedV3GasPriceMismatch, err) - }) - t.Run("shard mismatch on inner should error", func(t *testing.T) { - t.Parallel() - - tx := getDefaultTx() - args := createMockArgRelayedTxV3Processor() - args.ShardCoordinator = &testscommon.ShardsCoordinatorMock{ - ComputeIdCalled: func(address []byte) uint32 { - if bytes.Equal(address, tx.SndAddr) { - return 0 - } - - return 1 - }, - } - proc, err := transaction.NewRelayedTxV3Processor(args) - require.NoError(t, err) - - err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrRelayedTxV3SenderShardMismatch, err) - }) - t.Run("should work", func(t *testing.T) { - t.Parallel() - - proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) - require.NoError(t, err) - - tx := getDefaultTx() - err = proc.CheckRelayedTx(tx) - require.NoError(t, err) - }) -} diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 6d2fbeb80f3..51910b537e2 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -31,8 +31,6 @@ var _ process.TransactionProcessor = (*txProcessor)(nil) // for move balance transactions that provide more gas than needed const RefundGasMessage = "refundedGas" -const nonRelayedV3UserTxIdx = -1 - type relayedFees struct { totalFee, remainingFee, relayerFee *big.Int } @@ -40,41 +38,37 @@ type relayedFees struct { // txProcessor implements TransactionProcessor interface and can modify account states according to a transaction type txProcessor struct { *baseTxProcessor - txFeeHandler process.TransactionFeeHandler - receiptForwarder process.IntermediateTransactionHandler - badTxForwarder process.IntermediateTransactionHandler - argsParser process.ArgumentsParser - scrForwarder process.IntermediateTransactionHandler - signMarshalizer marshal.Marshalizer - enableEpochsHandler common.EnableEpochsHandler - txLogsProcessor process.TransactionLogProcessor - relayedTxV3Processor process.RelayedTxV3Processor - failedTxLogsAccumulator process.FailedTxLogsAccumulator + txFeeHandler process.TransactionFeeHandler + receiptForwarder process.IntermediateTransactionHandler + badTxForwarder process.IntermediateTransactionHandler + argsParser process.ArgumentsParser + scrForwarder process.IntermediateTransactionHandler + signMarshalizer marshal.Marshalizer + enableEpochsHandler common.EnableEpochsHandler + txLogsProcessor process.TransactionLogProcessor } // ArgsNewTxProcessor defines the arguments needed for new tx processor type ArgsNewTxProcessor struct { - Accounts state.AccountsAdapter - Hasher hashing.Hasher - PubkeyConv core.PubkeyConverter - Marshalizer marshal.Marshalizer - SignMarshalizer marshal.Marshalizer - ShardCoordinator sharding.Coordinator - ScProcessor process.SmartContractProcessor - TxFeeHandler process.TransactionFeeHandler - TxTypeHandler process.TxTypeHandler - EconomicsFee process.FeeHandler - ReceiptForwarder process.IntermediateTransactionHandler - BadTxForwarder process.IntermediateTransactionHandler - ArgsParser process.ArgumentsParser - ScrForwarder process.IntermediateTransactionHandler - EnableRoundsHandler process.EnableRoundsHandler - EnableEpochsHandler common.EnableEpochsHandler - TxVersionChecker process.TxVersionCheckerHandler - GuardianChecker process.GuardianChecker - TxLogsProcessor process.TransactionLogProcessor - RelayedTxV3Processor process.RelayedTxV3Processor - FailedTxLogsAccumulator process.FailedTxLogsAccumulator + Accounts state.AccountsAdapter + Hasher hashing.Hasher + PubkeyConv core.PubkeyConverter + Marshalizer marshal.Marshalizer + SignMarshalizer marshal.Marshalizer + ShardCoordinator sharding.Coordinator + ScProcessor process.SmartContractProcessor + TxFeeHandler process.TransactionFeeHandler + TxTypeHandler process.TxTypeHandler + EconomicsFee process.FeeHandler + ReceiptForwarder process.IntermediateTransactionHandler + BadTxForwarder process.IntermediateTransactionHandler + ArgsParser process.ArgumentsParser + ScrForwarder process.IntermediateTransactionHandler + EnableRoundsHandler process.EnableRoundsHandler + EnableEpochsHandler common.EnableEpochsHandler + TxVersionChecker process.TxVersionCheckerHandler + GuardianChecker process.GuardianChecker + TxLogsProcessor process.TransactionLogProcessor } // NewTxProcessor creates a new txProcessor engine @@ -134,7 +128,6 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { common.RelayedTransactionsFlag, common.RelayedTransactionsV2Flag, common.RelayedNonceFixFlag, - common.RelayedTransactionsV3Flag, common.FixRelayedBaseCostFlag, }) if err != nil { @@ -149,12 +142,6 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { if check.IfNil(args.TxLogsProcessor) { return nil, process.ErrNilTxLogsProcessor } - if check.IfNil(args.RelayedTxV3Processor) { - return nil, process.ErrNilRelayedTxV3Processor - } - if check.IfNil(args.FailedTxLogsAccumulator) { - return nil, process.ErrNilFailedTxLogsAccumulator - } baseTxProcess := &baseTxProcessor{ accounts: args.Accounts, @@ -171,17 +158,15 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { } txProc := &txProcessor{ - baseTxProcessor: baseTxProcess, - txFeeHandler: args.TxFeeHandler, - receiptForwarder: args.ReceiptForwarder, - badTxForwarder: args.BadTxForwarder, - argsParser: args.ArgsParser, - scrForwarder: args.ScrForwarder, - signMarshalizer: args.SignMarshalizer, - enableEpochsHandler: args.EnableEpochsHandler, - txLogsProcessor: args.TxLogsProcessor, - relayedTxV3Processor: args.RelayedTxV3Processor, - failedTxLogsAccumulator: args.FailedTxLogsAccumulator, + baseTxProcessor: baseTxProcess, + txFeeHandler: args.TxFeeHandler, + receiptForwarder: args.ReceiptForwarder, + badTxForwarder: args.BadTxForwarder, + argsParser: args.ArgsParser, + scrForwarder: args.ScrForwarder, + signMarshalizer: args.SignMarshalizer, + enableEpochsHandler: args.EnableEpochsHandler, + txLogsProcessor: args.TxLogsProcessor, } return txProc, nil @@ -255,8 +240,6 @@ func (txProc *txProcessor) ProcessTransaction(tx *transaction.Transaction) (vmco return txProc.processRelayedTx(tx, acntSnd, acntDst) case process.RelayedTxV2: return txProc.processRelayedTxV2(tx, acntSnd, acntDst) - case process.RelayedTxV3: - return txProc.processRelayedTxV3(tx, acntSnd) } return vmcommon.UserError, txProc.executingFailedTransaction(tx, acntSnd, process.ErrWrongTransaction) @@ -621,7 +604,7 @@ func (txProc *txProcessor) finishExecutionOfRelayedTx( userTx *transaction.Transaction, ) (vmcommon.ReturnCode, error) { computedFees := txProc.computeRelayedTxFees(tx, userTx) - err := txProc.processTxAtRelayer(relayerAcnt, computedFees.totalFee, computedFees.relayerFee, tx) + txHash, err := txProc.processTxAtRelayer(relayerAcnt, computedFees.totalFee, computedFees.relayerFee, tx) if err != nil { return 0, err } @@ -635,27 +618,7 @@ func (txProc *txProcessor) finishExecutionOfRelayedTx( return 0, err } - originalTxHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) - if err != nil { - errRemove := txProc.removeValueAndConsumedFeeFromUser(userTx, tx.Value, originalTxHash, tx, err) - if errRemove != nil { - return vmcommon.UserError, errRemove - } - - return vmcommon.UserError, txProc.executeFailedRelayedUserTx( - userTx, - tx.SndAddr, - tx.Value, - tx.Nonce, - tx, - originalTxHash, - err.Error(), - nonRelayedV3UserTxIdx) - } - - defer txProc.saveFailedLogsIfNeeded(originalTxHash) - - return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce, originalTxHash, nonRelayedV3UserTxIdx) + return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce, txHash) } func (txProc *txProcessor) processTxAtRelayer( @@ -663,33 +626,33 @@ func (txProc *txProcessor) processTxAtRelayer( totalFee *big.Int, relayerFee *big.Int, tx *transaction.Transaction, -) error { +) ([]byte, error) { + txHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) + if err != nil { + return nil, err + } + if !check.IfNil(relayerAcnt) { - err := relayerAcnt.SubFromBalance(tx.GetValue()) + err = relayerAcnt.SubFromBalance(tx.GetValue()) if err != nil { - return err + return nil, err } err = relayerAcnt.SubFromBalance(totalFee) if err != nil { - return err + return nil, err } relayerAcnt.IncreaseNonce(1) err = txProc.accounts.SaveAccount(relayerAcnt) if err != nil { - return err - } - - txHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) - if err != nil { - return err + return nil, err } txProc.txFeeHandler.ProcessTransactionFee(relayerFee, big.NewInt(0), txHash) } - return nil + return txHash, nil } func (txProc *txProcessor) addFeeAndValueToDest(acntDst state.UserAccountHandler, txValue *big.Int, remainingFee *big.Int) error { @@ -706,132 +669,6 @@ func (txProc *txProcessor) addFeeAndValueToDest(acntDst state.UserAccountHandler return txProc.accounts.SaveAccount(acntDst) } -func (txProc *txProcessor) processRelayedTxV3( - tx *transaction.Transaction, - relayerAcnt state.UserAccountHandler, -) (vmcommon.ReturnCode, error) { - if !txProc.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsV3Flag) { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3Disabled) - } - if check.IfNil(relayerAcnt) { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrNilRelayerAccount) - } - err := txProc.relayedTxV3Processor.CheckRelayedTx(tx) - if err != nil { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) - } - - snapshot := txProc.accounts.JournalLen() - - // process fees on both relayer and sender - relayerFee, totalFee, err := txProc.economicsFee.ComputeRelayedTxFees(tx) - if err != nil { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) - } - - err = txProc.processTxAtRelayer(relayerAcnt, totalFee, relayerFee, tx) - if err != nil { - return 0, err - } - - innerTxs := tx.GetInnerTransactions() - - originalTxHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) - if err != nil { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) - } - - var innerTxRetCode vmcommon.ReturnCode - var innerTxErr error - var innerTxFee *big.Int - innerTxsTotalFees := big.NewInt(0) - executedUserTxs := make([]*transaction.Transaction, 0) - for innerTxIdx, innerTx := range innerTxs { - innerTxFee, innerTxRetCode, innerTxErr = txProc.processInnerTx(tx, innerTx, originalTxHash, innerTxIdx) - innerTxsTotalFees.Add(innerTxsTotalFees, innerTxFee) - if innerTxErr != nil || innerTxRetCode != vmcommon.Ok { - continue - } - - executedUserTxs = append(executedUserTxs, innerTx) - } - - allUserTxsSucceeded := len(executedUserTxs) == len(innerTxs) && innerTxErr == nil && innerTxRetCode == vmcommon.Ok - if !allUserTxsSucceeded { - log.Trace("failed to execute all inner transactions", "total", len(innerTxs), "executed transactions", len(executedUserTxs)) - - txProc.saveFailedLogsIfNeeded(originalTxHash) - } - - expectedMaxInnerTxsTotalFees := big.NewInt(0).Sub(totalFee, relayerFee) - if innerTxsTotalFees.Cmp(expectedMaxInnerTxsTotalFees) > 0 { - log.Debug("reverting relayed transaction, total inner transactions fees mismatch", - "computed max fees at relayer", expectedMaxInnerTxsTotalFees.Uint64(), - "total inner fees consumed", innerTxsTotalFees.Uint64()) - - errRevert := txProc.accounts.RevertToSnapshot(snapshot) - if errRevert != nil { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, errRevert) - } - - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrConsumedFeesMismatch) - } - - return vmcommon.Ok, nil -} - -func (txProc *txProcessor) processInnerTx( - tx *transaction.Transaction, - innerTx *transaction.Transaction, - originalTxHash []byte, - innerTxIdx int, -) (*big.Int, vmcommon.ReturnCode, error) { - - txFee := txProc.computeInnerTxFee(innerTx) - - acntSnd, err := txProc.getAccountFromAddress(innerTx.SndAddr) - if err != nil { - return txFee, vmcommon.UserError, txProc.executeFailedRelayedUserTx( - innerTx, - innerTx.RelayerAddr, - big.NewInt(0), - tx.Nonce, - tx, - originalTxHash, - err.Error(), - innerTxIdx) - } - - if check.IfNil(acntSnd) { - return txFee, vmcommon.UserError, txProc.executeFailedRelayedUserTx( - innerTx, - innerTx.RelayerAddr, - big.NewInt(0), - tx.Nonce, - tx, - originalTxHash, - process.ErrRelayedTxV3SenderShardMismatch.Error(), - innerTxIdx) - } - - // TODO: remove adding and then removing the fee at the sender - err = txProc.addFeeAndValueToDest(acntSnd, big.NewInt(0), txFee) - if err != nil { - return txFee, vmcommon.UserError, txProc.executeFailedRelayedUserTx( - innerTx, - innerTx.RelayerAddr, - big.NewInt(0), - tx.Nonce, - tx, - originalTxHash, - err.Error(), - innerTxIdx) - } - - result, err := txProc.processUserTx(tx, innerTx, tx.Value, tx.Nonce, originalTxHash, innerTxIdx) - return txFee, result, err -} - func (txProc *txProcessor) processRelayedTxV2( tx *transaction.Transaction, relayerAcnt, acntDst state.UserAccountHandler, @@ -851,10 +688,6 @@ func (txProc *txProcessor) processRelayedTxV2( return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrInvalidArguments) } - if len(tx.InnerTransactions) > 0 { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrMultipleRelayedTxTypesIsNotAllowed) - } - userTx := makeUserTxFromRelayedTxV2Args(args) userTx.GasPrice = tx.GasPrice userTx.GasLimit = tx.GasLimit - txProc.economicsFee.ComputeGasLimit(tx) @@ -878,9 +711,6 @@ func (txProc *txProcessor) processRelayedTx( if !txProc.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsFlag) { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxDisabled) } - if len(tx.InnerTransactions) > 0 { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrMultipleRelayedTxTypesIsNotAllowed) - } userTx := &transaction.Transaction{} err = txProc.signMarshalizer.Unmarshal(userTx, args[0]) @@ -978,7 +808,7 @@ func (txProc *txProcessor) addNonExecutableLog(executionErr error, originalTxHas Address: originalTx.GetRcvAddr(), } - return txProc.failedTxLogsAccumulator.SaveLogs(originalTxHash, originalTx, []*vmcommon.LogEntry{logEntry}) + return txProc.txLogsProcessor.SaveLog(originalTxHash, originalTx, []*vmcommon.LogEntry{logEntry}) } @@ -1009,7 +839,6 @@ func (txProc *txProcessor) processUserTx( relayedTxValue *big.Int, relayedNonce uint64, originalTxHash []byte, - innerTxIdx int, ) (vmcommon.ReturnCode, error) { relayerAdr := originalTx.SndAddr @@ -1026,8 +855,7 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error(), - innerTxIdx) + err.Error()) } txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) @@ -1044,8 +872,7 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error(), - innerTxIdx) + err.Error()) } scrFromTx, err := txProc.makeSCRFromUserTx(userTx, relayerAdr, relayedTxValue, originalTxHash) @@ -1057,10 +884,6 @@ func (txProc *txProcessor) processUserTx( switch txType { case process.MoveBalance: err = txProc.processMoveBalance(userTx, acntSnd, acntDst, dstShardTxType, originalTxHash, true) - intraShard := txProc.shardCoordinator.SameShard(userTx.SndAddr, userTx.RcvAddr) - if err == nil && intraShard { - txProc.createCompleteEventLog(scrFromTx, originalTxHash) - } case process.SCDeployment: err = txProc.processMoveBalanceCostRelayedUserTx(userTx, scrFromTx, acntSnd, originalTxHash) if err != nil { @@ -1095,8 +918,7 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error(), - innerTxIdx) + err.Error()) } if errors.Is(err, process.ErrInvalidMetaTransaction) || errors.Is(err, process.ErrAccountNotPayable) { @@ -1107,8 +929,7 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error(), - innerTxIdx) + err.Error()) } if errors.Is(err, process.ErrFailedTransaction) { @@ -1186,14 +1007,8 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( originalTx *transaction.Transaction, originalTxHash []byte, errorMsg string, - innerTxIdx int, ) error { - returnMessage := []byte(errorMsg) - isUserTxOfRelayedV3 := innerTxIdx != nonRelayedV3UserTxIdx - if isUserTxOfRelayedV3 { - returnMessage = []byte(fmt.Sprintf("%s while executing inner tx at index %d", errorMsg, innerTxIdx)) - } scrForRelayer := &smartContractResult.SmartContractResult{ Nonce: relayedNonce, Value: big.NewInt(0).Set(relayedTxValue), @@ -1201,7 +1016,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( SndAddr: userTx.SndAddr, PrevTxHash: originalTxHash, OriginalTxHash: originalTxHash, - ReturnMessage: returnMessage, + ReturnMessage: []byte(errorMsg), } relayerAcnt, err := txProc.getAccountFromAddress(relayerAdr) @@ -1241,7 +1056,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( return err } - if txProc.enableEpochsHandler.IsFlagEnabled(common.AddFailedRelayedTxToInvalidMBsFlag) && !isRelayedV3(originalTx.InnerTransactions) { + if txProc.enableEpochsHandler.IsFlagEnabled(common.AddFailedRelayedTxToInvalidMBsFlag) { err = txProc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{originalTx}, originalTxHash) if err != nil { return err @@ -1275,36 +1090,6 @@ func isNonExecutableError(executionErr error) bool { errors.Is(executionErr, process.ErrTransactionNotExecutable) } -func (txProc *txProcessor) createCompleteEventLog(scr data.TransactionHandler, originalTxHash []byte) { - scrHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, scr) - if err != nil { - scrHash = originalTxHash - } - - completedTxLog := &vmcommon.LogEntry{ - Identifier: []byte(core.CompletedTxEventIdentifier), - Address: scr.GetRcvAddr(), - Topics: [][]byte{scrHash}, - } - - ignorableError := txProc.txLogsProcessor.SaveLog(scrHash, scr, []*vmcommon.LogEntry{completedTxLog}) - if ignorableError != nil { - log.Debug("txProcessor.createCompleteEventLog txLogsProcessor.SaveLog()", "error", ignorableError.Error()) - } -} - -func (txProc *txProcessor) saveFailedLogsIfNeeded(originalTxHash []byte) { - logsTx, logs, ok := txProc.failedTxLogsAccumulator.GetLogs(originalTxHash) - if ok { - ignorableErr := txProc.txLogsProcessor.SaveLog(originalTxHash, logsTx, logs) - if ignorableErr != nil { - log.Debug("txLogsProcessor.SaveLog failed", "error", ignorableErr.Error()) - } - } - - txProc.failedTxLogsAccumulator.Remove(originalTxHash) -} - // IsInterfaceNil returns true if there is no value under the interface func (txProc *txProcessor) IsInterfaceNil() bool { return txProc == nil diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 4c325a8f78e..88797d31a0c 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -13,6 +13,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/marshal" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" "github.com/multiversx/mx-chain-vm-common-go/parsers" @@ -32,7 +33,6 @@ import ( "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/processMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" "github.com/multiversx/mx-chain-go/vm" ) @@ -79,27 +79,25 @@ func createAccountStub(sndAddr, rcvAddr []byte, func createArgsForTxProcessor() txproc.ArgsNewTxProcessor { args := txproc.ArgsNewTxProcessor{ - Accounts: &stateMock.AccountsStub{}, - Hasher: &hashingMocks.HasherMock{}, - PubkeyConv: createMockPubKeyConverter(), - Marshalizer: &mock.MarshalizerMock{}, - SignMarshalizer: &mock.MarshalizerMock{}, - ShardCoordinator: mock.NewOneShardCoordinatorMock(), - ScProcessor: &testscommon.SCProcessorMock{}, - TxFeeHandler: &mock.FeeAccumulatorStub{}, - TxTypeHandler: &testscommon.TxTypeHandlerMock{}, - EconomicsFee: feeHandlerMock(), - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: &testscommon.ArgumentParserMock{}, - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedBaseCostFlag), - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + Accounts: &stateMock.AccountsStub{}, + Hasher: &hashingMocks.HasherMock{}, + PubkeyConv: createMockPubKeyConverter(), + Marshalizer: &mock.MarshalizerMock{}, + SignMarshalizer: &mock.MarshalizerMock{}, + ShardCoordinator: mock.NewOneShardCoordinatorMock(), + ScProcessor: &testscommon.SCProcessorMock{}, + TxFeeHandler: &mock.FeeAccumulatorStub{}, + TxTypeHandler: &testscommon.TxTypeHandlerMock{}, + EconomicsFee: feeHandlerMock(), + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: &testscommon.ArgumentParserMock{}, + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedBaseCostFlag), + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, } return args } @@ -331,28 +329,6 @@ func TestNewTxProcessor_NilGuardianCheckerShouldErr(t *testing.T) { assert.Nil(t, txProc) } -func TestNewTxProcessor_NilRelayedTxV3ProcessorShouldErr(t *testing.T) { - t.Parallel() - - args := createArgsForTxProcessor() - args.RelayedTxV3Processor = nil - txProc, err := txproc.NewTxProcessor(args) - - assert.Equal(t, process.ErrNilRelayedTxV3Processor, err) - assert.Nil(t, txProc) -} - -func TestNewTxProcessor_NilFailedTxLogsAccumulatorShouldErr(t *testing.T) { - t.Parallel() - - args := createArgsForTxProcessor() - args.FailedTxLogsAccumulator = nil - txProc, err := txproc.NewTxProcessor(args) - - assert.Equal(t, process.ErrNilFailedTxLogsAccumulator, err) - assert.Nil(t, txProc) -} - func TestNewTxProcessor_OkValsShouldWork(t *testing.T) { t.Parallel() @@ -2065,530 +2041,6 @@ func TestTxProcessor_ProcessRelayedTransactionV2(t *testing.T) { assert.Equal(t, vmcommon.Ok, returnCode) } -func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { - t.Parallel() - - marshaller := &mock.MarshalizerMock{} - - userAddr := []byte("user") - tx := &transaction.Transaction{} - tx.Nonce = 0 - tx.SndAddr = []byte("sSRC") - tx.RcvAddr = []byte("sSRC") - tx.Value = big.NewInt(0) - tx.GasPrice = 1 - tx.GasLimit = 8 - - userTx := &transaction.Transaction{} - userTx.Nonce = 0 - userTx.SndAddr = userAddr - userTx.RcvAddr = []byte("sDST") - userTx.Value = big.NewInt(0) - userTx.Data = []byte("execute@param1") - userTx.GasPrice = 1 - userTx.GasLimit = 4 - userTx.RelayerAddr = tx.SndAddr - - tx.InnerTransactions = []*transaction.Transaction{userTx} - - t.Run("flag not active should error", func(t *testing.T) { - t.Parallel() - - pubKeyConverter := testscommon.NewPubkeyConverterMock(4) - acntSrc := createUserAcc(tx.SndAddr) - _ = acntSrc.AddToBalance(big.NewInt(100)) - acntDst := createUserAcc(tx.RcvAddr) - _ = acntDst.AddToBalance(big.NewInt(10)) - - acntFinal := createUserAcc(userTx.RcvAddr) - _ = acntFinal.AddToBalance(big.NewInt(10)) - - adb := &stateMock.AccountsStub{} - adb.LoadAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { - if bytes.Equal(address, tx.SndAddr) { - return acntSrc, nil - } - if bytes.Equal(address, tx.RcvAddr) { - return acntDst, nil - } - if bytes.Equal(address, userTx.RcvAddr) { - return acntFinal, nil - } - - return nil, errors.New("failure") - } - - scProcessorMock := &testscommon.SCProcessorMock{} - shardC, _ := sharding.NewMultiShardCoordinator(1, 0) - esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) - argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), - } - txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) - - args := createArgsForTxProcessor() - args.Accounts = adb - args.ScProcessor = scProcessorMock - args.ShardCoordinator = shardC - args.TxTypeHandler = txTypeHandler - args.PubkeyConv = pubKeyConverter - args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{} - execTx, _ := txproc.NewTxProcessor(args) - - returnCode, err := execTx.ProcessTransaction(tx) - assert.Equal(t, process.ErrFailedTransaction, err) - assert.Equal(t, vmcommon.UserError, returnCode) - }) - t.Run("value on parent tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - txCopy.Value = big.NewInt(1) - testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) - }) - t.Run("different receiver on tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - txCopy.RcvAddr = userTx.SndAddr - testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) - }) - t.Run("empty relayer on inner tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - userTxCopy := *userTx - userTxCopy.RelayerAddr = nil - txCopy.InnerTransactions = []*transaction.Transaction{&userTxCopy} - testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) - }) - t.Run("different relayer on inner tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - userTxCopy := *userTx - userTxCopy.RelayerAddr = []byte("other") - txCopy.InnerTransactions = []*transaction.Transaction{&userTxCopy} - testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) - }) - t.Run("different gas price on inner tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - txCopy.GasPrice = userTx.GasPrice + 1 - testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) - }) - t.Run("higher gas limit on inner tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - txCopy.GasLimit = userTx.GasLimit - 1 - testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) - }) - t.Run("failure to add fees on destination should skip transaction and continue", func(t *testing.T) { - t.Parallel() - - providedAddrFail := []byte("fail addr") - providedInitialBalance := big.NewInt(100) - pubKeyConverter := testscommon.NewPubkeyConverterMock(4) - - accounts := map[string]state.UserAccountHandler{} - adb := &stateMock.AccountsStub{} - adb.LoadAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { - if bytes.Equal(address, providedAddrFail) { - return &stateMock.UserAccountStub{ - AddToBalanceCalled: func(value *big.Int) error { - return errors.New("won't add to balance") - }, - }, nil - } - - acnt, exists := accounts[string(address)] - if !exists { - acnt = createUserAcc(address) - accounts[string(address)] = acnt - _ = acnt.AddToBalance(providedInitialBalance) - } - - return acnt, nil - } - - scProcessorMock := &testscommon.SCProcessorMock{} - shardC, _ := sharding.NewMultiShardCoordinator(1, 0) - esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) - argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), - } - txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) - - args := createArgsForTxProcessor() - args.Accounts = adb - args.ScProcessor = scProcessorMock - args.ShardCoordinator = shardC - args.TxTypeHandler = txTypeHandler - args.PubkeyConv = pubKeyConverter - args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedBaseCostFlag) - args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ - ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { - return big.NewInt(1) - }, - ComputeRelayedTxFeesCalled: func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { - relayerFee := big.NewInt(0).SetInt64(int64(len(tx.GetUserTransactions()))) // gasPrice = 1 - totalFee := *relayerFee - for _, innerTx := range tx.GetUserTransactions() { - totalFee.Add(&totalFee, big.NewInt(0).SetUint64(innerTx.GetGasLimit())) - } - - return relayerFee, &totalFee, nil - }, - } - args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ - EconomicsFee: args.EconomicsFee, - ShardCoordinator: args.ShardCoordinator, - MaxTransactionsAllowed: 10, - }) - logs := make([]*vmcommon.LogEntry, 0) - args.TxLogsProcessor = &mock.TxLogsProcessorStub{ - SaveLogCalled: func(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error { - logs = append(logs, vmLogs...) - return nil - }, - } - execTx, _ := txproc.NewTxProcessor(args) - - txCopy := *tx - innerTx1 := &transaction.Transaction{ - Nonce: 0, - Value: big.NewInt(10), - RcvAddr: []byte("sDST"), - SndAddr: []byte("sender inner tx 1"), - GasPrice: 1, - GasLimit: 1, - RelayerAddr: txCopy.SndAddr, - } - innerTx2 := &transaction.Transaction{ - Nonce: 0, - Value: big.NewInt(10), - RcvAddr: []byte("sDST"), - SndAddr: []byte("sender inner tx 2"), - GasPrice: 1, - GasLimit: 1, - RelayerAddr: txCopy.SndAddr, - } - innerTx3 := &transaction.Transaction{ - Nonce: 0, - Value: big.NewInt(10), - RcvAddr: []byte("sDST"), - SndAddr: providedAddrFail, - GasPrice: 1, - GasLimit: 1, - RelayerAddr: txCopy.SndAddr, - } - - txCopy.InnerTransactions = []*transaction.Transaction{innerTx1, innerTx2, innerTx3} - returnCode, err := execTx.ProcessTransaction(&txCopy) - assert.NoError(t, err) - assert.Equal(t, vmcommon.Ok, returnCode) - - expectedBalance := providedInitialBalance - for _, acnt := range accounts { - switch string(acnt.AddressBytes()) { - case "sSRC": - continue // relayer - case "sDST": - expectedBalance = big.NewInt(120) // 2 successful txs received - case "sender inner tx 1", "sender inner tx 2": - expectedBalance = big.NewInt(90) // one successful tx sent from each - default: - assert.Fail(t, "should not be other participants") - } - - assert.Equal(t, expectedBalance, acnt.GetBalance(), fmt.Sprintf("checks failed for address: %s", string(acnt.AddressBytes()))) - } - - require.Equal(t, 2, len(logs)) - for _, log := range logs { - require.Equal(t, core.CompletedTxEventIdentifier, string(log.Identifier)) - } - }) - t.Run("one inner fails should return success on relayed", func(t *testing.T) { - t.Parallel() - - providedInitialBalance := big.NewInt(100) - pubKeyConverter := testscommon.NewPubkeyConverterMock(4) - - accounts := map[string]state.UserAccountHandler{} - adb := &stateMock.AccountsStub{} - adb.LoadAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { - acnt, exists := accounts[string(address)] - if !exists { - acnt = createUserAcc(address) - accounts[string(address)] = acnt - _ = acnt.AddToBalance(providedInitialBalance) - } - - return acnt, nil - } - - scProcessorMock := &testscommon.SCProcessorMock{} - shardC, _ := sharding.NewMultiShardCoordinator(1, 0) - esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) - argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), - } - txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) - - args := createArgsForTxProcessor() - args.Accounts = adb - args.ScProcessor = scProcessorMock - args.ShardCoordinator = shardC - args.TxTypeHandler = txTypeHandler - args.PubkeyConv = pubKeyConverter - args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedBaseCostFlag) - args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ - ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { - return big.NewInt(int64(tx.GetGasPrice() * tx.GetGasLimit())) - }, - ComputeRelayedTxFeesCalled: func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { - relayerFee := big.NewInt(0).SetInt64(int64(len(tx.GetUserTransactions()))) // gasPrice = 1 - totalFee := *relayerFee - for _, innerTx := range tx.GetUserTransactions() { - totalFee.Add(&totalFee, big.NewInt(0).SetUint64(innerTx.GetGasLimit())) - } - - return relayerFee, &totalFee, nil - }, - } - args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ - EconomicsFee: args.EconomicsFee, - ShardCoordinator: args.ShardCoordinator, - MaxTransactionsAllowed: 10, - }) - wasGetLogsCalled := false - wasRemoveCalled := false - args.FailedTxLogsAccumulator = &processMocks.FailedTxLogsAccumulatorMock{ - GetLogsCalled: func(txHash []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) { - wasGetLogsCalled = true - - return &smartContractResult.SmartContractResult{}, []*vmcommon.LogEntry{}, true - }, - RemoveCalled: func(txHash []byte) { - wasRemoveCalled = true - }, - } - execTx, _ := txproc.NewTxProcessor(args) - - txCopy := *tx - usertTxCopy := *userTx // same inner tx twice should fail second time - txCopy.InnerTransactions = append(txCopy.InnerTransactions, &usertTxCopy) - returnCode, err := execTx.ProcessTransaction(&txCopy) - assert.NoError(t, err) - assert.Equal(t, vmcommon.Ok, returnCode) - assert.True(t, wasGetLogsCalled) - assert.True(t, wasRemoveCalled) - }) - t.Run("fees consumed mismatch should error", func(t *testing.T) { - t.Parallel() - - providedInitialBalance := big.NewInt(100) - pubKeyConverter := testscommon.NewPubkeyConverterMock(4) - - accounts := map[string]state.UserAccountHandler{} - adb := &stateMock.AccountsStub{} - adb.LoadAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { - acnt, exists := accounts[string(address)] - if !exists { - acnt = createUserAcc(address) - accounts[string(address)] = acnt - _ = acnt.AddToBalance(providedInitialBalance) - } - - return acnt, nil - } - wasRevertToSnapshotCalled := false - adb.RevertToSnapshotCalled = func(snapshot int) error { - wasRevertToSnapshotCalled = true - return nil - } - - scProcessorMock := &testscommon.SCProcessorMock{} - shardC, _ := sharding.NewMultiShardCoordinator(1, 0) - esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) - argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), - } - txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) - - args := createArgsForTxProcessor() - args.Accounts = adb - args.ScProcessor = scProcessorMock - args.ShardCoordinator = shardC - args.TxTypeHandler = txTypeHandler - args.PubkeyConv = pubKeyConverter - args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedBaseCostFlag) - increasingFee := big.NewInt(0) - args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ - ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { - increasingFee.Add(increasingFee, big.NewInt(1)) - return increasingFee - }, - } - args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ - EconomicsFee: args.EconomicsFee, - ShardCoordinator: args.ShardCoordinator, - MaxTransactionsAllowed: 10, - }) - execTx, _ := txproc.NewTxProcessor(args) - - txCopy := *tx - innerTx1 := &transaction.Transaction{ - Nonce: 0, - Value: big.NewInt(10), - RcvAddr: []byte("sDST"), - SndAddr: []byte("sender inner tx 1"), - GasPrice: 1, - GasLimit: 1, - RelayerAddr: txCopy.SndAddr, - } - innerTx2 := &transaction.Transaction{ - Nonce: 0, - Value: big.NewInt(10), - RcvAddr: []byte("sDST"), - SndAddr: []byte("sender inner tx 2"), - GasPrice: 1, - GasLimit: 1, - RelayerAddr: txCopy.SndAddr, - } - - txCopy.InnerTransactions = []*transaction.Transaction{innerTx1, innerTx2} - returnCode, err := execTx.ProcessTransaction(&txCopy) - assert.Error(t, err) - assert.Equal(t, vmcommon.UserError, returnCode) - assert.True(t, wasRevertToSnapshotCalled) - }) - t.Run("should work", func(t *testing.T) { - t.Parallel() - testProcessRelayedTransactionV3(t, tx, userTx.SndAddr, userTx.RcvAddr, nil, vmcommon.Ok) - }) -} - -func testProcessRelayedTransactionV3( - t *testing.T, - tx *transaction.Transaction, - innerSender []byte, - finalRcvr []byte, - expectedErr error, - expectedCode vmcommon.ReturnCode, -) { - pubKeyConverter := testscommon.NewPubkeyConverterMock(4) - marshaller := &mock.MarshalizerMock{} - - acntSrc := createUserAcc(tx.SndAddr) - _ = acntSrc.AddToBalance(big.NewInt(100)) - acntDst := createUserAcc(tx.RcvAddr) - _ = acntDst.AddToBalance(big.NewInt(10)) - - acntFinal := createUserAcc(finalRcvr) - _ = acntFinal.AddToBalance(big.NewInt(10)) - acntInnerSender := createUserAcc(innerSender) - _ = acntInnerSender.AddToBalance(big.NewInt(10)) - - adb := &stateMock.AccountsStub{} - adb.LoadAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { - if bytes.Equal(address, tx.SndAddr) { - return acntSrc, nil - } - if bytes.Equal(address, tx.RcvAddr) { - return acntDst, nil - } - if bytes.Equal(address, finalRcvr) { - return acntFinal, nil - } - if bytes.Equal(address, innerSender) { - return acntInnerSender, nil - } - - return nil, errors.New("failure") - } - - scProcessorMock := &testscommon.SCProcessorMock{} - shardC, _ := sharding.NewMultiShardCoordinator(1, 0) - esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) - argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), - } - txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) - - args := createArgsForTxProcessor() - args.Accounts = adb - args.ScProcessor = scProcessorMock - args.ShardCoordinator = shardC - args.TxTypeHandler = txTypeHandler - args.PubkeyConv = pubKeyConverter - args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedBaseCostFlag) - args.EconomicsFee = &economicsmocks.EconomicsHandlerMock{ - ComputeTxFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { - return big.NewInt(4) - }, - ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { - return big.NewInt(4) - }, - ComputeGasLimitCalled: func(tx data.TransactionWithFeeHandler) uint64 { - return 4 - }, - ComputeRelayedTxFeesCalled: func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { - relayerFee := big.NewInt(0).SetInt64(int64(len(tx.GetUserTransactions()))) // gasPrice = 1 - totalFee := *relayerFee - for _, innerTx := range tx.GetUserTransactions() { - totalFee.Add(&totalFee, big.NewInt(0).SetUint64(innerTx.GetGasLimit())) - } - - return relayerFee, &totalFee, nil - }, - } - args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ - EconomicsFee: args.EconomicsFee, - ShardCoordinator: args.ShardCoordinator, - MaxTransactionsAllowed: 10, - }) - - execTx, _ := txproc.NewTxProcessor(args) - - returnCode, err := execTx.ProcessTransaction(tx) - assert.Equal(t, expectedErr, err) - assert.Equal(t, expectedCode, returnCode) -} - func TestTxProcessor_ProcessRelayedTransaction(t *testing.T) { t.Parallel() @@ -3846,12 +3298,12 @@ func TestTxProcessor_AddNonExecutableLog(t *testing.T) { originalTxHash, err := core.CalculateHash(args.Marshalizer, args.Hasher, originalTx) assert.Nil(t, err) numLogsSaved := 0 - args.FailedTxLogsAccumulator = &processMocks.FailedTxLogsAccumulatorMock{ - SaveLogsCalled: func(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { + args.TxLogsProcessor = &mock.TxLogsProcessorStub{ + SaveLogCalled: func(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error { assert.Equal(t, originalTxHash, txHash) assert.Equal(t, originalTx, tx) - assert.Equal(t, 1, len(logs)) - firstLog := logs[0] + assert.Equal(t, 1, len(vmLogs)) + firstLog := vmLogs[0] assert.Equal(t, core.SignalErrorOperation, string(firstLog.Identifier)) assert.Equal(t, sender, firstLog.Address) assert.Empty(t, firstLog.Data) @@ -3880,20 +3332,21 @@ func TestTxProcessor_ProcessMoveBalanceToNonPayableContract(t *testing.T) { t.Parallel() shardCoordinator := mock.NewOneShardCoordinatorMock() + marshaller := marshal.JsonMarshalizer{} innerTx := transaction.Transaction{} innerTx.Nonce = 1 innerTx.SndAddr = []byte("SRC") innerTx.RcvAddr = make([]byte, 32) innerTx.Value = big.NewInt(100) - innerTx.RelayerAddr = []byte("SRC") tx := transaction.Transaction{} tx.Nonce = 0 tx.SndAddr = []byte("SRC") tx.RcvAddr = []byte("SRC") tx.Value = big.NewInt(0) - tx.InnerTransactions = []*transaction.Transaction{&innerTx} + marshalledData, _ := marshaller.Marshal(&innerTx) + tx.Data = []byte("relayedTx@" + hex.EncodeToString(marshalledData)) shardCoordinator.ComputeIdCalled = func(address []byte) uint32 { return 0 @@ -3909,19 +3362,20 @@ func TestTxProcessor_ProcessMoveBalanceToNonPayableContract(t *testing.T) { args := createArgsForTxProcessor() args.Accounts = adb args.ShardCoordinator = shardCoordinator + args.SignMarshalizer = &marshaller cnt := 0 args.TxTypeHandler = &testscommon.TxTypeHandlerMock{ ComputeTransactionTypeCalled: func(tx data.TransactionHandler) (process.TransactionType, process.TransactionType) { cnt++ if cnt == 1 { - return process.RelayedTxV3, process.RelayedTxV3 + return process.RelayedTx, process.RelayedTx } return process.MoveBalance, process.MoveBalance }, } args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub( - common.RelayedTransactionsV3Flag, + common.RelayedTransactionsFlag, common.FixRelayedBaseCostFlag, common.FixRelayedMoveBalanceToNonPayableSCFlag, ) @@ -3930,6 +3384,11 @@ func TestTxProcessor_ProcessMoveBalanceToNonPayableContract(t *testing.T) { return false, nil }, } + args.ArgsParser = &testscommon.ArgumentParserMock{ + ParseCallDataCalled: func(data string) (string, [][]byte, error) { + return core.RelayedTransaction, [][]byte{marshalledData}, nil + }, + } execTx, _ := txproc.NewTxProcessor(args) _, err := execTx.ProcessTransaction(&tx) @@ -3943,7 +3402,7 @@ func TestTxProcessor_IsInterfaceNil(t *testing.T) { t.Parallel() args := createArgsForTxProcessor() - args.RelayedTxV3Processor = nil + args.Hasher = nil proc, _ := txproc.NewTxProcessor(args) require.True(t, proc.IsInterfaceNil()) diff --git a/process/transactionEvaluator/transactionEvaluator.go b/process/transactionEvaluator/transactionEvaluator.go index 032aeefdc80..9e61d138419 100644 --- a/process/transactionEvaluator/transactionEvaluator.go +++ b/process/transactionEvaluator/transactionEvaluator.go @@ -119,7 +119,7 @@ func (ate *apiTransactionEvaluator) ComputeTransactionGasLimit(tx *transaction.T switch txTypeOnSender { case process.SCDeployment, process.SCInvoking, process.BuiltInFunctionCall, process.MoveBalance: return ate.simulateTransactionCost(tx, txTypeOnSender) - case process.RelayedTx, process.RelayedTxV2, process.RelayedTxV3: + case process.RelayedTx, process.RelayedTxV2: // TODO implement in the next PR return &transaction.CostResponse{ GasUnits: 0, diff --git a/process/transactionLog/failedTxLogsAccumulator.go b/process/transactionLog/failedTxLogsAccumulator.go deleted file mode 100644 index a0d973541bc..00000000000 --- a/process/transactionLog/failedTxLogsAccumulator.go +++ /dev/null @@ -1,109 +0,0 @@ -package transactionLog - -import ( - "sync" - - "github.com/multiversx/mx-chain-core-go/core/check" - "github.com/multiversx/mx-chain-core-go/data" - "github.com/multiversx/mx-chain-go/process" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" -) - -type logData struct { - tx data.TransactionHandler - logs []*vmcommon.LogEntry -} - -type failedTxLogsAccumulator struct { - mut sync.RWMutex - logsMap map[string]*logData -} - -// NewFailedTxLogsAccumulator returns a new instance of failedTxLogsAccumulator -func NewFailedTxLogsAccumulator() *failedTxLogsAccumulator { - return &failedTxLogsAccumulator{ - logsMap: make(map[string]*logData), - } -} - -// GetLogs returns the accumulated logs for the provided txHash -func (accumulator *failedTxLogsAccumulator) GetLogs(txHash []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) { - if len(txHash) == 0 { - return nil, nil, false - } - - logsData, found := accumulator.getLogDataCopy(txHash) - - if !found { - return nil, nil, found - } - - return logsData.tx, logsData.logs, found -} - -func (accumulator *failedTxLogsAccumulator) getLogDataCopy(txHash []byte) (logData, bool) { - accumulator.mut.RLock() - defer accumulator.mut.RUnlock() - - logsData, found := accumulator.logsMap[string(txHash)] - if !found { - return logData{}, found - } - - logsDataCopy := logData{ - tx: logsData.tx, - } - - logsDataCopy.logs = append(logsDataCopy.logs, logsData.logs...) - - return logsDataCopy, found -} - -// SaveLogs saves the logs into the internal map -func (accumulator *failedTxLogsAccumulator) SaveLogs(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { - if len(txHash) == 0 { - return process.ErrNilTxHash - } - - if check.IfNil(tx) { - return process.ErrNilTransaction - } - - if len(logs) == 0 { - return nil - } - - accumulator.mut.Lock() - defer accumulator.mut.Unlock() - - _, found := accumulator.logsMap[string(txHash)] - if !found { - accumulator.logsMap[string(txHash)] = &logData{ - tx: tx, - logs: logs, - } - - return nil - } - - accumulator.logsMap[string(txHash)].logs = append(accumulator.logsMap[string(txHash)].logs, logs...) - - return nil -} - -// Remove removes the accumulated logs for the provided txHash -func (accumulator *failedTxLogsAccumulator) Remove(txHash []byte) { - if len(txHash) == 0 { - return - } - - accumulator.mut.Lock() - defer accumulator.mut.Unlock() - - delete(accumulator.logsMap, string(txHash)) -} - -// IsInterfaceNil returns true if there is no value under the interface -func (accumulator *failedTxLogsAccumulator) IsInterfaceNil() bool { - return accumulator == nil -} diff --git a/process/transactionLog/failedTxLogsAccumulator_test.go b/process/transactionLog/failedTxLogsAccumulator_test.go deleted file mode 100644 index 691f4b41ffa..00000000000 --- a/process/transactionLog/failedTxLogsAccumulator_test.go +++ /dev/null @@ -1,168 +0,0 @@ -package transactionLog - -import ( - "fmt" - "sync" - "testing" - - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-go/process" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/stretchr/testify/require" -) - -var ( - providedHash = []byte("hash") - providedTx = &transaction.Transaction{Nonce: 123} - providedLogs = []*vmcommon.LogEntry{ - { - Identifier: []byte("identifier"), - Address: []byte("addr"), - Topics: [][]byte{[]byte("topic")}, - Data: [][]byte{[]byte("data")}, - }, - } -) - -func TestNewFailedTxLogsAccumulator(t *testing.T) { - t.Parallel() - - accumulator := NewFailedTxLogsAccumulator() - require.NotNil(t, accumulator) -} - -func TestFailedTxLogsAccumulator_IsInterfaceNil(t *testing.T) { - t.Parallel() - - var accumulator *failedTxLogsAccumulator - require.True(t, accumulator.IsInterfaceNil()) - - accumulator = NewFailedTxLogsAccumulator() - require.False(t, accumulator.IsInterfaceNil()) -} - -func TestFailedTxLogsAccumulator_GetLogs(t *testing.T) { - t.Parallel() - - accumulator := NewFailedTxLogsAccumulator() - tx, logs, ok := accumulator.GetLogs([]byte("")) - require.False(t, ok) - require.Nil(t, tx) - require.Nil(t, logs) - - err := accumulator.SaveLogs(providedHash, providedTx, providedLogs) - require.NoError(t, err) - - tx, logs, ok = accumulator.GetLogs([]byte("missing hash")) - require.False(t, ok) - require.Nil(t, tx) - require.Nil(t, logs) - - tx, logs, ok = accumulator.GetLogs(providedHash) - require.True(t, ok) - require.Equal(t, providedTx, tx) - require.Equal(t, providedLogs, logs) -} - -func TestFailedTxLogsAccumulator_SaveLogs(t *testing.T) { - t.Parallel() - - t.Run("empty hash should error", func(t *testing.T) { - t.Parallel() - - accumulator := NewFailedTxLogsAccumulator() - err := accumulator.SaveLogs([]byte(""), nil, nil) - require.Equal(t, process.ErrNilTxHash, err) - }) - t.Run("nil tx should error", func(t *testing.T) { - t.Parallel() - - accumulator := NewFailedTxLogsAccumulator() - err := accumulator.SaveLogs(providedHash, nil, nil) - require.Equal(t, process.ErrNilTransaction, err) - }) - t.Run("empty logs should return nil", func(t *testing.T) { - t.Parallel() - - accumulator := NewFailedTxLogsAccumulator() - err := accumulator.SaveLogs(providedHash, providedTx, nil) - require.NoError(t, err) - }) - t.Run("should work and append logs", func(t *testing.T) { - t.Parallel() - - accumulator := NewFailedTxLogsAccumulator() - err := accumulator.SaveLogs(providedHash, providedTx, providedLogs) - require.NoError(t, err) - - providedNewLogs := []*vmcommon.LogEntry{ - { - Identifier: []byte("identifier 2"), - Address: []byte("addr"), - Topics: [][]byte{[]byte("topic 2")}, - Data: [][]byte{[]byte("data 2")}, - }, - } - err = accumulator.SaveLogs(providedHash, providedTx, providedNewLogs) - require.NoError(t, err) - - expectedLogs := append(providedLogs, providedNewLogs...) - receivedTx, receivedLogs, ok := accumulator.GetLogs(providedHash) - require.True(t, ok) - require.Equal(t, providedTx, receivedTx) - require.Equal(t, expectedLogs, receivedLogs) - }) -} - -func TestFailedTxLogsAccumulator_Remove(t *testing.T) { - t.Parallel() - - accumulator := NewFailedTxLogsAccumulator() - err := accumulator.SaveLogs(providedHash, providedTx, providedLogs) - require.NoError(t, err) - _, _, ok := accumulator.GetLogs(providedHash) - require.True(t, ok) - - accumulator.Remove([]byte("")) // coverage only - - accumulator.Remove(providedHash) - _, _, ok = accumulator.GetLogs(providedHash) - require.False(t, ok) -} - -func TestTxLogProcessor_ConcurrentOperations(t *testing.T) { - t.Parallel() - - require.NotPanics(t, func() { - accumulator := NewFailedTxLogsAccumulator() - - numCalls := 1000 - wg := sync.WaitGroup{} - wg.Add(numCalls) - - for i := 0; i < numCalls; i++ { - go func(idx int) { - switch idx % 3 { - case 0: - err := accumulator.SaveLogs(providedHash, providedTx, []*vmcommon.LogEntry{ - { - Identifier: []byte(fmt.Sprintf("identifier %d", idx)), - Address: []byte("addr"), - Topics: [][]byte{[]byte(fmt.Sprintf("topic %d", idx))}, - Data: [][]byte{[]byte(fmt.Sprintf("data %d", idx))}, - }, - }) - require.NoError(t, err) - case 1: - _, _, _ = accumulator.GetLogs(providedHash) - case 2: - accumulator.Remove(providedHash) - } - - wg.Done() - }(i) - } - - wg.Wait() - }) -} diff --git a/sharding/mock/enableEpochsHandlerMock.go b/sharding/mock/enableEpochsHandlerMock.go index 9a842f9adae..48dfcedfa52 100644 --- a/sharding/mock/enableEpochsHandlerMock.go +++ b/sharding/mock/enableEpochsHandlerMock.go @@ -43,21 +43,6 @@ func (mock *EnableEpochsHandlerMock) GetCurrentEpoch() uint32 { return mock.CurrentEpoch } -// FixGasRemainingForSaveKeyValueBuiltinFunctionEnabled - -func (mock *EnableEpochsHandlerMock) FixGasRemainingForSaveKeyValueBuiltinFunctionEnabled() bool { - return false -} - -// IsRelayedTransactionsV3FlagEnabled - -func (mock *EnableEpochsHandlerMock) IsRelayedTransactionsV3FlagEnabled() bool { - return false -} - -// IsFixRelayedBaseCostFlagEnabled - -func (mock *EnableEpochsHandlerMock) IsFixRelayedBaseCostFlagEnabled() bool { - return false -} - // IsInterfaceNil returns true if there is no value under the interface func (mock *EnableEpochsHandlerMock) IsInterfaceNil() bool { return mock == nil diff --git a/testscommon/components/default.go b/testscommon/components/default.go index 8e1942037dd..514b8355407 100644 --- a/testscommon/components/default.go +++ b/testscommon/components/default.go @@ -20,7 +20,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" "github.com/multiversx/mx-chain-go/testscommon/nodeTypeProviderMock" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" "github.com/multiversx/mx-chain-go/testscommon/stakingcommon" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -157,7 +156,6 @@ func GetDefaultProcessComponents(shardCoordinator sharding.Coordinator) *mock.Pr return &mock.PrivateKeyStub{} }, }, - HardforkTriggerField: &testscommon.HardforkTriggerStub{}, - RelayedTxV3ProcessorField: &processMocks.RelayedTxV3ProcessorMock{}, + HardforkTriggerField: &testscommon.HardforkTriggerStub{}, } } diff --git a/testscommon/economicsmocks/economicsDataHandlerStub.go b/testscommon/economicsmocks/economicsDataHandlerStub.go index c76ce6c59a2..4ef784c596f 100644 --- a/testscommon/economicsmocks/economicsDataHandlerStub.go +++ b/testscommon/economicsmocks/economicsDataHandlerStub.go @@ -5,7 +5,6 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data" - "github.com/multiversx/mx-chain-go/process" ) // EconomicsHandlerStub - @@ -47,8 +46,6 @@ type EconomicsHandlerStub struct { ComputeGasLimitInEpochCalled func(tx data.TransactionWithFeeHandler, epoch uint32) uint64 ComputeGasUsedAndFeeBasedOnRefundValueInEpochCalled func(tx data.TransactionWithFeeHandler, refundValue *big.Int, epoch uint32) (uint64, *big.Int) ComputeTxFeeBasedOnGasUsedInEpochCalled func(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int - ComputeRelayedTxFeesCalled func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) - SetTxTypeHandlerCalled func(txTypeHandler process.TxTypeHandler) error ComputeMoveBalanceFeeInEpochCalled func(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int } @@ -368,22 +365,6 @@ func (e *EconomicsHandlerStub) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.Transac return nil } -// ComputeRelayedTxFees - -func (e *EconomicsHandlerStub) ComputeRelayedTxFees(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { - if e.ComputeRelayedTxFeesCalled != nil { - return e.ComputeRelayedTxFeesCalled(tx) - } - return big.NewInt(0), big.NewInt(0), nil -} - -// SetTxTypeHandler - -func (e *EconomicsHandlerStub) SetTxTypeHandler(txTypeHandler process.TxTypeHandler) error { - if e.SetTxTypeHandlerCalled != nil { - return e.SetTxTypeHandlerCalled(txTypeHandler) - } - return nil -} - // IsInterfaceNil returns true if there is no value under the interface func (e *EconomicsHandlerStub) IsInterfaceNil() bool { return e == nil diff --git a/testscommon/economicsmocks/economicsHandlerMock.go b/testscommon/economicsmocks/economicsHandlerMock.go index 0c92fff0238..b1e4321f389 100644 --- a/testscommon/economicsmocks/economicsHandlerMock.go +++ b/testscommon/economicsmocks/economicsHandlerMock.go @@ -5,7 +5,6 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data" - "github.com/multiversx/mx-chain-go/process" ) // EconomicsHandlerMock - @@ -48,8 +47,6 @@ type EconomicsHandlerMock struct { ComputeGasLimitInEpochCalled func(tx data.TransactionWithFeeHandler, epoch uint32) uint64 ComputeGasUsedAndFeeBasedOnRefundValueInEpochCalled func(tx data.TransactionWithFeeHandler, refundValue *big.Int, epoch uint32) (uint64, *big.Int) ComputeTxFeeBasedOnGasUsedInEpochCalled func(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int - ComputeRelayedTxFeesCalled func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) - SetTxTypeHandlerCalled func(txTypeHandler process.TxTypeHandler) error } // LeaderPercentage - @@ -346,22 +343,6 @@ func (ehm *EconomicsHandlerMock) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.Trans return nil } -// ComputeRelayedTxFees - -func (ehm *EconomicsHandlerMock) ComputeRelayedTxFees(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { - if ehm.ComputeRelayedTxFeesCalled != nil { - return ehm.ComputeRelayedTxFeesCalled(tx) - } - return big.NewInt(0), big.NewInt(0), nil -} - -// SetTxTypeHandler - -func (ehm *EconomicsHandlerMock) SetTxTypeHandler(txTypeHandler process.TxTypeHandler) error { - if ehm.SetTxTypeHandlerCalled != nil { - return ehm.SetTxTypeHandlerCalled(txTypeHandler) - } - return nil -} - // IsInterfaceNil returns true if there is no value under the interface func (ehm *EconomicsHandlerMock) IsInterfaceNil() bool { return ehm == nil diff --git a/testscommon/processMocks/failedTxLogsAccumulatorMock.go b/testscommon/processMocks/failedTxLogsAccumulatorMock.go deleted file mode 100644 index 903e56cd79f..00000000000 --- a/testscommon/processMocks/failedTxLogsAccumulatorMock.go +++ /dev/null @@ -1,41 +0,0 @@ -package processMocks - -import ( - "github.com/multiversx/mx-chain-core-go/data" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" -) - -// FailedTxLogsAccumulatorMock - -type FailedTxLogsAccumulatorMock struct { - GetLogsCalled func(txHash []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) - SaveLogsCalled func(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error - RemoveCalled func(txHash []byte) -} - -// GetLogs - -func (mock *FailedTxLogsAccumulatorMock) GetLogs(txHash []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) { - if mock.GetLogsCalled != nil { - return mock.GetLogsCalled(txHash) - } - return nil, nil, false -} - -// SaveLogs - -func (mock *FailedTxLogsAccumulatorMock) SaveLogs(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { - if mock.SaveLogsCalled != nil { - return mock.SaveLogsCalled(txHash, tx, logs) - } - return nil -} - -// Remove - -func (mock *FailedTxLogsAccumulatorMock) Remove(txHash []byte) { - if mock.RemoveCalled != nil { - mock.RemoveCalled(txHash) - } -} - -// IsInterfaceNil - -func (mock *FailedTxLogsAccumulatorMock) IsInterfaceNil() bool { - return mock == nil -} diff --git a/testscommon/processMocks/relayedTxV3ProcessorMock.go b/testscommon/processMocks/relayedTxV3ProcessorMock.go deleted file mode 100644 index 85af9584af5..00000000000 --- a/testscommon/processMocks/relayedTxV3ProcessorMock.go +++ /dev/null @@ -1,23 +0,0 @@ -package processMocks - -import ( - "github.com/multiversx/mx-chain-core-go/data/transaction" -) - -// RelayedTxV3ProcessorMock - -type RelayedTxV3ProcessorMock struct { - CheckRelayedTxCalled func(tx *transaction.Transaction) error -} - -// CheckRelayedTx - -func (mock *RelayedTxV3ProcessorMock) CheckRelayedTx(tx *transaction.Transaction) error { - if mock.CheckRelayedTxCalled != nil { - return mock.CheckRelayedTxCalled(tx) - } - return nil -} - -// IsInterfaceNil - -func (mock *RelayedTxV3ProcessorMock) IsInterfaceNil() bool { - return mock == nil -} diff --git a/update/factory/exportHandlerFactory.go b/update/factory/exportHandlerFactory.go index a8ed95f4ceb..c13f25f3f5a 100644 --- a/update/factory/exportHandlerFactory.go +++ b/update/factory/exportHandlerFactory.go @@ -18,7 +18,6 @@ import ( mxFactory "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/genesis/process/disabled" "github.com/multiversx/mx-chain-go/process" - processDisabled "github.com/multiversx/mx-chain-go/process/disabled" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" @@ -589,7 +588,6 @@ func (e *exportHandlerFactory) createInterceptors() error { FullArchiveInterceptorsContainer: e.fullArchiveInterceptorsContainer, AntifloodHandler: e.networkComponents.InputAntiFloodHandler(), NodeOperationMode: e.nodeOperationMode, - RelayedTxV3Processor: processDisabled.NewRelayedTxV3Processor(), } fullSyncInterceptors, err := NewFullSyncInterceptorsContainerFactory(argsInterceptors) if err != nil { diff --git a/update/factory/fullSyncInterceptors.go b/update/factory/fullSyncInterceptors.go index 67d5a86a503..0fe0298c4d6 100644 --- a/update/factory/fullSyncInterceptors.go +++ b/update/factory/fullSyncInterceptors.go @@ -75,7 +75,6 @@ type ArgsNewFullSyncInterceptorsContainerFactory struct { FullArchiveInterceptorsContainer process.InterceptorsContainer AntifloodHandler process.P2PAntifloodHandler NodeOperationMode common.NodeOperation - RelayedTxV3Processor process.RelayedTxV3Processor } // NewFullSyncInterceptorsContainerFactory is responsible for creating a new interceptors factory object @@ -146,7 +145,6 @@ func NewFullSyncInterceptorsContainerFactory( EpochStartTrigger: args.EpochStartTrigger, WhiteListerVerifiedTxs: args.WhiteListerVerifiedTxs, ArgsParser: smartContract.NewArgumentParser(), - RelayedTxV3Processor: args.RelayedTxV3Processor, } icf := &fullSyncInterceptorsContainerFactory{ From 0678c6eb479d913087a82e61e71dd274f1735119 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 21 Oct 2024 08:50:26 +0300 Subject: [PATCH 87/99] updated indexer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 8718f3e9d10..b1eb1aa4ddb 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiversx/mx-chain-communication-go v1.1.0 github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6 + github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b 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.16 diff --git a/go.sum b/go.sum index 232f91ed5a7..32ad88ef7af 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c h1: github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6 h1:2F5WyCIvFVs4CONd9kJxibY1NIfJLYFAwqNJvC31qNA= -github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6/go.mod h1:AJew7KVcICVyVDlXpDQzvjcSnKs0aCYl7eXnJwg+15E= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b h1:GYvm0yGkdQ3OCfNqnyIQNzAzydN3cES8noJZ3eZHN1A= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= 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= From 953bb39d3627e20276876a66a966676e18556766 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 21 Oct 2024 10:54:07 +0300 Subject: [PATCH 88/99] possible fix for failing test --- factory/processing/txSimulatorProcessComponents_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/factory/processing/txSimulatorProcessComponents_test.go b/factory/processing/txSimulatorProcessComponents_test.go index aad848600d8..0c919b0ba95 100644 --- a/factory/processing/txSimulatorProcessComponents_test.go +++ b/factory/processing/txSimulatorProcessComponents_test.go @@ -9,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-go/process/mock" "github.com/multiversx/mx-chain-go/testscommon/components" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { @@ -40,6 +41,7 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { assert.Nil(t, err) assert.False(t, check.IfNil(apiTransactionEvaluator)) assert.False(t, check.IfNil(vmContainerFactory)) + require.NoError(t, vmContainerFactory.Close()) }) t.Run("should work for metachain", func(t *testing.T) { processArgs := components.GetProcessComponentsFactoryArgs(shardCoordinatorForMetachain) @@ -49,5 +51,6 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { assert.Nil(t, err) assert.False(t, check.IfNil(apiTransactionEvaluator)) assert.False(t, check.IfNil(vmContainerFactory)) + require.NoError(t, vmContainerFactory.Close()) }) } From 919d287c618073636f8a3a636db5fcae9bc30b03 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 21 Oct 2024 13:20:20 +0300 Subject: [PATCH 89/99] fixes after review --- node/external/dtos.go | 1 - node/external/transactionAPI/gasUsedAndFeeProcessor.go | 3 --- 2 files changed, 4 deletions(-) diff --git a/node/external/dtos.go b/node/external/dtos.go index ad8d073967b..f884d8d32c9 100644 --- a/node/external/dtos.go +++ b/node/external/dtos.go @@ -17,5 +17,4 @@ type ArgsCreateTransaction struct { Options uint32 Guardian string GuardianSigHex string - Relayer string } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index ab5c77fee40..bc01297ef85 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -62,9 +62,6 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction if !scr.IsRefund || scr.RcvAddr != tx.Sender { continue } - if scr.RcvAddr != tx.Sender { - continue - } gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value) hasRefundForSender = true From 2bcbc152fd4075631d12d070e093b119957d4b0c Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 21 Oct 2024 14:12:47 +0300 Subject: [PATCH 90/99] removed config --- cmd/node/config/config.toml | 3 --- config/config.go | 7 ------- testscommon/generalConfig.go | 3 --- 3 files changed, 13 deletions(-) diff --git a/cmd/node/config/config.toml b/cmd/node/config/config.toml index 7f07d4dd380..6e1205d5f7e 100644 --- a/cmd/node/config/config.toml +++ b/cmd/node/config/config.toml @@ -946,6 +946,3 @@ # MaxRoundsOfInactivityAccepted defines the number of rounds missed by a main or higher level backup machine before # the current machine will take over and propose/sign blocks. Used in both single-key and multi-key modes. MaxRoundsOfInactivityAccepted = 3 - -[RelayedTransactionConfig] - MaxTransactionsAllowed = 50 diff --git a/config/config.go b/config/config.go index 412ab59f776..49ef257c341 100644 --- a/config/config.go +++ b/config/config.go @@ -228,8 +228,6 @@ type Config struct { PeersRatingConfig PeersRatingConfig PoolsCleanersConfig PoolsCleanersConfig Redundancy RedundancyConfig - - RelayedTransactionConfig RelayedTransactionConfig } // PeersRatingConfig will hold settings related to peers rating @@ -642,8 +640,3 @@ type PoolsCleanersConfig struct { type RedundancyConfig struct { MaxRoundsOfInactivityAccepted int } - -// RelayedTransactionConfig represents the config options to be used for relayed transactions -type RelayedTransactionConfig struct { - MaxTransactionsAllowed int -} diff --git a/testscommon/generalConfig.go b/testscommon/generalConfig.go index 53299443ebe..1eea96a2bdb 100644 --- a/testscommon/generalConfig.go +++ b/testscommon/generalConfig.go @@ -429,9 +429,6 @@ func GetGeneralConfig() config.Config { ResourceStats: config.ResourceStatsConfig{ RefreshIntervalInSec: 1, }, - RelayedTransactionConfig: config.RelayedTransactionConfig{ - MaxTransactionsAllowed: 10, - }, } } From 520f93f7db12bd54c49a670ed49d193830e8a52e Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 21 Oct 2024 15:47:40 +0300 Subject: [PATCH 91/99] more fixes after review --- config/tomlConfig_test.go | 24 +++++++++---------- .../multiShard/relayedTx/common.go | 6 ++--- .../multiShard/relayedTx/relayedTx_test.go | 12 +++++----- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index e7095b0b096..39a582b1ef2 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -867,22 +867,22 @@ func TestEnableEpochConfig(t *testing.T) { UseGasBoundedShouldFailExecutionEnableEpoch = 96 # DynamicESDTEnableEpoch represents the epoch when dynamic NFT feature is enabled - DynamicESDTEnableEpoch = 96 + DynamicESDTEnableEpoch = 97 # EGLDInMultiTransferEnableEpoch represents the epoch when EGLD in MultiTransfer is enabled - EGLDInMultiTransferEnableEpoch = 97 + EGLDInMultiTransferEnableEpoch = 98 # CryptoOpcodesV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled - CryptoOpcodesV2EnableEpoch = 98 + CryptoOpcodesV2EnableEpoch = 99 # FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled - FixRelayedBaseCostEnableEpoch = 99 + FixRelayedBaseCostEnableEpoch = 100 # MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled - MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 100 + MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 101 # FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled - FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 101 + FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 102 # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ @@ -998,12 +998,12 @@ func TestEnableEpochConfig(t *testing.T) { AlwaysMergeContextsInEEIEnableEpoch: 94, CleanupAuctionOnLowWaitingListEnableEpoch: 95, UseGasBoundedShouldFailExecutionEnableEpoch: 96, - DynamicESDTEnableEpoch: 96, - EGLDInMultiTransferEnableEpoch: 97, - CryptoOpcodesV2EnableEpoch: 98, - FixRelayedBaseCostEnableEpoch: 99, - MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 100, - FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 101, + DynamicESDTEnableEpoch: 97, + EGLDInMultiTransferEnableEpoch: 98, + CryptoOpcodesV2EnableEpoch: 99, + FixRelayedBaseCostEnableEpoch: 100, + MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 101, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 102, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 54d99ff869d..a9098c6c668 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -15,16 +15,16 @@ import ( ) // CreateGeneralSetupForRelayTxTest will create the general setup for relayed transactions -func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { +func CreateGeneralSetupForRelayTxTest(baseCostFixEnabled bool) ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { initialVal := big.NewInt(10000000000) epochsConfig := integrationTests.GetDefaultEnableEpochsConfig() - if !relayedV3Test { + if !baseCostFixEnabled { epochsConfig.FixRelayedBaseCostEnableEpoch = integrationTests.UnreachableEpoch epochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch = integrationTests.UnreachableEpoch } nodes, idxProposers := createAndMintNodes(initialVal, epochsConfig) - players, relayerAccount := createAndMintPlayers(relayedV3Test, nodes, initialVal) + players, relayerAccount := createAndMintPlayers(baseCostFixEnabled, nodes, initialVal) return nodes, idxProposers, players, relayerAccount } diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index 87a54633953..41ece5b81eb 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -51,14 +51,14 @@ func TestRelayedTransactionInMultiShardEnvironmentWithAttestationContract(t *tes func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, - relayedV3Test bool, + baseCostFixEnabled bool, ) func(t *testing.T) { return func(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(baseCostFixEnabled) defer func() { for _, n := range nodes { n.Close() @@ -115,14 +115,14 @@ func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, - relayedV3Test bool, + baseCostFixEnabled bool, ) func(t *testing.T) { return func(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(baseCostFixEnabled) defer func() { for _, n := range nodes { n.Close() @@ -211,14 +211,14 @@ func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( func testRelayedTransactionInMultiShardEnvironmentWithESDTTX( createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, - relayedV3Test bool, + baseCostFixEnabled bool, ) func(t *testing.T) { return func(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(baseCostFixEnabled) defer func() { for _, n := range nodes { n.Close() From 4306c57eaa83d6b58d9c59c4d4754b3163ba9bca Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 21 Oct 2024 16:48:47 +0300 Subject: [PATCH 92/99] new version of mx-chain-comm-go --- cmd/node/config/external.toml | 2 +- go.mod | 2 +- go.sum | 4 ++-- node/chainSimulator/components/memoryComponents.go | 4 ++-- outport/factory/hostDriverFactory_test.go | 2 +- outport/factory/outportFactory_test.go | 6 +++--- testscommon/components/components.go | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/node/config/external.toml b/cmd/node/config/external.toml index 1058e0c3fb7..6fbbbb195c6 100644 --- a/cmd/node/config/external.toml +++ b/cmd/node/config/external.toml @@ -51,7 +51,7 @@ # URL for the WebSocket client/server connection # This value represents the IP address and port number that the WebSocket client or server will use to establish a connection. - URL = "127.0.0.1:22111" + URL = "ws://127.0.0.1:22111" # After a message will be sent it will wait for an ack message if this flag is enabled WithAcknowledge = true diff --git a/go.mod b/go.mod index d2b76ce9593..ef4af183e27 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.1.0 + github.com/multiversx/mx-chain-communication-go v1.1.1-0.20241021133229-d0833256e3ec github.com/multiversx/mx-chain-core-go v1.2.22 github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.7.9 diff --git a/go.sum b/go.sum index 0b789eb79b2..335ffcb2984 100644 --- a/go.sum +++ b/go.sum @@ -385,8 +385,8 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI= github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= -github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= -github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= +github.com/multiversx/mx-chain-communication-go v1.1.1-0.20241021133229-d0833256e3ec h1:KwpeVZXSHzic8DV9zaJZmaBgDNIIpSdbGz4Q+9fZyiI= +github.com/multiversx/mx-chain-communication-go v1.1.1-0.20241021133229-d0833256e3ec/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= github.com/multiversx/mx-chain-core-go v1.2.22 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pTF333gWPpd+FNk= github.com/multiversx/mx-chain-core-go v1.2.22/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= diff --git a/node/chainSimulator/components/memoryComponents.go b/node/chainSimulator/components/memoryComponents.go index 3b12e720756..639dafc753d 100644 --- a/node/chainSimulator/components/memoryComponents.go +++ b/node/chainSimulator/components/memoryComponents.go @@ -9,11 +9,11 @@ import ( // CreateMemUnit creates a new in-memory storage unit func CreateMemUnit() storage.Storer { - capacity := uint32(10) + capacity := uint32(10_000_000) shards := uint32(1) sizeInBytes := uint64(0) cache, _ := storageunit.NewCache(storageunit.CacheConfig{Type: storageunit.LRUCache, Capacity: capacity, Shards: shards, SizeInBytes: sizeInBytes}) - persist, _ := database.NewlruDB(100000) + persist, _ := database.NewlruDB(10_000_000) unit, _ := storageunit.NewStorageUnit(cache, persist) return unit diff --git a/outport/factory/hostDriverFactory_test.go b/outport/factory/hostDriverFactory_test.go index d41079c0f55..d005ea4ba74 100644 --- a/outport/factory/hostDriverFactory_test.go +++ b/outport/factory/hostDriverFactory_test.go @@ -15,7 +15,7 @@ func TestCreateHostDriver(t *testing.T) { args := ArgsHostDriverFactory{ HostConfig: config.HostDriversConfig{ - URL: "localhost", + URL: "ws://localhost", RetryDurationInSec: 1, MarshallerType: "json", Mode: data.ModeClient, diff --git a/outport/factory/outportFactory_test.go b/outport/factory/outportFactory_test.go index 93b4657427b..94d8c38839c 100644 --- a/outport/factory/outportFactory_test.go +++ b/outport/factory/outportFactory_test.go @@ -122,7 +122,7 @@ func TestCreateOutport_SubscribeMultipleHostDrivers(t *testing.T) { Marshaller: &testscommon.MarshalizerMock{}, HostConfig: config.HostDriversConfig{ Enabled: true, - URL: "localhost", + URL: "ws://localhost", RetryDurationInSec: 1, MarshallerType: "json", Mode: data.ModeClient, @@ -132,7 +132,7 @@ func TestCreateOutport_SubscribeMultipleHostDrivers(t *testing.T) { Marshaller: &testscommon.MarshalizerMock{}, HostConfig: config.HostDriversConfig{ Enabled: false, - URL: "localhost", + URL: "ws://localhost", RetryDurationInSec: 1, MarshallerType: "json", Mode: data.ModeClient, @@ -142,7 +142,7 @@ func TestCreateOutport_SubscribeMultipleHostDrivers(t *testing.T) { Marshaller: &testscommon.MarshalizerMock{}, HostConfig: config.HostDriversConfig{ Enabled: true, - URL: "localhost", + URL: "ws://localhost", RetryDurationInSec: 1, MarshallerType: "json", Mode: data.ModeClient, diff --git a/testscommon/components/components.go b/testscommon/components/components.go index 0e3dcc14cd1..55b09fe99de 100644 --- a/testscommon/components/components.go +++ b/testscommon/components/components.go @@ -687,7 +687,7 @@ func GetStatusComponentsFactoryArgsAndProcessComponents(shardCoordinator shardin { MarshallerType: "json", Mode: "client", - URL: "localhost:12345", + URL: "ws://localhost:12345", RetryDurationInSec: 1, }, }, From 5897fbc85dc57227b1b3ebd714d810ad577de881 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 22 Oct 2024 12:12:16 +0300 Subject: [PATCH 93/99] fix for workflow --- .../build_and_run_chain_simulator_and_execute_system_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index f766ccddbf5..8cf5c879345 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -164,7 +164,7 @@ jobs: - name: Run tests and generate HTML report run: | set +e - pytest mx-chain-testing-suite/scenarios/ --html=report.html --self-contained-html --continue-on-collection-errors + pytest --html=report.html --self-contained-html --continue-on-collection-errors PYTEST_EXIT_CODE=$? set -e echo "PYTEST_EXIT_CODE=$PYTEST_EXIT_CODE" >> $GITHUB_ENV From 0b88dd59484f856aac69f3b37d6efb677958540f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 22 Oct 2024 13:19:09 +0300 Subject: [PATCH 94/99] reverted last commit --- .../build_and_run_chain_simulator_and_execute_system_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index 8cf5c879345..f766ccddbf5 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -164,7 +164,7 @@ jobs: - name: Run tests and generate HTML report run: | set +e - pytest --html=report.html --self-contained-html --continue-on-collection-errors + pytest mx-chain-testing-suite/scenarios/ --html=report.html --self-contained-html --continue-on-collection-errors PYTEST_EXIT_CODE=$? set -e echo "PYTEST_EXIT_CODE=$PYTEST_EXIT_CODE" >> $GITHUB_ENV From f8f6b35b3a0c04ad10f835baf0c0f27480953867 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 23 Oct 2024 21:57:41 +0300 Subject: [PATCH 95/99] fix gasUsed and fee for relayed v1 and v2 --- .../transactionAPI/apiTransactionProcessor.go | 2 +- .../transactionAPI/gasUsedAndFeeProcessor.go | 80 ++++++--- .../gasUsedAndFeeProcessor_test.go | 48 ++++++ .../relayedV1CreateNewDelegationContract.json | 158 ++++++++++++++++++ .../transactionsFeeProcessor.go | 46 +++-- 5 files changed, 295 insertions(+), 39 deletions(-) create mode 100644 node/external/transactionAPI/testData/relayedV1CreateNewDelegationContract.json diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index c4e75bc29b9..c67ad1cb445 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -201,7 +201,7 @@ func (atp *apiTransactionProcessor) populateComputedFieldInitiallyPaidFee(tx *tr isFeeFixActive := atp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) isRelayedAfterFix := tx.IsRelayed && isFeeFixActive if isRelayedAfterFix { - fee, _ = atp.gasUsedAndFeeProcessor.getFeeOfRelayed(tx) + _, fee, _ = atp.gasUsedAndFeeProcessor.getFeeOfRelayed(tx) tx.InitiallyPaidFee = fee.String() } } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index bc01297ef85..06c2c7d3bfc 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -4,6 +4,7 @@ import ( "math/big" "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/common" @@ -49,7 +50,7 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = tx.InitiallyPaidFee } - initialTotalFee, isRelayed := gfp.getFeeOfRelayed(tx) + userTx, initialTotalFee, isRelayed := gfp.getFeeOfRelayed(tx) isRelayedAfterFix := isRelayed && isFeeFixActive if isRelayedAfterFix { tx.InitiallyPaidFee = initialTotalFee.String() @@ -63,26 +64,26 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction continue } - gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value) + gfp.setGasUsedAndFeeBaseOnRefundValue(tx, userTx, scr.Value) hasRefundForSender = true break } - gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) + gfp.prepareTxWithResultsBasedOnLogs(tx, userTx, hasRefundForSender) } -func (gfp *gasUsedAndFeeProcessor) getFeeOfRelayed(tx *transaction.ApiTransactionResult) (*big.Int, bool) { +func (gfp *gasUsedAndFeeProcessor) getFeeOfRelayed(tx *transaction.ApiTransactionResult) (*transaction.ApiTransactionResult, *big.Int, bool) { if !tx.IsRelayed { - return nil, false + return nil, nil, false } if len(tx.Data) == 0 { - return nil, false + return nil, nil, false } funcName, args, err := gfp.argsParser.ParseCallData(string(tx.Data)) if err != nil { - return nil, false + return nil, nil, false } if funcName == core.RelayedTransaction { @@ -93,32 +94,33 @@ func (gfp *gasUsedAndFeeProcessor) getFeeOfRelayed(tx *transaction.ApiTransactio return gfp.handleRelayedV2(args, tx) } - return nil, false + return nil, nil, false } -func (gfp *gasUsedAndFeeProcessor) handleRelayedV1(args [][]byte, tx *transaction.ApiTransactionResult) (*big.Int, bool) { +func (gfp *gasUsedAndFeeProcessor) handleRelayedV1(args [][]byte, tx *transaction.ApiTransactionResult) (*transaction.ApiTransactionResult, *big.Int, bool) { if len(args) != 1 { - return nil, false + return nil, nil, false } innerTx := &transaction.Transaction{} err := gfp.marshaller.Unmarshal(innerTx, args[0]) if err != nil { - return nil, false + return nil, nil, false } gasUsed := gfp.feeComputer.ComputeGasLimit(tx) fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) - innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ + innerTxApiResult := &transaction.ApiTransactionResult{ Tx: innerTx, Epoch: tx.Epoch, - }) + } + innerFee := gfp.feeComputer.ComputeTransactionFee(innerTxApiResult) - return big.NewInt(0).Add(fee, innerFee), true + return innerTxApiResult, big.NewInt(0).Add(fee, innerFee), true } -func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transaction.ApiTransactionResult) (*big.Int, bool) { +func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transaction.ApiTransactionResult) (*transaction.ApiTransactionResult, *big.Int, bool) { innerTx := &transaction.Transaction{} innerTx.RcvAddr = args[0] innerTx.Nonce = big.NewInt(0).SetBytes(args[1]).Uint64() @@ -132,16 +134,18 @@ func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transactio gasUsed := gfp.feeComputer.ComputeGasLimit(tx) fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) - innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ + innerTxApiResult := &transaction.ApiTransactionResult{ Tx: innerTx, Epoch: tx.Epoch, - }) + } + innerFee := gfp.feeComputer.ComputeTransactionFee(innerTxApiResult) - return big.NewInt(0).Add(fee, innerFee), true + return innerTxApiResult, big.NewInt(0).Add(fee, innerFee), true } func (gfp *gasUsedAndFeeProcessor) prepareTxWithResultsBasedOnLogs( tx *transaction.ApiTransactionResult, + userTx *transaction.ApiTransactionResult, hasRefund bool, ) { if tx.Logs == nil || (tx.Function == "" && tx.Operation == datafield.OperationTransfer) { @@ -149,15 +153,26 @@ func (gfp *gasUsedAndFeeProcessor) prepareTxWithResultsBasedOnLogs( } for _, event := range tx.Logs.Events { - gfp.setGasUsedAndFeeBaseOnLogEvent(tx, hasRefund, event) + gfp.setGasUsedAndFeeBaseOnLogEvent(tx, userTx, hasRefund, event) } } -func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transaction.ApiTransactionResult, hasRefund bool, event *transaction.Events) { +func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transaction.ApiTransactionResult, userTx *transaction.ApiTransactionResult, hasRefund bool, event *transaction.Events) { if core.WriteLogIdentifier == event.Identifier && !hasRefund { - gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, big.NewInt(0)) - tx.GasUsed = gasUsed - tx.Fee = fee.String() + if !check.IfNilReflect(userTx) && gfp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) { + gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, big.NewInt(0)) + gasUsedRelayedTx := gfp.feeComputer.ComputeGasLimit(tx) + feeRelayedTx := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) + + tx.GasUsed = gasUsed + gasUsedRelayedTx + + fee.Add(fee, feeRelayedTx) + tx.Fee = fee.String() + } else { + gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, big.NewInt(0)) + tx.GasUsed = gasUsed + tx.Fee = fee.String() + } } if core.SignalErrorOperation == event.Identifier { fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, tx.GasLimit) @@ -166,14 +181,29 @@ func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transactio } } -func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnRefundValue(tx *transaction.ApiTransactionResult, refund *big.Int) { +func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnRefundValue( + tx *transaction.ApiTransactionResult, + userTx *transaction.ApiTransactionResult, + refund *big.Int, +) { + if !check.IfNilReflect(userTx) && gfp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) { + gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, refund) + gasUsedRelayedTx := gfp.feeComputer.ComputeGasLimit(tx) + feeRelayedTx := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) + + tx.GasUsed = gasUsed + gasUsedRelayedTx + + fee.Add(fee, feeRelayedTx) + tx.Fee = fee.String() + + return + } gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, refund) tx.GasUsed = gasUsed tx.Fee = fee.String() - } func (gfp *gasUsedAndFeeProcessor) isESDTOperationWithSCCall(tx *transaction.ApiTransactionResult) bool { diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index c6abd9278d6..8c5c80826c0 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -346,3 +346,51 @@ func TestComputeAndAttachGasUsedAndFeeFailedRelayedV1(t *testing.T) { require.Equal(t, "1198000000000000", txWithSRefundSCR.Fee) require.Equal(t, "1274230000000000", txWithSRefundSCR.InitiallyPaidFee) } + +func TestComputeAndAttachGasUsedAndFeeRelayedV1CreateNewDelegationContractWithRefund(t *testing.T) { + t.Parallel() + + enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || + flag == common.PenalizedTooMuchGasFlag || + flag == common.FixRelayedBaseCostFlag + }, + } + feeComp, _ := fee.NewFeeComputer(createEconomicsData(enableEpochsHandler)) + computer := fee.NewTestFeeComputer(feeComp) + + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + pubKeyConverter, + smartContract.NewArgumentParser(), + &marshal.JsonMarshalizer{}, + enableEpochsHandler, + ) + + txWithSRefundSCR := &transaction.ApiTransactionResult{} + err := core.LoadJsonFile(txWithSRefundSCR, "testData/relayedV1CreateNewDelegationContract.json") + require.NoError(t, err) + + snd, _ := pubKeyConverter.Decode(txWithSRefundSCR.Sender) + rcv, _ := pubKeyConverter.Decode(txWithSRefundSCR.Receiver) + val, _ := big.NewInt(0).SetString(txWithSRefundSCR.Value, 10) + txWithSRefundSCR.Tx = &transaction.Transaction{ + Nonce: txWithSRefundSCR.Nonce, + Value: val, + RcvAddr: rcv, + SndAddr: snd, + GasPrice: txWithSRefundSCR.GasPrice, + GasLimit: txWithSRefundSCR.GasLimit, + Data: txWithSRefundSCR.Data, + } + + txWithSRefundSCR.InitiallyPaidFee = "" + txWithSRefundSCR.Fee = "" + txWithSRefundSCR.GasUsed = 0 + + gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) + require.Equal(t, uint64(56328500), txWithSRefundSCR.GasUsed) + require.Equal(t, "1878500000000000", txWithSRefundSCR.Fee) + require.Equal(t, "2177505000000000", txWithSRefundSCR.InitiallyPaidFee) +} diff --git a/node/external/transactionAPI/testData/relayedV1CreateNewDelegationContract.json b/node/external/transactionAPI/testData/relayedV1CreateNewDelegationContract.json new file mode 100644 index 00000000000..a15e3c533ae --- /dev/null +++ b/node/external/transactionAPI/testData/relayedV1CreateNewDelegationContract.json @@ -0,0 +1,158 @@ +{ + "type": "normal", + "processingTypeOnSource": "RelayedTx", + "processingTypeOnDestination": "RelayedTx", + "hash": "94cb3bd3e2dca9920115f05549c9eee4dfc1d33e4ac3edd0741eb51165148b52", + "nonce": 0, + "round": 7, + "epoch": 1, + "value": "0", + "receiver": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "sender": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "gasPrice": 1000000000, + "gasLimit": 86229000, + "data": "cmVsYXllZFR4QDdiMjI2ZTZmNmU2MzY1MjIzYTMwMmMyMjczNjU2ZTY0NjU3MjIyM2EyMjY3NjM2ZjM5MzYzMjdhNTI2OTU5NTg0NTM0MzQ3MzQyMzE3Mzc2NTY0ODczNDg0YTM5MzM2NDc4NDI2NTc3NjU3NjY0NjM0Yjc1MmI1Nzc5NTUzNzZiM2QyMjJjMjI3MjY1NjM2NTY5NzY2NTcyMjIzYTIyNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE1MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDUyZjJmMzgzZDIyMmMyMjc2NjE2Yzc1NjUyMjNhMzIzNTMwMzEzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAyYzIyNjc2MTczNTA3MjY5NjM2NTIyM2EzMTMwMzAzMDMwMzAzMDMwMzAzMDJjMjI2NzYxNzM0YzY5NmQ2OTc0MjIzYTM4MzUzMDMwMzAzMDMwMzAyYzIyNjQ2MTc0NjEyMjNhMjI1OTMzNGE2YzU5NTg1MjZjNTQ2ZDU2MzM1MjQ3NTY3MzVhNTc2NDY4NjQ0NzZjNzY2MjZiNGU3NjYyNmU1Mjc5NTk1NzRlMzA1MTQ0NDE3NzUxNDQ0MTc3MjIyYzIyNzM2OTY3NmU2MTc0NzU3MjY1MjIzYTIyNTk1MTUzNTQ0MjMwMzE0ZjUwNGY0NDU5MzM0ZDU2NDQ1NDRkNWE3NzRkNzY2NjZiNzI1MDUwMzk2ZTM1NjQ1MzU4NjI3MDQ5NWE2MjcwNDM1MTQ5MzMzNDRkNTY2NzZiNzYzMzc0Njk2MTRmNGMzNjQ0NWE2NjM4NTU2NTJmNjg2Zjc5MzkzNTRiNGI2NTVhNDI2YjcwNzAzMTU1NzY3NzU5MzY0NzU3NDI3NzNkM2QyMjJjMjI2MzY4NjE2OTZlNDk0NDIyM2EyMjU5MzI2ODY4NjE1NzM0M2QyMjJjMjI3NjY1NzI3MzY5NmY2ZTIyM2EzMjdk", + "signature": "bf5d14d237b951d23247e99113fa15566ebbd0dccd215b743ae9629f226ab3f9ba333622567c5606e2ed06104df52f81f05fad2488be9cb50a83e1356e0d070e", + "sourceShard": 1, + "destinationShard": 1, + "blockNonce": 7, + "blockHash": "5f2a597d07b4b5ae84195178eb6f83493bb1230c7f316b40a0d9b6efbe1a4da5", + "notarizedAtSourceInMetaNonce": 9, + "NotarizedAtSourceInMetaHash": "34cd7dc91fc9773ddd2e09d900087b96cfecf6280a6dc25a1894c2db161cded1", + "notarizedAtDestinationInMetaNonce": 9, + "notarizedAtDestinationInMetaHash": "34cd7dc91fc9773ddd2e09d900087b96cfecf6280a6dc25a1894c2db161cded1", + "miniblockType": "TxBlock", + "miniblockHash": "03ef037eb1fd03f89a9b5ece12aa422223b440cb1fd02c4a6b82d65268121d28", + "hyperblockNonce": 9, + "hyperblockHash": "34cd7dc91fc9773ddd2e09d900087b96cfecf6280a6dc25a1894c2db161cded1", + "timestamp": 1729691671, + "smartContractResults": [ + { + "hash": "6e71137c75ad162d97ce45502d38f0af96362c06f03378f03a4e50bec6ce31ea", + "nonce": 1, + "value": 299005000000000, + "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "sender": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "prevTxHash": "c825db2f9e6d17e41ed12e1aac86eecd7a828eeea0caf63a6e6a979f02a74f70", + "originalTxHash": "94cb3bd3e2dca9920115f05549c9eee4dfc1d33e4ac3edd0741eb51165148b52", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "returnMessage": "gas refund for relayer", + "logs": { + "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "events": [ + { + "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "identifier": "completedTxEvent", + "topics": [ + "yCXbL55tF+Qe0S4arIbuzXqCju6gyvY6bmqXnwKnT3A=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer", + "isRefund": true + }, + { + "hash": "c825db2f9e6d17e41ed12e1aac86eecd7a828eeea0caf63a6e6a979f02a74f70", + "nonce": 0, + "value": 2501000000000000000000, + "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "relayerAddress": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "relayedValue": 0, + "data": "createNewDelegationContract@00@00", + "prevTxHash": "94cb3bd3e2dca9920115f05549c9eee4dfc1d33e4ac3edd0741eb51165148b52", + "originalTxHash": "94cb3bd3e2dca9920115f05549c9eee4dfc1d33e4ac3edd0741eb51165148b52", + "gasLimit": 84900500, + "gasPrice": 1000000000, + "callType": 0, + "logs": { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "identifier": "transferValueOnly", + "topics": [ + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" + ], + "data": "RGVwbG95U21hcnRDb250cmFjdA==", + "additionalData": [ + "RGVwbG95U21hcnRDb250cmFjdA==", + "X2luaXQ=", + "AA==", + "AA==" + ] + }, + { + "address": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "identifier": "delegate", + "topics": [ + "h5RY6SJT9AAA", + "h5RY6SJT9AAA", + "AQ==", + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" + ], + "data": null, + "additionalData": null + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", + "identifier": "transferValueOnly", + "topics": [ + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAB//8=" + ], + "data": "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", + "additionalData": [ + "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", + "c3Rha2U=" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", + "identifier": "SCDeploy", + "topics": [ + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=", + "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=", + "/uYNe6O98aIOSpF57HocNxS4JQ7FILx6+N7MEN3oAQY=" + ], + "data": null, + "additionalData": null + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "identifier": "writeLog", + "topics": [ + "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=" + ], + "data": "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==", + "additionalData": [ + "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==" + ] + } + ] + }, + "operation": "transfer", + "function": "createNewDelegationContract" + } + ], + "status": "success", + "receivers": [ + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6" + ], + "receiversShardIDs": [ + 4294967295 + ], + "operation": "transfer", + "function": "createNewDelegationContract", + "isRelayed": true, + "chainID": "chain", + "version": 2, + "options": 0 +} diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index e0d56acbde3..ae59d6454d7 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -6,6 +6,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-core-go/data" outportcore "github.com/multiversx/mx-chain-core-go/data/outport" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" @@ -135,7 +136,7 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans feeInfo.SetFee(initialPaidFee) } - totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) + userTx, totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) isRelayedAfterFix := isRelayed && isFeeFixActive if isRelayedAfterFix { feeInfo.SetFee(totalFee) @@ -144,11 +145,16 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans } - tep.prepareTxWithResults(txHashHex, txWithResult, isRelayedAfterFix) + tep.prepareTxWithResults(txHashHex, txWithResult, userTx, epoch) } } -func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults, isRelayedAfterFix bool) { +func (tep *transactionsFeeProcessor) prepareTxWithResults( + txHashHex string, + txWithResults *transactionWithResults, + userTx data.TransactionHandler, + epoch uint32, +) { hasRefund := false for _, scrHandler := range txWithResults.scrs { scr, ok := scrHandler.GetTxHandler().(*smartContractResult.SmartContractResult) @@ -157,6 +163,20 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi } if isSCRForSenderWithRefund(scr, txHashHex, txWithResults.GetTxHandler()) || isRefundForRelayed(scr, txWithResults.GetTxHandler()) { + if !check.IfNilReflect(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, scr.Value) + + tx := txWithResults.GetTxHandler() + gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) + feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) + + txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) + txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) + hasRefund = true + + break + } + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), scr.Value) txWithResults.GetFeeInfo().SetGasUsed(gasUsed) @@ -169,14 +189,14 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) } -func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) (*big.Int, bool) { +func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) (data.TransactionHandler, *big.Int, bool) { if len(tx.GetTxHandler().GetData()) == 0 { - return nil, false + return nil, nil, false } funcName, args, err := tep.argsParser.ParseCallData(string(tx.GetTxHandler().GetData())) if err != nil { - return nil, false + return nil, nil, false } if funcName == core.RelayedTransaction { @@ -187,18 +207,18 @@ func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) return tep.handleRelayedV2(args, tx) } - return nil, false + return nil, nil, false } -func (tep *transactionsFeeProcessor) handleRelayedV1(args [][]byte, tx *transactionWithResults) (*big.Int, bool) { +func (tep *transactionsFeeProcessor) handleRelayedV1(args [][]byte, tx *transactionWithResults) (data.TransactionHandler, *big.Int, bool) { if len(args) != 1 { - return nil, false + return nil, nil, false } innerTx := &transaction.Transaction{} err := tep.marshaller.Unmarshal(innerTx, args[0]) if err != nil { - return nil, false + return nil, nil, false } txHandler := tx.GetTxHandler() @@ -207,10 +227,10 @@ func (tep *transactionsFeeProcessor) handleRelayedV1(args [][]byte, tx *transact innerFee := tep.txFeeCalculator.ComputeTxFee(innerTx) - return big.NewInt(0).Add(fee, innerFee), true + return innerTx, big.NewInt(0).Add(fee, innerFee), true } -func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transactionWithResults) (*big.Int, bool) { +func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transactionWithResults) (data.TransactionHandler, *big.Int, bool) { txHandler := tx.GetTxHandler() innerTx := &transaction.Transaction{} @@ -228,7 +248,7 @@ func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transact innerFee := tep.txFeeCalculator.ComputeTxFee(innerTx) - return big.NewInt(0).Add(fee, innerFee), true + return innerTx, big.NewInt(0).Add(fee, innerFee), true } func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( From 79e9f2cc236d69ff789cd7a39b28829d9460b696 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 24 Oct 2024 09:06:06 +0300 Subject: [PATCH 96/99] fixed also prepareTxWithResultsBasedOnLogs --- .../transactionsfee/transactionsFeeProcessor.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index ae59d6454d7..f1d60d0034d 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -186,7 +186,7 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults( } } - tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) + tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, userTx, hasRefund, epoch) } func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) (data.TransactionHandler, *big.Int, bool) { @@ -254,7 +254,9 @@ func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transact func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( txHashHex string, txWithResults *transactionWithResults, + userTx data.TransactionHandler, hasRefund bool, + epoch uint32, ) { tx := txWithResults.GetTxHandler() if check.IfNil(tx) { @@ -269,6 +271,19 @@ func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( for _, event := range txWithResults.log.GetLogEvents() { if core.WriteLogIdentifier == string(event.GetIdentifier()) && !hasRefund { + if !check.IfNilReflect(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, big.NewInt(0)) + + gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) + feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) + + txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) + txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) + hasRefund = true + + break + } + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), big.NewInt(0)) txWithResults.GetFeeInfo().SetGasUsed(gasUsed) txWithResults.GetFeeInfo().SetFee(fee) From 158ca36cdc80fe47ead80ec41663c2a0b362ea1b Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 24 Oct 2024 10:02:14 +0300 Subject: [PATCH 97/99] fixes after review --- .../transactionsFeeProcessor.go | 62 +++++++++++++++++-- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index f1d60d0034d..d94b83694bb 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -163,7 +163,7 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults( } if isSCRForSenderWithRefund(scr, txHashHex, txWithResults.GetTxHandler()) || isRefundForRelayed(scr, txWithResults.GetTxHandler()) { - if !check.IfNilReflect(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { + if !check.IfNil(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, scr.Value) tx := txWithResults.GetTxHandler() @@ -271,7 +271,7 @@ func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( for _, event := range txWithResults.log.GetLogEvents() { if core.WriteLogIdentifier == string(event.GetIdentifier()) && !hasRefund { - if !check.IfNilReflect(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { + if !check.IfNil(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, big.NewInt(0)) gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) @@ -326,10 +326,62 @@ func (tep *transactionsFeeProcessor) prepareScrsNoTx(transactionsAndScrs *transa continue } - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txFromStorage, scr.Value) + userTx := tep.getUserTxOfRelayed(txFromStorage) + if check.IfNil(userTx) { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txFromStorage, scr.Value) - scrHandler.GetFeeInfo().SetGasUsed(gasUsed) - scrHandler.GetFeeInfo().SetFee(fee) + scrHandler.GetFeeInfo().SetGasUsed(gasUsed) + scrHandler.GetFeeInfo().SetFee(fee) + } else { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, scr.Value) + + gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(txFromStorage) + feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(txFromStorage, gasUsedRelayedTx) + + scrHandler.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) + scrHandler.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) + } + } + + return nil +} + +func (tep *transactionsFeeProcessor) getUserTxOfRelayed(tx data.TransactionHandler) data.TransactionHandler { + if len(tx.GetData()) == 0 { + return nil + } + + funcName, args, err := tep.argsParser.ParseCallData(string(tx.GetData())) + if err != nil { + return nil + } + + if funcName == core.RelayedTransaction { + if len(args) != 1 { + return nil + } + + userTx := &transaction.Transaction{} + err := tep.marshaller.Unmarshal(userTx, args[0]) + if err != nil { + return nil + } + + return userTx + } + + if funcName == core.RelayedTransactionV2 { + userTx := &transaction.Transaction{} + userTx.RcvAddr = args[0] + userTx.Nonce = big.NewInt(0).SetBytes(args[1]).Uint64() + userTx.Data = args[2] + userTx.Signature = args[3] + userTx.Value = big.NewInt(0) + userTx.GasPrice = tx.GetGasPrice() + userTx.GasLimit = tx.GetGasLimit() - tep.txFeeCalculator.ComputeGasLimit(tx) + userTx.SndAddr = tx.GetRcvAddr() + + return userTx } return nil From 6f7ae0b36182ac3177b5e4fe1d8ba89178fb96ed Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 24 Oct 2024 11:53:56 +0300 Subject: [PATCH 98/99] fix linter --- outport/process/transactionsfee/transactionsFeeProcessor.go | 1 - 1 file changed, 1 deletion(-) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index d94b83694bb..f66ffd3f9cf 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -279,7 +279,6 @@ func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) - hasRefund = true break } From 895c6b2922bdfa8b18ed62903d75807bb76064a3 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 24 Oct 2024 15:40:57 +0300 Subject: [PATCH 99/99] fixes after review, removed duplicated code --- .../transactionAPI/gasUsedAndFeeProcessor.go | 15 +---- .../transactionsFeeProcessor.go | 59 ++++++++----------- 2 files changed, 26 insertions(+), 48 deletions(-) diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 06c2c7d3bfc..c4cd9578394 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -159,20 +159,7 @@ func (gfp *gasUsedAndFeeProcessor) prepareTxWithResultsBasedOnLogs( func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transaction.ApiTransactionResult, userTx *transaction.ApiTransactionResult, hasRefund bool, event *transaction.Events) { if core.WriteLogIdentifier == event.Identifier && !hasRefund { - if !check.IfNilReflect(userTx) && gfp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) { - gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, big.NewInt(0)) - gasUsedRelayedTx := gfp.feeComputer.ComputeGasLimit(tx) - feeRelayedTx := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) - - tx.GasUsed = gasUsed + gasUsedRelayedTx - - fee.Add(fee, feeRelayedTx) - tx.Fee = fee.String() - } else { - gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, big.NewInt(0)) - tx.GasUsed = gasUsed - tx.Fee = fee.String() - } + gfp.setGasUsedAndFeeBaseOnRefundValue(tx, userTx, big.NewInt(0)) } if core.SignalErrorOperation == event.Identifier { fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, tx.GasLimit) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index f66ffd3f9cf..30bcf0fca76 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -163,24 +163,7 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults( } if isSCRForSenderWithRefund(scr, txHashHex, txWithResults.GetTxHandler()) || isRefundForRelayed(scr, txWithResults.GetTxHandler()) { - if !check.IfNil(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, scr.Value) - - tx := txWithResults.GetTxHandler() - gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) - feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) - - txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) - txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) - hasRefund = true - - break - } - - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), scr.Value) - - txWithResults.GetFeeInfo().SetGasUsed(gasUsed) - txWithResults.GetFeeInfo().SetFee(fee) + tep.setGasUsedAndFeeBasedOnRefundValue(txWithResults, userTx, scr.Value, epoch) hasRefund = true break } @@ -271,22 +254,7 @@ func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( for _, event := range txWithResults.log.GetLogEvents() { if core.WriteLogIdentifier == string(event.GetIdentifier()) && !hasRefund { - if !check.IfNil(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, big.NewInt(0)) - - gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) - feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) - - txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) - txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) - - break - } - - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), big.NewInt(0)) - txWithResults.GetFeeInfo().SetGasUsed(gasUsed) - txWithResults.GetFeeInfo().SetFee(fee) - + tep.setGasUsedAndFeeBasedOnRefundValue(txWithResults, userTx, big.NewInt(0), epoch) continue } if core.SignalErrorOperation == string(event.GetIdentifier()) { @@ -295,7 +263,30 @@ func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( txWithResults.GetFeeInfo().SetFee(fee) } } +} + +func (tep *transactionsFeeProcessor) setGasUsedAndFeeBasedOnRefundValue( + txWithResults *transactionWithResults, + userTx data.TransactionHandler, + refund *big.Int, + epoch uint32, +) { + if !check.IfNil(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, refund) + + tx := txWithResults.GetTxHandler() + gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) + feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) + + txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) + txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) + + return + } + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), refund) + txWithResults.GetFeeInfo().SetGasUsed(gasUsed) + txWithResults.GetFeeInfo().SetFee(fee) } func (tep *transactionsFeeProcessor) prepareScrsNoTx(transactionsAndScrs *transactionsAndScrsHolder) error {