Skip to content

Commit

Permalink
Merge branch 'develop' into test/admin-functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis authored Jan 20, 2024
2 parents 63b9502 + bd413ec commit b3b3e5d
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 31 deletions.
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

* [1577](https://github.com/zeta-chain/node/pull/1577) - add chain header tests in E2E tests and fix admin tests

### Features

### Fixes

* [1535](https://github.com/zeta-chain/node/issues/1535) - Avoid voting on wrong ballots due to false blockNumber in EVM tx receipt
* [1588](https://github.com/zeta-chain/node/pull/1588) - fix chain params comparison logic

## Version: v12.0.0

### Breaking Changes
Expand Down Expand Up @@ -39,6 +46,8 @@ Getting the correct TSS address for Bitcoin now requires proviidng the Bitcoin c

### Fixes

* [1576](https://github.com/zeta-chain/node/pull/1576) - Fix zetaclient crash due to out of bound integer conversion and log prints.
* [1575](https://github.com/zeta-chain/node/issues/1575) - Skip unsupported chain parameters by IsSupported flag
* [1554](https://github.com/zeta-chain/node/pull/1554) - Screen out unconfirmed UTXOs that are not created by TSS itself
* [1560](https://github.com/zeta-chain/node/issues/1560) - Zetaclient post evm-chain outtx hashes only when receipt is available
* [1516](https://github.com/zeta-chain/node/issues/1516) - Unprivileged outtx tracker removal
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ require (
github.com/cosmos/gogoproto v1.4.7
github.com/cosmos/iavl v0.19.6 // indirect
github.com/cosmos/ibc-go/v6 v6.1.0
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.4 // indirect
github.com/creachadair/taskgroup v0.3.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1
Expand Down Expand Up @@ -293,8 +293,8 @@ require (
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
gitlab.com/thorchain/binance-sdk v1.2.3-0.20210117202539-d569b6b9ba5d // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,8 @@ github.com/cosmos/iavl v0.19.6/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONAp
github.com/cosmos/ibc-go/v6 v6.1.0 h1:o7oXws2vKkKfOFzJI+oNylRn44PCNt5wzHd/zKQKbvQ=
github.com/cosmos/ibc-go/v6 v6.1.0/go.mod h1:CY3zh2HLfetRiW8LY6kVHMATe90Wj/UOoY8T6cuB0is=
github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY=
github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA=
github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI=
github.com/cosmos/ledger-cosmos-go v0.12.4 h1:drvWt+GJP7Aiw550yeb3ON/zsrgW0jgh5saFCr7pDnw=
github.com/cosmos/ledger-cosmos-go v0.12.4/go.mod h1:fjfVWRf++Xkygt9wzCsjEBdjcf7wiiY35fv3ctT+k4M=
github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9QWFanOyI=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
Expand Down Expand Up @@ -3037,11 +3037,11 @@ github.com/zeta-chain/keystone/keys v0.0.0-20231105174229-903bc9405da2/go.mod h1
github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20230816152528-db7d2bf9144b h1:aZRt5BtXdoDdyrUKwcv3B7mS30m/B854cjKjmnXBE5A=
github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20230816152528-db7d2bf9144b/go.mod h1:v79f+eY6PMpmLv188FAubst4XV2Mm8mUmx1OgmdFG3c=
github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=
github.com/zondax/hid v0.9.1 h1:gQe66rtmyZ8VeGFcOpbuH3r7erYtNEAezCAYu8LdkJo=
github.com/zondax/hid v0.9.1/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=
github.com/zondax/hid v0.9.2 h1:WCJFnEDMiqGF64nlZz28E9qLVZ0KSJ7xpc5DLEyma2U=
github.com/zondax/hid v0.9.2/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=
github.com/zondax/ledger-go v0.12.1/go.mod h1:KatxXrVDzgWwbssUWsF5+cOJHXPvzQ09YSlzGNuhOEo=
github.com/zondax/ledger-go v0.14.1 h1:Pip65OOl4iJ84WTpA4BKChvOufMhhbxED3BaihoZN4c=
github.com/zondax/ledger-go v0.14.1/go.mod h1:fZ3Dqg6qcdXWSOJFKMG8GCTnD7slO/RL2feOQv8K320=
github.com/zondax/ledger-go v0.14.3 h1:wEpJt2CEcBJ428md/5MgSLsXLBos98sBOyxNmCjfUCw=
github.com/zondax/ledger-go v0.14.3/go.mod h1:IKKaoxupuB43g4NxeQmbLXv7T9AlQyie1UpHb342ycI=
gitlab.com/bosi/decorder v0.2.3/go.mod h1:9K1RB5+VPNQYtXtTDAzd2OEftsZb1oV0IrJrzChSdGE=
gitlab.com/thorchain/binance-sdk v1.2.3-0.20210117202539-d569b6b9ba5d h1:GGPSI9gU22zW75m1YO7ZEMFtVEI5NgyK4g17CIXFjqI=
gitlab.com/thorchain/binance-sdk v1.2.3-0.20210117202539-d569b6b9ba5d/go.mod h1:SW01IZMpqlPNPdhHnn99qnJNvg8ll/agyyW7p85npwY=
Expand Down
18 changes: 18 additions & 0 deletions x/observer/types/chain_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,21 @@ func GetDefaultZetaPrivnetChainParams() *ChainParams {
IsSupported: false,
}
}

// ChainParamsEqual returns true if two chain params are equal
func ChainParamsEqual(params1, params2 ChainParams) bool {
return params1.ChainId == params2.ChainId &&
params1.ConfirmationCount == params2.ConfirmationCount &&
params1.ZetaTokenContractAddress == params2.ZetaTokenContractAddress &&
params1.ConnectorContractAddress == params2.ConnectorContractAddress &&
params1.Erc20CustodyContractAddress == params2.Erc20CustodyContractAddress &&
params1.InTxTicker == params2.InTxTicker &&
params1.OutTxTicker == params2.OutTxTicker &&
params1.WatchUtxoTicker == params2.WatchUtxoTicker &&
params1.GasPriceTicker == params2.GasPriceTicker &&
params1.OutboundTxScheduleInterval == params2.OutboundTxScheduleInterval &&
params1.OutboundTxScheduleLookahead == params2.OutboundTxScheduleLookahead &&
params1.BallotThreshold.Equal(params2.BallotThreshold) &&
params1.MinObserverDelegation.Equal(params2.MinObserverDelegation) &&
params1.IsSupported == params2.IsSupported
}
6 changes: 6 additions & 0 deletions x/observer/types/chain_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func TestUpdateChainParamsSuiteSuite(t *testing.T) {
suite.Run(t, new(UpdateChainParamsSuite))
}

func TestChainParamsEqual(t *testing.T) {
params := types.GetDefaultChainParams()
require.True(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[0]))
require.False(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[1]))
}

func (s *UpdateChainParamsSuite) SetupTest() {
s.evmParams = &types.ChainParams{
ConfirmationCount: 1,
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ func (ob *BitcoinChainClient) LoadLastBlock() error {
if ob.chain.ChainId == 18444 { // bitcoin regtest: start from block 100
ob.SetLastBlockHeightScanned(100)
}
ob.logger.ChainLogger.Info().Msgf("%s: start scanning from block %d", ob.chain.String(), ob.lastBlock)
ob.logger.ChainLogger.Info().Msgf("%s: start scanning from block %d", ob.chain.String(), ob.GetLastBlockHeightScanned())

return nil
}
Expand Down
39 changes: 27 additions & 12 deletions zetaclient/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type EVMLog struct {
const (
DonationMessage = "I am rich!"
TopicsZetaSent = 3 // [signature, zetaTxSenderAddress, destinationChainId] https://github.com/zeta-chain/protocol-contracts/blob/d65814debf17648a6c67d757ba03646415842790/contracts/evm/ZetaConnector.base.sol#L34
TopicsZetaReceived = 4 // [signature, sourceChainId, destinationAddress] https://github.com/zeta-chain/protocol-contracts/blob/d65814debf17648a6c67d757ba03646415842790/contracts/evm/ZetaConnector.base.sol#L45
TopicsZetaReceived = 4 // [signature, sourceChainId, destinationAddress, internalSendHash] https://github.com/zeta-chain/protocol-contracts/blob/d65814debf17648a6c67d757ba03646415842790/contracts/evm/ZetaConnector.base.sol#L45
TopicsZetaReverted = 3 // [signature, destinationChainId, internalSendHash] https://github.com/zeta-chain/protocol-contracts/blob/d65814debf17648a6c67d757ba03646415842790/contracts/evm/ZetaConnector.base.sol#L54
TopicsWithdrawn = 3 // [signature, recipient, asset] https://github.com/zeta-chain/protocol-contracts/blob/d65814debf17648a6c67d757ba03646415842790/contracts/evm/ERC20Custody.sol#L43
TopicsDeposited = 2 // [signature, asset] https://github.com/zeta-chain/protocol-contracts/blob/d65814debf17648a6c67d757ba03646415842790/contracts/evm/ERC20Custody.sol#L42
Expand Down Expand Up @@ -721,14 +721,29 @@ func (ob *EVMChainClient) checkConfirmedTx(txHash string, nonce uint64) (*ethtyp
return nil, nil, false
}

// check confirmations
confHeight := receipt.BlockNumber.Uint64() + ob.GetChainParams().ConfirmationCount
if confHeight >= math.MaxInt64 {
log.Error().Msgf("confirmTxByHash: confHeight is too large for txHash %s nonce %d", txHash, nonce)
// cross-check receipt against the block
block, err := ob.GetBlockByNumberCached(receipt.BlockNumber.Uint64())
if err != nil {
log.Error().Err(err).Msgf("confirmTxByHash: GetBlockByNumberCached error, txHash %s nonce %d block %d",
txHash, nonce, receipt.BlockNumber)
return nil, nil, false
}
// #nosec G701 non negative value
if receipt.TransactionIndex >= uint(len(block.Transactions())) {
log.Error().Msgf("confirmTxByHash: transaction index %d out of range [0, %d), txHash %s nonce %d block %d",
receipt.TransactionIndex, len(block.Transactions()), txHash, nonce, receipt.BlockNumber)
return nil, nil, false
}
if confHeight > ob.GetLastBlockHeight() {
log.Info().Msgf("confirmTxByHash: txHash %s nonce %d included but not confirmed: receipt block %d, current block %d",
txAtIndex := block.Transactions()[receipt.TransactionIndex]
if txAtIndex.Hash() != transaction.Hash() {
log.Error().Msgf("confirmTxByHash: transaction at index %d has different hash %s, txHash %s nonce %d block %d",
receipt.TransactionIndex, txAtIndex.Hash().Hex(), txHash, nonce, receipt.BlockNumber)
return nil, nil, false
}

// check confirmations
if !ob.HasEnoughConfirmations(receipt, ob.GetLastBlockHeight()) {
log.Debug().Msgf("confirmTxByHash: txHash %s nonce %d included but not confirmed: receipt block %d, current block %d",
txHash, nonce, receipt.BlockNumber, ob.GetLastBlockHeight())
return nil, nil, false
}
Expand Down Expand Up @@ -848,11 +863,11 @@ func (ob *EVMChainClient) observeInTX(sampledLogger zerolog.Logger) error {
}

// get and update latest block height
header, err := ob.evmClient.HeaderByNumber(context.Background(), nil)
blockNumber, err := ob.evmClient.BlockNumber(context.Background())
if err != nil {
return err
}
ob.SetLastBlockHeight(header.Number.Uint64())
ob.SetLastBlockHeight(blockNumber)

// increment prom counter
counter, err := ob.GetPromCounter("rpc_getBlockByNumber_count")
Expand All @@ -862,10 +877,10 @@ func (ob *EVMChainClient) observeInTX(sampledLogger zerolog.Logger) error {
counter.Inc()

// skip if current height is too low
if header.Number.Uint64() < ob.GetChainParams().ConfirmationCount {
return fmt.Errorf("observeInTX: skipping observer, current block number %d is too low", header.Number.Uint64())
if blockNumber < ob.GetChainParams().ConfirmationCount {
return fmt.Errorf("observeInTX: skipping observer, current block number %d is too low", blockNumber)
}
confirmedBlockNum := header.Number.Uint64() - ob.GetChainParams().ConfirmationCount
confirmedBlockNum := blockNumber - ob.GetChainParams().ConfirmationCount

// skip if no new block is confirmed
lastScanned := ob.GetLastBlockHeightScanned()
Expand Down
15 changes: 9 additions & 6 deletions zetaclient/zetacore_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ func (b *ZetaCoreBridge) UpdateConfigFromCore(cfg *config.Config, init bool) err
return err
}
if plan != nil && bn == plan.Height-1 { // stop zetaclients; notify operator to upgrade and restart
b.logger.Warn().Msgf("Active upgrade plan detected and upgrade height reached: %s at height %d; ZetaClient is stopped; please kill this process, replace zetaclientd binary with upgraded version, and restart zetaclientd", plan.Name, plan.Height)
b.logger.Warn().Msgf("Active upgrade plan detected and upgrade height reached: %s at height %d; ZetaClient is stopped;"+
"please kill this process, replace zetaclientd binary with upgraded version, and restart zetaclientd", plan.Name, plan.Height)
b.pause <- struct{}{} // notify CoreObserver to stop ChainClients, Signers, and CoreObservder itself
}

Expand All @@ -212,14 +213,16 @@ func (b *ZetaCoreBridge) UpdateConfigFromCore(cfg *config.Config, init bool) err
for _, chainParam := range chainParams {
err := config.ValidateChainParams(chainParam)
if err != nil {
b.logger.Debug().Err(err).Msgf(
"Invalid core params for chain %s",
common.GetChainFromChainID(chainParam.ChainId).ChainName,
)
b.logger.Warn().Err(err).Msgf("Invalid chain params for chain %d", chainParam.ChainId)
continue
}
if !chainParam.GetIsSupported() {
b.logger.Info().Msgf("Chain %d is not supported yet", chainParam.ChainId)
continue
}
if common.IsBitcoinChain(chainParam.ChainId) {
newBTCParams = chainParam
} else {
} else if common.IsEVMChain(chainParam.ChainId) {
newEVMParams[chainParam.ChainId] = chainParam
}
}
Expand Down
9 changes: 6 additions & 3 deletions zetaclient/zetacore_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package zetaclient

import (
"fmt"
"math"
"strings"
"time"

observertypes "github.com/zeta-chain/zetacore/x/observer/types"

sdkmath "cosmossdk.io/math"

"github.com/pkg/errors"
Expand Down Expand Up @@ -158,7 +161,7 @@ func (co *CoreObserver) startCctxScheduler() {
co.logger.ZetaChainWatcher.Error().Err(err).Msgf("couldn't get operator balance")
} else {
diff := co.lastOperatorBalance.Sub(balance)
if diff.GT(sdkmath.NewInt(0)) {
if diff.GT(sdkmath.NewInt(0)) && diff.LT(sdkmath.NewInt(math.MaxInt64)) {
co.ts.AddFeeEntry(bn, diff.Int64())
co.lastOperatorBalance = balance
}
Expand Down Expand Up @@ -355,7 +358,7 @@ func (co *CoreObserver) getUpdatedChainOb(chainID int64) (ChainClient, error) {
curParams := chainOb.GetChainParams()
if common.IsEVMChain(chainID) {
evmCfg, found := co.cfg.GetEVMConfig(chainID)
if found && curParams != evmCfg.ChainParams {
if found && !observertypes.ChainParamsEqual(curParams, evmCfg.ChainParams) {
chainOb.SetChainParams(evmCfg.ChainParams)
co.logger.ZetaChainWatcher.Info().Msgf(
"updated chain params for chainID %d, new params: %v",
Expand All @@ -365,7 +368,7 @@ func (co *CoreObserver) getUpdatedChainOb(chainID int64) (ChainClient, error) {
}
} else if common.IsBitcoinChain(chainID) {
_, btcCfg, found := co.cfg.GetBTCConfig()
if found && curParams != btcCfg.ChainParams {
if found && !observertypes.ChainParamsEqual(curParams, btcCfg.ChainParams) {
chainOb.SetChainParams(btcCfg.ChainParams)
co.logger.ZetaChainWatcher.Info().Msgf(
"updated chain params for Bitcoin, new params: %v",
Expand Down

0 comments on commit b3b3e5d

Please sign in to comment.