Skip to content

Commit

Permalink
cmd/geth: fixes db unavailability for chain commands (ethereum#21415)
Browse files Browse the repository at this point in the history
* chaincmd should make config nodes instead of full nodes

* add documentation for using makeConfigNode instead of makeFullNode;

* add documentation to functions

* code style
  • Loading branch information
renaynay authored Aug 6, 2020
1 parent 4fde0ca commit d21303f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit d21303f

Please sign in to comment.