diff --git a/clients/elrond/client.go b/clients/elrond/client.go index 6b78b83c..fb9b8668 100644 --- a/clients/elrond/client.go +++ b/clients/elrond/client.go @@ -253,7 +253,8 @@ func (c *client) ProposeSetStatus(ctx context.Context, batch *clients.TransferBa txBuilder.ArgBytes([]byte{stat}) } - hash, err := c.txHandler.SendTransactionReturnHash(ctx, txBuilder, c.gasMapConfig.ProposeStatus) + gasLimit := c.gasMapConfig.ProposeStatusBase + uint64(len(batch.Deposits))*c.gasMapConfig.ProposeStatusForEach + hash, err := c.txHandler.SendTransactionReturnHash(ctx, txBuilder, gasLimit) if err == nil { c.log.Info("proposed set statuses"+batch.String(), "transaction hash", hash) } diff --git a/clients/elrond/client_test.go b/clients/elrond/client_test.go index 21da481d..1c1350fb 100644 --- a/clients/elrond/client_test.go +++ b/clients/elrond/client_test.go @@ -35,9 +35,10 @@ func createMockClientArgs() ClientArgs { Sign: 10, ProposeTransferBase: 20, ProposeTransferForEach: 30, - ProposeStatus: 40, - PerformActionBase: 50, - PerformActionForEach: 60, + ProposeStatusBase: 40, + ProposeStatusForEach: 50, + PerformActionBase: 60, + PerformActionForEach: 70, }, Proxy: &interactors.ElrondProxyStub{}, Log: logger.GetOrCreate("test"), @@ -379,7 +380,8 @@ func TestClient_ProposeSetStatus(t *testing.T) { expectedDataField := strings.Join(expectedArgs, "@") assert.Equal(t, expectedDataField, dataField) - assert.Equal(t, c.gasMapConfig.ProposeStatus, gasLimit) + expectedGasLimit := c.gasMapConfig.ProposeStatusBase + uint64(len(expectedStatus))*c.gasMapConfig.ProposeStatusForEach + assert.Equal(t, gasLimit, expectedGasLimit) return expectedHash, nil }, diff --git a/clients/ethereum/client.go b/clients/ethereum/client.go index db5cdaa3..b7261ac3 100644 --- a/clients/ethereum/client.go +++ b/clients/ethereum/client.go @@ -30,32 +30,34 @@ type argListsBatch struct { // ArgsEthereumClient is the DTO used in the ethereum's client constructor type ArgsEthereumClient struct { - ClientWrapper ClientWrapper - Erc20ContractsHandler Erc20ContractsHolder - Log elrondCore.Logger - AddressConverter core.AddressConverter - Broadcaster Broadcaster - PrivateKey *ecdsa.PrivateKey - TokensMapper TokensMapper - SignatureHolder SignaturesHolder - SafeContractAddress common.Address - GasHandler GasHandler - TransferGasLimit uint64 + ClientWrapper ClientWrapper + Erc20ContractsHandler Erc20ContractsHolder + Log elrondCore.Logger + AddressConverter core.AddressConverter + Broadcaster Broadcaster + PrivateKey *ecdsa.PrivateKey + TokensMapper TokensMapper + SignatureHolder SignaturesHolder + SafeContractAddress common.Address + GasHandler GasHandler + TransferGasLimitBase uint64 + TransferGasLimitForEach uint64 } type client struct { - clientWrapper ClientWrapper - erc20ContractsHandler Erc20ContractsHolder - log elrondCore.Logger - addressConverter core.AddressConverter - broadcaster Broadcaster - privateKey *ecdsa.PrivateKey - publicKey *ecdsa.PublicKey - tokensMapper TokensMapper - signatureHolder SignaturesHolder - safeContractAddress common.Address - gasHandler GasHandler - transferGasLimit uint64 + clientWrapper ClientWrapper + erc20ContractsHandler Erc20ContractsHolder + log elrondCore.Logger + addressConverter core.AddressConverter + broadcaster Broadcaster + privateKey *ecdsa.PrivateKey + publicKey *ecdsa.PublicKey + tokensMapper TokensMapper + signatureHolder SignaturesHolder + safeContractAddress common.Address + gasHandler GasHandler + transferGasLimitBase uint64 + transferGasLimitForEach uint64 } // NewEthereumClient will create a new Ethereum client @@ -72,18 +74,19 @@ func NewEthereumClient(args ArgsEthereumClient) (*client, error) { } c := &client{ - clientWrapper: args.ClientWrapper, - erc20ContractsHandler: args.Erc20ContractsHandler, - log: args.Log, - addressConverter: args.AddressConverter, - broadcaster: args.Broadcaster, - privateKey: args.PrivateKey, - publicKey: publicKeyECDSA, - tokensMapper: args.TokensMapper, - signatureHolder: args.SignatureHolder, - safeContractAddress: args.SafeContractAddress, - gasHandler: args.GasHandler, - transferGasLimit: args.TransferGasLimit, + clientWrapper: args.ClientWrapper, + erc20ContractsHandler: args.Erc20ContractsHandler, + log: args.Log, + addressConverter: args.AddressConverter, + broadcaster: args.Broadcaster, + privateKey: args.PrivateKey, + publicKey: publicKeyECDSA, + tokensMapper: args.TokensMapper, + signatureHolder: args.SignatureHolder, + safeContractAddress: args.SafeContractAddress, + gasHandler: args.GasHandler, + transferGasLimitBase: args.TransferGasLimitBase, + transferGasLimitForEach: args.TransferGasLimitForEach, } c.log.Info("NewEthereumClient", @@ -121,7 +124,10 @@ func checkArgs(args ArgsEthereumClient) error { if check.IfNil(args.GasHandler) { return errNilGasHandler } - if args.TransferGasLimit == 0 { + if args.TransferGasLimitBase == 0 { + return errInvalidGasLimit + } + if args.TransferGasLimitForEach == 0 { return errInvalidGasLimit } @@ -313,7 +319,7 @@ func (c *client) ExecuteTransfer( auth.Nonce = big.NewInt(nonce) auth.Value = big.NewInt(0) - auth.GasLimit = c.transferGasLimit + auth.GasLimit = c.transferGasLimitBase + uint64(len(batch.Deposits))*c.transferGasLimitForEach auth.Context = ctx auth.GasPrice = gasPrice diff --git a/clients/ethereum/client_test.go b/clients/ethereum/client_test.go index e72f5bb2..3a8bbf45 100644 --- a/clients/ethereum/client_test.go +++ b/clients/ethereum/client_test.go @@ -48,10 +48,11 @@ func createMockEthereumClientArgs() ArgsEthereumClient { return append([]byte("ERC20"), sourceBytes...), nil }, }, - SignatureHolder: &testsCommon.SignaturesHolderStub{}, - SafeContractAddress: testsCommon.CreateRandomEthereumAddress(), - GasHandler: &testsCommon.GasHandlerStub{}, - TransferGasLimit: 100, + SignatureHolder: &testsCommon.SignaturesHolderStub{}, + SafeContractAddress: testsCommon.CreateRandomEthereumAddress(), + GasHandler: &testsCommon.GasHandlerStub{}, + TransferGasLimitBase: 50, + TransferGasLimitForEach: 20, } } @@ -161,9 +162,17 @@ func TestNewEthereumClient(t *testing.T) { assert.Equal(t, errNilGasHandler, err) assert.True(t, check.IfNil(c)) }) - t.Run("0 transfer gas limit", func(t *testing.T) { + t.Run("0 transfer gas limit base", func(t *testing.T) { args := createMockEthereumClientArgs() - args.TransferGasLimit = 0 + args.TransferGasLimitBase = 0 + c, err := NewEthereumClient(args) + + assert.Equal(t, errInvalidGasLimit, err) + assert.True(t, check.IfNil(c)) + }) + t.Run("0 transfer gas limit for each", func(t *testing.T) { + args := createMockEthereumClientArgs() + args.TransferGasLimitForEach = 0 c, err := NewEthereumClient(args) assert.Equal(t, errInvalidGasLimit, err) diff --git a/cmd/bridge/config/config.toml b/cmd/bridge/config/config.toml index c05db1d8..124276a8 100644 --- a/cmd/bridge/config/config.toml +++ b/cmd/bridge/config/config.toml @@ -3,7 +3,8 @@ MultisigContractAddress = "3009d97FfeD62E57d444e552A9eDF9Ee6Bc8644c" # the eth address for the bridge contract SafeContractAddress = "A6504Cc508889bbDBd4B748aFf6EA6b5D0d2684c" PrivateKeyFile = "keys/ethereum.sk" # the path to the file containing the relayer eth private key - GasLimit = 500000 + GasLimitBase = 200000 + GasLimitForEach = 30000 IntervalToWaitForTransferInSeconds = 600 #10 minutes MaxRetriesOnQuorumReached = 3 [Eth.GasStation] @@ -27,7 +28,8 @@ Sign = 8000000 ProposeTransferBase = 11000000 ProposeTransferForEach = 3000000 - ProposeStatus = 30000000 + ProposeStatusBase = 10000000 + ProposeStatusForEach = 7000000 PerformActionBase = 25000000 PerformActionForEach = 2000000 diff --git a/config/config.go b/config/config.go index 77dfab5e..b22f1d68 100644 --- a/config/config.go +++ b/config/config.go @@ -30,7 +30,8 @@ type EthereumConfig struct { SafeContractAddress string PrivateKeyFile string IntervalToResendTxsInSeconds uint64 - GasLimit uint64 + GasLimitBase uint64 + GasLimitForEach uint64 GasStation GasStationConfig MaxRetriesOnQuorumReached uint64 IntervalToWaitForTransferInSeconds uint64 @@ -151,7 +152,8 @@ type ElrondGasMapConfig struct { Sign uint64 ProposeTransferBase uint64 ProposeTransferForEach uint64 - ProposeStatus uint64 + ProposeStatusBase uint64 + ProposeStatusForEach uint64 PerformActionBase uint64 PerformActionForEach uint64 } diff --git a/factory/ethElrondBridgeComponents.go b/factory/ethElrondBridgeComponents.go index 3ef3e9dd..61c94aed 100644 --- a/factory/ethElrondBridgeComponents.go +++ b/factory/ethElrondBridgeComponents.go @@ -383,17 +383,18 @@ func (components *ethElrondBridgeComponents) createEthereumClient(args ArgsEther safeContractAddress := common.HexToAddress(ethereumConfigs.SafeContractAddress) argsEthClient := ethereum.ArgsEthereumClient{ - ClientWrapper: args.ClientWrapper, - Erc20ContractsHandler: args.Erc20ContractsHolder, - Log: core.NewLoggerWithIdentifier(logger.GetOrCreate(ethClientLogId), ethClientLogId), - AddressConverter: components.addressConverter, - Broadcaster: components.broadcaster, - PrivateKey: privateKey, - TokensMapper: tokensMapper, - SignatureHolder: signaturesHolder, - SafeContractAddress: safeContractAddress, - GasHandler: gs, - TransferGasLimit: ethereumConfigs.GasLimit, + ClientWrapper: args.ClientWrapper, + Erc20ContractsHandler: args.Erc20ContractsHolder, + Log: core.NewLoggerWithIdentifier(logger.GetOrCreate(ethClientLogId), ethClientLogId), + AddressConverter: components.addressConverter, + Broadcaster: components.broadcaster, + PrivateKey: privateKey, + TokensMapper: tokensMapper, + SignatureHolder: signaturesHolder, + SafeContractAddress: safeContractAddress, + GasHandler: gs, + TransferGasLimitBase: ethereumConfigs.GasLimitBase, + TransferGasLimitForEach: ethereumConfigs.GasLimitForEach, } components.ethClient, err = ethereum.NewEthereumClient(argsEthClient) diff --git a/factory/ethElrondBridgeComponents_test.go b/factory/ethElrondBridgeComponents_test.go index 230fcf53..30c51361 100644 --- a/factory/ethElrondBridgeComponents_test.go +++ b/factory/ethElrondBridgeComponents_test.go @@ -34,7 +34,8 @@ func createMockEthElrondBridgeArgs() ArgsEthereumToElrondBridge { SafeContractAddress: "5DdDe022a65F8063eE9adaC54F359CBF46166068", PrivateKeyFile: "testdata/grace.sk", IntervalToResendTxsInSeconds: 0, - GasLimit: 500000, + GasLimitBase: 200000, + GasLimitForEach: 30000, GasStation: config.GasStationConfig{ Enabled: true, URL: "", diff --git a/integrationTests/relayers/ethToElrond_test.go b/integrationTests/relayers/ethToElrond_test.go index 93547964..2863b6e5 100644 --- a/integrationTests/relayers/ethToElrond_test.go +++ b/integrationTests/relayers/ethToElrond_test.go @@ -187,7 +187,8 @@ func createBridgeComponentsConfig(index int) config.Config { MultisigContractAddress: "3009d97FfeD62E57d444e552A9eDF9Ee6Bc8644c", PrivateKeyFile: fmt.Sprintf("testdata/ethereum%d.sk", index), IntervalToResendTxsInSeconds: 10, - GasLimit: 500000, + GasLimitBase: 200000, + GasLimitForEach: 30000, GasStation: config.GasStationConfig{ Enabled: false, }, diff --git a/testsCommon/gasMap.go b/testsCommon/gasMap.go index 8dc231e9..63b3c7ad 100644 --- a/testsCommon/gasMap.go +++ b/testsCommon/gasMap.go @@ -10,8 +10,9 @@ func CreateTestElrondGasMap() config.ElrondGasMapConfig { Sign: 101, ProposeTransferBase: 102, ProposeTransferForEach: 103, - ProposeStatus: 104, - PerformActionBase: 105, - PerformActionForEach: 106, + ProposeStatusBase: 104, + ProposeStatusForEach: 105, + PerformActionBase: 106, + PerformActionForEach: 107, } }