Skip to content

Commit

Permalink
Release/v0.19.17.3 (#1260)
Browse files Browse the repository at this point in the history
* Validate Chain-id and GenesisHeight while app starts

* Validate Chain-id and GenesisHeight while app starts

* Validate Chain-id and GenesisHeight while app starts
  • Loading branch information
lcmmhcc authored Dec 8, 2021
1 parent fb9021b commit 41a7567
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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{}) {
Expand All @@ -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)

Expand Down
20 changes: 20 additions & 0 deletions app/types/chain_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 <make mainnet> to rebuild if chain-id is <%s>, Current GenesisHeight is <%d>", chainID, tendermintTypes.GetStartBlockHeight())
}
if isTestNetChainID(chainID) && !tendermintTypes.IsTestNet() {
return fmt.Errorf("Must use <make testnet> to rebuild if chain-id is <%s>, Current GenesisHeight is <%d>", chainID, tendermintTypes.GetStartBlockHeight())
}
return nil
}
4 changes: 3 additions & 1 deletion cmd/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion libs/tendermint/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -1208,4 +1208,4 @@ func IsMainNet() bool {
// 1121818 is testnet GenesisHeight
func IsTestNet() bool {
return startBlockHeightStr == "1121818"
}
}

0 comments on commit 41a7567

Please sign in to comment.