From 83568e2ae64f42a19a4c889f6decc6cca7c42527 Mon Sep 17 00:00:00 2001 From: Charlie Chen <34498985+ws4charlie@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:11:11 -0600 Subject: [PATCH] fix: Trailofbits - make sure block number always increases (#1639) * make sure block number always increases * update changelog * added log prints * update changelog --------- Co-authored-by: Lucas Bertrand --- changelog.md | 1 + zetaclient/bitcoin_client.go | 12 ++++++++---- zetaclient/evm_client.go | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index d68bff7e2e..4ad8ef044f 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ ### Fixes +* [1638](https://github.com/zeta-chain/node/issues/1638) - additional check to make sure external chain height always increases * [1672](https://github.com/zeta-chain/node/pull/1672) - paying 50% more than base gas price to buffer EIP1559 gas price increase * [1642](https://github.com/zeta-chain/node/pull/1642) - Change WhitelistERC20 authorization from group1 to group2 * [1610](https://github.com/zeta-chain/node/issues/1610) - add pending outtx hash to tracker after monitoring for 10 minutes diff --git a/zetaclient/bitcoin_client.go b/zetaclient/bitcoin_client.go index d802d2b953..5dee82bdb8 100644 --- a/zetaclient/bitcoin_client.go +++ b/zetaclient/bitcoin_client.go @@ -372,10 +372,13 @@ func (ob *BitcoinChainClient) observeInTx() error { // get and update latest block height cnt, err := ob.rpcClient.GetBlockCount() if err != nil { - return fmt.Errorf("observeInTxBTC: error getting block count: %s", err) + return fmt.Errorf("observeInTxBTC: error getting block number: %s", err) } if cnt < 0 { - return fmt.Errorf("observeInTxBTC: block count is negative: %d", cnt) + return fmt.Errorf("observeInTxBTC: block number is negative: %d", cnt) + } + if cnt < ob.GetLastBlockHeight() { + return fmt.Errorf("observeInTxBTC: block number should not decrease: current %d last %d", cnt, ob.GetLastBlockHeight()) } ob.SetLastBlockHeight(cnt) @@ -439,7 +442,7 @@ func (ob *BitcoinChainClient) observeInTx() error { ob.logger.WatchInTx.Error().Err(err).Msgf("observeInTxBTC: error posting to zeta core for tx %s", inTx.TxHash) return err // we have to re-scan this block next time } else if zetaHash != "" { - ob.logger.WatchInTx.Info().Msgf("observeInTxBTC: BTC deposit detected and reported: PostVoteInbound zeta tx: %s ballot %s", zetaHash, ballot) + ob.logger.WatchInTx.Info().Msgf("observeInTxBTC: PostVoteInbound zeta tx hash: %s inTx %s ballot %s", zetaHash, inTx.TxHash, ballot) } } @@ -633,11 +636,12 @@ func FilterAndParseIncomingTx( } inTx, err := GetBtcEvent(tx, targetAddress, blockNumber, logger, chainID) if err != nil { - logger.Error().Err(err).Msg("error getting btc event") + logger.Error().Err(err).Msgf("FilterAndParseIncomingTx: error getting btc event for tx %s in block %d", tx.Txid, blockNumber) continue } if inTx != nil { inTxs = append(inTxs, inTx) + logger.Info().Msgf("FilterAndParseIncomingTx: found btc event for tx %s in block %d", tx.Txid, blockNumber) } } return inTxs diff --git a/zetaclient/evm_client.go b/zetaclient/evm_client.go index 8d5b78655e..a4cf459c8b 100644 --- a/zetaclient/evm_client.go +++ b/zetaclient/evm_client.go @@ -940,6 +940,9 @@ func (ob *EVMChainClient) observeInTX(sampledLogger zerolog.Logger) error { if err != nil { return err } + if blockNumber < ob.GetLastBlockHeight() { + return fmt.Errorf("observeInTX: block number should not decrease: current %d last %d", blockNumber, ob.GetLastBlockHeight()) + } ob.SetLastBlockHeight(blockNumber) // increment prom counter