From d0a4989a8def7e6bad182d1513e8d4a093c1672d Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Thu, 2 Feb 2023 12:52:19 +0100 Subject: [PATCH] cmd, eth, node: deprecate personal namespace (#26390) * eth: cmd: deprecate personal namespace * eth: cmd: move deprecation to node * node: disable toml of enablepersonal * node: disable personal on ipc as well * Update node/node.go Co-authored-by: Martin Holst Swende * console: error -> warn * node: less roulette --------- Co-authored-by: Martin Holst Swende --- cmd/geth/consolecmd.go | 4 ++-- cmd/geth/consolecmd_test.go | 2 +- cmd/geth/main.go | 1 + cmd/utils/flags.go | 10 ++++++++++ console/console.go | 3 ++- node/config.go | 3 +++ node/node.go | 20 ++++++++++++++++---- 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/cmd/geth/consolecmd.go b/cmd/geth/consolecmd.go index 83c6b66a8..23f6fd277 100644 --- a/cmd/geth/consolecmd.go +++ b/cmd/geth/consolecmd.go @@ -77,7 +77,7 @@ func localConsole(ctx *cli.Context) error { // Attach to the newly started node and create the JavaScript console. client, err := stack.Attach() if err != nil { - return fmt.Errorf("Failed to attach to the inproc geth: %v", err) + return fmt.Errorf("failed to attach to the inproc geth: %v", err) } config := console.Config{ DataDir: utils.MakeDataDir(ctx), @@ -87,7 +87,7 @@ func localConsole(ctx *cli.Context) error { } console, err := console.New(config) if err != nil { - return fmt.Errorf("Failed to start the JavaScript console: %v", err) + return fmt.Errorf("failed to start the JavaScript console: %v", err) } defer console.Stop(false) diff --git a/cmd/geth/consolecmd_test.go b/cmd/geth/consolecmd_test.go index a5a23ccdf..c5bdfa6ec 100644 --- a/cmd/geth/consolecmd_test.go +++ b/cmd/geth/consolecmd_test.go @@ -30,7 +30,7 @@ import ( ) const ( - ipcAPIs = "admin:1.0 debug:1.0 engine:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0" + ipcAPIs = "admin:1.0 debug:1.0 engine:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 rpc:1.0 txpool:1.0 web3:1.0" httpAPIs = "eth:1.0 net:1.0 rpc:1.0 web3:1.0" ) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index e3ffcc515..9998670e5 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -65,6 +65,7 @@ var ( utils.USBFlag, utils.SmartCardDaemonPathFlag, utils.OverrideShanghai, + utils.EnablePersonal, utils.EthashCacheDirFlag, utils.EthashCachesInMemoryFlag, utils.EthashCachesOnDiskFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 597fc5603..78b3cbee6 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -785,6 +785,11 @@ var ( Usage: "Allow for unprotected (non EIP155 signed) transactions to be submitted via RPC", Category: flags.APICategory, } + EnablePersonal = &cli.BoolFlag{ + Name: "rpc.enabledeprecatedpersonal", + Usage: "Enables the (deprecated) personal namespace", + Category: flags.APICategory, + } // Network Settings MaxPeersFlag = &cli.IntFlag{ @@ -1466,6 +1471,10 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) { cfg.JWTSecret = ctx.String(JWTSecretFlag.Name) } + if ctx.IsSet(EnablePersonal.Name) { + cfg.EnablePersonal = true + } + if ctx.IsSet(ExternalSignerFlag.Name) { cfg.ExternalSigner = ctx.String(ExternalSignerFlag.Name) } @@ -1853,6 +1862,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { cfg.EthDiscoveryURLs = SplitAndTrim(urls) } } + // Override any default configs for hard coded networks. switch { case ctx.Bool(MainnetFlag.Name): diff --git a/console/console.go b/console/console.go index f72c35072..cdee53684 100644 --- a/console/console.go +++ b/console/console.go @@ -215,7 +215,7 @@ func (c *Console) initExtensions() error { } // Compute aliases from server-provided modules. - aliases := map[string]struct{}{"eth": {}, "personal": {}} + aliases := map[string]struct{}{"eth": {}} for api := range apis { if api == "web3" { continue @@ -260,6 +260,7 @@ func (c *Console) initPersonal(vm *goja.Runtime, bridge *bridge) { if personal == nil || c.prompter == nil { return } + log.Warn("Enabling deprecated personal namespace") jeth := vm.NewObject() vm.Set("jeth", jeth) jeth.Set("openWallet", personal.Get("openWallet")) diff --git a/node/config.go b/node/config.go index e2099ee0f..43ac824a0 100644 --- a/node/config.go +++ b/node/config.go @@ -199,6 +199,9 @@ type Config struct { // JWTSecret is the path to the hex-encoded jwt secret. JWTSecret string `toml:",omitempty"` + + // EnablePersonal enables the deprecated personal namespace. + EnablePersonal 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 4d9072e2c..760e34d33 100644 --- a/node/node.go +++ b/node/node.go @@ -376,13 +376,25 @@ func (n *Node) obtainJWTSecret(cliParam string) ([]byte, error) { // startup. It's not meant to be called at any time afterwards as it makes certain // assumptions about the state of the node. func (n *Node) startRPC() error { - if err := n.startInProc(); err != nil { + // Filter out personal api + var apis []rpc.API + for _, api := range n.rpcAPIs { + if api.Namespace == "personal" { + if n.config.EnablePersonal { + log.Warn("Deprecated personal namespace activated") + } else { + continue + } + } + apis = append(apis, api) + } + if err := n.startInProc(apis); err != nil { return err } // Configure IPC. if n.ipc.endpoint != "" { - if err := n.ipc.start(n.rpcAPIs); err != nil { + if err := n.ipc.start(apis); err != nil { return err } } @@ -510,8 +522,8 @@ func (n *Node) stopRPC() { } // startInProc registers all RPC APIs on the inproc server. -func (n *Node) startInProc() error { - for _, api := range n.rpcAPIs { +func (n *Node) startInProc(apis []rpc.API) error { + for _, api := range apis { if err := n.inprocHandler.RegisterName(api.Namespace, api.Service); err != nil { return err }