diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-04-11 18:21:47 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-04-11 18:21:47 +0800 |
commit | 8abf06d378e3f6512dfce6e74d76431de024fad7 (patch) | |
tree | f92ed05c9d9e15e3cf77bd73955608e42a422739 /cmd | |
parent | a7161caedf865e3e777473bc676286d2a376afbb (diff) | |
parent | 4081868452ba5cdb92ae5d2cee8d055f20fcf4aa (diff) | |
download | dexon-8abf06d378e3f6512dfce6e74d76431de024fad7.tar.gz dexon-8abf06d378e3f6512dfce6e74d76431de024fad7.tar.zst dexon-8abf06d378e3f6512dfce6e74d76431de024fad7.zip |
Merge pull request #2430 from bas-vk/chaincmd
cmd/utils: bugfix where database is opened multiple times
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/utils/flags.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 2f10938e3..a2927108f 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -776,16 +776,20 @@ func SetupNetwork(ctx *cli.Context) { params.TargetGasLimit = common.String2Big(ctx.GlobalString(TargetGasLimitFlag.Name)) } -// MustMakeChainConfig reads the chain configuration from the given database. +// MustMakeChainConfig reads the chain configuration from the database in ctx.Datadir. func MustMakeChainConfig(ctx *cli.Context) *core.ChainConfig { - var ( - db = MakeChainDatabase(ctx) - genesis = core.GetBlock(db, core.GetCanonicalHash(db, 0)) - ) + db := MakeChainDatabase(ctx) defer db.Close() + return MustMakeChainConfigFromDb(ctx, db) +} + +// MustMakeChainConfigFromDb reads the chain configuration from the given database. +func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfig { + genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0)) + if genesis != nil { - // Exsting genesis block, use stored config if available. + // Existing genesis block, use stored config if available. storedConfig, err := core.GetChainConfig(db, genesis.Hash()) if err == nil { return storedConfig @@ -829,7 +833,7 @@ func MakeChain(ctx *cli.Context) (chain *core.BlockChain, chainDb ethdb.Database } } - chainConfig := MustMakeChainConfig(ctx) + chainConfig := MustMakeChainConfigFromDb(ctx, chainDb) var eventMux event.TypeMux chain, err = core.NewBlockChain(chainDb, chainConfig, ethash.New(), &eventMux) |