From 6e1fb4af29b3ab388a7fed8ace067a846bbceadd Mon Sep 17 00:00:00 2001 From: charliec Date: Wed, 1 Nov 2023 00:28:37 -0500 Subject: [PATCH] skip garbage trackers and increase btc gas fee --- zetaclient/bitcoin_client.go | 5 +---- zetaclient/btc_signer.go | 8 ++++++++ zetaclient/evm_client.go | 6 +++--- zetaclient/utils.go | 9 +++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/zetaclient/bitcoin_client.go b/zetaclient/bitcoin_client.go index 42a31c39dd..672bec4132 100644 --- a/zetaclient/bitcoin_client.go +++ b/zetaclient/bitcoin_client.go @@ -77,7 +77,6 @@ const ( minConfirmations = 0 maxHeightDiff = 10000 dustOffset = 2000 - bytesPerKB = 1000 btcBlocksPerDay = 144 ) @@ -490,9 +489,7 @@ func (ob *BitcoinChainClient) PostGasPrice() error { if *feeResult.FeeRate > math2.MaxInt64 { return fmt.Errorf("gas price is too large: %f", *feeResult.FeeRate) } - // #nosec G701 always in range - feeRate := new(big.Int).SetInt64(int64(*feeResult.FeeRate * 1e8)) - feeRatePerByte := new(big.Int).Div(feeRate, big.NewInt(bytesPerKB)) + feeRatePerByte := feeRateToSatPerByte(*feeResult.FeeRate) bn, err := ob.rpcClient.GetBlockCount() if err != nil { return err diff --git a/zetaclient/btc_signer.go b/zetaclient/btc_signer.go index f426fee681..8f131f5814 100644 --- a/zetaclient/btc_signer.go +++ b/zetaclient/btc_signer.go @@ -291,6 +291,14 @@ func (signer *BTCSigner) TryProcessOutTx(send *types.CrossChainTx, outTxMan *Out return } + // Add 1 satoshi/byte to gasPrice to avoid minRelayTxFee issue + networkInfo, err := signer.rpcClient.GetNetworkInfo() + if err != nil { + logger.Error().Err(err).Msgf("cannot get bitcoin network info") + } + satPerByte := feeRateToSatPerByte(networkInfo.RelayFee) + gasprice.Add(gasprice, satPerByte) + logger.Info().Msgf("SignWithdrawTx: to %s, value %d sats", addr.EncodeAddress(), params.Amount.Uint64()) logger.Info().Msgf("using utxos: %v", btcClient.utxos) tx, err := signer.SignWithdrawTx(to, float64(params.Amount.Uint64())/1e8, gasprice, sizelimit, btcClient, height, diff --git a/zetaclient/evm_client.go b/zetaclient/evm_client.go index eb0ed1341b..911c0ce9c4 100644 --- a/zetaclient/evm_client.go +++ b/zetaclient/evm_client.go @@ -462,9 +462,9 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co // The lowest nonce we observe outTx for each chain var lowestOutTxNonceToObserve = map[int64]uint64{ - 5: 110900, // Goerli - 97: 102200, // BSC testnet - 80001: 153000, // Mumbai + 5: 113000, // Goerli + 97: 102600, // BSC testnet + 80001: 154500, // Mumbai } // FIXME: there's a chance that a txhash in OutTxChan may not deliver when Stop() is called diff --git a/zetaclient/utils.go b/zetaclient/utils.go index 56ba3000d9..4dda2e5e6b 100644 --- a/zetaclient/utils.go +++ b/zetaclient/utils.go @@ -3,6 +3,7 @@ package zetaclient import ( "errors" "math" + "math/big" "time" "github.com/btcsuite/btcd/txscript" @@ -11,8 +12,16 @@ import ( const ( satoshiPerBitcoin = 1e8 + bytesPerKB = 1000 ) +// feeRateToSatPerByte converts a fee rate in BTC/KB to sat/byte. +func feeRateToSatPerByte(rate float64) *big.Int { + // #nosec G701 always in range + satPerKB := new(big.Int).SetInt64(int64(rate * satoshiPerBitcoin)) + return new(big.Int).Div(satPerKB, big.NewInt(bytesPerKB)) +} + func getSatoshis(btc float64) (int64, error) { // The amount is only considered invalid if it cannot be represented // as an integer type. This may happen if f is NaN or +-Infinity.