diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index f6dc1cf4bf..842d1ffe04 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -290,7 +290,13 @@ func importChain(ctx *cli.Context) error { stack, _ := makeConfigNode(ctx) defer stack.Close() - chain, db := utils.MakeChain(ctx, stack, false) + db := utils.MakeChainDatabase(ctx, stack, false) + + // if the error is not nil, no genesis is present in the db and so the default + // behavior of creating the genesis block applies. + genesis, _ := core.ReadGenesis(db) + + chain, db := utils.MakeChainWithGenesisBlockAndChainDB(genesis, db, ctx, stack, false) defer db.Close() // Start periodically gathering memory profiles diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 9f309286bd..7ed6aae168 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2138,6 +2138,10 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh gspec = MakeGenesis(ctx) chainDb = MakeChainDatabase(ctx, stack, readonly) ) + return MakeChainWithGenesisBlockAndChainDB(gspec, chainDb, ctx, stack, readonly) +} + +func MakeChainWithGenesisBlockAndChainDB(gspec *core.Genesis, chainDb ethdb.Database, ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockChain, ethdb.Database) { config, err := core.LoadChainConfig(chainDb, gspec) if err != nil { Fatalf("%v", err)