From 8023a4b2b4455262cc18585cca9f937f73ec7eed Mon Sep 17 00:00:00 2001 From: skosito Date: Fri, 8 Mar 2024 15:10:32 +0100 Subject: [PATCH] Remove duplicate ValidateChainParams function --- zetaclient/config/types.go | 63 ------------------------ zetaclient/zetabridge/zetacore_bridge.go | 2 +- 2 files changed, 1 insertion(+), 64 deletions(-) diff --git a/zetaclient/config/types.go b/zetaclient/config/types.go index 200066f109..69e4e8da2c 100644 --- a/zetaclient/config/types.go +++ b/zetaclient/config/types.go @@ -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 @@ -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) -} diff --git a/zetaclient/zetabridge/zetacore_bridge.go b/zetaclient/zetabridge/zetacore_bridge.go index 9e5a38ca11..58243136a2 100644 --- a/zetaclient/zetabridge/zetacore_bridge.go +++ b/zetaclient/zetabridge/zetacore_bridge.go @@ -218,7 +218,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