diff --git a/zetaclient/bitcoin_client.go b/zetaclient/bitcoin_client.go index 72bce508cb..ab9563f802 100644 --- a/zetaclient/bitcoin_client.go +++ b/zetaclient/bitcoin_client.go @@ -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, @@ -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 } @@ -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 { diff --git a/zetaclient/zetacore_observer.go b/zetaclient/zetacore_observer.go index 343228004a..bc568816b2 100644 --- a/zetaclient/zetacore_observer.go +++ b/zetaclient/zetacore_observer.go @@ -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