Skip to content

Commit

Permalink
Remove duplicate ValidateChainParams function
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Mar 8, 2024
1 parent f8e8565 commit 8023a4b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 64 deletions.
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 @@ -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
Expand Down

0 comments on commit 8023a4b

Please sign in to comment.