Skip to content

Commit

Permalink
Handle "extraGasLimitRelayedTxV3".
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Jan 9, 2025
1 parent 279b4ec commit 3da9818
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 30 deletions.
9 changes: 9 additions & 0 deletions cmd/rosetta/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
Expand Down Expand Up @@ -205,6 +211,7 @@ func getAllCliFlags() []cli.Flag {
cliFlagMinGasPrice,
cliFlagMinGasLimit,
cliFlagExtraGasLimitGuardedTx,
cliFlagExtraGasLimitRelayedTxV3,
cliFlagGasPerDataByte,
cliFlagGasPriceModifier,
cliFlagGasLimitCustomTransfer,
Expand Down Expand Up @@ -237,6 +244,7 @@ type parsedCliFlags struct {
minGasPrice uint64
minGasLimit uint64
extraGasLimitGuardedTx uint64
extraGasLimitRelayedTxV3 uint64
gasPerDataByte uint64
gasPriceModifier float64
gasLimitCustomTransfer uint64
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions cmd/rosetta/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions server/factory/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ArgsCreateNetworkProvider struct {
MinGasPrice uint64
MinGasLimit uint64
ExtraGasLimitGuardedTx uint64
ExtraGasLimitRelayedTxV3 uint64
NativeCurrencySymbol string
CustomCurrencies []resources.Currency
GenesisBlockHash string
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 17 additions & 9 deletions server/provider/networkProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ArgsNewNetworkProvider struct {
MinGasPrice uint64
MinGasLimit uint64
ExtraGasLimitGuardedTx uint64
ExtraGasLimitRelayedTxV3 uint64
NativeCurrencySymbol string
CustomCurrencies []resources.Currency
GenesisBlockHash string
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))

Expand All @@ -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
}
Expand Down
7 changes: 5 additions & 2 deletions server/provider/networkProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -388,6 +390,7 @@ func createDefaultArgsNewNetworkProvider() ArgsNewNetworkProvider {
MinGasPrice: 1000000000,
MinGasLimit: 50000,
ExtraGasLimitGuardedTx: 50000,
ExtraGasLimitRelayedTxV3: 50000,
NativeCurrencySymbol: "XeGLD",
GenesisBlockHash: strings.Repeat("0", 64),
GenesisTimestamp: 123456789,
Expand Down
19 changes: 10 additions & 9 deletions server/resources/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/services/transactionsFeaturesDetector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 16 additions & 9 deletions testscommon/networkProviderMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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))

Expand All @@ -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
}
Expand Down

0 comments on commit 3da9818

Please sign in to comment.