Skip to content

Commit 36c4fdc

Browse files
gballetbulgakovk
authored andcommitted
cmd/utils: don't enumerate USB unless --usb is set (ethereum#22130)
USB enumeration still occured. Make sure it will only occur if --usb is set. This also deprecates the 'NoUSB' config file option in favor of a new option 'USB'.
1 parent 4c7ceb6 commit 36c4fdc

File tree

12 files changed

+21
-23
lines changed

12 files changed

+21
-23
lines changed

cmd/geth/accountcmd_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ func tmpDatadirWithKeystore(t *testing.T) string {
4343
}
4444

4545
func TestAccountListEmpty(t *testing.T) {
46-
geth := runGeth(t, "--nousb", "account", "list")
46+
geth := runGeth(t, "account", "list")
4747
geth.ExpectExit()
4848
}
4949

5050
func TestAccountList(t *testing.T) {
5151
datadir := tmpDatadirWithKeystore(t)
52-
geth := runGeth(t, "--nousb", "account", "list", "--datadir", datadir)
52+
geth := runGeth(t, "account", "list", "--datadir", datadir)
5353
defer geth.ExpectExit()
5454
if runtime.GOOS == "windows" {
5555
geth.Expect(`
@@ -139,7 +139,7 @@ Fatal: Passwords do not match
139139

140140
func TestAccountUpdate(t *testing.T) {
141141
datadir := tmpDatadirWithKeystore(t)
142-
geth := runGeth(t, "--nousb", "account", "update",
142+
geth := runGeth(t, "account", "update",
143143
"--datadir", datadir, "--lightkdf",
144144
"f466859ead1932d743d622cb74fc058882e8648a")
145145
defer geth.ExpectExit()
@@ -154,7 +154,7 @@ Repeat password: {{.InputLine "foobar2"}}
154154
}
155155

156156
func TestWalletImport(t *testing.T) {
157-
geth := runGeth(t, "--nousb", "wallet", "import", "--lightkdf", "testdata/guswallet.json")
157+
geth := runGeth(t, "wallet", "import", "--lightkdf", "testdata/guswallet.json")
158158
defer geth.ExpectExit()
159159
geth.Expect(`
160160
!! Unsupported terminal, password will be echoed.
@@ -169,7 +169,7 @@ Address: {d4584b5f6229b7be90727b0fc8c6b91bb427821f}
169169
}
170170

171171
func TestWalletImportBadPassword(t *testing.T) {
172-
geth := runGeth(t, "--nousb", "wallet", "import", "--lightkdf", "testdata/guswallet.json")
172+
geth := runGeth(t, "wallet", "import", "--lightkdf", "testdata/guswallet.json")
173173
defer geth.ExpectExit()
174174
geth.Expect(`
175175
!! Unsupported terminal, password will be echoed.

cmd/geth/consolecmd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func runMinimalGeth(t *testing.T, args ...string) *testgeth {
4242
// --ropsten to make the 'writing genesis to disk' faster (no accounts)
4343
// --networkid=1337 to avoid cache bump
4444
// --syncmode=full to avoid allocating fast sync bloom
45-
allArgs := []string{"--ropsten", "--nousb", "--networkid", "1337", "--syncmode=full", "--port", "0",
45+
allArgs := []string{"--ropsten", "--networkid", "1337", "--syncmode=full", "--port", "0",
4646
"--nat", "none", "--nodiscover", "--maxpeers", "0", "--cache", "64"}
4747
return runGeth(t, append(allArgs, args...)...)
4848
}

cmd/geth/dao_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
115115
if err := ioutil.WriteFile(json, []byte(genesis), 0600); err != nil {
116116
t.Fatalf("test %d: failed to write genesis file: %v", test, err)
117117
}
118-
runGeth(t, "--datadir", datadir, "--nousb", "--networkid", "1337", "init", json).WaitExit()
118+
runGeth(t, "--datadir", datadir, "--networkid", "1337", "init", json).WaitExit()
119119
} else {
120120
// Force chain initialization
121-
args := []string{"--port", "0", "--nousb", "--networkid", "1337", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--ipcdisable", "--datadir", datadir}
121+
args := []string{"--port", "0", "--networkid", "1337", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--ipcdisable", "--datadir", datadir}
122122
runGeth(t, append(args, []string{"--exec", "2+2", "console"}...)...).WaitExit()
123123
}
124124
// Retrieve the DAO config flag from the database

cmd/geth/genesis_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ func TestCustomGenesis(t *testing.T) {
8181
if err := ioutil.WriteFile(json, []byte(tt.genesis), 0600); err != nil {
8282
t.Fatalf("test %d: failed to write genesis file: %v", i, err)
8383
}
84-
runGeth(t, "--nousb", "--datadir", datadir, "init", json).WaitExit()
84+
runGeth(t, "--datadir", datadir, "init", json).WaitExit()
8585

8686
// Query the custom genesis block
87-
geth := runGeth(t, "--nousb", "--networkid", "1337", "--syncmode=full",
87+
geth := runGeth(t, "--networkid", "1337", "--syncmode=full",
8888
"--datadir", datadir, "--maxpeers", "0", "--port", "0",
8989
"--nodiscover", "--nat", "none", "--ipcdisable",
9090
"--exec", tt.query, "console")

cmd/geth/les_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ var nextIPC = uint32(0)
130130

131131
func startGethWithIpc(t *testing.T, name string, args ...string) *gethrpc {
132132
ipcName := fmt.Sprintf("geth-%d.ipc", atomic.AddUint32(&nextIPC, 1))
133-
args = append([]string{"--networkid=42", "--port=0", "--nousb", "--ipcpath", ipcName}, args...)
133+
args = append([]string{"--networkid=42", "--port=0", "--ipcpath", ipcName}, args...)
134134
t.Logf("Starting %v with rpc: %v", name, args)
135135

136136
g := &gethrpc{
@@ -148,7 +148,7 @@ func startGethWithIpc(t *testing.T, name string, args ...string) *gethrpc {
148148
}
149149

150150
func initGeth(t *testing.T) string {
151-
args := []string{"--nousb", "--networkid=42", "init", "./testdata/clique.json"}
151+
args := []string{"--networkid=42", "init", "./testdata/clique.json"}
152152
t.Logf("Initializing geth: %v ", args)
153153
g := runGeth(t, args...)
154154
datadir := g.Datadir
@@ -159,7 +159,7 @@ func initGeth(t *testing.T) string {
159159
func startLightServer(t *testing.T) *gethrpc {
160160
datadir := initGeth(t)
161161
t.Logf("Importing keys to geth")
162-
runGeth(t, "--nousb", "--datadir", datadir, "--password", "./testdata/password.txt", "account", "import", "./testdata/key.prv", "--lightkdf").WaitExit()
162+
runGeth(t, "--datadir", datadir, "--password", "./testdata/password.txt", "account", "import", "./testdata/key.prv", "--lightkdf").WaitExit()
163163
account := "0x02f0d131f1f97aef08aec6e3291b957d9efe7105"
164164
server := startGethWithIpc(t, "lightserver", "--allow-insecure-unlock", "--datadir", datadir, "--password", "./testdata/password.txt", "--unlock", account, "--mine", "--light.serve=100", "--light.maxpeers=1", "--nodiscover", "--nat=extip:127.0.0.1", "--verbosity=4")
165165
return server

cmd/utils/flags.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,12 +1233,12 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
12331233
if ctx.GlobalIsSet(LightKDFFlag.Name) {
12341234
cfg.UseLightweightKDF = ctx.GlobalBool(LightKDFFlag.Name)
12351235
}
1236-
if ctx.GlobalIsSet(USBFlag.Name) {
1237-
cfg.NoUSB = !ctx.GlobalBool(USBFlag.Name)
1238-
}
1239-
if ctx.GlobalIsSet(NoUSBFlag.Name) {
1236+
if ctx.GlobalIsSet(NoUSBFlag.Name) || cfg.NoUSB {
12401237
log.Warn("Option nousb is deprecated and USB is deactivated by default. Use --usb to enable")
12411238
}
1239+
if ctx.GlobalIsSet(USBFlag.Name) {
1240+
cfg.USB = ctx.GlobalBool(USBFlag.Name)
1241+
}
12421242
if ctx.GlobalIsSet(InsecureUnlockAllowedFlag.Name) {
12431243
cfg.InsecureUnlockAllowed = ctx.GlobalBool(InsecureUnlockAllowedFlag.Name)
12441244
}

miner/stress_clique.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ func makeSealer(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
178178
NoDiscovery: true,
179179
MaxPeers: 25,
180180
},
181-
NoUSB: true,
182181
}
183182
// Start the node and configure a full Ethereum node on it
184183
stack, err := node.New(config)

miner/stress_ethash.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
155155
NoDiscovery: true,
156156
MaxPeers: 25,
157157
},
158-
NoUSB: true,
159158
UseLightweightKDF: true,
160159
}
161160
// Create the node and configure a full Ethereum node on it

node/api_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ func TestStartRPC(t *testing.T) {
248248
// Apply some sane defaults.
249249
config := test.cfg
250250
// config.Logger = testlog.Logger(t, log.LvlDebug)
251-
config.NoUSB = true
252251
config.P2P.NoDiscovery = true
253252

254253
// Create Node.

node/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ type Config struct {
9595
// NoUSB disables hardware wallet monitoring and connectivity.
9696
NoUSB bool `toml:",omitempty"`
9797

98+
// USB enables hardware wallet monitoring and connectivity.
99+
USB bool `toml:",omitempty"`
100+
98101
// SmartCardDaemonPath is the path to the smartcard daemon's socket
99102
SmartCardDaemonPath string `toml:",omitempty"`
100103

@@ -476,7 +479,7 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
476479
// we can have both, but it's very confusing for the user to see the same
477480
// accounts in both externally and locally, plus very racey.
478481
backends = append(backends, keystore.NewKeyStore(keydir, scryptN, scryptP))
479-
if !conf.NoUSB {
482+
if conf.USB {
480483
// Start a USB hub for Ledger hardware wallets
481484
if ledgerhub, err := usbwallet.NewLedgerHub(); err != nil {
482485
log.Warn(fmt.Sprintf("Failed to start Ledger hub, disabling: %v", err))

0 commit comments

Comments
 (0)