cmd/utils: improve parsing of --miner.etherbase address (#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.
This commit is contained in:
Felix Lange 2023-01-24 11:11:33 +01:00 committed by GitHub
parent 163e996d0e
commit 59a48e0289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -21,6 +21,7 @@ import (
"bytes"
"context"
"crypto/ecdsa"
"encoding/hex"
"errors"
"fmt"
"math"
@ -1344,15 +1345,20 @@ 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 !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 {
log.Info("Failed to decode etherbase", "err", err)
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.
func MakePasswordList(ctx *cli.Context) []string {