cmd/utils: renames flags related to http-rpc server (#20935)

* rpc flags related to starting http server renamed to http

* old rpc flags aliased and still functional

* pprof flags fixed

* renames gpo related flags

* linted

* renamed rpc flags for consistency and clarity

* added warn logs

* added more warn logs for all deprecated flags for consistency

* moves legacy flags to separate file, hides older flags under show-deprecated-flags command

* legacy prefix and moved some more legacy flags to legacy file

* fixed circular import

* added docs

* fixed imports lint error

* added notes about when flags were deprecated

* cmd/utils: group flags by deprecation date + reorder by date,

* modified deprecated comments for consistency, added warn log for --rpc

* making sure deprecated flags are still functional

* show-deprecated-flags command cleaned up

* fixed lint errors

* corrected merge conflict

* IsSet --> GlobalIsSet

* uncategorized flags, if not deprecated, displayed under misc

Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
rene
2020-05-05 10:19:17 +02:00
committed by GitHub
parent 587656619d
commit c989bca173
7 changed files with 420 additions and 143 deletions

View File

@ -165,10 +165,6 @@ var (
Usage: "Network identifier (integer, 1=Frontier, 3=Ropsten, 4=Rinkeby, 5=Görli)",
Value: eth.DefaultConfig.NetworkId,
}
LegacyTestnetFlag = cli.BoolFlag{ // TODO(q9f): Remove after Ropsten is discontinued.
Name: "testnet",
Usage: "Pre-configured test network (Deprecated: Please choose one of --goerli, --rinkeby, or --ropsten.)",
}
GoerliFlag = cli.BoolFlag{
Name: "goerli",
Usage: "Görli network: pre-configured proof-of-authority test network",
@ -242,11 +238,6 @@ var (
Usage: "Comma separated block number-to-hash mappings to enforce (<number>=<hash>)",
}
// Light server and client settings
LightLegacyServFlag = cli.IntFlag{ // Deprecated in favor of light.serve, remove in 2021
Name: "lightserv",
Usage: "Maximum percentage of time allowed for serving LES requests (deprecated, use --light.serve)",
Value: eth.DefaultConfig.LightServ,
}
LightServeFlag = cli.IntFlag{
Name: "light.serve",
Usage: "Maximum percentage of time allowed for serving LES requests (multi-threaded processing allows values over 100)",
@ -262,11 +253,6 @@ var (
Usage: "Outgoing bandwidth limit for serving light clients (kilobytes/sec, 0 = unlimited)",
Value: eth.DefaultConfig.LightEgress,
}
LightLegacyPeersFlag = cli.IntFlag{ // Deprecated in favor of light.maxpeers, remove in 2021
Name: "lightpeers",
Usage: "Maximum number of light clients to serve, or light servers to attach to (deprecated, use --light.maxpeers)",
Value: eth.DefaultConfig.LightPeers,
}
LightMaxPeersFlag = cli.IntFlag{
Name: "light.maxpeers",
Usage: "Maximum number of light clients to serve, or light servers to attach to",
@ -418,11 +404,6 @@ var (
Usage: "Number of CPU threads to use for mining",
Value: 0,
}
MinerLegacyThreadsFlag = cli.IntFlag{
Name: "minerthreads",
Usage: "Number of CPU threads to use for mining (deprecated, use --miner.threads)",
Value: 0,
}
MinerNotifyFlag = cli.StringFlag{
Name: "miner.notify",
Usage: "Comma separated HTTP URL list to notify of new work packages",
@ -432,11 +413,6 @@ var (
Usage: "Target gas floor for mined blocks",
Value: eth.DefaultConfig.Miner.GasFloor,
}
MinerLegacyGasTargetFlag = cli.Uint64Flag{
Name: "targetgaslimit",
Usage: "Target gas floor for mined blocks (deprecated, use --miner.gastarget)",
Value: eth.DefaultConfig.Miner.GasFloor,
}
MinerGasLimitFlag = cli.Uint64Flag{
Name: "miner.gaslimit",
Usage: "Target gas ceiling for mined blocks",
@ -447,29 +423,15 @@ var (
Usage: "Minimum gas price for mining a transaction",
Value: eth.DefaultConfig.Miner.GasPrice,
}
MinerLegacyGasPriceFlag = BigFlag{
Name: "gasprice",
Usage: "Minimum gas price for mining a transaction (deprecated, use --miner.gasprice)",
Value: eth.DefaultConfig.Miner.GasPrice,
}
MinerEtherbaseFlag = cli.StringFlag{
Name: "miner.etherbase",
Usage: "Public address for block mining rewards (default = first account)",
Value: "0",
}
MinerLegacyEtherbaseFlag = cli.StringFlag{
Name: "etherbase",
Usage: "Public address for block mining rewards (default = first account, deprecated, use --miner.etherbase)",
Value: "0",
}
MinerExtraDataFlag = cli.StringFlag{
Name: "miner.extradata",
Usage: "Block extra data set by the miner (default = client version)",
}
MinerLegacyExtraDataFlag = cli.StringFlag{
Name: "extradata",
Usage: "Block extra data set by the miner (default = client version, deprecated, use --miner.extradata)",
}
MinerRecommitIntervalFlag = cli.DurationFlag{
Name: "miner.recommit",
Usage: "Time interval to recreate the block being mined",
@ -529,32 +491,32 @@ var (
Name: "ipcpath",
Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
}
RPCEnabledFlag = cli.BoolFlag{
Name: "rpc",
HTTPEnabledFlag = cli.BoolFlag{
Name: "http",
Usage: "Enable the HTTP-RPC server",
}
RPCListenAddrFlag = cli.StringFlag{
Name: "rpcaddr",
HTTPListenAddrFlag = cli.StringFlag{
Name: "http.addr",
Usage: "HTTP-RPC server listening interface",
Value: node.DefaultHTTPHost,
}
RPCPortFlag = cli.IntFlag{
Name: "rpcport",
HTTPPortFlag = cli.IntFlag{
Name: "http.port",
Usage: "HTTP-RPC server listening port",
Value: node.DefaultHTTPPort,
}
RPCCORSDomainFlag = cli.StringFlag{
Name: "rpccorsdomain",
HTTPCORSDomainFlag = cli.StringFlag{
Name: "http.corsdomain",
Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
Value: "",
}
RPCVirtualHostsFlag = cli.StringFlag{
Name: "rpcvhosts",
HTTPVirtualHostsFlag = cli.StringFlag{
Name: "http.vhosts",
Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
Value: strings.Join(node.DefaultConfig.HTTPVirtualHosts, ","),
}
RPCApiFlag = cli.StringFlag{
Name: "rpcapi",
HTTPApiFlag = cli.StringFlag{
Name: "http.api",
Usage: "API's offered over the HTTP-RPC interface",
Value: "",
}
@ -563,22 +525,22 @@ var (
Usage: "Enable the WS-RPC server",
}
WSListenAddrFlag = cli.StringFlag{
Name: "wsaddr",
Name: "ws.addr",
Usage: "WS-RPC server listening interface",
Value: node.DefaultWSHost,
}
WSPortFlag = cli.IntFlag{
Name: "wsport",
Name: "ws.port",
Usage: "WS-RPC server listening port",
Value: node.DefaultWSPort,
}
WSApiFlag = cli.StringFlag{
Name: "wsapi",
Name: "ws.api",
Usage: "API's offered over the WS-RPC interface",
Value: "",
}
WSAllowedOriginsFlag = cli.StringFlag{
Name: "wsorigins",
Name: "ws.origins",
Usage: "Origins from which to accept websockets requests",
Value: "",
}
@ -685,12 +647,12 @@ var (
// Gas price oracle settings
GpoBlocksFlag = cli.IntFlag{
Name: "gpoblocks",
Name: "gpo.blocks",
Usage: "Number of recent blocks to check for gas prices",
Value: eth.DefaultConfig.GPO.Blocks,
}
GpoPercentileFlag = cli.IntFlag{
Name: "gpopercentile",
Name: "gpo.percentile",
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
Value: eth.DefaultConfig.GPO.Percentile,
}
@ -924,23 +886,51 @@ func splitAndTrim(input string) []string {
// setHTTP creates the HTTP RPC listener interface string from the set
// command line flags, returning empty if the HTTP endpoint is disabled.
func setHTTP(ctx *cli.Context, cfg *node.Config) {
if ctx.GlobalBool(RPCEnabledFlag.Name) && cfg.HTTPHost == "" {
if ctx.GlobalBool(LegacyRPCEnabledFlag.Name) && cfg.HTTPHost == "" {
log.Warn("The flag --rpc is deprecated and will be removed in the future, please use --http")
cfg.HTTPHost = "127.0.0.1"
if ctx.GlobalIsSet(RPCListenAddrFlag.Name) {
cfg.HTTPHost = ctx.GlobalString(RPCListenAddrFlag.Name)
if ctx.GlobalIsSet(LegacyRPCListenAddrFlag.Name) {
cfg.HTTPHost = ctx.GlobalString(LegacyRPCListenAddrFlag.Name)
log.Warn("The flag --rpcaddr is deprecated and will be removed in the future, please use --http.addr")
}
}
if ctx.GlobalIsSet(RPCPortFlag.Name) {
cfg.HTTPPort = ctx.GlobalInt(RPCPortFlag.Name)
if ctx.GlobalBool(HTTPEnabledFlag.Name) && cfg.HTTPHost == "" {
cfg.HTTPHost = "127.0.0.1"
if ctx.GlobalIsSet(HTTPListenAddrFlag.Name) {
cfg.HTTPHost = ctx.GlobalString(HTTPListenAddrFlag.Name)
}
}
if ctx.GlobalIsSet(RPCCORSDomainFlag.Name) {
cfg.HTTPCors = splitAndTrim(ctx.GlobalString(RPCCORSDomainFlag.Name))
if ctx.GlobalIsSet(LegacyRPCPortFlag.Name) {
cfg.HTTPPort = ctx.GlobalInt(LegacyRPCPortFlag.Name)
log.Warn("The flag --rpcport is deprecated and will be removed in the future, please use --http.port")
}
if ctx.GlobalIsSet(RPCApiFlag.Name) {
cfg.HTTPModules = splitAndTrim(ctx.GlobalString(RPCApiFlag.Name))
if ctx.GlobalIsSet(HTTPPortFlag.Name) {
cfg.HTTPPort = ctx.GlobalInt(HTTPPortFlag.Name)
}
if ctx.GlobalIsSet(RPCVirtualHostsFlag.Name) {
cfg.HTTPVirtualHosts = splitAndTrim(ctx.GlobalString(RPCVirtualHostsFlag.Name))
if ctx.GlobalIsSet(LegacyRPCCORSDomainFlag.Name) {
cfg.HTTPCors = splitAndTrim(ctx.GlobalString(LegacyRPCCORSDomainFlag.Name))
log.Warn("The flag --rpccorsdomain is deprecated and will be removed in the future, please use --http.corsdomain")
}
if ctx.GlobalIsSet(HTTPCORSDomainFlag.Name) {
cfg.HTTPCors = splitAndTrim(ctx.GlobalString(HTTPCORSDomainFlag.Name))
}
if ctx.GlobalIsSet(LegacyRPCApiFlag.Name) {
cfg.HTTPModules = splitAndTrim(ctx.GlobalString(LegacyRPCApiFlag.Name))
log.Warn("The flag --rpcapi is deprecated and will be removed in the future, please use --http.api")
}
if ctx.GlobalIsSet(HTTPApiFlag.Name) {
cfg.HTTPModules = splitAndTrim(ctx.GlobalString(HTTPApiFlag.Name))
}
if ctx.GlobalIsSet(LegacyRPCVirtualHostsFlag.Name) {
cfg.HTTPVirtualHosts = splitAndTrim(ctx.GlobalString(LegacyRPCVirtualHostsFlag.Name))
log.Warn("The flag --rpcvhosts is deprecated and will be removed in the future, please use --http.vhosts")
}
if ctx.GlobalIsSet(HTTPVirtualHostsFlag.Name) {
cfg.HTTPVirtualHosts = splitAndTrim(ctx.GlobalString(HTTPVirtualHostsFlag.Name))
}
}
@ -967,16 +957,34 @@ func setGraphQL(ctx *cli.Context, cfg *node.Config) {
func setWS(ctx *cli.Context, cfg *node.Config) {
if ctx.GlobalBool(WSEnabledFlag.Name) && cfg.WSHost == "" {
cfg.WSHost = "127.0.0.1"
if ctx.GlobalIsSet(LegacyWSListenAddrFlag.Name) {
cfg.WSHost = ctx.GlobalString(LegacyWSListenAddrFlag.Name)
log.Warn("The flag --wsaddr is deprecated and will be removed in the future, please use --ws.addr")
}
if ctx.GlobalIsSet(WSListenAddrFlag.Name) {
cfg.WSHost = ctx.GlobalString(WSListenAddrFlag.Name)
}
}
if ctx.GlobalIsSet(LegacyWSPortFlag.Name) {
cfg.WSPort = ctx.GlobalInt(LegacyWSPortFlag.Name)
log.Warn("The flag --wsport is deprecated and will be removed in the future, please use --ws.port")
}
if ctx.GlobalIsSet(WSPortFlag.Name) {
cfg.WSPort = ctx.GlobalInt(WSPortFlag.Name)
}
if ctx.GlobalIsSet(LegacyWSAllowedOriginsFlag.Name) {
cfg.WSOrigins = splitAndTrim(ctx.GlobalString(LegacyWSAllowedOriginsFlag.Name))
log.Warn("The flag --wsorigins is deprecated and will be removed in the future, please use --ws.origins")
}
if ctx.GlobalIsSet(WSAllowedOriginsFlag.Name) {
cfg.WSOrigins = splitAndTrim(ctx.GlobalString(WSAllowedOriginsFlag.Name))
}
if ctx.GlobalIsSet(LegacyWSApiFlag.Name) {
cfg.WSModules = splitAndTrim(ctx.GlobalString(LegacyWSApiFlag.Name))
log.Warn("The flag --wsapi is deprecated and will be removed in the future, please use --ws.api")
}
if ctx.GlobalIsSet(WSApiFlag.Name) {
cfg.WSModules = splitAndTrim(ctx.GlobalString(WSApiFlag.Name))
}
@ -996,8 +1004,9 @@ func setIPC(ctx *cli.Context, cfg *node.Config) {
// setLes configures the les server and ultra light client settings from the command line flags.
func setLes(ctx *cli.Context, cfg *eth.Config) {
if ctx.GlobalIsSet(LightLegacyServFlag.Name) {
cfg.LightServ = ctx.GlobalInt(LightLegacyServFlag.Name)
if ctx.GlobalIsSet(LegacyLightServFlag.Name) {
cfg.LightServ = ctx.GlobalInt(LegacyLightServFlag.Name)
log.Warn("The flag --lightserv is deprecated and will be removed in the future, please use --light.serve")
}
if ctx.GlobalIsSet(LightServeFlag.Name) {
cfg.LightServ = ctx.GlobalInt(LightServeFlag.Name)
@ -1008,8 +1017,9 @@ func setLes(ctx *cli.Context, cfg *eth.Config) {
if ctx.GlobalIsSet(LightEgressFlag.Name) {
cfg.LightEgress = ctx.GlobalInt(LightEgressFlag.Name)
}
if ctx.GlobalIsSet(LightLegacyPeersFlag.Name) {
cfg.LightPeers = ctx.GlobalInt(LightLegacyPeersFlag.Name)
if ctx.GlobalIsSet(LegacyLightPeersFlag.Name) {
cfg.LightPeers = ctx.GlobalInt(LegacyLightPeersFlag.Name)
log.Warn("The flag --lightpeers is deprecated and will be removed in the future, please use --light.maxpeers")
}
if ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
cfg.LightPeers = ctx.GlobalInt(LightMaxPeersFlag.Name)
@ -1073,8 +1083,10 @@ func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error
func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
// Extract the current etherbase, new flag overriding legacy one
var etherbase string
if ctx.GlobalIsSet(MinerLegacyEtherbaseFlag.Name) {
etherbase = ctx.GlobalString(MinerLegacyEtherbaseFlag.Name)
if ctx.GlobalIsSet(LegacyMinerEtherbaseFlag.Name) {
etherbase = ctx.GlobalString(LegacyMinerEtherbaseFlag.Name)
log.Warn("The flag --etherbase is deprecated and will be removed in the future, please use --miner.etherbase")
}
if ctx.GlobalIsSet(MinerEtherbaseFlag.Name) {
etherbase = ctx.GlobalString(MinerEtherbaseFlag.Name)
@ -1119,27 +1131,27 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
setBootstrapNodesV5(ctx, cfg)
lightClient := ctx.GlobalString(SyncModeFlag.Name) == "light"
lightServer := (ctx.GlobalInt(LightLegacyServFlag.Name) != 0 || ctx.GlobalInt(LightServeFlag.Name) != 0)
lightServer := (ctx.GlobalInt(LegacyLightServFlag.Name) != 0 || ctx.GlobalInt(LightServeFlag.Name) != 0)
lightPeers := ctx.GlobalInt(LightLegacyPeersFlag.Name)
lightPeers := ctx.GlobalInt(LegacyLightPeersFlag.Name)
if ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
lightPeers = ctx.GlobalInt(LightMaxPeersFlag.Name)
}
if lightClient && !ctx.GlobalIsSet(LightLegacyPeersFlag.Name) && !ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
if lightClient && !ctx.GlobalIsSet(LegacyLightPeersFlag.Name) && !ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
// dynamic default - for clients we use 1/10th of the default for servers
lightPeers /= 10
}
if ctx.GlobalIsSet(MaxPeersFlag.Name) {
cfg.MaxPeers = ctx.GlobalInt(MaxPeersFlag.Name)
if lightServer && !ctx.GlobalIsSet(LightLegacyPeersFlag.Name) && !ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
if lightServer && !ctx.GlobalIsSet(LegacyLightPeersFlag.Name) && !ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
cfg.MaxPeers += lightPeers
}
} else {
if lightServer {
cfg.MaxPeers += lightPeers
}
if lightClient && (ctx.GlobalIsSet(LightLegacyPeersFlag.Name) || ctx.GlobalIsSet(LightMaxPeersFlag.Name)) && cfg.MaxPeers < lightPeers {
if lightClient && (ctx.GlobalIsSet(LegacyLightPeersFlag.Name) || ctx.GlobalIsSet(LightMaxPeersFlag.Name)) && cfg.MaxPeers < lightPeers {
cfg.MaxPeers = lightPeers
}
}
@ -1259,9 +1271,18 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) {
}
func setGPO(ctx *cli.Context, cfg *gasprice.Config) {
if ctx.GlobalIsSet(LegacyGpoBlocksFlag.Name) {
cfg.Blocks = ctx.GlobalInt(LegacyGpoBlocksFlag.Name)
log.Warn("The flag --gpoblocks is deprecated and will be removed in the future, please use --gpo.blocks")
}
if ctx.GlobalIsSet(GpoBlocksFlag.Name) {
cfg.Blocks = ctx.GlobalInt(GpoBlocksFlag.Name)
}
if ctx.GlobalIsSet(LegacyGpoPercentileFlag.Name) {
cfg.Percentile = ctx.GlobalInt(LegacyGpoPercentileFlag.Name)
log.Warn("The flag --gpopercentile is deprecated and will be removed in the future, please use --gpo.percentile")
}
if ctx.GlobalIsSet(GpoPercentileFlag.Name) {
cfg.Percentile = ctx.GlobalInt(GpoPercentileFlag.Name)
}
@ -1341,14 +1362,16 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
if ctx.GlobalIsSet(MinerNotifyFlag.Name) {
cfg.Notify = strings.Split(ctx.GlobalString(MinerNotifyFlag.Name), ",")
}
if ctx.GlobalIsSet(MinerLegacyExtraDataFlag.Name) {
cfg.ExtraData = []byte(ctx.GlobalString(MinerLegacyExtraDataFlag.Name))
if ctx.GlobalIsSet(LegacyMinerExtraDataFlag.Name) {
cfg.ExtraData = []byte(ctx.GlobalString(LegacyMinerExtraDataFlag.Name))
log.Warn("The flag --extradata is deprecated and will be removed in the future, please use --miner.extradata")
}
if ctx.GlobalIsSet(MinerExtraDataFlag.Name) {
cfg.ExtraData = []byte(ctx.GlobalString(MinerExtraDataFlag.Name))
}
if ctx.GlobalIsSet(MinerLegacyGasTargetFlag.Name) {
cfg.GasFloor = ctx.GlobalUint64(MinerLegacyGasTargetFlag.Name)
if ctx.GlobalIsSet(LegacyMinerGasTargetFlag.Name) {
cfg.GasFloor = ctx.GlobalUint64(LegacyMinerGasTargetFlag.Name)
log.Warn("The flag --targetgaslimit is deprecated and will be removed in the future, please use --miner.gastarget")
}
if ctx.GlobalIsSet(MinerGasTargetFlag.Name) {
cfg.GasFloor = ctx.GlobalUint64(MinerGasTargetFlag.Name)
@ -1356,8 +1379,9 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
if ctx.GlobalIsSet(MinerGasLimitFlag.Name) {
cfg.GasCeil = ctx.GlobalUint64(MinerGasLimitFlag.Name)
}
if ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) {
cfg.GasPrice = GlobalBig(ctx, MinerLegacyGasPriceFlag.Name)
if ctx.GlobalIsSet(LegacyMinerGasPriceFlag.Name) {
cfg.GasPrice = GlobalBig(ctx, LegacyMinerGasPriceFlag.Name)
log.Warn("The flag --gasprice is deprecated and will be removed in the future, please use --miner.gasprice")
}
if ctx.GlobalIsSet(MinerGasPriceFlag.Name) {
cfg.GasPrice = GlobalBig(ctx, MinerGasPriceFlag.Name)
@ -1451,7 +1475,7 @@ func SetShhConfig(ctx *cli.Context, stack *node.Node, cfg *whisper.Config) {
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
// Avoid conflicting network flags
CheckExclusive(ctx, DeveloperFlag, LegacyTestnetFlag, RopstenFlag, RinkebyFlag, GoerliFlag)
CheckExclusive(ctx, LightLegacyServFlag, LightServeFlag, SyncModeFlag, "light")
CheckExclusive(ctx, LegacyLightServFlag, LightServeFlag, SyncModeFlag, "light")
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
var ks *keystore.KeyStore
@ -1571,7 +1595,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
log.Info("Using developer account", "address", developer.Address)
cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address)
if !ctx.GlobalIsSet(MinerGasPriceFlag.Name) && !ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) {
if !ctx.GlobalIsSet(MinerGasPriceFlag.Name) && !ctx.GlobalIsSet(LegacyMinerGasPriceFlag.Name) {
cfg.Miner.GasPrice = big.NewInt(1)
}
default: