From ac732fd8144f107339d3c5ee3134b3348a0a2711 Mon Sep 17 00:00:00 2001 From: araskachoi Date: Thu, 28 Jan 2021 17:39:54 -0800 Subject: [PATCH] fix chainid error --- server/start.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/start.go b/server/start.go index c1a190556..c339c811c 100644 --- a/server/start.go +++ b/server/start.go @@ -19,6 +19,7 @@ import ( pvm "github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/rpc/client/local" + tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -76,6 +77,21 @@ which accepts a path for the resulting pprof file. serverCtx := sdkserver.GetServerContextFromCmd(cmd) clientCtx := client.GetClientContextFromCmd(cmd) + // validate genesis file before running start + var genesisf string + + clientCtx.ChainID, _ = cmd.Flags().GetString(flags.FlagChainID) + if clientCtx.ChainID == "" { + genesisf = serverCtx.Config.GenesisFile() + genDoc, err := tmtypes.GenesisDocFromFile(genesisf) + if err != nil { + return fmt.Errorf("%s - chainID could not be found", + err.Error(), + ) + } + clientCtx.ChainID = genDoc.ChainID + } + withTM, _ := cmd.Flags().GetBool(flagWithTendermint) if !withTM { serverCtx.Logger.Info("starting ABCI without Tendermint") @@ -120,6 +136,8 @@ which accepts a path for the resulting pprof file. cmd.Flags().Uint64(sdkserver.FlagStateSyncSnapshotInterval, 0, "State sync snapshot interval") cmd.Flags().Uint32(sdkserver.FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep") + cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") + // add support for all Tendermint-specific command line options tcmd.AddNodeFlags(cmd) return cmd