From d21303f9ddac0c01fa5acb8a8dd98758daa73d15 Mon Sep 17 00:00:00 2001 From: rene <41963722+renaynay@users.noreply.github.com> Date: Thu, 6 Aug 2020 09:24:36 +0200 Subject: [PATCH] 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 --- cmd/geth/chaincmd.go | 13 +++++++------ cmd/geth/config.go | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index e98fe4c19..b98597e30 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -239,8 +239,7 @@ func initGenesis(ctx *cli.Context) error { if err := json.NewDecoder(file).Decode(genesis); err != nil { utils.Fatalf("invalid genesis file: %v", err) } - - // Open an initialise both full and light databases + // Open and initialise both full and light databases stack, _ := makeConfigNode(ctx) defer stack.Close() @@ -409,7 +408,8 @@ func importPreimages(ctx *cli.Context) error { if len(ctx.Args()) < 1 { utils.Fatalf("This command requires an argument.") } - stack, _ := makeFullNode(ctx) + + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack) @@ -427,7 +427,8 @@ func exportPreimages(ctx *cli.Context) error { if len(ctx.Args()) < 1 { utils.Fatalf("This command requires an argument.") } - stack, _ := makeFullNode(ctx) + + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack) @@ -449,7 +450,7 @@ func copyDb(ctx *cli.Context) error { utils.Fatalf("Source ancient chain directory path argument missing") } // Initialize a new chain for the running node to sync into - stack, _ := makeFullNode(ctx) + stack, _ := makeConfigNode(ctx) defer stack.Close() chain, chainDb := utils.MakeChain(ctx, stack, false) @@ -557,7 +558,7 @@ func confirmAndRemoveDB(database string, kind string) { } func dump(ctx *cli.Context) error { - stack, _ := makeFullNode(ctx) + stack, _ := makeConfigNode(ctx) defer stack.Close() chain, chainDb := utils.MakeChain(ctx, stack, true) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index a777f3705..5fa64abe3 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -105,6 +105,7 @@ func defaultNodeConfig() node.Config { return cfg } +// makeConfigNode loads geth configuration and creates a blank node instance. func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { // Load defaults. cfg := gethConfig{ @@ -145,6 +146,7 @@ func enableWhisper(ctx *cli.Context) bool { return false } +// makeFullNode loads geth configuration and creates the Ethereum backend. func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { stack, cfg := makeConfigNode(ctx)