cmd/{geth,utils}: read genesis block from db in chain import

Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
This commit is contained in:
Guillaume Ballet 2024-12-06 18:43:03 +01:00
parent 67a3b08795
commit f5266f3e8f
2 changed files with 11 additions and 1 deletions

View file

@ -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

View file

@ -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)