Unverified Commit d21303f9 authored by rene's avatar rene Committed by GitHub

cmd/geth: fixes db unavailability for chain commands (#21415)

* chaincmd should make config nodes instead of full nodes

* add documentation for using makeConfigNode instead of makeFullNode;

* add documentation to functions

* code style
parent 4fde0cab
...@@ -239,8 +239,7 @@ func initGenesis(ctx *cli.Context) error { ...@@ -239,8 +239,7 @@ func initGenesis(ctx *cli.Context) error {
if err := json.NewDecoder(file).Decode(genesis); err != nil { if err := json.NewDecoder(file).Decode(genesis); err != nil {
utils.Fatalf("invalid genesis file: %v", err) utils.Fatalf("invalid genesis file: %v", err)
} }
// Open and initialise both full and light databases
// Open an initialise both full and light databases
stack, _ := makeConfigNode(ctx) stack, _ := makeConfigNode(ctx)
defer stack.Close() defer stack.Close()
...@@ -409,7 +408,8 @@ func importPreimages(ctx *cli.Context) error { ...@@ -409,7 +408,8 @@ func importPreimages(ctx *cli.Context) error {
if len(ctx.Args()) < 1 { if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.") utils.Fatalf("This command requires an argument.")
} }
stack, _ := makeFullNode(ctx)
stack, _ := makeConfigNode(ctx)
defer stack.Close() defer stack.Close()
db := utils.MakeChainDatabase(ctx, stack) db := utils.MakeChainDatabase(ctx, stack)
...@@ -427,7 +427,8 @@ func exportPreimages(ctx *cli.Context) error { ...@@ -427,7 +427,8 @@ func exportPreimages(ctx *cli.Context) error {
if len(ctx.Args()) < 1 { if len(ctx.Args()) < 1 {
utils.Fatalf("This command requires an argument.") utils.Fatalf("This command requires an argument.")
} }
stack, _ := makeFullNode(ctx)
stack, _ := makeConfigNode(ctx)
defer stack.Close() defer stack.Close()
db := utils.MakeChainDatabase(ctx, stack) db := utils.MakeChainDatabase(ctx, stack)
...@@ -449,7 +450,7 @@ func copyDb(ctx *cli.Context) error { ...@@ -449,7 +450,7 @@ func copyDb(ctx *cli.Context) error {
utils.Fatalf("Source ancient chain directory path argument missing") utils.Fatalf("Source ancient chain directory path argument missing")
} }
// Initialize a new chain for the running node to sync into // Initialize a new chain for the running node to sync into
stack, _ := makeFullNode(ctx) stack, _ := makeConfigNode(ctx)
defer stack.Close() defer stack.Close()
chain, chainDb := utils.MakeChain(ctx, stack, false) chain, chainDb := utils.MakeChain(ctx, stack, false)
...@@ -557,7 +558,7 @@ func confirmAndRemoveDB(database string, kind string) { ...@@ -557,7 +558,7 @@ func confirmAndRemoveDB(database string, kind string) {
} }
func dump(ctx *cli.Context) error { func dump(ctx *cli.Context) error {
stack, _ := makeFullNode(ctx) stack, _ := makeConfigNode(ctx)
defer stack.Close() defer stack.Close()
chain, chainDb := utils.MakeChain(ctx, stack, true) chain, chainDb := utils.MakeChain(ctx, stack, true)
......
...@@ -105,6 +105,7 @@ func defaultNodeConfig() node.Config { ...@@ -105,6 +105,7 @@ func defaultNodeConfig() node.Config {
return cfg return cfg
} }
// makeConfigNode loads geth configuration and creates a blank node instance.
func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
// Load defaults. // Load defaults.
cfg := gethConfig{ cfg := gethConfig{
...@@ -145,6 +146,7 @@ func enableWhisper(ctx *cli.Context) bool { ...@@ -145,6 +146,7 @@ func enableWhisper(ctx *cli.Context) bool {
return false return false
} }
// makeFullNode loads geth configuration and creates the Ethereum backend.
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
stack, cfg := makeConfigNode(ctx) stack, cfg := makeConfigNode(ctx)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment