From 3da9818b6d2c72137a85c2c904f298b384e14d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 9 Jan 2025 16:50:35 +0200 Subject: [PATCH] Handle "extraGasLimitRelayedTxV3". --- cmd/rosetta/cli.go | 9 +++++++ cmd/rosetta/main.go | 1 + server/factory/provider.go | 2 ++ server/provider/networkProvider.go | 26 ++++++++++++------- server/provider/networkProvider_test.go | 7 +++-- server/resources/network.go | 19 +++++++------- .../services/transactionsFeaturesDetector.go | 2 +- testscommon/networkProviderMock.go | 25 +++++++++++------- 8 files changed, 61 insertions(+), 30 deletions(-) diff --git a/cmd/rosetta/cli.go b/cmd/rosetta/cli.go index 135627e5..e58a555f 100644 --- a/cmd/rosetta/cli.go +++ b/cmd/rosetta/cli.go @@ -120,6 +120,12 @@ VERSION: Value: 50000, } + cliFlagExtraGasLimitRelayedTxV3 = cli.UintFlag{ + Name: "extra-gas-limit-relayed-tx-v3", + Usage: "Specifies the extra gas limit for relayed transactions (necessary to compute fees in some circumstances).", + Value: 50000, + } + cliFlagGasPerDataByte = cli.UintFlag{ Name: "gas-per-data-byte", Usage: "Specifies the gas required per data byte (for transaction construction).", @@ -205,6 +211,7 @@ func getAllCliFlags() []cli.Flag { cliFlagMinGasPrice, cliFlagMinGasLimit, cliFlagExtraGasLimitGuardedTx, + cliFlagExtraGasLimitRelayedTxV3, cliFlagGasPerDataByte, cliFlagGasPriceModifier, cliFlagGasLimitCustomTransfer, @@ -237,6 +244,7 @@ type parsedCliFlags struct { minGasPrice uint64 minGasLimit uint64 extraGasLimitGuardedTx uint64 + extraGasLimitRelayedTxV3 uint64 gasPerDataByte uint64 gasPriceModifier float64 gasLimitCustomTransfer uint64 @@ -269,6 +277,7 @@ func getParsedCliFlags(ctx *cli.Context) parsedCliFlags { minGasPrice: ctx.GlobalUint64(cliFlagMinGasPrice.Name), minGasLimit: ctx.GlobalUint64(cliFlagMinGasLimit.Name), extraGasLimitGuardedTx: ctx.GlobalUint64(cliFlagExtraGasLimitGuardedTx.Name), + extraGasLimitRelayedTxV3: ctx.GlobalUint64(cliFlagExtraGasLimitRelayedTxV3.Name), gasPerDataByte: ctx.GlobalUint64(cliFlagGasPerDataByte.Name), gasPriceModifier: ctx.GlobalFloat64(cliFlagGasPriceModifier.Name), gasLimitCustomTransfer: ctx.GlobalUint64(cliFlagGasLimitCustomTransfer.Name), diff --git a/cmd/rosetta/main.go b/cmd/rosetta/main.go index dbf0ad49..bb65fa6a 100644 --- a/cmd/rosetta/main.go +++ b/cmd/rosetta/main.go @@ -76,6 +76,7 @@ func startRosetta(ctx *cli.Context) error { MinGasPrice: cliFlags.minGasPrice, MinGasLimit: cliFlags.minGasLimit, ExtraGasLimitGuardedTx: cliFlags.extraGasLimitGuardedTx, + ExtraGasLimitRelayedTxV3: cliFlags.extraGasLimitRelayedTxV3, NativeCurrencySymbol: cliFlags.nativeCurrencySymbol, CustomCurrencies: customCurrencies, GenesisBlockHash: cliFlags.genesisBlock, diff --git a/server/factory/provider.go b/server/factory/provider.go index c982958e..beaf4bfb 100644 --- a/server/factory/provider.go +++ b/server/factory/provider.go @@ -42,6 +42,7 @@ type ArgsCreateNetworkProvider struct { MinGasPrice uint64 MinGasLimit uint64 ExtraGasLimitGuardedTx uint64 + ExtraGasLimitRelayedTxV3 uint64 NativeCurrencySymbol string CustomCurrencies []resources.Currency GenesisBlockHash string @@ -139,6 +140,7 @@ func CreateNetworkProvider(args ArgsCreateNetworkProvider) (NetworkProvider, err MinGasPrice: args.MinGasPrice, MinGasLimit: args.MinGasLimit, ExtraGasLimitGuardedTx: args.ExtraGasLimitGuardedTx, + ExtraGasLimitRelayedTxV3: args.ExtraGasLimitRelayedTxV3, NativeCurrencySymbol: args.NativeCurrencySymbol, CustomCurrencies: args.CustomCurrencies, GenesisBlockHash: args.GenesisBlockHash, diff --git a/server/provider/networkProvider.go b/server/provider/networkProvider.go index 9cf07987..b7762f77 100644 --- a/server/provider/networkProvider.go +++ b/server/provider/networkProvider.go @@ -35,6 +35,7 @@ type ArgsNewNetworkProvider struct { MinGasPrice uint64 MinGasLimit uint64 ExtraGasLimitGuardedTx uint64 + ExtraGasLimitRelayedTxV3 uint64 NativeCurrencySymbol string CustomCurrencies []resources.Currency GenesisBlockHash string @@ -118,15 +119,16 @@ func NewNetworkProvider(args ArgsNewNetworkProvider) (*networkProvider, error) { pubKeyConverter: args.PubKeyConverter, networkConfig: &resources.NetworkConfig{ - BlockchainName: args.BlockchainName, - NetworkID: args.NetworkID, - NetworkName: args.NetworkName, - GasPerDataByte: args.GasPerDataByte, - GasPriceModifier: args.GasPriceModifier, - GasLimitCustomTransfer: args.GasLimitCustomTransfer, - MinGasPrice: args.MinGasPrice, - MinGasLimit: args.MinGasLimit, - ExtraGasLimitGuardedTx: args.ExtraGasLimitGuardedTx, + BlockchainName: args.BlockchainName, + NetworkID: args.NetworkID, + NetworkName: args.NetworkName, + GasPerDataByte: args.GasPerDataByte, + GasPriceModifier: args.GasPriceModifier, + GasLimitCustomTransfer: args.GasLimitCustomTransfer, + MinGasPrice: args.MinGasPrice, + MinGasLimit: args.MinGasLimit, + ExtraGasLimitGuardedTx: args.ExtraGasLimitGuardedTx, + ExtraGasLimitRelayedTxV3: args.ExtraGasLimitRelayedTxV3, }, blocksCache: blocksCache, @@ -456,6 +458,7 @@ func (provider *networkProvider) GetMempoolTransactionByHash(hash string) (*tran func (provider *networkProvider) ComputeTransactionFeeForMoveBalance(tx *transaction.ApiTransactionResult) *big.Int { minGasLimit := provider.networkConfig.MinGasLimit extraGasLimitGuardedTx := provider.networkConfig.ExtraGasLimitGuardedTx + extraGasLimitRelayedTxV3 := provider.networkConfig.ExtraGasLimitRelayedTxV3 gasPerDataByte := provider.networkConfig.GasPerDataByte gasLimit := minGasLimit + gasPerDataByte*uint64(len(tx.Data)) @@ -464,6 +467,11 @@ func (provider *networkProvider) ComputeTransactionFeeForMoveBalance(tx *transac gasLimit += extraGasLimitGuardedTx } + isRelayedV3 := len(tx.RelayerAddress) > 0 + if isRelayedV3 { + gasLimit += extraGasLimitRelayedTxV3 + } + fee := core.SafeMul(gasLimit, tx.GasPrice) return fee } diff --git a/server/provider/networkProvider_test.go b/server/provider/networkProvider_test.go index 9f38e4bc..87728580 100644 --- a/server/provider/networkProvider_test.go +++ b/server/provider/networkProvider_test.go @@ -29,7 +29,8 @@ func TestNewNetworkProvider(t *testing.T) { GasLimitCustomTransfer: 200000, MinGasPrice: 1000000001, MinGasLimit: 50001, - ExtraGasLimitGuardedTx: 50001, + ExtraGasLimitGuardedTx: 50002, + ExtraGasLimitRelayedTxV3: 50003, NativeCurrencySymbol: "XeGLD", CustomCurrencies: []resources.Currency{ {Symbol: "FOO-abcdef", Decimals: 6}, @@ -62,7 +63,8 @@ func TestNewNetworkProvider(t *testing.T) { assert.Equal(t, uint64(200000), provider.GetNetworkConfig().GasLimitCustomTransfer) assert.Equal(t, uint64(1000000001), provider.GetNetworkConfig().MinGasPrice) assert.Equal(t, uint64(50001), provider.GetNetworkConfig().MinGasLimit) - assert.Equal(t, uint64(50001), provider.GetNetworkConfig().ExtraGasLimitGuardedTx) + assert.Equal(t, uint64(50002), provider.GetNetworkConfig().ExtraGasLimitGuardedTx) + assert.Equal(t, uint64(50003), provider.GetNetworkConfig().ExtraGasLimitRelayedTxV3) assert.Equal(t, "XeGLD", provider.GetNativeCurrency().Symbol) assert.Equal(t, []resources.Currency{ {Symbol: "FOO-abcdef", Decimals: 6}, @@ -388,6 +390,7 @@ func createDefaultArgsNewNetworkProvider() ArgsNewNetworkProvider { MinGasPrice: 1000000000, MinGasLimit: 50000, ExtraGasLimitGuardedTx: 50000, + ExtraGasLimitRelayedTxV3: 50000, NativeCurrencySymbol: "XeGLD", GenesisBlockHash: strings.Repeat("0", 64), GenesisTimestamp: 123456789, diff --git a/server/resources/network.go b/server/resources/network.go index 3f5c129a..14063702 100644 --- a/server/resources/network.go +++ b/server/resources/network.go @@ -2,15 +2,16 @@ package resources // NetworkConfig is a resource type NetworkConfig struct { - BlockchainName string - NetworkID string - NetworkName string - MinGasPrice uint64 - MinGasLimit uint64 - GasPerDataByte uint64 - GasPriceModifier float64 - GasLimitCustomTransfer uint64 - ExtraGasLimitGuardedTx uint64 + BlockchainName string + NetworkID string + NetworkName string + MinGasPrice uint64 + MinGasLimit uint64 + GasPerDataByte uint64 + GasPriceModifier float64 + GasLimitCustomTransfer uint64 + ExtraGasLimitGuardedTx uint64 + ExtraGasLimitRelayedTxV3 uint64 } // NodeStatusApiResponse is an API resource diff --git a/server/services/transactionsFeaturesDetector.go b/server/services/transactionsFeaturesDetector.go index e6b91a9e..14650070 100644 --- a/server/services/transactionsFeaturesDetector.go +++ b/server/services/transactionsFeaturesDetector.go @@ -60,6 +60,7 @@ func (detector *transactionsFeaturesDetector) doesContractResultHoldRewardsOfCla // that only consume the "data movement" component of the gas: // - "sending value to non-payable contract" // - "meta transaction is invalid" +// See: MX-16423. Analyze whether we can simplify the conditions below, or possibly discard them completely / replace them with simpler ones. func (detector *transactionsFeaturesDetector) isInvalidTransactionOfTypeMoveBalanceThatOnlyConsumesDataMovementGas(tx *transaction.ApiTransactionResult) bool { isInvalid := tx.Type == string(transaction.TxTypeInvalid) isMoveBalance := tx.ProcessingTypeOnSource == transactionProcessingTypeMoveBalance && tx.ProcessingTypeOnDestination == transactionProcessingTypeMoveBalance @@ -68,7 +69,6 @@ func (detector *transactionsFeaturesDetector) isInvalidTransactionOfTypeMoveBala return false } - // TODO: Analyze whether we can simplify the conditions below, or possibly discard them completely / replace them with simpler ones. withSendingValueToNonPayableContract := detector.eventsController.hasSignalErrorOfSendingValueToNonPayableContract(tx) withMetaTransactionIsInvalid := detector.eventsController.hasSignalErrorOfMetaTransactionIsInvalid(tx) return withSendingValueToNonPayableContract || withMetaTransactionIsInvalid diff --git a/testscommon/networkProviderMock.go b/testscommon/networkProviderMock.go index 84e8b739..6025a535 100644 --- a/testscommon/networkProviderMock.go +++ b/testscommon/networkProviderMock.go @@ -66,15 +66,16 @@ func NewNetworkProviderMock() *networkProviderMock { MockGenesisBlockHash: emptyHash, MockGenesisTimestamp: genesisTimestamp, MockNetworkConfig: &resources.NetworkConfig{ - BlockchainName: "MultiversX", - NetworkID: "T", - NetworkName: "testnet", - MinGasPrice: 1000000000, - MinGasLimit: 50000, - GasPerDataByte: 1500, - GasPriceModifier: 0.01, - GasLimitCustomTransfer: 200000, - ExtraGasLimitGuardedTx: 50000, + BlockchainName: "MultiversX", + NetworkID: "T", + NetworkName: "testnet", + MinGasPrice: 1000000000, + MinGasLimit: 50000, + GasPerDataByte: 1500, + GasPriceModifier: 0.01, + GasLimitCustomTransfer: 200000, + ExtraGasLimitGuardedTx: 50000, + ExtraGasLimitRelayedTxV3: 50000, }, MockGenesisBalances: make([]*resources.GenesisBalance, 0), MockNodeStatus: &resources.AggregatedNodeStatus{ @@ -326,6 +327,7 @@ func (mock *networkProviderMock) ComputeReceiptHash(_ *transaction.ApiReceipt) ( func (mock *networkProviderMock) ComputeTransactionFeeForMoveBalance(tx *transaction.ApiTransactionResult) *big.Int { minGasLimit := mock.MockNetworkConfig.MinGasLimit extraGasLimitGuardedTx := mock.MockNetworkConfig.ExtraGasLimitGuardedTx + extraGasLimitRelayedTxV3 := mock.MockNetworkConfig.ExtraGasLimitRelayedTxV3 gasPerDataByte := mock.MockNetworkConfig.GasPerDataByte gasLimit := minGasLimit + gasPerDataByte*uint64(len(tx.Data)) @@ -334,6 +336,11 @@ func (mock *networkProviderMock) ComputeTransactionFeeForMoveBalance(tx *transac gasLimit += extraGasLimitGuardedTx } + isRelayedV3 := len(tx.RelayerAddress) > 0 + if isRelayedV3 { + gasLimit += extraGasLimitRelayedTxV3 + } + fee := core.SafeMul(gasLimit, tx.GasPrice) return fee }