diff --git a/Makefile b/Makefile index fa76402e2d..219e85d199 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ export GO111MODULE=on GithubTop=github.com -Version=v0.19.17.2 +Version=v0.19.17.3 CosmosSDK=v0.39.2 Tendermint=v0.33.9 Iavl=v0.14.3 diff --git a/app/app.go b/app/app.go index 8cb53b421c..741fa993d8 100644 --- a/app/app.go +++ b/app/app.go @@ -14,6 +14,7 @@ import ( "github.com/okex/exchain/app/refund" okexchain "github.com/okex/exchain/app/types" bam "github.com/okex/exchain/libs/cosmos-sdk/baseapp" + "github.com/okex/exchain/libs/cosmos-sdk/client/flags" "github.com/okex/exchain/libs/cosmos-sdk/codec" "github.com/okex/exchain/libs/cosmos-sdk/server" "github.com/okex/exchain/libs/cosmos-sdk/server/config" @@ -32,6 +33,7 @@ import ( "github.com/okex/exchain/libs/tendermint/crypto/tmhash" "github.com/okex/exchain/libs/tendermint/libs/log" tmos "github.com/okex/exchain/libs/tendermint/libs/os" + tendermintTypes "github.com/okex/exchain/libs/tendermint/types" "github.com/okex/exchain/x/ammswap" "github.com/okex/exchain/x/backend" "github.com/okex/exchain/x/common/analyzer" @@ -56,6 +58,7 @@ import ( "github.com/okex/exchain/x/staking" "github.com/okex/exchain/x/stream" "github.com/okex/exchain/x/token" + "github.com/spf13/viper" dbm "github.com/tendermint/tm-db" ) @@ -193,6 +196,7 @@ func NewOKExChainApp( invCheckPeriod uint, baseAppOptions ...func(*bam.BaseApp), ) *OKExChainApp { + logger.Info(fmt.Sprintf("GenesisHeight<%d>", tendermintTypes.GetStartBlockHeight())) onceLog.Do(func() { iavllog := logger.With("module", "iavl") logFunc := func(level int, format string, args ...interface{}) { @@ -216,6 +220,11 @@ func NewOKExChainApp( logger.Error(fmt.Sprintf("the config of OKExChain was parsed error : %s", err.Error())) panic(err) } + chainId := viper.GetString(flags.FlagChainID) + if err = okexchain.IsValidateChainIdWithGenesisHeight(chainId); err != nil { + logger.Error(err.Error()) + panic(err) + } cdc := okexchaincodec.MakeCodec(ModuleBasics) diff --git a/app/types/chain_id.go b/app/types/chain_id.go index c83d30934b..a49b9cae31 100644 --- a/app/types/chain_id.go +++ b/app/types/chain_id.go @@ -7,6 +7,7 @@ import ( "strings" sdkerrors "github.com/okex/exchain/libs/cosmos-sdk/types/errors" + tendermintTypes "github.com/okex/exchain/libs/tendermint/types" ) var ( @@ -16,6 +17,9 @@ var ( ethermintChainID = regexp.MustCompile(fmt.Sprintf(`^(%s)%s(%s)$`, regexChainID, regexSeparator, regexEpoch)) ) +const mainnetChainId = "exchain-66" +const testnetChainId = "exchain-65" + // IsValidChainID returns false if the given chain identifier is incorrectly formatted. func IsValidChainID(chainID string) bool { if len(chainID) > 48 { @@ -24,6 +28,12 @@ func IsValidChainID(chainID string) bool { return ethermintChainID.MatchString(chainID) } +func isMainNetChainID(chainID string) bool { + return chainID == mainnetChainId +} +func isTestNetChainID(chainID string) bool { + return chainID == testnetChainId +} // ParseChainID parses a string chain identifier's epoch to an Ethereum-compatible // chain-id in *big.Int format. The function returns an error if the chain-id has an invalid format @@ -46,3 +56,13 @@ func ParseChainID(chainID string) (*big.Int, error) { return chainIDInt, nil } + +func IsValidateChainIdWithGenesisHeight(chainID string) error { + if isMainNetChainID(chainID) && !tendermintTypes.IsMainNet() { + return fmt.Errorf("Must use to rebuild if chain-id is <%s>, Current GenesisHeight is <%d>", chainID, tendermintTypes.GetStartBlockHeight()) + } + if isTestNetChainID(chainID) && !tendermintTypes.IsTestNet() { + return fmt.Errorf("Must use to rebuild if chain-id is <%s>, Current GenesisHeight is <%d>", chainID, tendermintTypes.GetStartBlockHeight()) + } + return nil +} diff --git a/cmd/client/config.go b/cmd/client/config.go index 49572c5fcc..76a734d2e0 100644 --- a/cmd/client/config.go +++ b/cmd/client/config.go @@ -54,7 +54,9 @@ func ValidateChainID(baseCmd *cobra.Command) *cobra.Command { if !ethermint.IsValidChainID(chainID) { return fmt.Errorf("invalid chain-id format: %s", chainID) } - + if err := ethermint.IsValidateChainIdWithGenesisHeight(chainID); err != nil { + return err + } return baseRunE(cmd, args) } diff --git a/libs/tendermint/types/block.go b/libs/tendermint/types/block.go index 7adebd26bc..241cd416c8 100644 --- a/libs/tendermint/types/block.go +++ b/libs/tendermint/types/block.go @@ -1208,4 +1208,4 @@ func IsMainNet() bool { // 1121818 is testnet GenesisHeight func IsTestNet() bool { return startBlockHeightStr == "1121818" -} \ No newline at end of file +}