From 663b037c93880c48262009400a38595345b2299c Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 11 Apr 2023 15:16:22 +0800 Subject: [PATCH 01/17] node: add a switch of open datadir or not Signed-off-by: jsvisa --- node/config.go | 4 ++++ node/node.go | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/node/config.go b/node/config.go index 37a7d5837fa2..fe4a1b8c999f 100644 --- a/node/config.go +++ b/node/config.go @@ -203,7 +203,11 @@ type Config struct { // EnablePersonal enables the deprecated personal namespace. EnablePersonal bool `toml:"-"` + // DBEngine is the backing database implementation to use DBEngine string `toml:",omitempty"` + + // NoOpenDataDir stands for weather or not opens the datadir + NoOpenDataDir bool `toml:"-"` } // IPCEndpoint resolves an IPC endpoint based on a configured value, taking into diff --git a/node/node.go b/node/node.go index 2f89bc1ad274..2423bc6c7b93 100644 --- a/node/node.go +++ b/node/node.go @@ -116,8 +116,10 @@ func New(conf *Config) (*Node, error) { node.rpcAPIs = append(node.rpcAPIs, node.apis()...) // Acquire the instance directory lock. - if err := node.openDataDir(); err != nil { - return nil, err + if !conf.NoOpenDataDir { + if err := node.openDataDir(); err != nil { + return nil, err + } } keyDir, isEphem, err := getKeyStoreDir(conf) if err != nil { From caa6047e8e178fd32639e2970945e4820ee350a5 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 11 Apr 2023 15:36:27 +0800 Subject: [PATCH 02/17] cmd/geth: make config node support openDataDir or not Signed-off-by: jsvisa --- cmd/geth/config.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 0b856d1c1b7a..3268c0c43ea3 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -120,13 +120,14 @@ func defaultNodeConfig() node.Config { } // makeConfigNode loads geth configuration and creates a blank node instance. -func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { +func makeConfigNode(ctx *cli.Context, openDataDir bool) (*node.Node, gethConfig) { // Load defaults. cfg := gethConfig{ Eth: ethconfig.Defaults, Node: defaultNodeConfig(), Metrics: metrics.DefaultConfig, } + cfg.Node.NoOpenDataDir = !openDataDir // Load config file. if file := ctx.String(configFileFlag.Name); file != "" { From 2595bd20ea73a37ed515e97412b3513a0dd86541 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 11 Apr 2023 15:44:09 +0800 Subject: [PATCH 03/17] cmd/geth: don't open datadir in accountcmd Signed-off-by: jsvisa --- cmd/geth/accountcmd.go | 8 ++++---- cmd/geth/chaincmd.go | 14 +++++++------- cmd/geth/config.go | 4 ++-- cmd/geth/dbcmd.go | 32 ++++++++++++++++---------------- cmd/geth/snapshot.go | 14 +++++++------- cmd/geth/verkle.go | 4 ++-- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index a36da7d55f2c..6356ffa5d8ca 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -189,7 +189,7 @@ nodes. ) func accountList(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, false) var index int for _, wallet := range stack.AccountManager().Wallets() { for _, account := range wallet.Accounts() { @@ -300,7 +300,7 @@ func accountUpdate(ctx *cli.Context) error { if ctx.Args().Len() == 0 { utils.Fatalf("No accounts specified to update") } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, false) backends := stack.AccountManager().Backends(keystore.KeyStoreType) if len(backends) == 0 { utils.Fatalf("Keystore is not available") @@ -327,7 +327,7 @@ func importWallet(ctx *cli.Context) error { utils.Fatalf("Could not read wallet file: %v", err) } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, false) passphrase := utils.GetPassPhraseWithList("", false, 0, utils.MakePasswordList(ctx)) backends := stack.AccountManager().Backends(keystore.KeyStoreType) @@ -352,7 +352,7 @@ func accountImport(ctx *cli.Context) error { if err != nil { utils.Fatalf("Failed to load the private key: %v", err) } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, false) passphrase := utils.GetPassPhraseWithList("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx)) backends := stack.AccountManager().Backends(keystore.KeyStoreType) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 96999075a316..f8a4008a1f44 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -187,7 +187,7 @@ func initGenesis(ctx *cli.Context) error { utils.Fatalf("invalid genesis file: %v", err) } // Open and initialise both full and light databases - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() for _, name := range []string{"chaindata", "lightchaindata"} { @@ -218,7 +218,7 @@ func dumpGenesis(ctx *cli.Context) error { return nil } // dump whatever already exists in the datadir - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) for _, name := range []string{"chaindata", "lightchaindata"} { db, err := stack.OpenDatabase(name, 0, 0, "", true) if err != nil { @@ -254,7 +254,7 @@ func importChain(ctx *cli.Context) error { // Start system runtime metrics collection go metrics.CollectProcessMetrics(3 * time.Second) - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() chain, db := utils.MakeChain(ctx, stack, false) @@ -329,7 +329,7 @@ func exportChain(ctx *cli.Context) error { utils.Fatalf("This command requires an argument.") } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() chain, _ := utils.MakeChain(ctx, stack, true) @@ -368,7 +368,7 @@ func importPreimages(ctx *cli.Context) error { utils.Fatalf("This command requires an argument.") } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, false) @@ -386,7 +386,7 @@ func exportPreimages(ctx *cli.Context) error { if ctx.Args().Len() < 1 { utils.Fatalf("This command requires an argument.") } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -458,7 +458,7 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth } func dump(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() conf, db, root, err := parseDumpConfig(ctx, stack) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 3268c0c43ea3..5458392fdf27 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -158,7 +158,7 @@ func makeConfigNode(ctx *cli.Context, openDataDir bool) (*node.Node, gethConfig) // makeFullNode loads geth configuration and creates the Ethereum backend. func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { - stack, cfg := makeConfigNode(ctx) + stack, cfg := makeConfigNode(ctx, true) if ctx.IsSet(utils.OverrideShanghai.Name) { v := ctx.Uint64(utils.OverrideShanghai.Name) cfg.Eth.OverrideShanghai = &v @@ -187,7 +187,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { // dumpConfig is the dumpconfig command. func dumpConfig(ctx *cli.Context) error { - _, cfg := makeConfigNode(ctx) + _, cfg := makeConfigNode(ctx, true) comment := "" if cfg.Eth.Genesis != nil { diff --git a/cmd/geth/dbcmd.go b/cmd/geth/dbcmd.go index b409b19260e0..111501e2d1ee 100644 --- a/cmd/geth/dbcmd.go +++ b/cmd/geth/dbcmd.go @@ -108,7 +108,7 @@ a data corruption.`, utils.CacheFlag, utils.CacheDatabaseFlag, }, utils.NetworkFlags, utils.DatabasePathFlags), - Description: `This command performs a database compaction. + Description: `This command performs a database compaction. WARNING: This operation may take a very long time to finish, and may cause database corruption if it is aborted during execution'!`, } @@ -130,7 +130,7 @@ corruption if it is aborted during execution'!`, Flags: flags.Merge([]cli.Flag{ utils.SyncModeFlag, }, utils.NetworkFlags, utils.DatabasePathFlags), - Description: `This command deletes the specified database key from the database. + Description: `This command deletes the specified database key from the database. WARNING: This is a low-level operation which may cause database corruption!`, } dbPutCmd = &cli.Command{ @@ -141,7 +141,7 @@ WARNING: This is a low-level operation which may cause database corruption!`, Flags: flags.Merge([]cli.Flag{ utils.SyncModeFlag, }, utils.NetworkFlags, utils.DatabasePathFlags), - Description: `This command sets a given database key to the given value. + Description: `This command sets a given database key to the given value. WARNING: This is a low-level operation which may cause database corruption!`, } dbGetSlotsCmd = &cli.Command{ @@ -196,7 +196,7 @@ WARNING: This is a low-level operation which may cause database corruption!`, ) func removeDB(ctx *cli.Context) error { - stack, config := makeConfigNode(ctx) + stack, config := makeConfigNode(ctx, true) // Remove the full node state database path := stack.ResolvePath("chaindata") @@ -277,7 +277,7 @@ func inspect(ctx *cli.Context) error { start = d } } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -301,7 +301,7 @@ func checkStateContent(ctx *cli.Context) error { start = d } } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -354,7 +354,7 @@ func showLeveldbStats(db ethdb.KeyValueStater) { } func dbStats(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -365,7 +365,7 @@ func dbStats(ctx *cli.Context) error { } func dbCompact(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, false) @@ -389,7 +389,7 @@ func dbGet(ctx *cli.Context) error { if ctx.NArg() != 1 { return fmt.Errorf("required arguments: %v", ctx.Command.ArgsUsage) } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -415,7 +415,7 @@ func dbDelete(ctx *cli.Context) error { if ctx.NArg() != 1 { return fmt.Errorf("required arguments: %v", ctx.Command.ArgsUsage) } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, false) @@ -442,7 +442,7 @@ func dbPut(ctx *cli.Context) error { if ctx.NArg() != 2 { return fmt.Errorf("required arguments: %v", ctx.Command.ArgsUsage) } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, false) @@ -476,7 +476,7 @@ func dbDumpTrie(ctx *cli.Context) error { if ctx.NArg() < 3 { return fmt.Errorf("required arguments: %v", ctx.Command.ArgsUsage) } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -550,7 +550,7 @@ func freezerInspect(ctx *cli.Context) error { log.Info("Could not read count param", "err", err) return err } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) ancient := stack.ResolveAncient("chaindata", ctx.String(utils.AncientFlag.Name)) stack.Close() return rawdb.InspectFreezerTable(ancient, freezer, table, start, end) @@ -572,7 +572,7 @@ func importLDBdata(ctx *cli.Context) error { } var ( fName = ctx.Args().Get(0) - stack, _ = makeConfigNode(ctx) + stack, _ = makeConfigNode(ctx, true) interrupt = make(chan os.Signal, 1) stop = make(chan struct{}) ) @@ -668,7 +668,7 @@ func exportChaindata(ctx *cli.Context) error { return fmt.Errorf("invalid data type %s, supported types: %s", kind, strings.Join(kinds, ", ")) } var ( - stack, _ = makeConfigNode(ctx) + stack, _ = makeConfigNode(ctx, true) interrupt = make(chan os.Signal, 1) stop = make(chan struct{}) ) @@ -687,7 +687,7 @@ func exportChaindata(ctx *cli.Context) error { } func showMetaData(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) ancients, err := db.Ancients() diff --git a/cmd/geth/snapshot.go b/cmd/geth/snapshot.go index 0759341fd966..2b6613679b53 100644 --- a/cmd/geth/snapshot.go +++ b/cmd/geth/snapshot.go @@ -160,7 +160,7 @@ block is used. // Deprecation: this command should be deprecated once the hash-based // scheme is deprecated. func pruneState(ctx *cli.Context) error { - stack, config := makeConfigNode(ctx) + stack, config := makeConfigNode(ctx, true) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, false) @@ -196,7 +196,7 @@ func pruneState(ctx *cli.Context) error { } func verifyState(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) @@ -241,7 +241,7 @@ func verifyState(ctx *cli.Context) error { // checkDanglingStorage iterates the snap storage data, and verifies that all // storage also has corresponding account data. func checkDanglingStorage(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() return snapshot.CheckDanglingStorage(utils.MakeChainDatabase(ctx, stack, true)) @@ -251,7 +251,7 @@ func checkDanglingStorage(ctx *cli.Context) error { // Basically it just iterates the trie, ensure all nodes and associated // contract codes are present. func traverseState(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) @@ -341,7 +341,7 @@ func traverseState(ctx *cli.Context) error { // contract codes are present. It's basically identical to traverseState // but it will check each trie node. func traverseRawState(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) @@ -483,7 +483,7 @@ func parseRoot(input string) (common.Hash, error) { } func dumpState(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() conf, db, root, err := parseDumpConfig(ctx, stack) @@ -577,7 +577,7 @@ func checkAccount(ctx *cli.Context) error { default: return errors.New("malformed address or hash") } - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) defer chaindb.Close() diff --git a/cmd/geth/verkle.go b/cmd/geth/verkle.go index a5756ceab003..295ed37b7272 100644 --- a/cmd/geth/verkle.go +++ b/cmd/geth/verkle.go @@ -111,7 +111,7 @@ func checkChildren(root verkle.VerkleNode, resolver verkle.NodeResolverFn) error } func verifyVerkle(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) @@ -159,7 +159,7 @@ func verifyVerkle(ctx *cli.Context) error { } func expandVerkle(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeConfigNode(ctx, true) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) From da6667286b0c23510cc17b15cd33c344e93079f9 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 18 Apr 2023 23:30:08 +0800 Subject: [PATCH 04/17] Revert "cmd/geth: don't open datadir in accountcmd" This reverts commit ff6c0ee1b83c1d1bf155b0713aac566b9b17dea8. Signed-off-by: jsvisa --- cmd/geth/accountcmd.go | 8 ++++---- cmd/geth/chaincmd.go | 14 +++++++------- cmd/geth/config.go | 4 ++-- cmd/geth/dbcmd.go | 32 ++++++++++++++++---------------- cmd/geth/snapshot.go | 14 +++++++------- cmd/geth/verkle.go | 4 ++-- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index 6356ffa5d8ca..a36da7d55f2c 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -189,7 +189,7 @@ nodes. ) func accountList(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, false) + stack, _ := makeConfigNode(ctx) var index int for _, wallet := range stack.AccountManager().Wallets() { for _, account := range wallet.Accounts() { @@ -300,7 +300,7 @@ func accountUpdate(ctx *cli.Context) error { if ctx.Args().Len() == 0 { utils.Fatalf("No accounts specified to update") } - stack, _ := makeConfigNode(ctx, false) + stack, _ := makeConfigNode(ctx) backends := stack.AccountManager().Backends(keystore.KeyStoreType) if len(backends) == 0 { utils.Fatalf("Keystore is not available") @@ -327,7 +327,7 @@ func importWallet(ctx *cli.Context) error { utils.Fatalf("Could not read wallet file: %v", err) } - stack, _ := makeConfigNode(ctx, false) + stack, _ := makeConfigNode(ctx) passphrase := utils.GetPassPhraseWithList("", false, 0, utils.MakePasswordList(ctx)) backends := stack.AccountManager().Backends(keystore.KeyStoreType) @@ -352,7 +352,7 @@ func accountImport(ctx *cli.Context) error { if err != nil { utils.Fatalf("Failed to load the private key: %v", err) } - stack, _ := makeConfigNode(ctx, false) + stack, _ := makeConfigNode(ctx) passphrase := utils.GetPassPhraseWithList("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx)) backends := stack.AccountManager().Backends(keystore.KeyStoreType) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index f8a4008a1f44..96999075a316 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -187,7 +187,7 @@ func initGenesis(ctx *cli.Context) error { utils.Fatalf("invalid genesis file: %v", err) } // Open and initialise both full and light databases - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() for _, name := range []string{"chaindata", "lightchaindata"} { @@ -218,7 +218,7 @@ func dumpGenesis(ctx *cli.Context) error { return nil } // dump whatever already exists in the datadir - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) for _, name := range []string{"chaindata", "lightchaindata"} { db, err := stack.OpenDatabase(name, 0, 0, "", true) if err != nil { @@ -254,7 +254,7 @@ func importChain(ctx *cli.Context) error { // Start system runtime metrics collection go metrics.CollectProcessMetrics(3 * time.Second) - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() chain, db := utils.MakeChain(ctx, stack, false) @@ -329,7 +329,7 @@ func exportChain(ctx *cli.Context) error { utils.Fatalf("This command requires an argument.") } - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() chain, _ := utils.MakeChain(ctx, stack, true) @@ -368,7 +368,7 @@ func importPreimages(ctx *cli.Context) error { utils.Fatalf("This command requires an argument.") } - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, false) @@ -386,7 +386,7 @@ func exportPreimages(ctx *cli.Context) error { if ctx.Args().Len() < 1 { utils.Fatalf("This command requires an argument.") } - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -458,7 +458,7 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth } func dump(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() conf, db, root, err := parseDumpConfig(ctx, stack) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 5458392fdf27..3268c0c43ea3 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -158,7 +158,7 @@ func makeConfigNode(ctx *cli.Context, openDataDir bool) (*node.Node, gethConfig) // makeFullNode loads geth configuration and creates the Ethereum backend. func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { - stack, cfg := makeConfigNode(ctx, true) + stack, cfg := makeConfigNode(ctx) if ctx.IsSet(utils.OverrideShanghai.Name) { v := ctx.Uint64(utils.OverrideShanghai.Name) cfg.Eth.OverrideShanghai = &v @@ -187,7 +187,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { // dumpConfig is the dumpconfig command. func dumpConfig(ctx *cli.Context) error { - _, cfg := makeConfigNode(ctx, true) + _, cfg := makeConfigNode(ctx) comment := "" if cfg.Eth.Genesis != nil { diff --git a/cmd/geth/dbcmd.go b/cmd/geth/dbcmd.go index 111501e2d1ee..b409b19260e0 100644 --- a/cmd/geth/dbcmd.go +++ b/cmd/geth/dbcmd.go @@ -108,7 +108,7 @@ a data corruption.`, utils.CacheFlag, utils.CacheDatabaseFlag, }, utils.NetworkFlags, utils.DatabasePathFlags), - Description: `This command performs a database compaction. + Description: `This command performs a database compaction. WARNING: This operation may take a very long time to finish, and may cause database corruption if it is aborted during execution'!`, } @@ -130,7 +130,7 @@ corruption if it is aborted during execution'!`, Flags: flags.Merge([]cli.Flag{ utils.SyncModeFlag, }, utils.NetworkFlags, utils.DatabasePathFlags), - Description: `This command deletes the specified database key from the database. + Description: `This command deletes the specified database key from the database. WARNING: This is a low-level operation which may cause database corruption!`, } dbPutCmd = &cli.Command{ @@ -141,7 +141,7 @@ WARNING: This is a low-level operation which may cause database corruption!`, Flags: flags.Merge([]cli.Flag{ utils.SyncModeFlag, }, utils.NetworkFlags, utils.DatabasePathFlags), - Description: `This command sets a given database key to the given value. + Description: `This command sets a given database key to the given value. WARNING: This is a low-level operation which may cause database corruption!`, } dbGetSlotsCmd = &cli.Command{ @@ -196,7 +196,7 @@ WARNING: This is a low-level operation which may cause database corruption!`, ) func removeDB(ctx *cli.Context) error { - stack, config := makeConfigNode(ctx, true) + stack, config := makeConfigNode(ctx) // Remove the full node state database path := stack.ResolvePath("chaindata") @@ -277,7 +277,7 @@ func inspect(ctx *cli.Context) error { start = d } } - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -301,7 +301,7 @@ func checkStateContent(ctx *cli.Context) error { start = d } } - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -354,7 +354,7 @@ func showLeveldbStats(db ethdb.KeyValueStater) { } func dbStats(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -365,7 +365,7 @@ func dbStats(ctx *cli.Context) error { } func dbCompact(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, false) @@ -389,7 +389,7 @@ func dbGet(ctx *cli.Context) error { if ctx.NArg() != 1 { return fmt.Errorf("required arguments: %v", ctx.Command.ArgsUsage) } - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -415,7 +415,7 @@ func dbDelete(ctx *cli.Context) error { if ctx.NArg() != 1 { return fmt.Errorf("required arguments: %v", ctx.Command.ArgsUsage) } - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, false) @@ -442,7 +442,7 @@ func dbPut(ctx *cli.Context) error { if ctx.NArg() != 2 { return fmt.Errorf("required arguments: %v", ctx.Command.ArgsUsage) } - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, false) @@ -476,7 +476,7 @@ func dbDumpTrie(ctx *cli.Context) error { if ctx.NArg() < 3 { return fmt.Errorf("required arguments: %v", ctx.Command.ArgsUsage) } - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -550,7 +550,7 @@ func freezerInspect(ctx *cli.Context) error { log.Info("Could not read count param", "err", err) return err } - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) ancient := stack.ResolveAncient("chaindata", ctx.String(utils.AncientFlag.Name)) stack.Close() return rawdb.InspectFreezerTable(ancient, freezer, table, start, end) @@ -572,7 +572,7 @@ func importLDBdata(ctx *cli.Context) error { } var ( fName = ctx.Args().Get(0) - stack, _ = makeConfigNode(ctx, true) + stack, _ = makeConfigNode(ctx) interrupt = make(chan os.Signal, 1) stop = make(chan struct{}) ) @@ -668,7 +668,7 @@ func exportChaindata(ctx *cli.Context) error { return fmt.Errorf("invalid data type %s, supported types: %s", kind, strings.Join(kinds, ", ")) } var ( - stack, _ = makeConfigNode(ctx, true) + stack, _ = makeConfigNode(ctx) interrupt = make(chan os.Signal, 1) stop = make(chan struct{}) ) @@ -687,7 +687,7 @@ func exportChaindata(ctx *cli.Context) error { } func showMetaData(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) ancients, err := db.Ancients() diff --git a/cmd/geth/snapshot.go b/cmd/geth/snapshot.go index 2b6613679b53..0759341fd966 100644 --- a/cmd/geth/snapshot.go +++ b/cmd/geth/snapshot.go @@ -160,7 +160,7 @@ block is used. // Deprecation: this command should be deprecated once the hash-based // scheme is deprecated. func pruneState(ctx *cli.Context) error { - stack, config := makeConfigNode(ctx, true) + stack, config := makeConfigNode(ctx) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, false) @@ -196,7 +196,7 @@ func pruneState(ctx *cli.Context) error { } func verifyState(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) @@ -241,7 +241,7 @@ func verifyState(ctx *cli.Context) error { // checkDanglingStorage iterates the snap storage data, and verifies that all // storage also has corresponding account data. func checkDanglingStorage(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() return snapshot.CheckDanglingStorage(utils.MakeChainDatabase(ctx, stack, true)) @@ -251,7 +251,7 @@ func checkDanglingStorage(ctx *cli.Context) error { // Basically it just iterates the trie, ensure all nodes and associated // contract codes are present. func traverseState(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) @@ -341,7 +341,7 @@ func traverseState(ctx *cli.Context) error { // contract codes are present. It's basically identical to traverseState // but it will check each trie node. func traverseRawState(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) @@ -483,7 +483,7 @@ func parseRoot(input string) (common.Hash, error) { } func dumpState(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() conf, db, root, err := parseDumpConfig(ctx, stack) @@ -577,7 +577,7 @@ func checkAccount(ctx *cli.Context) error { default: return errors.New("malformed address or hash") } - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) defer chaindb.Close() diff --git a/cmd/geth/verkle.go b/cmd/geth/verkle.go index 295ed37b7272..a5756ceab003 100644 --- a/cmd/geth/verkle.go +++ b/cmd/geth/verkle.go @@ -111,7 +111,7 @@ func checkChildren(root verkle.VerkleNode, resolver verkle.NodeResolverFn) error } func verifyVerkle(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) @@ -159,7 +159,7 @@ func verifyVerkle(ctx *cli.Context) error { } func expandVerkle(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx, true) + stack, _ := makeConfigNode(ctx) defer stack.Close() chaindb := utils.MakeChainDatabase(ctx, stack, true) From 55cd46a835e3a78549af1f93260931b5a5c30041 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 18 Apr 2023 23:30:15 +0800 Subject: [PATCH 05/17] Revert "cmd/geth: make config node support openDataDir or not" This reverts commit 0d87f07a389cc3b426dc17525e1b2461d5468eb8. Signed-off-by: jsvisa --- cmd/geth/config.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 3268c0c43ea3..0b856d1c1b7a 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -120,14 +120,13 @@ func defaultNodeConfig() node.Config { } // makeConfigNode loads geth configuration and creates a blank node instance. -func makeConfigNode(ctx *cli.Context, openDataDir bool) (*node.Node, gethConfig) { +func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { // Load defaults. cfg := gethConfig{ Eth: ethconfig.Defaults, Node: defaultNodeConfig(), Metrics: metrics.DefaultConfig, } - cfg.Node.NoOpenDataDir = !openDataDir // Load config file. if file := ctx.String(configFileFlag.Name); file != "" { From 9c23a71378f1ab33ff3b9c8c6c61339a4569c45c Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 18 Apr 2023 23:30:21 +0800 Subject: [PATCH 06/17] Revert "node: add a switch of open datadir or not" This reverts commit fa4d47aa6752e3b81c4244c64e2a11815a2418f1. Signed-off-by: jsvisa --- node/config.go | 4 ---- node/node.go | 6 ++---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/node/config.go b/node/config.go index fe4a1b8c999f..37a7d5837fa2 100644 --- a/node/config.go +++ b/node/config.go @@ -203,11 +203,7 @@ type Config struct { // EnablePersonal enables the deprecated personal namespace. EnablePersonal bool `toml:"-"` - // DBEngine is the backing database implementation to use DBEngine string `toml:",omitempty"` - - // NoOpenDataDir stands for weather or not opens the datadir - NoOpenDataDir bool `toml:"-"` } // IPCEndpoint resolves an IPC endpoint based on a configured value, taking into diff --git a/node/node.go b/node/node.go index 2423bc6c7b93..2f89bc1ad274 100644 --- a/node/node.go +++ b/node/node.go @@ -116,10 +116,8 @@ func New(conf *Config) (*Node, error) { node.rpcAPIs = append(node.rpcAPIs, node.apis()...) // Acquire the instance directory lock. - if !conf.NoOpenDataDir { - if err := node.openDataDir(); err != nil { - return nil, err - } + if err := node.openDataDir(); err != nil { + return nil, err } keyDir, isEphem, err := getKeyStoreDir(conf) if err != nil { From a0d106d1b8e7ff31dbf53ec5e4b9a09462a6ee25 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 18 Apr 2023 23:45:56 +0800 Subject: [PATCH 07/17] node: add a new non-functional method Signed-off-by: jsvisa --- node/node.go | 108 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 33 deletions(-) diff --git a/node/node.go b/node/node.go index 2f89bc1ad274..0b98a6617de7 100644 --- a/node/node.go +++ b/node/node.go @@ -73,6 +73,22 @@ const ( closedState ) +// checkConfigName is used to check whether the name of an Ethereum node configuration is valid. +func checkConfigName(name string) error { + // Ensure that the instance name doesn't cause weird conflicts with + // other files in the data directory. + if strings.ContainsAny(name, `/\`) { + return errors.New(`Config.Name must not contain '/' or '\'`) + } + if name == datadirDefaultKeyStore { + return errors.New(`Config.Name cannot be "` + datadirDefaultKeyStore + `"`) + } + if strings.HasSuffix(name, ".ipc") { + return errors.New(`Config.Name cannot end in ".ipc"`) + } + return nil +} + // New creates a new P2P node, ready for protocol registration. func New(conf *Config) (*Node, error) { // Copy config and resolve the datadir so future changes to the current @@ -89,17 +105,8 @@ func New(conf *Config) (*Node, error) { if conf.Logger == nil { conf.Logger = log.New() } - - // Ensure that the instance name doesn't cause weird conflicts with - // other files in the data directory. - if strings.ContainsAny(conf.Name, `/\`) { - return nil, errors.New(`Config.Name must not contain '/' or '\'`) - } - if conf.Name == datadirDefaultKeyStore { - return nil, errors.New(`Config.Name cannot be "` + datadirDefaultKeyStore + `"`) - } - if strings.HasSuffix(conf.Name, ".ipc") { - return nil, errors.New(`Config.Name cannot end in ".ipc"`) + if err := checkConfigName(conf.Name); err != nil { + return nil, err } node := &Node{ @@ -112,48 +119,83 @@ func New(conf *Config) (*Node, error) { databases: make(map[*closeTrackingDB]struct{}), } - // Register built-in APIs. - node.rpcAPIs = append(node.rpcAPIs, node.apis()...) - // Acquire the instance directory lock. if err := node.openDataDir(); err != nil { return nil, err } + + if err := node.init(conf); err != nil { + return nil, err + } + + return node, nil +} + +// NewNonfunctional creates a new P2P node which is incapable of networking, and is not chain-aware. +func NewNonfunctional(conf *Config) (*Node, error) { + if err := checkConfigName(conf.Name); err != nil { + return nil, err + } + + logger := conf.Logger + if logger == nil { + logger = log.New() + } + + node := &Node{ + config: conf, + inprocHandler: rpc.NewServer(), + eventmux: new(event.TypeMux), + log: logger, + stop: make(chan struct{}), + server: &p2p.Server{Config: conf.P2P}, + databases: make(map[*closeTrackingDB]struct{}), + } + if err := node.init(conf); err != nil { + return nil, err + } + + return node, nil +} + +func (n *Node) init(conf *Config) error { + // Register built-in APIs. + n.rpcAPIs = append(n.rpcAPIs, n.apis()...) + keyDir, isEphem, err := getKeyStoreDir(conf) if err != nil { - return nil, err + return err } - node.keyDir = keyDir - node.keyDirTemp = isEphem + n.keyDir = keyDir + n.keyDirTemp = isEphem // Creates an empty AccountManager with no backends. Callers (e.g. cmd/geth) // are required to add the backends later on. - node.accman = accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: conf.InsecureUnlockAllowed}) + n.accman = accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: conf.InsecureUnlockAllowed}) // Initialize the p2p server. This creates the node key and discovery databases. - node.server.Config.PrivateKey = node.config.NodeKey() - node.server.Config.Name = node.config.NodeName() - node.server.Config.Logger = node.log - node.config.checkLegacyFiles() - if node.server.Config.NodeDatabase == "" { - node.server.Config.NodeDatabase = node.config.NodeDB() + n.server.Config.PrivateKey = n.config.NodeKey() + n.server.Config.Name = n.config.NodeName() + n.server.Config.Logger = n.log + n.config.checkLegacyFiles() + if n.server.Config.NodeDatabase == "" { + n.server.Config.NodeDatabase = n.config.NodeDB() } // Check HTTP/WS prefixes are valid. if err := validatePrefix("HTTP", conf.HTTPPathPrefix); err != nil { - return nil, err + return err } if err := validatePrefix("WebSocket", conf.WSPathPrefix); err != nil { - return nil, err + return err } // Configure RPC servers. - node.http = newHTTPServer(node.log, conf.HTTPTimeouts) - node.httpAuth = newHTTPServer(node.log, conf.HTTPTimeouts) - node.ws = newHTTPServer(node.log, rpc.DefaultHTTPTimeouts) - node.wsAuth = newHTTPServer(node.log, rpc.DefaultHTTPTimeouts) - node.ipc = newIPCServer(node.log, conf.IPCEndpoint()) - - return node, nil + n.http = newHTTPServer(n.log, conf.HTTPTimeouts) + n.httpAuth = newHTTPServer(n.log, conf.HTTPTimeouts) + n.ws = newHTTPServer(n.log, rpc.DefaultHTTPTimeouts) + n.wsAuth = newHTTPServer(n.log, rpc.DefaultHTTPTimeouts) + n.ipc = newIPCServer(n.log, conf.IPCEndpoint()) + return nil } // Start starts all registered lifecycles, RPC services and p2p networking. From 4e7a4914ec8ab74a074c7e9335834b7c750aa242 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 18 Apr 2023 23:52:19 +0800 Subject: [PATCH 08/17] geth/config: slim node Signed-off-by: jsvisa --- cmd/geth/config.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 0b856d1c1b7a..f62188d3a0ae 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -184,6 +184,36 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { return stack, backend } +// makeSlimNode loads geth configuration and creates a blank node instance which is not chain-aware. +func makeSlimNode(ctx *cli.Context) (*node.Node, gethConfig) { + // Load defaults. + cfg := gethConfig{ + Eth: ethconfig.Defaults, + Node: defaultNodeConfig(), + Metrics: metrics.DefaultConfig, + } + + // Load config file. + if file := ctx.String(configFileFlag.Name); file != "" { + if err := loadConfig(file, &cfg); err != nil { + utils.Fatalf("%v", err) + } + } + + // Apply flags. + utils.SetNodeConfig(ctx, &cfg.Node) + stack, err := node.NewNonfunctional(&cfg.Node) + if err != nil { + utils.Fatalf("Failed to create the protocol stack: %v", err) + } + // Node doesn't by default populate account manager backends + if err := setAccountManagerBackends(stack); err != nil { + utils.Fatalf("Failed to set account manager backends: %v", err) + } + + return stack, cfg +} + // dumpConfig is the dumpconfig command. func dumpConfig(ctx *cli.Context) error { _, cfg := makeConfigNode(ctx) From 045b3691e7e2d5c5a260414fbbbf34643084c56a Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 18 Apr 2023 23:53:39 +0800 Subject: [PATCH 09/17] geth/accountcmd: use slim node Signed-off-by: jsvisa --- cmd/geth/accountcmd.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index a36da7d55f2c..7215e7d800d0 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -189,7 +189,7 @@ nodes. ) func accountList(ctx *cli.Context) error { - stack, _ := makeConfigNode(ctx) + stack, _ := makeSlimNode(ctx) var index int for _, wallet := range stack.AccountManager().Wallets() { for _, account := range wallet.Accounts() { @@ -300,7 +300,7 @@ func accountUpdate(ctx *cli.Context) error { if ctx.Args().Len() == 0 { utils.Fatalf("No accounts specified to update") } - stack, _ := makeConfigNode(ctx) + stack, _ := makeSlimNode(ctx) backends := stack.AccountManager().Backends(keystore.KeyStoreType) if len(backends) == 0 { utils.Fatalf("Keystore is not available") @@ -327,7 +327,7 @@ func importWallet(ctx *cli.Context) error { utils.Fatalf("Could not read wallet file: %v", err) } - stack, _ := makeConfigNode(ctx) + stack, _ := makeSlimNode(ctx) passphrase := utils.GetPassPhraseWithList("", false, 0, utils.MakePasswordList(ctx)) backends := stack.AccountManager().Backends(keystore.KeyStoreType) @@ -352,7 +352,7 @@ func accountImport(ctx *cli.Context) error { if err != nil { utils.Fatalf("Failed to load the private key: %v", err) } - stack, _ := makeConfigNode(ctx) + stack, _ := makeSlimNode(ctx) passphrase := utils.GetPassPhraseWithList("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx)) backends := stack.AccountManager().Backends(keystore.KeyStoreType) From df1a28bf97817305396a3a64d936455d1f260b78 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Sat, 22 Apr 2023 23:38:31 +0800 Subject: [PATCH 10/17] cmd/geth: accountcmd no need to init node stack Signed-off-by: jsvisa --- cmd/geth/accountcmd.go | 54 +++++++++++++++++++++++------------------- cmd/geth/config.go | 30 ----------------------- 2 files changed, 29 insertions(+), 55 deletions(-) diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index 7215e7d800d0..dcdf30647a47 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -25,6 +25,7 @@ import ( "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/node" "github.com/urfave/cli/v2" ) @@ -188,14 +189,32 @@ nodes. } ) +// makeKeyStore creates a keystore with given datadir and keystore dir +func makeKeyStore(ctx *cli.Context) *keystore.KeyStore { + cfg := node.DefaultConfig + + // Apply flags. + utils.SetDataDir(ctx, &cfg) + if ctx.IsSet(utils.KeyStoreDirFlag.Name) { + cfg.KeyStoreDir = ctx.String(utils.KeyStoreDirFlag.Name) + } + + keydir, err := cfg.KeyDirConfig() + if err != nil { + utils.Fatalf("Failed to geth the keystore directory: %v", err) + } + + scryptN := keystore.StandardScryptN + scryptP := keystore.StandardScryptP + ks := keystore.NewKeyStore(keydir, scryptN, scryptP) + + return ks +} + func accountList(ctx *cli.Context) error { - stack, _ := makeSlimNode(ctx) - var index int - for _, wallet := range stack.AccountManager().Wallets() { - for _, account := range wallet.Accounts() { - fmt.Printf("Account #%d: {%x} %s\n", index, account.Address, &account.URL) - index++ - } + ks := makeKeyStore(ctx) + for index, account := range ks.Accounts() { + fmt.Printf("Account #%d: {%x} %s\n", index, account.Address, &account.URL) } return nil } @@ -300,12 +319,7 @@ func accountUpdate(ctx *cli.Context) error { if ctx.Args().Len() == 0 { utils.Fatalf("No accounts specified to update") } - stack, _ := makeSlimNode(ctx) - backends := stack.AccountManager().Backends(keystore.KeyStoreType) - if len(backends) == 0 { - utils.Fatalf("Keystore is not available") - } - ks := backends[0].(*keystore.KeyStore) + ks := makeKeyStore(ctx) for _, addr := range ctx.Args().Slice() { account, oldPassword := unlockAccount(ks, addr, 0, nil) @@ -327,14 +341,9 @@ func importWallet(ctx *cli.Context) error { utils.Fatalf("Could not read wallet file: %v", err) } - stack, _ := makeSlimNode(ctx) + ks := makeKeyStore(ctx) passphrase := utils.GetPassPhraseWithList("", false, 0, utils.MakePasswordList(ctx)) - backends := stack.AccountManager().Backends(keystore.KeyStoreType) - if len(backends) == 0 { - utils.Fatalf("Keystore is not available") - } - ks := backends[0].(*keystore.KeyStore) acct, err := ks.ImportPreSaleKey(keyJSON, passphrase) if err != nil { utils.Fatalf("%v", err) @@ -352,14 +361,9 @@ func accountImport(ctx *cli.Context) error { if err != nil { utils.Fatalf("Failed to load the private key: %v", err) } - stack, _ := makeSlimNode(ctx) + ks := makeKeyStore(ctx) passphrase := utils.GetPassPhraseWithList("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx)) - backends := stack.AccountManager().Backends(keystore.KeyStoreType) - if len(backends) == 0 { - utils.Fatalf("Keystore is not available") - } - ks := backends[0].(*keystore.KeyStore) acct, err := ks.ImportECDSA(key, passphrase) if err != nil { utils.Fatalf("Could not create the account: %v", err) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index f62188d3a0ae..0b856d1c1b7a 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -184,36 +184,6 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { return stack, backend } -// makeSlimNode loads geth configuration and creates a blank node instance which is not chain-aware. -func makeSlimNode(ctx *cli.Context) (*node.Node, gethConfig) { - // Load defaults. - cfg := gethConfig{ - Eth: ethconfig.Defaults, - Node: defaultNodeConfig(), - Metrics: metrics.DefaultConfig, - } - - // Load config file. - if file := ctx.String(configFileFlag.Name); file != "" { - if err := loadConfig(file, &cfg); err != nil { - utils.Fatalf("%v", err) - } - } - - // Apply flags. - utils.SetNodeConfig(ctx, &cfg.Node) - stack, err := node.NewNonfunctional(&cfg.Node) - if err != nil { - utils.Fatalf("Failed to create the protocol stack: %v", err) - } - // Node doesn't by default populate account manager backends - if err := setAccountManagerBackends(stack); err != nil { - utils.Fatalf("Failed to set account manager backends: %v", err) - } - - return stack, cfg -} - // dumpConfig is the dumpconfig command. func dumpConfig(ctx *cli.Context) error { _, cfg := makeConfigNode(ctx) From 8821607dbb035a2a6edf043d54863e8300199335 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Sat, 22 Apr 2023 23:41:51 +0800 Subject: [PATCH 11/17] cmd/geth: apply lightscrypt n,p Signed-off-by: jsvisa --- cmd/geth/accountcmd.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index dcdf30647a47..c08bacda5f9e 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -198,6 +198,9 @@ func makeKeyStore(ctx *cli.Context) *keystore.KeyStore { if ctx.IsSet(utils.KeyStoreDirFlag.Name) { cfg.KeyStoreDir = ctx.String(utils.KeyStoreDirFlag.Name) } + if ctx.IsSet(utils.LightKDFFlag.Name) { + cfg.UseLightweightKDF = ctx.Bool(utils.LightKDFFlag.Name) + } keydir, err := cfg.KeyDirConfig() if err != nil { @@ -206,6 +209,10 @@ func makeKeyStore(ctx *cli.Context) *keystore.KeyStore { scryptN := keystore.StandardScryptN scryptP := keystore.StandardScryptP + if cfg.UseLightweightKDF { + scryptN = keystore.LightScryptN + scryptP = keystore.LightScryptP + } ks := keystore.NewKeyStore(keydir, scryptN, scryptP) return ks From 1e4691a884e4518f19b93dd26d9b5bb6fd62165a Mon Sep 17 00:00:00 2001 From: jsvisa Date: Sat, 22 Apr 2023 23:50:44 +0800 Subject: [PATCH 12/17] cmd/geth: dry Signed-off-by: jsvisa --- cmd/geth/accountcmd.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index c08bacda5f9e..fe086f8ee57a 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -189,8 +189,8 @@ nodes. } ) -// makeKeyStore creates a keystore with given datadir and keystore dir -func makeKeyStore(ctx *cli.Context) *keystore.KeyStore { +// getAccountConfig gets accountcmd related config options +func getAccountConfig(ctx *cli.Context) node.Config { cfg := node.DefaultConfig // Apply flags. @@ -202,9 +202,15 @@ func makeKeyStore(ctx *cli.Context) *keystore.KeyStore { cfg.UseLightweightKDF = ctx.Bool(utils.LightKDFFlag.Name) } + return cfg +} + +// makeKeyStore creates a keystore with given datadir and keystore dir +func makeKeyStore(ctx *cli.Context) *keystore.KeyStore { + cfg := getAccountConfig(ctx) keydir, err := cfg.KeyDirConfig() if err != nil { - utils.Fatalf("Failed to geth the keystore directory: %v", err) + utils.Fatalf("Failed to get the keystore directory: %v", err) } scryptN := keystore.StandardScryptN @@ -284,21 +290,14 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr // accountCreate creates a new account into the keystore defined by the CLI flags. func accountCreate(ctx *cli.Context) error { - cfg := gethConfig{Node: defaultNodeConfig()} - // Load config file. - if file := ctx.String(configFileFlag.Name); file != "" { - if err := loadConfig(file, &cfg); err != nil { - utils.Fatalf("%v", err) - } - } - utils.SetNodeConfig(ctx, &cfg.Node) - keydir, err := cfg.Node.KeyDirConfig() + cfg := getAccountConfig(ctx) + keydir, err := cfg.KeyDirConfig() if err != nil { - utils.Fatalf("Failed to read configuration: %v", err) + utils.Fatalf("Failed to get the keystore directory: %v", err) } scryptN := keystore.StandardScryptN scryptP := keystore.StandardScryptP - if cfg.Node.UseLightweightKDF { + if cfg.UseLightweightKDF { scryptN = keystore.LightScryptN scryptP = keystore.LightScryptP } From f116f36f848356af14ce2618d605f5b8c68abcab Mon Sep 17 00:00:00 2001 From: jsvisa Date: Sat, 22 Apr 2023 23:51:26 +0800 Subject: [PATCH 13/17] Revert "node: add a new non-functional method" This reverts commit a0d106d1b8e7ff31dbf53ec5e4b9a09462a6ee25. Signed-off-by: jsvisa --- node/node.go | 108 ++++++++++++++++----------------------------------- 1 file changed, 33 insertions(+), 75 deletions(-) diff --git a/node/node.go b/node/node.go index 0b98a6617de7..2f89bc1ad274 100644 --- a/node/node.go +++ b/node/node.go @@ -73,22 +73,6 @@ const ( closedState ) -// checkConfigName is used to check whether the name of an Ethereum node configuration is valid. -func checkConfigName(name string) error { - // Ensure that the instance name doesn't cause weird conflicts with - // other files in the data directory. - if strings.ContainsAny(name, `/\`) { - return errors.New(`Config.Name must not contain '/' or '\'`) - } - if name == datadirDefaultKeyStore { - return errors.New(`Config.Name cannot be "` + datadirDefaultKeyStore + `"`) - } - if strings.HasSuffix(name, ".ipc") { - return errors.New(`Config.Name cannot end in ".ipc"`) - } - return nil -} - // New creates a new P2P node, ready for protocol registration. func New(conf *Config) (*Node, error) { // Copy config and resolve the datadir so future changes to the current @@ -105,97 +89,71 @@ func New(conf *Config) (*Node, error) { if conf.Logger == nil { conf.Logger = log.New() } - if err := checkConfigName(conf.Name); err != nil { - return nil, err - } - node := &Node{ - config: conf, - inprocHandler: rpc.NewServer(), - eventmux: new(event.TypeMux), - log: conf.Logger, - stop: make(chan struct{}), - server: &p2p.Server{Config: conf.P2P}, - databases: make(map[*closeTrackingDB]struct{}), - } - - // Acquire the instance directory lock. - if err := node.openDataDir(); err != nil { - return nil, err - } - - if err := node.init(conf); err != nil { - return nil, err + // Ensure that the instance name doesn't cause weird conflicts with + // other files in the data directory. + if strings.ContainsAny(conf.Name, `/\`) { + return nil, errors.New(`Config.Name must not contain '/' or '\'`) } - - return node, nil -} - -// NewNonfunctional creates a new P2P node which is incapable of networking, and is not chain-aware. -func NewNonfunctional(conf *Config) (*Node, error) { - if err := checkConfigName(conf.Name); err != nil { - return nil, err + if conf.Name == datadirDefaultKeyStore { + return nil, errors.New(`Config.Name cannot be "` + datadirDefaultKeyStore + `"`) } - - logger := conf.Logger - if logger == nil { - logger = log.New() + if strings.HasSuffix(conf.Name, ".ipc") { + return nil, errors.New(`Config.Name cannot end in ".ipc"`) } node := &Node{ config: conf, inprocHandler: rpc.NewServer(), eventmux: new(event.TypeMux), - log: logger, + log: conf.Logger, stop: make(chan struct{}), server: &p2p.Server{Config: conf.P2P}, databases: make(map[*closeTrackingDB]struct{}), } - if err := node.init(conf); err != nil { - return nil, err - } - - return node, nil -} -func (n *Node) init(conf *Config) error { // Register built-in APIs. - n.rpcAPIs = append(n.rpcAPIs, n.apis()...) + node.rpcAPIs = append(node.rpcAPIs, node.apis()...) + // Acquire the instance directory lock. + if err := node.openDataDir(); err != nil { + return nil, err + } keyDir, isEphem, err := getKeyStoreDir(conf) if err != nil { - return err + return nil, err } - n.keyDir = keyDir - n.keyDirTemp = isEphem + node.keyDir = keyDir + node.keyDirTemp = isEphem // Creates an empty AccountManager with no backends. Callers (e.g. cmd/geth) // are required to add the backends later on. - n.accman = accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: conf.InsecureUnlockAllowed}) + node.accman = accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: conf.InsecureUnlockAllowed}) // Initialize the p2p server. This creates the node key and discovery databases. - n.server.Config.PrivateKey = n.config.NodeKey() - n.server.Config.Name = n.config.NodeName() - n.server.Config.Logger = n.log - n.config.checkLegacyFiles() - if n.server.Config.NodeDatabase == "" { - n.server.Config.NodeDatabase = n.config.NodeDB() + node.server.Config.PrivateKey = node.config.NodeKey() + node.server.Config.Name = node.config.NodeName() + node.server.Config.Logger = node.log + node.config.checkLegacyFiles() + if node.server.Config.NodeDatabase == "" { + node.server.Config.NodeDatabase = node.config.NodeDB() } // Check HTTP/WS prefixes are valid. if err := validatePrefix("HTTP", conf.HTTPPathPrefix); err != nil { - return err + return nil, err } if err := validatePrefix("WebSocket", conf.WSPathPrefix); err != nil { - return err + return nil, err } // Configure RPC servers. - n.http = newHTTPServer(n.log, conf.HTTPTimeouts) - n.httpAuth = newHTTPServer(n.log, conf.HTTPTimeouts) - n.ws = newHTTPServer(n.log, rpc.DefaultHTTPTimeouts) - n.wsAuth = newHTTPServer(n.log, rpc.DefaultHTTPTimeouts) - n.ipc = newIPCServer(n.log, conf.IPCEndpoint()) - return nil + node.http = newHTTPServer(node.log, conf.HTTPTimeouts) + node.httpAuth = newHTTPServer(node.log, conf.HTTPTimeouts) + node.ws = newHTTPServer(node.log, rpc.DefaultHTTPTimeouts) + node.wsAuth = newHTTPServer(node.log, rpc.DefaultHTTPTimeouts) + node.ipc = newIPCServer(node.log, conf.IPCEndpoint()) + + return node, nil } // Start starts all registered lifecycles, RPC services and p2p networking. From 93e1635f5aab97a0d4d71e0b53180b643a01dc82 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Mon, 24 Apr 2023 22:54:23 +0800 Subject: [PATCH 14/17] node: make conf.GetKeyStoreDir public Signed-off-by: jsvisa --- node/config.go | 6 +++--- node/node.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/node/config.go b/node/config.go index 37a7d5837fa2..35115eaa8528 100644 --- a/node/config.go +++ b/node/config.go @@ -448,10 +448,10 @@ func (c *Config) KeyDirConfig() (string, error) { return keydir, err } -// getKeyStoreDir retrieves the key directory and will create +// GetKeyStoreDir retrieves the key directory and will create // and ephemeral one if necessary. -func getKeyStoreDir(conf *Config) (string, bool, error) { - keydir, err := conf.KeyDirConfig() +func (c *Config) GetKeyStoreDir() (string, bool, error) { + keydir, err := c.KeyDirConfig() if err != nil { return "", false, err } diff --git a/node/node.go b/node/node.go index 2f89bc1ad274..e8494ac3b29e 100644 --- a/node/node.go +++ b/node/node.go @@ -119,7 +119,7 @@ func New(conf *Config) (*Node, error) { if err := node.openDataDir(); err != nil { return nil, err } - keyDir, isEphem, err := getKeyStoreDir(conf) + keyDir, isEphem, err := conf.GetKeyStoreDir() if err != nil { return nil, err } From 068e437af21249a3681395d4782a27a0b244158f Mon Sep 17 00:00:00 2001 From: jsvisa Date: Mon, 24 Apr 2023 23:20:09 +0800 Subject: [PATCH 15/17] cmd/geth: refactor Signed-off-by: jsvisa --- cmd/geth/accountcmd.go | 82 ++++++++++++++++++++++++++---------------- cmd/geth/config.go | 8 ++--- 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index fe086f8ee57a..6b6cec2e7d74 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -25,7 +25,6 @@ import ( "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/node" "github.com/urfave/cli/v2" ) @@ -189,46 +188,51 @@ nodes. } ) -// getAccountConfig gets accountcmd related config options -func getAccountConfig(ctx *cli.Context) node.Config { - cfg := node.DefaultConfig +// getAccountConfig gets configuration from command line and config file +func getAccountConfig(ctx *cli.Context) gethConfig { + // Load defaults. + cfg := gethConfig{Node: defaultNodeConfig()} - // Apply flags. - utils.SetDataDir(ctx, &cfg) - if ctx.IsSet(utils.KeyStoreDirFlag.Name) { - cfg.KeyStoreDir = ctx.String(utils.KeyStoreDirFlag.Name) - } - if ctx.IsSet(utils.LightKDFFlag.Name) { - cfg.UseLightweightKDF = ctx.Bool(utils.LightKDFFlag.Name) + // Load config file. + if file := ctx.String(configFileFlag.Name); file != "" { + if err := loadConfig(file, &cfg); err != nil { + utils.Fatalf("%v", err) + } } + // Apply flags. + utils.SetNodeConfig(ctx, &cfg.Node) + return cfg } -// makeKeyStore creates a keystore with given datadir and keystore dir -func makeKeyStore(ctx *cli.Context) *keystore.KeyStore { +// makeAccountManager creates an account manager with backends +func makeAccountManager(ctx *cli.Context) *accounts.Manager { cfg := getAccountConfig(ctx) - keydir, err := cfg.KeyDirConfig() + am := accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: cfg.Node.InsecureUnlockAllowed}) + keydir, isEphemeral, err := cfg.Node.GetKeyStoreDir() if err != nil { utils.Fatalf("Failed to get the keystore directory: %v", err) } - - scryptN := keystore.StandardScryptN - scryptP := keystore.StandardScryptP - if cfg.UseLightweightKDF { - scryptN = keystore.LightScryptN - scryptP = keystore.LightScryptP + if isEphemeral { + utils.Fatalf("Can't use ephemeral directory as keystore path") } - ks := keystore.NewKeyStore(keydir, scryptN, scryptP) - return ks + if err := setAccountManagerBackends(&cfg.Node, am, keydir); err != nil { + utils.Fatalf("Failed to set account manager backends: %v", err) + } + return am } func accountList(ctx *cli.Context) error { - ks := makeKeyStore(ctx) - for index, account := range ks.Accounts() { - fmt.Printf("Account #%d: {%x} %s\n", index, account.Address, &account.URL) + am := makeAccountManager(ctx) + var index int + for _, wallet := range am.Wallets() { + for _, account := range wallet.Accounts() { + fmt.Printf("Account #%d: {%x} %s\n", index, account.Address, &account.URL) + } } + return nil } @@ -291,13 +295,16 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr // accountCreate creates a new account into the keystore defined by the CLI flags. func accountCreate(ctx *cli.Context) error { cfg := getAccountConfig(ctx) - keydir, err := cfg.KeyDirConfig() + keydir, isEphemeral, err := cfg.Node.GetKeyStoreDir() if err != nil { utils.Fatalf("Failed to get the keystore directory: %v", err) } + if isEphemeral { + utils.Fatalf("Can't use ephemeral directory as keystore path") + } scryptN := keystore.StandardScryptN scryptP := keystore.StandardScryptP - if cfg.UseLightweightKDF { + if cfg.Node.UseLightweightKDF { scryptN = keystore.LightScryptN scryptP = keystore.LightScryptP } @@ -325,7 +332,12 @@ func accountUpdate(ctx *cli.Context) error { if ctx.Args().Len() == 0 { utils.Fatalf("No accounts specified to update") } - ks := makeKeyStore(ctx) + am := makeAccountManager(ctx) + backends := am.Backends(keystore.KeyStoreType) + if len(backends) == 0 { + utils.Fatalf("Keystore is not available") + } + ks := backends[0].(*keystore.KeyStore) for _, addr := range ctx.Args().Slice() { account, oldPassword := unlockAccount(ks, addr, 0, nil) @@ -347,7 +359,12 @@ func importWallet(ctx *cli.Context) error { utils.Fatalf("Could not read wallet file: %v", err) } - ks := makeKeyStore(ctx) + am := makeAccountManager(ctx) + backends := am.Backends(keystore.KeyStoreType) + if len(backends) == 0 { + utils.Fatalf("Keystore is not available") + } + ks := backends[0].(*keystore.KeyStore) passphrase := utils.GetPassPhraseWithList("", false, 0, utils.MakePasswordList(ctx)) acct, err := ks.ImportPreSaleKey(keyJSON, passphrase) @@ -367,7 +384,12 @@ func accountImport(ctx *cli.Context) error { if err != nil { utils.Fatalf("Failed to load the private key: %v", err) } - ks := makeKeyStore(ctx) + am := makeAccountManager(ctx) + backends := am.Backends(keystore.KeyStoreType) + if len(backends) == 0 { + utils.Fatalf("Keystore is not available") + } + ks := backends[0].(*keystore.KeyStore) passphrase := utils.GetPassPhraseWithList("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx)) acct, err := ks.ImportECDSA(key, passphrase) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 0b856d1c1b7a..85efd5ba1cfb 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -26,6 +26,7 @@ import ( "github.com/urfave/cli/v2" + "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/external" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/scwallet" @@ -142,7 +143,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { utils.Fatalf("Failed to create the protocol stack: %v", err) } // Node doesn't by default populate account manager backends - if err := setAccountManagerBackends(stack); err != nil { + if err := setAccountManagerBackends(stack.Config(), stack.AccountManager(), stack.KeyStoreDir()); err != nil { utils.Fatalf("Failed to set account manager backends: %v", err) } @@ -269,10 +270,7 @@ func deprecated(field string) bool { } } -func setAccountManagerBackends(stack *node.Node) error { - conf := stack.Config() - am := stack.AccountManager() - keydir := stack.KeyStoreDir() +func setAccountManagerBackends(conf *node.Config, am *accounts.Manager, keydir string) error { scryptN := keystore.StandardScryptN scryptP := keystore.StandardScryptP if conf.UseLightweightKDF { From c06cc037f04a2ea454cc1d733dc233c1f1277449 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 25 Apr 2023 11:04:56 +0200 Subject: [PATCH 16/17] cmd/geth: reuse loader for defaults --- cmd/geth/accountcmd.go | 22 ++-------------------- cmd/geth/config.go | 11 +++++++++-- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index 6b6cec2e7d74..d8f8aa89308b 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -188,27 +188,9 @@ nodes. } ) -// getAccountConfig gets configuration from command line and config file -func getAccountConfig(ctx *cli.Context) gethConfig { - // Load defaults. - cfg := gethConfig{Node: defaultNodeConfig()} - - // Load config file. - if file := ctx.String(configFileFlag.Name); file != "" { - if err := loadConfig(file, &cfg); err != nil { - utils.Fatalf("%v", err) - } - } - - // Apply flags. - utils.SetNodeConfig(ctx, &cfg.Node) - - return cfg -} - // makeAccountManager creates an account manager with backends func makeAccountManager(ctx *cli.Context) *accounts.Manager { - cfg := getAccountConfig(ctx) + cfg := loadBaseConfig(ctx) am := accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: cfg.Node.InsecureUnlockAllowed}) keydir, isEphemeral, err := cfg.Node.GetKeyStoreDir() if err != nil { @@ -294,7 +276,7 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr // accountCreate creates a new account into the keystore defined by the CLI flags. func accountCreate(ctx *cli.Context) error { - cfg := getAccountConfig(ctx) + cfg := loadBaseConfig(ctx) keydir, isEphemeral, err := cfg.Node.GetKeyStoreDir() if err != nil { utils.Fatalf("Failed to get the keystore directory: %v", err) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 85efd5ba1cfb..9237ac009ff8 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -120,8 +120,9 @@ func defaultNodeConfig() node.Config { return cfg } -// makeConfigNode loads geth configuration and creates a blank node instance. -func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { +// loadBaseConfig loads the gethConfig based on the given command line +// parameters and config file. +func loadBaseConfig(ctx *cli.Context) gethConfig { // Load defaults. cfg := gethConfig{ Eth: ethconfig.Defaults, @@ -138,6 +139,12 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { // Apply flags. utils.SetNodeConfig(ctx, &cfg.Node) + return cfg +} + +// makeConfigNode loads geth configuration and creates a blank node instance. +func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { + cfg := loadBaseConfig(ctx) stack, err := node.New(&cfg.Node) if err != nil { utils.Fatalf("Failed to create the protocol stack: %v", err) From fa46d8e98c8bdb27586c5a76619d8e63d76642c6 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Tue, 25 Apr 2023 12:55:46 +0200 Subject: [PATCH 17/17] add back index increment --- cmd/geth/accountcmd.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index d8f8aa89308b..cc22684e0bad 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -212,6 +212,7 @@ func accountList(ctx *cli.Context) error { for _, wallet := range am.Wallets() { for _, account := range wallet.Accounts() { fmt.Printf("Account #%d: {%x} %s\n", index, account.Address, &account.URL) + index++ } }