Skip to content

Commit 3000e5f

Browse files
authored
Merge pull request #131 from sgz13140/feat/gas-price
support increase the gas price when submit checkpoint to eth
2 parents 71a1822 + 20e5c34 commit 3000e5f

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

bridge/setu/broadcaster/broadcaster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (tb *TxBroadcaster) BroadcastToMatic(msg bor.CallMsg) error {
120120
maticClient := helper.GetMaticClient()
121121

122122
// get auth
123-
auth, err := helper.GenerateAuthObj(maticClient, *msg.To, msg.Data)
123+
auth, err := helper.GenerateAuthObj(maticClient, *msg.To, msg.Data, false)
124124

125125
if err != nil {
126126
tb.logger.Error("Error generating auth object", "error", err)

helper/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ const (
103103

104104
DefaultBttcChainID string = "15001"
105105

106+
DefaultEnableIncreaseGasPrice = false
107+
DefaultGasPriceIncreasePercent = 0
108+
106109
DefaultLogsType = "json"
107110
DefaultChain = "mainnet"
108111

@@ -168,6 +171,9 @@ type Configuration struct {
168171
BscMaxQueryBlocks int64 `mapstructure:"bsc_max_query_blocks"` // bsc max number of blocks in one query logs
169172
TronMaxQueryBlocks int64 `mapstructure:"tron_max_query_blocks"` // tron max number of blocks in one query logs
170173
HeimdallMaxQueryBlocks int64 `mapstructure:"heimdall_max_query_blocks"` // heimdall max number of blocks in one query logs
174+
175+
EnableIncreaseGasPrice bool `mapstructure:"enable_increase_gas_price"` // whether enable increase gas price when submit checkpoint to eth
176+
GasPriceIncreasePercent int64 `mapstructure:"gas_price_increase_percent"` // the increase percent of gas price when submit tx. newGasPrice = oldGasPrice * (100 + GasPriceIncreasePercent) / 100
171177
}
172178

173179
var conf Configuration
@@ -330,6 +336,9 @@ func GetDefaultHeimdallConfig() Configuration {
330336
BscMaxQueryBlocks: DefaultBscMaxQueryBlocks,
331337
TronMaxQueryBlocks: DefaultTronMaxQueryBlocks,
332338
HeimdallMaxQueryBlocks: DefaultHeimdallMaxQueryBlocks,
339+
340+
EnableIncreaseGasPrice: DefaultEnableIncreaseGasPrice,
341+
GasPriceIncreasePercent: DefaultGasPriceIncreasePercent,
333342
}
334343
}
335344

helper/tx.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"google.golang.org/protobuf/proto"
2323
)
2424

25-
func GenerateAuthObj(client *ethclient.Client, address common.Address, data []byte) (auth *bind.TransactOpts, err error) {
25+
func GenerateAuthObj(client *ethclient.Client, address common.Address, data []byte, enableIncreaseGasPrice bool) (auth *bind.TransactOpts, err error) {
2626
// generate call msg
2727
callMsg := ethereum.CallMsg{
2828
To: &address,
@@ -46,6 +46,18 @@ func GenerateAuthObj(client *ethclient.Client, address common.Address, data []by
4646
return
4747
}
4848

49+
if enableIncreaseGasPrice {
50+
gasPriceIncreasePercent := GetConfig().GasPriceIncreasePercent
51+
if gasPriceIncreasePercent > 0 {
52+
multiplier := big.NewInt(100 + gasPriceIncreasePercent)
53+
divisor := big.NewInt(100)
54+
originGasPrice := gasprice
55+
gasprice = new(big.Int).Mul(gasprice, multiplier)
56+
gasprice.Div(gasprice, divisor)
57+
Logger.Debug("Adjust gas price", "originGasPrice", originGasPrice, "adjustedGasPrice", gasprice)
58+
}
59+
}
60+
4961
mainChainMaxGasPrice := GetConfig().MainchainMaxGasPrice
5062
// Check if configured or not, Use default in case of invalid value
5163
if mainChainMaxGasPrice <= 0 {
@@ -106,7 +118,15 @@ func (c *ContractCaller) SendCheckpoint(signedData []byte, sigs [][3]*big.Int,
106118
case hmtypes.RootChainTypeBsc:
107119
client = GetBscClient()
108120
}
109-
auth, err := GenerateAuthObj(client, rootChainAddress, data)
121+
var auth *bind.TransactOpts
122+
123+
if rootChain == hmtypes.RootChainTypeEth {
124+
enableIncreaseGasPrice := GetConfig().EnableIncreaseGasPrice
125+
auth, err = GenerateAuthObj(client, rootChainAddress, data, enableIncreaseGasPrice)
126+
} else {
127+
auth, err = GenerateAuthObj(client, rootChainAddress, data, false)
128+
}
129+
110130
if err != nil {
111131
Logger.Error("Unable to create auth object", "error", err)
112132
return err
@@ -141,7 +161,7 @@ func (c *ContractCaller) SendTick(signedData []byte, sigs []byte, slashManagerAd
141161
return err
142162
}
143163

144-
auth, err := GenerateAuthObj(GetMainClient(), slashManagerAddress, data)
164+
auth, err := GenerateAuthObj(GetMainClient(), slashManagerAddress, data, false)
145165
if err != nil {
146166
Logger.Error("Unable to create auth object", "error", err)
147167
return err
@@ -173,7 +193,7 @@ func (c *ContractCaller) StakeFor(val common.Address, stakeAmount *big.Int, feeA
173193
return err
174194
}
175195

176-
auth, err := GenerateAuthObj(GetMainClient(), stakeManagerAddress, data)
196+
auth, err := GenerateAuthObj(GetMainClient(), stakeManagerAddress, data, false)
177197
if err != nil {
178198
Logger.Error("Unable to create auth object", "error", err)
179199
return err
@@ -206,7 +226,7 @@ func (c *ContractCaller) ApproveTokens(amount *big.Int, stakeManager common.Addr
206226
return err
207227
}
208228

209-
auth, err := GenerateAuthObj(GetMainClient(), tokenAddress, data)
229+
auth, err := GenerateAuthObj(GetMainClient(), tokenAddress, data, false)
210230
if err != nil {
211231
Logger.Error("Unable to create auth object", "error", err)
212232
return err
@@ -302,7 +322,7 @@ func (c *ContractCaller) SendMainStakingSync(syncMethod string, signedData []byt
302322
case hmtypes.RootChainTypeBsc:
303323
client = GetBscClient()
304324
}
305-
auth, err := GenerateAuthObj(client, stakingManager, data)
325+
auth, err := GenerateAuthObj(client, stakingManager, data, false)
306326
if err != nil {
307327
Logger.Error("Unable to create auth object", "error", err)
308328
return err

0 commit comments

Comments
 (0)