From baa62660721f22eb67ce9f9904df7a119be823d7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 26 Jul 2024 15:39:09 +0300 Subject: [PATCH 1/8] 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 f289f70a2703b3dffd0602efa2c6bfedec7eb14a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 11:33:27 +0300 Subject: [PATCH 2/8] 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 970a776943e38cf64c17aa06ec9b69f49f2022d0 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 17:40:26 +0300 Subject: [PATCH 3/8] 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 42bf1a3142d5f8d9174b7c78a6023077366ada57 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 12 Aug 2024 15:11:18 +0300 Subject: [PATCH 4/8] 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 a7a39d34e5049dd98be4d2d85e70977d3641c11e Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 13 Aug 2024 12:11:06 +0300 Subject: [PATCH 5/8] 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 d7e5ef83299b73654c135e76bfbd9609304be32d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 13 Aug 2024 19:59:03 +0300 Subject: [PATCH 6/8] 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 7/8] 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 6cec9edf3d3e7380c2f41eb39f6ece5ae9981459 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 19 Aug 2024 09:52:26 +0300 Subject: [PATCH 8/8] 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)