Skip to content

Commit

Permalink
cherry pick all hotfix from v10.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Oct 4, 2023
1 parent dec6172 commit e2b72f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
25 changes: 15 additions & 10 deletions zetaclient/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,12 @@ func (ob *BitcoinChainClient) observeInTx() error {

for _, inTx := range inTxs {
ob.logger.WatchInTx.Debug().Msgf("Processing inTx: %s", inTx.TxHash)
amount := big.NewFloat(inTx.Value)
amount = amount.Mul(amount, big.NewFloat(1e8))
amountInt, _ := amount.Int(nil)
sats, err := getSatoshis(inTx.Value)
if err != nil {
ob.logger.WatchInTx.Error().Err(err).Msgf("getSatoshis error: %s", err)
continue
}
amountInt := big.NewInt(sats)
message := hex.EncodeToString(inTx.MemoBytes)
zetaHash, err := ob.zetaClient.PostSend(
inTx.FromAddress,
Expand Down Expand Up @@ -379,17 +382,19 @@ func (ob *BitcoinChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64
}

var amount float64
if res.Amount > 0 {
ob.logger.ObserveOutTx.Warn().Msg("IsSendOutTxProcessed: res.Amount > 0")
if res.Amount >= 0 {
ob.logger.ObserveOutTx.Warn().Msgf("IsSendOutTxProcessed: res.Amount >= 0")
amount = res.Amount
} else if res.Amount == 0 {
ob.logger.ObserveOutTx.Error().Msg("IsSendOutTxProcessed: res.Amount == 0")
return false, false, nil
} else {
amount = -res.Amount
}

amountInSat, _ := big.NewFloat(amount * 1e8).Int(nil)
sats, err := getSatoshis(amount)
if err != nil {
ob.logger.ObserveOutTx.Warn().Msgf("IsSendOutTxProcessed: getSatoshis error: %s", err)
return false, false, nil
}
amountInSat := big.NewInt(sats)
if res.Confirmations < ob.ConfirmationsThreshold(amountInSat) {
return true, false, nil
}
Expand Down Expand Up @@ -665,7 +670,7 @@ func (ob *BitcoinChainClient) refreshPendingNonce() {
// #nosec G701 always positive
nonceLow := uint64(p.NonceLow)

if nonceLow > 0 && nonceLow >= pendingNonce {
if nonceLow > 0 && nonceLow > pendingNonce {
// get the last included outTx hash
txid, err := ob.getOutTxidByNonce(nonceLow-1, false)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion zetaclient/zetacore_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ func (co *CoreObserver) startSendScheduler() {
outTxID := fmt.Sprintf("%s-%d-%d", cctx.Index, params.ReceiverChainId, nonce) // would outTxID a better ID?

// Process Bitcoin OutTx
if common.IsBitcoinChain(c.ChainId) && !outTxMan.IsOutTxActive(outTxID) {
if common.IsBitcoinChain(c.ChainId) {
if outTxMan.IsOutTxActive(outTxID) {
break // there is no need to process cctx with future nonces
}
// #nosec G701 positive
if stop := co.processBitcoinOutTx(outTxMan, uint64(idx), cctx, signer, ob, currentHeight); stop {
break
Expand Down

0 comments on commit e2b72f7

Please sign in to comment.