From e33909649b1513863e17a73ad559aec90edb6e82 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 14 Jan 2025 10:56:12 +0800 Subject: [PATCH] cmd/utils: don't enumerate usb when --usb isn't set (#22130) --- cmd/XDC/main.go | 3 ++- cmd/utils/flags.go | 12 ++++++++++-- node/config.go | 4 ++++ p2p/simulations/adapters/docker.go | 1 - p2p/simulations/adapters/exec.go | 1 - p2p/simulations/adapters/inproc.go | 1 - 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/XDC/main.go b/cmd/XDC/main.go index ea6db1d893..d87f5e2b61 100644 --- a/cmd/XDC/main.go +++ b/cmd/XDC/main.go @@ -62,7 +62,8 @@ var ( utils.BootnodesV5Flag, utils.DataDirFlag, utils.KeyStoreDirFlag, - //utils.NoUSBFlag, + utils.NoUSBFlag, // deprecated + utils.USBFlag, utils.SmartCardDaemonPathFlag, //utils.EthashCacheDirFlag, //utils.EthashCachesInMemoryFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 0b3d9a32b0..3e96d68ca9 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -88,6 +88,11 @@ var ( Usage: "Directory for the keystore (default = inside the datadir)", Category: flags.AccountCategory, } + USBFlag = &cli.BoolFlag{ + Name: "usb", + Usage: "Enable monitoring and management of USB hardware wallets", + Category: flags.AccountCategory, + } SmartCardDaemonPathFlag = &cli.StringFlag{ Name: "pcscdpath", Usage: "Path to the smartcard daemon (pcscd) socket file", @@ -1220,8 +1225,11 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) { if ctx.IsSet(LightKDFFlag.Name) { cfg.UseLightweightKDF = ctx.Bool(LightKDFFlag.Name) } - if ctx.IsSet(NoUSBFlag.Name) { - cfg.NoUSB = ctx.Bool(NoUSBFlag.Name) + if ctx.IsSet(NoUSBFlag.Name) || cfg.NoUSB { + log.Warn("Option nousb is deprecated and USB is deactivated by default. Use --usb to enable") + } + if ctx.IsSet(USBFlag.Name) { + cfg.USB = ctx.Bool(USBFlag.Name) } if ctx.IsSet(AnnounceTxsFlag.Name) { cfg.AnnounceTxs = ctx.Bool(AnnounceTxsFlag.Name) diff --git a/node/config.go b/node/config.go index b4af885535..f6a261ee4b 100644 --- a/node/config.go +++ b/node/config.go @@ -87,8 +87,12 @@ type Config struct { InsecureUnlockAllowed bool `toml:",omitempty"` // NoUSB disables hardware wallet monitoring and connectivity. + // Deprecated: USB monitoring is disabled by default and must be enabled explicitly. NoUSB bool `toml:",omitempty"` + // USB enables hardware wallet monitoring and connectivity. + USB bool `toml:",omitempty"` + // SmartCardDaemonPath is the path to the smartcard daemon's socket. SmartCardDaemonPath string `toml:",omitempty"` diff --git a/p2p/simulations/adapters/docker.go b/p2p/simulations/adapters/docker.go index 712ad0d895..101f16313c 100644 --- a/p2p/simulations/adapters/docker.go +++ b/p2p/simulations/adapters/docker.go @@ -93,7 +93,6 @@ func (d *DockerAdapter) NewNode(config *NodeConfig) (Node, error) { conf.Stack.P2P.EnableMsgEvents = false conf.Stack.P2P.NoDiscovery = true conf.Stack.P2P.NAT = nil - conf.Stack.NoUSB = true conf.Stack.Logger = log.New("node.id", config.ID.String()) node := &DockerNode{ diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go index 153aa32d64..d9a840f60f 100644 --- a/p2p/simulations/adapters/exec.go +++ b/p2p/simulations/adapters/exec.go @@ -104,7 +104,6 @@ func (e *ExecAdapter) NewNode(config *NodeConfig) (Node, error) { conf.Stack.P2P.EnableMsgEvents = false conf.Stack.P2P.NoDiscovery = true conf.Stack.P2P.NAT = nil - conf.Stack.NoUSB = true // listen on a random localhost port (we'll get the actual port after // starting the node through the RPC admin.nodeInfo method) diff --git a/p2p/simulations/adapters/inproc.go b/p2p/simulations/adapters/inproc.go index 4363e5eaab..2b11b39f07 100644 --- a/p2p/simulations/adapters/inproc.go +++ b/p2p/simulations/adapters/inproc.go @@ -84,7 +84,6 @@ func (sa *SimAdapter) NewNode(config *NodeConfig) (Node, error) { Dialer: sa, EnableMsgEvents: true, }, - NoUSB: true, Logger: log.New("node.id", id.String()), }) if err != nil {