Skip to content

Commit

Permalink
cmd/utils: improve parsing of --miner.etherbase address (#26541)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fjl authored Jan 24, 2023
1 parent 163e996 commit 59a48e0
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"bytes"
"context"
"crypto/ecdsa"
"encoding/hex"
"errors"
"fmt"
"math"
Expand Down Expand Up @@ -1344,14 +1345,19 @@ func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error

// setEtherbase retrieves the etherbase from the directly specified command line flags.
func setEtherbase(ctx *cli.Context, cfg *ethconfig.Config) {
if ctx.IsSet(MinerEtherbaseFlag.Name) {
b, err := hexutil.Decode(ctx.String(MinerEtherbaseFlag.Name))
if err != nil || len(b) != common.AddressLength {
log.Info("Failed to decode etherbase", "err", err)
return
}
cfg.Miner.Etherbase = common.BytesToAddress(b)
if !ctx.IsSet(MinerEtherbaseFlag.Name) {
return
}
addr := ctx.String(MinerEtherbaseFlag.Name)
if strings.HasPrefix(addr, "0x") || strings.HasPrefix(addr, "0X") {
addr = addr[2:]
}
b, err := hex.DecodeString(addr)
if err != nil || len(b) != common.AddressLength {
Fatalf("-%s: invalid etherbase address %q", MinerEtherbaseFlag.Name, addr)
return
}
cfg.Miner.Etherbase = common.BytesToAddress(b)
}

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

0 comments on commit 59a48e0

Please sign in to comment.