Skip to content

Commit

Permalink
lower the gas price multiplier for evm chains
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Mar 11, 2024
1 parent 828529c commit 7e25cd0
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
### Fixes

* [1861](https://github.com/zeta-chain/node/pull/1861) - fix `ObserverSlashAmount` invalid read
* [1880](https://github.com/zeta-chain/node/issues/1880) - lower the gas price multiplier for EVM chains.

### Chores

Expand Down
7 changes: 5 additions & 2 deletions common/constant.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package common

const (
// DefaultGasPriceMultiplier is the default gas price multiplier for outbond txs
DefaultGasPriceMultiplier = 2
// EVMOuttxGasPriceMultiplier is the default gas price multiplier for EVM-chain outbond txs
EVMOuttxGasPriceMultiplier = 1.2

// BTCOuttxGasPriceMultiplier is the default gas price multiplier for BTC outbond txs
BTCOuttxGasPriceMultiplier = 2.0

// DonationMessage is the message for donation transactions
// Transaction sent to the TSS or ERC20 Custody address containing this message are considered as a donation
Expand Down
10 changes: 10 additions & 0 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ func StringToHash(chainID int64, hash string) ([]byte, error) {
return nil, fmt.Errorf("cannot convert hash to bytes for chain %d", chainID)
}

// GasPriceMultiplier returns the gas price multiplier for the given chain
func GasPriceMultiplier(chainID int64) float64 {
if IsEVMChain(chainID) {
return EVMOuttxGasPriceMultiplier
} else if IsBitcoinChain(chainID) {
return BTCOuttxGasPriceMultiplier
}
return 1.0
}

// ParseAddressAndData parses the message string into an address and data
// message is hex encoded byte array
// [ contractAddress calldata ]
Expand Down
69 changes: 69 additions & 0 deletions common/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package common_test

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/zeta-chain/zetacore/common"
)

func Test_GasPriceMultiplier(t *testing.T) {
tt := []struct {
name string
chainID int64
multiplier float64
}{
{
name: "get Ethereum multiplier",
chainID: 1,
multiplier: 1.2,
},
{
name: "get Goerli multiplier",
chainID: 5,
multiplier: 1.2,
},
{
name: "get BSC multiplier",
chainID: 56,
multiplier: 1.2,
},
{
name: "get BSC Testnet multiplier",
chainID: 97,
multiplier: 1.2,
},
{
name: "get Polygon multiplier",
chainID: 137,
multiplier: 1.2,
},
{
name: "get Mumbai Testnet multiplier",
chainID: 80001,
multiplier: 1.2,
},
{
name: "get Bitcoin multiplier",
chainID: 8332,
multiplier: 2.0,
},
{
name: "get Bitcoin Testnet multiplier",
chainID: 18332,
multiplier: 2.0,
},
{
name: "get unknown chain gas price multiplier",
chainID: 1234,
multiplier: 1.0,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
multiplier := common.GasPriceMultiplier(tc.chainID)
require.Equal(t, tc.multiplier, multiplier)
})
}

}
5 changes: 4 additions & 1 deletion zetaclient/bitcoin/bitcoin_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ func TestCalcDepositorFee828440(t *testing.T) {
var blockVb btcjson.GetBlockVerboseTxResult
err := testutils.LoadObjectFromJSONFile(&blockVb, path.Join("../", testutils.TestDataPathBTC, "block_trimmed_8332_828440.json"))
require.NoError(t, err)
dynamicFee828440 := DepositorFee(32 * common.DefaultGasPriceMultiplier)
avgGasRate := float64(32.0)
// #nosec G701 test - always in range
gasRate := int64(avgGasRate * common.BTCOuttxGasPriceMultiplier)
dynamicFee828440 := DepositorFee(gasRate)

// should return default fee if it's a regtest block
fee := CalcDepositorFee(&blockVb, 18444, &chaincfg.RegressionNetParams, log.Logger)
Expand Down
3 changes: 2 additions & 1 deletion zetaclient/bitcoin/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ func CalcDepositorFee(blockVb *btcjson.GetBlockVerboseTxResult, chainID int64, n
feeRate = defaultDepositorFeeRate // use default fee rate if calculation fails, should not happen
logger.Error().Err(err).Msgf("cannot calculate fee rate for block %d", blockVb.Height)
}
feeRate = feeRate * common.DefaultGasPriceMultiplier
// #nosec G701 always in range
feeRate = int64(float64(feeRate) * common.BTCOuttxGasPriceMultiplier)
return DepositorFee(feeRate)
}

Expand Down
6 changes: 4 additions & 2 deletions zetaclient/zetabridge/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ func (b *ZetaCoreBridge) WrapMessageWithAuthz(msg sdk.Msg) (sdk.Msg, authz2.Sign
}

func (b *ZetaCoreBridge) PostGasPrice(chain common.Chain, gasPrice uint64, supply string, blockNum uint64) (string, error) {
// double the gas price to avoid gas price spike
gasPrice = gasPrice * common.DefaultGasPriceMultiplier
// apply gas price multiplier for the chain
multiplier := common.GasPriceMultiplier(chain.ChainId)

Check warning on line 79 in zetaclient/zetabridge/tx.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/zetabridge/tx.go#L79

Added line #L79 was not covered by tests
// #nosec G701 always in range
gasPrice = uint64(float64(gasPrice) * multiplier)

Check warning on line 81 in zetaclient/zetabridge/tx.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/zetabridge/tx.go#L81

Added line #L81 was not covered by tests
signerAddress := b.keys.GetOperatorAddress().String()
msg := types.NewMsgGasPriceVoter(signerAddress, chain.ChainId, gasPrice, supply, blockNum)

Expand Down

0 comments on commit 7e25cd0

Please sign in to comment.