Skip to content

Commit

Permalink
convert math.Uint -> float64 for bitcoin only
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Sep 7, 2023
1 parent 41c4b6b commit d7a7e72
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions zetaclient/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (ob *BitcoinChainClient) ConfirmationsThreshold(amount *big.Int) int64 {
}

// returns isIncluded, isConfirmed, Error
func (ob *BitcoinChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, _ common.CoinType, logger zerolog.Logger, sendAmount float64) (bool, bool, error) {
func (ob *BitcoinChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, _ common.CoinType, logger zerolog.Logger, params *types.OutboundTxParams) (bool, bool, error) {
outTxID := ob.GetTxID(nonce)
logger.Info().Msgf("IsSendOutTxProcessed %s", outTxID)

Expand Down Expand Up @@ -370,8 +370,8 @@ func (ob *BitcoinChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64
} else if res.Amount == 0 {
// TODO: amount checking should be done in zeta core to block invalid cctx
// Note: we use original amount here as zetacore checks against cctx's amount
amount = sendAmount
ob.logger.ObserveOutTx.Error().Msg("IsSendOutTxProcessed: res.Amount == 0")
amount = float64(params.Amount.Uint64()) / 1e8
ob.logger.ObserveOutTx.Error().Msgf("IsSendOutTxProcessed: res.Amount == 0, using original amount %f", amount)
//return false, false, nil
} else {
amount = -res.Amount
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/btc_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (signer *BTCSigner) TryProcessOutTx(send *types.CrossChainTx, outTxMan *Out
// Early return if the send is already processed
// FIXME: handle revert case
outboundTxTssNonce := params.OutboundTxTssNonce
included, confirmed, _ := btcClient.IsSendOutTxProcessed(send.Index, outboundTxTssNonce, common.CoinType_Gas, logger, float64(params.Amount.Uint64())/1e8)
included, confirmed, _ := btcClient.IsSendOutTxProcessed(send.Index, outboundTxTssNonce, common.CoinType_Gas, logger, params)
if included || confirmed {
logger.Info().Msgf("CCTX already processed; exit signer")
return
Expand Down
3 changes: 2 additions & 1 deletion zetaclient/chainclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

Expand All @@ -15,7 +16,7 @@ type ChainClient interface {
Start()
Stop()
//GetBaseGasPrice() *big.Int
IsSendOutTxProcessed(sendHash string, nonce uint64, cointype common.CoinType, logger zerolog.Logger, sendAmount float64) (bool, bool, error)
IsSendOutTxProcessed(sendHash string, nonce uint64, cointype common.CoinType, logger zerolog.Logger, params *types.OutboundTxParams) (bool, bool, error)
//PostNonceIfNotRecorded(logger zerolog.Logger) error
SetCoreParams(observertypes.CoreParams)
GetCoreParams() observertypes.CoreParams
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (ob *EVMChainClient) Stop() {

// returns: isIncluded, isConfirmed, Error
// If isConfirmed, it also post to ZetaCore
func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, cointype common.CoinType, logger zerolog.Logger, _ float64) (bool, bool, error) {
func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, cointype common.CoinType, logger zerolog.Logger, _ *types.OutboundTxParams) (bool, bool, error) {
ob.mu.Lock()
params := ob.params
receipt, found1 := ob.outTXConfirmedReceipts[ob.GetTxID(nonce)]
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/evm_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (signer *EVMSigner) TryProcessOutTx(send *types.CrossChainTx, outTxMan *Out
}

// Early return if the cctx is already processed
included, confirmed, err := evmClient.IsSendOutTxProcessed(send.Index, send.GetCurrentOutTxParam().OutboundTxTssNonce, send.GetCurrentOutTxParam().CoinType, logger, 0)
included, confirmed, err := evmClient.IsSendOutTxProcessed(send.Index, send.GetCurrentOutTxParam().OutboundTxTssNonce, send.GetCurrentOutTxParam().CoinType, logger, nil)
if err != nil {
logger.Error().Err(err).Msg("IsSendOutTxProcessed failed")
}
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/zetacore_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (co *CoreObserver) startSendScheduler() {
}

// Monitor Core Logger for OutboundTxTssNonce
included, _, err := ob.IsSendOutTxProcessed(send.Index, params.OutboundTxTssNonce, params.CoinType, co.logger.ZetaChainWatcher, float64(params.Amount.Uint64())/1e8)
included, _, err := ob.IsSendOutTxProcessed(send.Index, params.OutboundTxTssNonce, params.CoinType, co.logger.ZetaChainWatcher, params)
if err != nil {
co.logger.ZetaChainWatcher.Error().Err(err).Msgf("IsSendOutTxProcessed fail, Chain ID: %s", c.ChainName)
continue
Expand Down

0 comments on commit d7a7e72

Please sign in to comment.