Skip to content

Commit

Permalink
make sure block number always increases
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Jan 25, 2024
1 parent b2826b7 commit 3ae445d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions zetaclient/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,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)

Expand Down
3 changes: 3 additions & 0 deletions zetaclient/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,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
Expand Down

0 comments on commit 3ae445d

Please sign in to comment.