Skip to content

Commit

Permalink
conmflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Nov 14, 2023
2 parents bd4a239 + c66a904 commit 9cd5ac3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixes

* [1372](https://github.com/zeta-chain/node/pull/1372) - Include Event Index as part for inbound tx digest
* [1367](https://github.com/zeta-chain/node/pull/1367) - fix minRelayTxFee issue and check misuse of bitcoin mainnet/testnet addresses
* [1358](https://github.com/zeta-chain/node/pull/1358) - add a new thread to zetaclient which checks zeta supply in all connected chains in every block

### Refactoring
Expand Down
5 changes: 1 addition & 4 deletions zetaclient/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const (
minConfirmations = 0
maxHeightDiff = 10000
btcBlocksPerDay = 144
bytesPerKB = 1000
)

func (ob *BitcoinChainClient) WithZetaClient(bridge *ZetaCoreBridge) {
Expand Down Expand Up @@ -543,9 +542,7 @@ func (ob *BitcoinChainClient) PostGasPrice() error {
if *feeResult.FeeRate > math.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
16 changes: 15 additions & 1 deletion zetaclient/btc_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,32 @@ func (signer *BTCSigner) TryProcessOutTx(
logger.Error().Msgf("cannot convert gas price %s ", params.OutboundTxGasPrice)
return
}


Check failure on line 296 in zetaclient/btc_signer.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
// Check receiver P2WPKH address
addr, err := btcutil.DecodeAddress(params.Receiver, config.BitconNetParams)
if err != nil {
logger.Error().Err(err).Msgf("cannot decode address %s ", params.Receiver)
return
}
if !addr.IsForNet(config.BitconNetParams) {
logger.Error().Msgf("address %s is not for network %s", params.Receiver, config.BitconNetParams.Name)
return
}
to, ok := addr.(*btcutil.AddressWitnessPubKeyHash)
if err != nil || !ok {
logger.Error().Err(err).Msgf("cannot convert address %s to P2WPKH address", params.Receiver)
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")
return
}
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)

Expand Down
8 changes: 4 additions & 4 deletions zetaclient/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,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: 70000, // Goerli
97: 95000, // BSC testnet
80001: 120000, // 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 Expand Up @@ -643,7 +643,7 @@ func (ob *EVMChainClient) queryTxByHash(txHash string, nonce uint64) (*ethtypes.
receipt, err := ob.evmClient.TransactionReceipt(ctxt, ethcommon.HexToHash(txHash))
if err != nil {
if err != ethereum.NotFound {
logger.Warn().Err(err).Msg("TransactionReceipt/TransactionByHash error")
logger.Warn().Err(err).Msgf("TransactionReceipt/TransactionByHash error, txHash %s", txHash)
}
return nil, nil, err
}
Expand Down
1 change: 1 addition & 0 deletions zetaclient/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type ZetaCoreBridger interface {

// BTCRPCClient is the interface for BTC RPC client
type BTCRPCClient interface {
GetNetworkInfo() (*btcjson.GetNetworkInfoResult, error)
SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (*chainhash.Hash, error)
ListUnspentMinMaxAddresses(minConf int, maxConf int, addrs []btcutil.Address) ([]btcjson.ListUnspentResult, error)
EstimateSmartFee(confTarget int64, mode *btcjson.EstimateSmartFeeMode) (*btcjson.EstimateSmartFeeResult, error)
Expand Down
8 changes: 8 additions & 0 deletions zetaclient/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,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 9cd5ac3

Please sign in to comment.