Skip to content

Commit

Permalink
skip garbage trackers and increase btc gas fee
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Nov 1, 2023
1 parent 0a45114 commit 6e1fb4a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
5 changes: 1 addition & 4 deletions zetaclient/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ const (
minConfirmations = 0
maxHeightDiff = 10000
dustOffset = 2000
bytesPerKB = 1000
btcBlocksPerDay = 144
)

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions zetaclient/btc_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions zetaclient/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zetaclient
import (
"errors"
"math"
"math/big"
"time"

"github.com/btcsuite/btcd/txscript"
Expand All @@ -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.
Expand Down

0 comments on commit 6e1fb4a

Please sign in to comment.