Skip to content

Commit 0f7197f

Browse files
author
yihuang
authored
Merge pull request #201 from mmsqe/release/v0.47.x_revert
Revert "fix(server): consensus failure while restart node with wrong chainId
2 parents 5910717 + fbb68a1 commit 0f7197f

File tree

2 files changed

+3
-38
lines changed

2 files changed

+3
-38
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
5656
### Bug Fixes
5757

5858
* [#19106](https://github.com/cosmos/cosmos-sdk/pull/19106) Allow empty public keys when setting signatures. Public keys aren't needed for every transaction.
59-
* (server) [#18920](https://github.com/cosmos/cosmos-sdk/pull/18920) Fixes consensus failure while restart node with wrong `chainId` in genesis.
6059

6160
## [v0.47.7](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.7) - 2023-12-20
6261

server/util.go

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
2626
tmcfg "github.com/cometbft/cometbft/config"
2727
tmlog "github.com/cometbft/cometbft/libs/log"
28-
"github.com/cometbft/cometbft/node"
29-
tmstore "github.com/cometbft/cometbft/store"
3028
tmtypes "github.com/cometbft/cometbft/types"
3129

3230
"github.com/cosmos/cosmos-sdk/baseapp"
@@ -461,13 +459,13 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) {
461459
homeDir := cast.ToString(appOpts.Get(flags.FlagHome))
462460
chainID := cast.ToString(appOpts.Get(flags.FlagChainID))
463461
if chainID == "" {
464-
// read the chainID from home directory (either from comet or genesis).
465-
chainId, err := readChainIdFromHome(homeDir)
462+
// fallback to genesis chain-id
463+
appGenesis, err := tmtypes.GenesisDocFromFile(filepath.Join(homeDir, "config", "genesis.json"))
466464
if err != nil {
467465
panic(err)
468466
}
469467

470-
chainID = chainId
468+
chainID = appGenesis.ChainID
471469
}
472470

473471
snapshotStore, err := GetSnapshotStore(appOpts)
@@ -502,38 +500,6 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) {
502500
}
503501
}
504502

505-
// readChainIdFromHome reads chain id from home directory.
506-
func readChainIdFromHome(homeDir string) (string, error) {
507-
cfg := tmcfg.DefaultConfig()
508-
cfg.SetRoot(homeDir)
509-
510-
// if the node's current height is not zero then try to read the chainID from comet db.
511-
db, err := node.DefaultDBProvider(&node.DBContext{ID: "blockstore", Config: cfg})
512-
if err != nil {
513-
return "", err
514-
}
515-
516-
blockStore := tmstore.NewBlockStore(db)
517-
defer func() {
518-
if err := blockStore.Close(); err != nil {
519-
panic(err)
520-
}
521-
}()
522-
523-
// if the blockStore.LoadBaseMeta() is nil (no blocks are created/synced so far), fallback to genesis chain-id.
524-
baseMeta := blockStore.LoadBaseMeta()
525-
if baseMeta != nil {
526-
return baseMeta.Header.ChainID, nil
527-
}
528-
529-
appGenesis, err := tmtypes.GenesisDocFromFile(filepath.Join(homeDir, "config", "genesis.json"))
530-
if err != nil {
531-
return "", err
532-
}
533-
534-
return appGenesis.ChainID, nil
535-
}
536-
537503
func GetSnapshotStore(appOpts types.AppOptions) (*snapshots.Store, error) {
538504
homeDir := cast.ToString(appOpts.Get(flags.FlagHome))
539505
snapshotDir := filepath.Join(homeDir, "data", "snapshots")

0 commit comments

Comments
 (0)