diff --git a/changelog.md b/changelog.md index db924b3ee5..d1f673cdef 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/common/constant.go b/common/constant.go index 2e10d21b87..534a1adfdb 100644 --- a/common/constant.go +++ b/common/constant.go @@ -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 diff --git a/common/utils.go b/common/utils.go index 62c4e27ad5..9e0e01e0d2 100644 --- a/common/utils.go +++ b/common/utils.go @@ -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 ] diff --git a/common/utils_test.go b/common/utils_test.go new file mode 100644 index 0000000000..a4ff016902 --- /dev/null +++ b/common/utils_test.go @@ -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) + }) + } + +} diff --git a/zetaclient/bitcoin/bitcoin_client_test.go b/zetaclient/bitcoin/bitcoin_client_test.go index f92f3a01fd..c65b719b4f 100644 --- a/zetaclient/bitcoin/bitcoin_client_test.go +++ b/zetaclient/bitcoin/bitcoin_client_test.go @@ -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) diff --git a/zetaclient/bitcoin/utils.go b/zetaclient/bitcoin/utils.go index b11c1a7056..2d3272f4fd 100644 --- a/zetaclient/bitcoin/utils.go +++ b/zetaclient/bitcoin/utils.go @@ -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) } diff --git a/zetaclient/zetabridge/tx.go b/zetaclient/zetabridge/tx.go index a142ad44f0..6d7aa6dcfc 100644 --- a/zetaclient/zetabridge/tx.go +++ b/zetaclient/zetabridge/tx.go @@ -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) + // #nosec G701 always in range + gasPrice = uint64(float64(gasPrice) * multiplier) signerAddress := b.keys.GetOperatorAddress().String() msg := types.NewMsgGasPriceVoter(signerAddress, chain.ChainId, gasPrice, supply, blockNum)