Skip to content

Commit d0f71c5

Browse files
fjlshekhirin
authored andcommitted
cmd/utils: improve parsing of --miner.etherbase address (ethereum#26541)
This fixes a regression where the flag did not accept values without the 0x prefix anymore. What's worse, if an invalid value was passed, the client would just log an INFO level message and continue.
1 parent abf47fb commit d0f71c5

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

cmd/utils/flags.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"bytes"
2222
"context"
2323
"crypto/ecdsa"
24+
"encoding/hex"
2425
"errors"
2526
"fmt"
2627
"math"
@@ -1344,14 +1345,19 @@ func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error
13441345

13451346
// setEtherbase retrieves the etherbase from the directly specified command line flags.
13461347
func setEtherbase(ctx *cli.Context, cfg *ethconfig.Config) {
1347-
if ctx.IsSet(MinerEtherbaseFlag.Name) {
1348-
b, err := hexutil.Decode(ctx.String(MinerEtherbaseFlag.Name))
1349-
if err != nil || len(b) != common.AddressLength {
1350-
log.Info("Failed to decode etherbase", "err", err)
1351-
return
1352-
}
1353-
cfg.Miner.Etherbase = common.BytesToAddress(b)
1348+
if !ctx.IsSet(MinerEtherbaseFlag.Name) {
1349+
return
1350+
}
1351+
addr := ctx.String(MinerEtherbaseFlag.Name)
1352+
if strings.HasPrefix(addr, "0x") || strings.HasPrefix(addr, "0X") {
1353+
addr = addr[2:]
1354+
}
1355+
b, err := hex.DecodeString(addr)
1356+
if err != nil || len(b) != common.AddressLength {
1357+
Fatalf("-%s: invalid etherbase address %q", MinerEtherbaseFlag.Name, addr)
1358+
return
13541359
}
1360+
cfg.Miner.Etherbase = common.BytesToAddress(b)
13551361
}
13561362

13571363
// MakePasswordList reads password lines from the file specified by the global --password flag.

0 commit comments

Comments
 (0)