From 5df7efd20d886a53ce64d764317c4436541e4916 Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Fri, 18 Oct 2024 17:11:21 +0200 Subject: [PATCH] Enable setting custom transfer gas per chain --- app/app.go | 2 +- chains/evm/config.go | 6 +++++- chains/evm/config_test.go | 3 +++ chains/evm/executor/executor.go | 11 +++++------ example/app/app.go | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/app.go b/app/app.go index 2a66468f..9500a23b 100644 --- a/app/app.go +++ b/app/app.go @@ -228,7 +228,7 @@ func Run() error { eventHandlers = append(eventHandlers, hubEventHandlers.NewRefreshEventHandler(l, topologyProvider, topologyStore, tssListener, coordinator, host, communication, connectionGate, keyshareStore, frostKeyshareStore, bridgeAddress)) eventHandlers = append(eventHandlers, hubEventHandlers.NewRetryEventHandler(l, tssListener, depositHandler, propStore, bridgeAddress, *config.GeneralChainConfig.Id, config.BlockConfirmations, msgChan)) evmListener := listener.NewEVMListener(client, eventHandlers, blockstore, sygmaMetrics, *config.GeneralChainConfig.Id, config.BlockRetryInterval, config.BlockConfirmations, config.BlockInterval) - executor := executor.NewExecutor(host, communication, coordinator, bridgeContract, keyshareStore, exitLock, config.GasLimit.Uint64()) + executor := executor.NewExecutor(host, communication, coordinator, bridgeContract, keyshareStore, exitLock, config.GasLimit.Uint64(), config.TransferGas) startBlock, err := blockstore.GetStartBlock(*config.GeneralChainConfig.Id, config.StartBlock, config.GeneralChainConfig.LatestBlock, config.GeneralChainConfig.FreshStart) if err != nil { diff --git a/chains/evm/config.go b/chains/evm/config.go index 666e7129..a6803b0d 100644 --- a/chains/evm/config.go +++ b/chains/evm/config.go @@ -29,6 +29,7 @@ type EVMConfig struct { MaxGasPrice *big.Int GasMultiplier *big.Float GasLimit *big.Int + TransferGas uint64 GasIncreasePercentage *big.Int StartBlock *big.Int BlockConfirmations *big.Int @@ -39,7 +40,7 @@ type EVMConfig struct { func (c *EVMConfig) String() string { privateKey, _ := crypto.HexToECDSA(c.GeneralChainConfig.Key) kp := secp256k1.NewKeypair(*privateKey) - return fmt.Sprintf(`Name: '%s', Id: '%d', Type: '%s', BlockstorePath: '%s', FreshStart: '%t', LatestBlock: '%t', Key address: '%s', Bridge: '%s', Handlers: %+v, MaxGasPrice: '%s', GasMultiplier: '%s', GasLimit: '%s', StartBlock: '%s', BlockConfirmations: '%s', BlockInterval: '%s', BlockRetryInterval: '%s'`, + return fmt.Sprintf(`Name: '%s', Id: '%d', Type: '%s', BlockstorePath: '%s', FreshStart: '%t', LatestBlock: '%t', Key address: '%s', Bridge: '%s', Handlers: %+v, MaxGasPrice: '%s', GasMultiplier: '%s', GasLimit: '%s', TransferGas: '%d', StartBlock: '%s', BlockConfirmations: '%s', BlockInterval: '%s', BlockRetryInterval: '%s'`, c.GeneralChainConfig.Name, *c.GeneralChainConfig.Id, c.GeneralChainConfig.Type, @@ -52,6 +53,7 @@ func (c *EVMConfig) String() string { c.MaxGasPrice, c.GasMultiplier, c.GasLimit, + c.TransferGas, c.StartBlock, c.BlockConfirmations, c.BlockInterval, @@ -68,6 +70,7 @@ type RawEVMConfig struct { GasMultiplier float64 `mapstructure:"gasMultiplier" default:"1"` GasIncreasePercentage int64 `mapstructure:"gasIncreasePercentage" default:"15"` GasLimit int64 `mapstructure:"gasLimit" default:"15000000"` + TransferGas uint64 `mapstructure:"transferGas" default:"250000"` StartBlock int64 `mapstructure:"startBlock"` BlockConfirmations int64 `mapstructure:"blockConfirmations" default:"10"` BlockInterval int64 `mapstructure:"blockInterval" default:"5"` @@ -114,6 +117,7 @@ func NewEVMConfig(chainConfig map[string]interface{}) (*EVMConfig, error) { FrostKeygen: c.FrostKeygen, BlockRetryInterval: time.Duration(c.BlockRetryInterval) * time.Second, GasLimit: big.NewInt(c.GasLimit), + TransferGas: c.TransferGas, MaxGasPrice: big.NewInt(c.MaxGasPrice), GasIncreasePercentage: big.NewInt(c.GasIncreasePercentage), GasMultiplier: big.NewFloat(c.GasMultiplier), diff --git a/chains/evm/config_test.go b/chains/evm/config_test.go index bbc55012..0453ea36 100644 --- a/chains/evm/config_test.go +++ b/chains/evm/config_test.go @@ -84,6 +84,7 @@ func (s *NewEVMConfigTestSuite) Test_ValidConfig() { Bridge: "bridgeAddress", FrostKeygen: "frostKeygen", GasLimit: big.NewInt(15000000), + TransferGas: 250000, MaxGasPrice: big.NewInt(500000000000), GasMultiplier: big.NewFloat(1), GasIncreasePercentage: big.NewInt(15), @@ -116,6 +117,7 @@ func (s *NewEVMConfigTestSuite) Test_ValidConfigWithCustomTxParams() { "gasMultiplier": 1000, "gasIncreasePercentage": 20, "gasLimit": 1000, + "transferGas": 300000, "startBlock": 1000, "blockConfirmations": 10, "blockRetryInterval": 10, @@ -146,6 +148,7 @@ func (s *NewEVMConfigTestSuite) Test_ValidConfigWithCustomTxParams() { }, }, GasLimit: big.NewInt(1000), + TransferGas: 300000, MaxGasPrice: big.NewInt(1000), GasMultiplier: big.NewFloat(1000), GasIncreasePercentage: big.NewInt(20), diff --git a/chains/evm/executor/executor.go b/chains/evm/executor/executor.go index 22fab36f..5a597c96 100644 --- a/chains/evm/executor/executor.go +++ b/chains/evm/executor/executor.go @@ -25,10 +25,6 @@ import ( "github.com/sygmaprotocol/sygma-core/relayer/proposal" ) -const ( - TRANSFER_GAS_COST uint64 = 200000 -) - type Batch struct { proposals []*transfer.TransferProposal gasLimit uint64 @@ -53,6 +49,7 @@ type Executor struct { bridge BridgeContract exitLock *sync.RWMutex transactionMaxGas uint64 + transferGasCost uint64 } func NewExecutor( @@ -63,6 +60,7 @@ func NewExecutor( fetcher signing.SaveDataFetcher, exitLock *sync.RWMutex, transactionMaxGas uint64, + transferGasCost uint64, ) *Executor { return &Executor{ host: host, @@ -72,6 +70,7 @@ func NewExecutor( fetcher: fetcher, exitLock: exitLock, transactionMaxGas: transactionMaxGas, + transferGasCost: transferGasCost, } } @@ -214,9 +213,9 @@ func (e *Executor) proposalBatches(proposals []*proposal.Proposal) ([]*Batch, er var propGasLimit uint64 l, ok := transferProposal.Data.Metadata["gasLimit"] if ok { - propGasLimit = l.(uint64) + TRANSFER_GAS_COST + propGasLimit = l.(uint64) + e.transferGasCost } else { - propGasLimit = TRANSFER_GAS_COST + propGasLimit = e.transferGasCost } currentBatch.gasLimit += propGasLimit if currentBatch.gasLimit >= e.transactionMaxGas { diff --git a/example/app/app.go b/example/app/app.go index e6743c5f..2ffe2a30 100644 --- a/example/app/app.go +++ b/example/app/app.go @@ -198,7 +198,7 @@ func Run() error { eventHandlers = append(eventHandlers, hubEventHandlers.NewRefreshEventHandler(l, nil, nil, tssListener, coordinator, host, communication, connectionGate, keyshareStore, frostKeyshareStore, bridgeAddress)) eventHandlers = append(eventHandlers, hubEventHandlers.NewRetryEventHandler(l, tssListener, depositHandler, propStore, bridgeAddress, *config.GeneralChainConfig.Id, config.BlockConfirmations, msgChan)) evmListener := listener.NewEVMListener(client, eventHandlers, blockstore, sygmaMetrics, *config.GeneralChainConfig.Id, config.BlockRetryInterval, config.BlockConfirmations, config.BlockInterval) - executor := executor.NewExecutor(host, communication, coordinator, bridgeContract, keyshareStore, exitLock, config.GasLimit.Uint64()) + executor := executor.NewExecutor(host, communication, coordinator, bridgeContract, keyshareStore, exitLock, config.GasLimit.Uint64(), config.TransferGas) chain := coreEvm.NewEVMChain(evmListener, mh, executor, *config.GeneralChainConfig.Id, config.StartBlock)