Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bridge/setu/broadcaster/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (tb *TxBroadcaster) BroadcastToMatic(msg bor.CallMsg) error {
maticClient := helper.GetMaticClient()

// get auth
auth, err := helper.GenerateAuthObj(maticClient, *msg.To, msg.Data)
auth, err := helper.GenerateAuthObj(maticClient, *msg.To, msg.Data, false)

if err != nil {
tb.logger.Error("Error generating auth object", "error", err)
Expand Down
9 changes: 9 additions & 0 deletions helper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ const (

DefaultBttcChainID string = "15001"

DefaultEnableIncreaseGasPrice = false
DefaultGasPriceIncreasePercent = 0

DefaultLogsType = "json"
DefaultChain = "mainnet"

Expand Down Expand Up @@ -168,6 +171,9 @@ type Configuration struct {
BscMaxQueryBlocks int64 `mapstructure:"bsc_max_query_blocks"` // bsc max number of blocks in one query logs
TronMaxQueryBlocks int64 `mapstructure:"tron_max_query_blocks"` // tron max number of blocks in one query logs
HeimdallMaxQueryBlocks int64 `mapstructure:"heimdall_max_query_blocks"` // heimdall max number of blocks in one query logs

EnableIncreaseGasPrice bool `mapstructure:"enable_increase_gas_price"` // whether enable increase gas price when submit checkpoint to eth
GasPriceIncreasePercent int64 `mapstructure:"gas_price_increase_percent"` // the increase percent of gas price when submit tx. newGasPrice = oldGasPrice * (100 + GasPriceIncreasePercent) / 100
}

var conf Configuration
Expand Down Expand Up @@ -330,6 +336,9 @@ func GetDefaultHeimdallConfig() Configuration {
BscMaxQueryBlocks: DefaultBscMaxQueryBlocks,
TronMaxQueryBlocks: DefaultTronMaxQueryBlocks,
HeimdallMaxQueryBlocks: DefaultHeimdallMaxQueryBlocks,

EnableIncreaseGasPrice: DefaultEnableIncreaseGasPrice,
GasPriceIncreasePercent: DefaultGasPriceIncreasePercent,
}
}

Expand Down
32 changes: 26 additions & 6 deletions helper/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"google.golang.org/protobuf/proto"
)

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

if enableIncreaseGasPrice {
gasPriceIncreasePercent := GetConfig().GasPriceIncreasePercent
if gasPriceIncreasePercent > 0 {
multiplier := big.NewInt(100 + gasPriceIncreasePercent)
divisor := big.NewInt(100)
originGasPrice := gasprice
gasprice = new(big.Int).Mul(gasprice, multiplier)
gasprice.Div(gasprice, divisor)
Logger.Debug("Adjust gas price", "originGasPrice", originGasPrice, "adjustedGasPrice", gasprice)
}
}

mainChainMaxGasPrice := GetConfig().MainchainMaxGasPrice
// Check if configured or not, Use default in case of invalid value
if mainChainMaxGasPrice <= 0 {
Expand Down Expand Up @@ -106,7 +118,15 @@ func (c *ContractCaller) SendCheckpoint(signedData []byte, sigs [][3]*big.Int,
case hmtypes.RootChainTypeBsc:
client = GetBscClient()
}
auth, err := GenerateAuthObj(client, rootChainAddress, data)
var auth *bind.TransactOpts

if rootChain == hmtypes.RootChainTypeEth {
enableIncreaseGasPrice := GetConfig().EnableIncreaseGasPrice
auth, err = GenerateAuthObj(client, rootChainAddress, data, enableIncreaseGasPrice)
} else {
auth, err = GenerateAuthObj(client, rootChainAddress, data, false)
}

if err != nil {
Logger.Error("Unable to create auth object", "error", err)
return err
Expand Down Expand Up @@ -141,7 +161,7 @@ func (c *ContractCaller) SendTick(signedData []byte, sigs []byte, slashManagerAd
return err
}

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

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

auth, err := GenerateAuthObj(GetMainClient(), tokenAddress, data)
auth, err := GenerateAuthObj(GetMainClient(), tokenAddress, data, false)
if err != nil {
Logger.Error("Unable to create auth object", "error", err)
return err
Expand Down Expand Up @@ -302,7 +322,7 @@ func (c *ContractCaller) SendMainStakingSync(syncMethod string, signedData []byt
case hmtypes.RootChainTypeBsc:
client = GetBscClient()
}
auth, err := GenerateAuthObj(client, stakingManager, data)
auth, err := GenerateAuthObj(client, stakingManager, data, false)
if err != nil {
Logger.Error("Unable to create auth object", "error", err)
return err
Expand Down
Loading