diff --git a/CHANGELOG.md b/CHANGELOG.md index 166f12ae0498..10ff12c2c93b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +56,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * [#19106](https://github.com/cosmos/cosmos-sdk/pull/19106) Allow empty public keys when setting signatures. Public keys aren't needed for every transaction. -* (server) [#18920](https://github.com/cosmos/cosmos-sdk/pull/18920) Fixes consensus failure while restart node with wrong `chainId` in genesis. ## [v0.47.7](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.7) - 2023-12-20 diff --git a/server/util.go b/server/util.go index 2348fb4c1634..98c193ad77e6 100644 --- a/server/util.go +++ b/server/util.go @@ -25,8 +25,6 @@ import ( tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" tmcfg "github.com/cometbft/cometbft/config" tmlog "github.com/cometbft/cometbft/libs/log" - "github.com/cometbft/cometbft/node" - tmstore "github.com/cometbft/cometbft/store" tmtypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/baseapp" @@ -461,13 +459,13 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) if chainID == "" { - // read the chainID from home directory (either from comet or genesis). - chainId, err := readChainIdFromHome(homeDir) + // fallback to genesis chain-id + appGenesis, err := tmtypes.GenesisDocFromFile(filepath.Join(homeDir, "config", "genesis.json")) if err != nil { panic(err) } - chainID = chainId + chainID = appGenesis.ChainID } snapshotStore, err := GetSnapshotStore(appOpts) @@ -502,38 +500,6 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { } } -// readChainIdFromHome reads chain id from home directory. -func readChainIdFromHome(homeDir string) (string, error) { - cfg := tmcfg.DefaultConfig() - cfg.SetRoot(homeDir) - - // if the node's current height is not zero then try to read the chainID from comet db. - db, err := node.DefaultDBProvider(&node.DBContext{ID: "blockstore", Config: cfg}) - if err != nil { - return "", err - } - - blockStore := tmstore.NewBlockStore(db) - defer func() { - if err := blockStore.Close(); err != nil { - panic(err) - } - }() - - // if the blockStore.LoadBaseMeta() is nil (no blocks are created/synced so far), fallback to genesis chain-id. - baseMeta := blockStore.LoadBaseMeta() - if baseMeta != nil { - return baseMeta.Header.ChainID, nil - } - - appGenesis, err := tmtypes.GenesisDocFromFile(filepath.Join(homeDir, "config", "genesis.json")) - if err != nil { - return "", err - } - - return appGenesis.ChainID, nil -} - func GetSnapshotStore(appOpts types.AppOptions) (*snapshots.Store, error) { homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) snapshotDir := filepath.Join(homeDir, "data", "snapshots")