Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down