Skip to content

Commit

Permalink
Enable setting custom transfer gas per chain
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 committed Oct 18, 2024
1 parent eed1e97 commit 5df7efd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion chains/evm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -52,6 +53,7 @@ func (c *EVMConfig) String() string {
c.MaxGasPrice,
c.GasMultiplier,
c.GasLimit,
c.TransferGas,
c.StartBlock,
c.BlockConfirmations,
c.BlockInterval,
Expand All @@ -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"`
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions chains/evm/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -116,6 +117,7 @@ func (s *NewEVMConfigTestSuite) Test_ValidConfigWithCustomTxParams() {
"gasMultiplier": 1000,
"gasIncreasePercentage": 20,
"gasLimit": 1000,
"transferGas": 300000,
"startBlock": 1000,
"blockConfirmations": 10,
"blockRetryInterval": 10,
Expand Down Expand Up @@ -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),
Expand Down
11 changes: 5 additions & 6 deletions chains/evm/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,6 +49,7 @@ type Executor struct {
bridge BridgeContract
exitLock *sync.RWMutex
transactionMaxGas uint64
transferGasCost uint64
}

func NewExecutor(
Expand All @@ -63,6 +60,7 @@ func NewExecutor(
fetcher signing.SaveDataFetcher,
exitLock *sync.RWMutex,
transactionMaxGas uint64,
transferGasCost uint64,
) *Executor {
return &Executor{
host: host,
Expand All @@ -72,6 +70,7 @@ func NewExecutor(
fetcher: fetcher,
exitLock: exitLock,
transactionMaxGas: transactionMaxGas,
transferGasCost: transferGasCost,
}
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion example/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 5df7efd

Please sign in to comment.