From 16f41238b89226f5cb2eb5ace54c73ce14167a8e Mon Sep 17 00:00:00 2001 From: JukLee0ira Date: Wed, 25 Jun 2025 17:57:33 +0800 Subject: [PATCH] cmd, console, node : deprecate personal namespace #26390 (#1153) --- cmd/XDC/consolecmd.go | 4 ++-- cmd/XDC/consolecmd_test.go | 2 +- cmd/XDC/main.go | 1 + cmd/utils/flags.go | 9 +++++++++ console/console.go | 4 +++- node/config.go | 3 +++ node/node.go | 20 ++++++++++++++++---- 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/cmd/XDC/consolecmd.go b/cmd/XDC/consolecmd.go index 30f9295b58..190e5e212b 100644 --- a/cmd/XDC/consolecmd.go +++ b/cmd/XDC/consolecmd.go @@ -82,7 +82,7 @@ func localConsole(ctx *cli.Context) error { // Attach to the newly started node and start the JavaScript console client, err := stack.Attach() if err != nil { - utils.Fatalf("Failed to attach to the inproc XDC: %v", err) + utils.Fatalf("failed to attach to the inproc XDC: %v", err) } config := console.Config{ DataDir: utils.MakeDataDir(ctx), @@ -93,7 +93,7 @@ func localConsole(ctx *cli.Context) error { console, err := console.New(config) if err != nil { - utils.Fatalf("Failed to start the JavaScript console: %v", err) + utils.Fatalf("failed to start the JavaScript console: %v", err) } defer console.Stop(false) diff --git a/cmd/XDC/consolecmd_test.go b/cmd/XDC/consolecmd_test.go index d6cda06b4b..a0f35ec790 100644 --- a/cmd/XDC/consolecmd_test.go +++ b/cmd/XDC/consolecmd_test.go @@ -30,7 +30,7 @@ import ( ) const ( - ipcAPIs = "XDCx:1.0 XDCxlending:1.0 XDPoS:1.0 admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0" + ipcAPIs = "XDCx:1.0 XDCxlending:1.0 XDPoS:1.0 admin:1.0 debug:1.0 eth: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/XDC/main.go b/cmd/XDC/main.go index 120b495e4d..fda725bdb2 100644 --- a/cmd/XDC/main.go +++ b/cmd/XDC/main.go @@ -68,6 +68,7 @@ var ( utils.NoUSBFlag, // deprecated utils.USBFlag, utils.SmartCardDaemonPathFlag, + utils.EnablePersonal, //utils.EthashCacheDirFlag, //utils.EthashCachesInMemoryFlag, //utils.EthashCachesOnDiskFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c7db243eab..a5049f7d0c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -587,6 +587,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, + } BatchRequestLimit = &cli.IntFlag{ Name: "rpc-batch-request-limit", Usage: "Maximum number of requests in a batch", @@ -1278,6 +1283,10 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) { cfg.JWTSecret = ctx.String(JWTSecretFlag.Name) } + if ctx.IsSet(EnablePersonal.Name) { + cfg.EnablePersonal = true + } + switch { case ctx.IsSet(DataDirFlag.Name): cfg.DataDir = ctx.String(DataDirFlag.Name) diff --git a/console/console.go b/console/console.go index 3ffdab414a..7b2d2c72cb 100644 --- a/console/console.go +++ b/console/console.go @@ -30,6 +30,7 @@ import ( "github.com/XinFinOrg/XDPoSChain/internal/jsre" "github.com/XinFinOrg/XDPoSChain/internal/jsre/deps" "github.com/XinFinOrg/XDPoSChain/internal/web3ext" + "github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/rpc" "github.com/dop251/goja" "github.com/mattn/go-colorable" @@ -186,7 +187,7 @@ func (c *Console) initExtensions() error { if err != nil { return fmt.Errorf("api modules: %v", err) } - aliases := map[string]struct{}{"eth": {}, "personal": {}} + aliases := map[string]struct{}{"eth": {}} for api := range apis { if api == "web3" { continue @@ -231,6 +232,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 13711f35ab..c6aaa18e3c 100644 --- a/node/config.go +++ b/node/config.go @@ -190,6 +190,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 b39dd07b4e..7321564131 100644 --- a/node/node.go +++ b/node/node.go @@ -387,13 +387,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 } } @@ -536,8 +548,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 }