@@ -25,8 +25,6 @@ import (
25
25
tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
26
26
tmcfg "github.com/cometbft/cometbft/config"
27
27
tmlog "github.com/cometbft/cometbft/libs/log"
28
- "github.com/cometbft/cometbft/node"
29
- tmstore "github.com/cometbft/cometbft/store"
30
28
tmtypes "github.com/cometbft/cometbft/types"
31
29
32
30
"github.com/cosmos/cosmos-sdk/baseapp"
@@ -461,13 +459,13 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) {
461
459
homeDir := cast .ToString (appOpts .Get (flags .FlagHome ))
462
460
chainID := cast .ToString (appOpts .Get (flags .FlagChainID ))
463
461
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" ) )
466
464
if err != nil {
467
465
panic (err )
468
466
}
469
467
470
- chainID = chainId
468
+ chainID = appGenesis . ChainID
471
469
}
472
470
473
471
snapshotStore , err := GetSnapshotStore (appOpts )
@@ -502,38 +500,6 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) {
502
500
}
503
501
}
504
502
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
-
537
503
func GetSnapshotStore (appOpts types.AppOptions ) (* snapshots.Store , error ) {
538
504
homeDir := cast .ToString (appOpts .Get (flags .FlagHome ))
539
505
snapshotDir := filepath .Join (homeDir , "data" , "snapshots" )
0 commit comments