Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/use-GetParamsIfExist
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis authored Mar 15, 2024
2 parents 89e86bf + ce26536 commit fa948ce
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 64 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [1864](https://github.com/zeta-chain/node/pull/1864) - prevent panic in param management
* [1848](https://github.com/zeta-chain/node/issues/1848) - create a method to observe deposits to tss address in one evm block
* [1885](https://github.com/zeta-chain/node/pull/1885) - change important metrics on port 8123 to be prometheus compatible
* [1863](https://github.com/zeta-chain/node/pull/1863) - remove duplicate ValidateChainParams function

### Features

Expand Down
63 changes: 0 additions & 63 deletions zetaclient/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ package config

import (
"encoding/json"
"fmt"
"strings"
"sync"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/zeta-chain/zetacore/common"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

// KeyringBackend is the type of keyring backend to use for the hotkey
Expand Down Expand Up @@ -138,63 +135,3 @@ func (c *Config) GetKeyringBackend() KeyringBackend {
defer c.cfgLock.RUnlock()
return c.KeyringBackend
}

// TODO: remove this duplicated function https://github.com/zeta-chain/node/issues/1838
// ValidateChainParams performs some basic checks on core params
func ValidateChainParams(chainParams *observertypes.ChainParams) error {
if chainParams == nil {
return fmt.Errorf("invalid chain params: nil")
}
chain := common.GetChainFromChainID(chainParams.ChainId)
if chain == nil {
return fmt.Errorf("invalid chain params: chain %d not supported", chainParams.ChainId)
}
if chainParams.ConfirmationCount < 1 {
return fmt.Errorf("invalid chain params: ConfirmationCount %d", chainParams.ConfirmationCount)
}
// zeta chain skips the rest of the checks for now
if chain.IsZetaChain() {
return nil
}

// check tickers
if chainParams.GasPriceTicker < 1 {
return fmt.Errorf("invalid chain params: GasPriceTicker %d", chainParams.GasPriceTicker)
}
if chainParams.InTxTicker < 1 {
return fmt.Errorf("invalid chain params: InTxTicker %d", chainParams.InTxTicker)
}
if chainParams.OutTxTicker < 1 {
return fmt.Errorf("invalid chain params: OutTxTicker %d", chainParams.OutTxTicker)
}
if chainParams.OutboundTxScheduleInterval < 1 {
return fmt.Errorf("invalid chain params: OutboundTxScheduleInterval %d", chainParams.OutboundTxScheduleInterval)
}
if chainParams.OutboundTxScheduleLookahead < 1 {
return fmt.Errorf("invalid chain params: OutboundTxScheduleLookahead %d", chainParams.OutboundTxScheduleLookahead)
}

// chain type specific checks
if common.IsBitcoinChain(chainParams.ChainId) && chainParams.WatchUtxoTicker < 1 {
return fmt.Errorf("invalid chain params: watchUtxo ticker %d", chainParams.WatchUtxoTicker)
}
if common.IsEVMChain(chainParams.ChainId) {
if !validCoreContractAddress(chainParams.ZetaTokenContractAddress) {
return fmt.Errorf("invalid chain params: zeta token contract address %s", chainParams.ZetaTokenContractAddress)
}
if !validCoreContractAddress(chainParams.ConnectorContractAddress) {
return fmt.Errorf("invalid chain params: connector contract address %s", chainParams.ConnectorContractAddress)
}
if !validCoreContractAddress(chainParams.Erc20CustodyContractAddress) {
return fmt.Errorf("invalid chain params: erc20 custody contract address %s", chainParams.Erc20CustodyContractAddress)
}
}
return nil
}

func validCoreContractAddress(address string) bool {
if !strings.HasPrefix(address, "0x") {
return false
}
return ethcommon.IsHexAddress(address)
}
2 changes: 1 addition & 1 deletion zetaclient/zetabridge/zetacore_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (b *ZetaCoreBridge) UpdateZetaCoreContext(coreContext *corecontext.ZetaCore

// check and update chain params for each chain
for _, chainParam := range chainParams {
err := config.ValidateChainParams(chainParam)
err := observertypes.ValidateChainParams(chainParam)
if err != nil {
b.logger.Warn().Err(err).Msgf("Invalid chain params for chain %d", chainParam.ChainId)
continue
Expand Down

0 comments on commit fa948ce

Please sign in to comment.