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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 420 additions and 143 deletions

View File

@ -222,11 +222,11 @@ func init() {
utils.LightKDFFlag, utils.LightKDFFlag,
utils.NoUSBFlag, utils.NoUSBFlag,
utils.SmartCardDaemonPathFlag, utils.SmartCardDaemonPathFlag,
utils.RPCListenAddrFlag, utils.HTTPListenAddrFlag,
utils.RPCVirtualHostsFlag, utils.HTTPVirtualHostsFlag,
utils.IPCDisabledFlag, utils.IPCDisabledFlag,
utils.IPCPathFlag, utils.IPCPathFlag,
utils.RPCEnabledFlag, utils.HTTPEnabledFlag,
rpcPortFlag, rpcPortFlag,
signerSecretFlag, signerSecretFlag,
customDBFlag, customDBFlag,
@ -579,9 +579,9 @@ func signer(c *cli.Context) error {
Service: api, Service: api,
Version: "1.0"}, Version: "1.0"},
} }
if c.GlobalBool(utils.RPCEnabledFlag.Name) { if c.GlobalBool(utils.HTTPEnabledFlag.Name) {
vhosts := splitAndTrim(c.GlobalString(utils.RPCVirtualHostsFlag.Name)) vhosts := splitAndTrim(c.GlobalString(utils.HTTPVirtualHostsFlag.Name))
cors := splitAndTrim(c.GlobalString(utils.RPCCORSDomainFlag.Name)) cors := splitAndTrim(c.GlobalString(utils.HTTPCORSDomainFlag.Name))
srv := rpc.NewServer() srv := rpc.NewServer()
err := node.RegisterApisFromWhitelist(rpcAPI, []string{"account"}, srv, false) err := node.RegisterApisFromWhitelist(rpcAPI, []string{"account"}, srv, false)
@ -591,7 +591,7 @@ func signer(c *cli.Context) error {
handler := node.NewHTTPHandlerStack(srv, cors, vhosts) handler := node.NewHTTPHandlerStack(srv, cors, vhosts)
// start http server // start http server
httpEndpoint := fmt.Sprintf("%s:%d", c.GlobalString(utils.RPCListenAddrFlag.Name), c.Int(rpcPortFlag.Name)) httpEndpoint := fmt.Sprintf("%s:%d", c.GlobalString(utils.HTTPListenAddrFlag.Name), c.Int(rpcPortFlag.Name))
httpServer, addr, err := node.StartHTTPEndpoint(httpEndpoint, rpc.DefaultHTTPTimeouts, handler) httpServer, addr, err := node.StartHTTPEndpoint(httpEndpoint, rpc.DefaultHTTPTimeouts, handler)
if err != nil { if err != nil {
utils.Fatalf("Could not start RPC api: %v", err) utils.Fatalf("Could not start RPC api: %v", err)

View File

@ -93,11 +93,11 @@ var (
utils.GCModeFlag, utils.GCModeFlag,
utils.SnapshotFlag, utils.SnapshotFlag,
utils.LightServeFlag, utils.LightServeFlag,
utils.LightLegacyServFlag, utils.LegacyLightServFlag,
utils.LightIngressFlag, utils.LightIngressFlag,
utils.LightEgressFlag, utils.LightEgressFlag,
utils.LightMaxPeersFlag, utils.LightMaxPeersFlag,
utils.LightLegacyPeersFlag, utils.LegacyLightPeersFlag,
utils.LightKDFFlag, utils.LightKDFFlag,
utils.UltraLightServersFlag, utils.UltraLightServersFlag,
utils.UltraLightFractionFlag, utils.UltraLightFractionFlag,
@ -114,17 +114,17 @@ var (
utils.MaxPendingPeersFlag, utils.MaxPendingPeersFlag,
utils.MiningEnabledFlag, utils.MiningEnabledFlag,
utils.MinerThreadsFlag, utils.MinerThreadsFlag,
utils.MinerLegacyThreadsFlag, utils.LegacyMinerThreadsFlag,
utils.MinerNotifyFlag, utils.MinerNotifyFlag,
utils.MinerGasTargetFlag, utils.MinerGasTargetFlag,
utils.MinerLegacyGasTargetFlag, utils.LegacyMinerGasTargetFlag,
utils.MinerGasLimitFlag, utils.MinerGasLimitFlag,
utils.MinerGasPriceFlag, utils.MinerGasPriceFlag,
utils.MinerLegacyGasPriceFlag, utils.LegacyMinerGasPriceFlag,
utils.MinerEtherbaseFlag, utils.MinerEtherbaseFlag,
utils.MinerLegacyEtherbaseFlag, utils.LegacyMinerEtherbaseFlag,
utils.MinerExtraDataFlag, utils.MinerExtraDataFlag,
utils.MinerLegacyExtraDataFlag, utils.LegacyMinerExtraDataFlag,
utils.MinerRecommitIntervalFlag, utils.MinerRecommitIntervalFlag,
utils.MinerNoVerfiyFlag, utils.MinerNoVerfiyFlag,
utils.NATFlag, utils.NATFlag,
@ -146,29 +146,41 @@ var (
utils.FakePoWFlag, utils.FakePoWFlag,
utils.NoCompactionFlag, utils.NoCompactionFlag,
utils.GpoBlocksFlag, utils.GpoBlocksFlag,
utils.LegacyGpoBlocksFlag,
utils.GpoPercentileFlag, utils.GpoPercentileFlag,
utils.LegacyGpoPercentileFlag,
utils.EWASMInterpreterFlag, utils.EWASMInterpreterFlag,
utils.EVMInterpreterFlag, utils.EVMInterpreterFlag,
configFileFlag, configFileFlag,
} }
rpcFlags = []cli.Flag{ rpcFlags = []cli.Flag{
utils.RPCEnabledFlag, utils.HTTPEnabledFlag,
utils.RPCListenAddrFlag, utils.HTTPListenAddrFlag,
utils.RPCPortFlag, utils.HTTPPortFlag,
utils.RPCCORSDomainFlag, utils.HTTPCORSDomainFlag,
utils.RPCVirtualHostsFlag, utils.HTTPVirtualHostsFlag,
utils.LegacyRPCEnabledFlag,
utils.LegacyRPCListenAddrFlag,
utils.LegacyRPCPortFlag,
utils.LegacyRPCCORSDomainFlag,
utils.LegacyRPCVirtualHostsFlag,
utils.GraphQLEnabledFlag, utils.GraphQLEnabledFlag,
utils.GraphQLListenAddrFlag, utils.GraphQLListenAddrFlag,
utils.GraphQLPortFlag, utils.GraphQLPortFlag,
utils.GraphQLCORSDomainFlag, utils.GraphQLCORSDomainFlag,
utils.GraphQLVirtualHostsFlag, utils.GraphQLVirtualHostsFlag,
utils.RPCApiFlag, utils.HTTPApiFlag,
utils.LegacyRPCApiFlag,
utils.WSEnabledFlag, utils.WSEnabledFlag,
utils.WSListenAddrFlag, utils.WSListenAddrFlag,
utils.LegacyWSListenAddrFlag,
utils.WSPortFlag, utils.WSPortFlag,
utils.LegacyWSPortFlag,
utils.WSApiFlag, utils.WSApiFlag,
utils.LegacyWSApiFlag,
utils.WSAllowedOriginsFlag, utils.WSAllowedOriginsFlag,
utils.LegacyWSAllowedOriginsFlag,
utils.IPCDisabledFlag, utils.IPCDisabledFlag,
utils.IPCPathFlag, utils.IPCPathFlag,
utils.InsecureUnlockAllowedFlag, utils.InsecureUnlockAllowedFlag,
@ -227,6 +239,8 @@ func init() {
dumpConfigCommand, dumpConfigCommand,
// See retesteth.go // See retesteth.go
retestethCommand, retestethCommand,
// See cmd/utils/flags_legacy.go
utils.ShowDeprecated,
} }
sort.Sort(cli.CommandsByName(app.Commands)) sort.Sort(cli.CommandsByName(app.Commands))
@ -234,6 +248,7 @@ func init() {
app.Flags = append(app.Flags, rpcFlags...) app.Flags = append(app.Flags, rpcFlags...)
app.Flags = append(app.Flags, consoleFlags...) app.Flags = append(app.Flags, consoleFlags...)
app.Flags = append(app.Flags, debug.Flags...) app.Flags = append(app.Flags, debug.Flags...)
app.Flags = append(app.Flags, debug.DeprecatedFlags...)
app.Flags = append(app.Flags, whisperFlags...) app.Flags = append(app.Flags, whisperFlags...)
app.Flags = append(app.Flags, metricsFlags...) app.Flags = append(app.Flags, metricsFlags...)
@ -360,7 +375,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
// Set contract backend for ethereum service if local node // Set contract backend for ethereum service if local node
// is serving LES requests. // is serving LES requests.
if ctx.GlobalInt(utils.LightLegacyServFlag.Name) > 0 || ctx.GlobalInt(utils.LightServeFlag.Name) > 0 { if ctx.GlobalInt(utils.LegacyLightServFlag.Name) > 0 || ctx.GlobalInt(utils.LightServeFlag.Name) > 0 {
var ethService *eth.Ethereum var ethService *eth.Ethereum
if err := stack.Service(&ethService); err != nil { if err := stack.Service(&ethService); err != nil {
utils.Fatalf("Failed to retrieve ethereum service: %v", err) utils.Fatalf("Failed to retrieve ethereum service: %v", err)
@ -445,16 +460,18 @@ func startNode(ctx *cli.Context, stack *node.Node) {
utils.Fatalf("Ethereum service not running: %v", err) utils.Fatalf("Ethereum service not running: %v", err)
} }
// Set the gas price to the limits from the CLI and start mining // Set the gas price to the limits from the CLI and start mining
gasprice := utils.GlobalBig(ctx, utils.MinerLegacyGasPriceFlag.Name) gasprice := utils.GlobalBig(ctx, utils.MinerGasPriceFlag.Name)
if ctx.IsSet(utils.MinerGasPriceFlag.Name) { if ctx.GlobalIsSet(utils.LegacyMinerGasPriceFlag.Name) && !ctx.GlobalIsSet(utils.MinerGasPriceFlag.Name) {
gasprice = utils.GlobalBig(ctx, utils.MinerGasPriceFlag.Name) gasprice = utils.GlobalBig(ctx, utils.LegacyMinerGasPriceFlag.Name)
} }
ethereum.TxPool().SetGasPrice(gasprice) ethereum.TxPool().SetGasPrice(gasprice)
threads := ctx.GlobalInt(utils.MinerLegacyThreadsFlag.Name) threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name)
if ctx.GlobalIsSet(utils.MinerThreadsFlag.Name) { if ctx.GlobalIsSet(utils.LegacyMinerThreadsFlag.Name) && !ctx.GlobalIsSet(utils.MinerThreadsFlag.Name) {
threads = ctx.GlobalInt(utils.MinerThreadsFlag.Name) threads = ctx.GlobalInt(utils.LegacyMinerThreadsFlag.Name)
log.Warn("The flag --minerthreads is deprecated and will be removed in the future, please use --miner.threads")
} }
if err := ethereum.StartMining(threads); err != nil { if err := ethereum.StartMining(threads); err != nil {
utils.Fatalf("Failed to start mining: %v", err) utils.Fatalf("Failed to start mining: %v", err)
} }

View File

@ -887,8 +887,8 @@ func retesteth(ctx *cli.Context) error {
Version: "1.0", Version: "1.0",
}, },
} }
vhosts := splitAndTrim(ctx.GlobalString(utils.RPCVirtualHostsFlag.Name)) vhosts := splitAndTrim(ctx.GlobalString(utils.HTTPVirtualHostsFlag.Name))
cors := splitAndTrim(ctx.GlobalString(utils.RPCCORSDomainFlag.Name)) cors := splitAndTrim(ctx.GlobalString(utils.HTTPCORSDomainFlag.Name))
// register apis and create handler stack // register apis and create handler stack
srv := rpc.NewServer() srv := rpc.NewServer()
@ -904,7 +904,7 @@ func retesteth(ctx *cli.Context) error {
WriteTimeout: 120 * time.Second, WriteTimeout: 120 * time.Second,
IdleTimeout: 120 * time.Second, IdleTimeout: 120 * time.Second,
} }
httpEndpoint := fmt.Sprintf("%s:%d", ctx.GlobalString(utils.RPCListenAddrFlag.Name), ctx.Int(rpcPortFlag.Name)) httpEndpoint := fmt.Sprintf("%s:%d", ctx.GlobalString(utils.HTTPListenAddrFlag.Name), ctx.Int(rpcPortFlag.Name))
httpServer, _, err := node.StartHTTPEndpoint(httpEndpoint, RetestethHTTPTimeouts, handler) httpServer, _, err := node.StartHTTPEndpoint(httpEndpoint, RetestethHTTPTimeouts, handler)
if err != nil { if err != nil {
utils.Fatalf("Could not start RPC api: %v", err) utils.Fatalf("Could not start RPC api: %v", err)

View File

@ -157,13 +157,12 @@ var AppHelpFlagGroups = []flagGroup{
Flags: []cli.Flag{ Flags: []cli.Flag{
utils.IPCDisabledFlag, utils.IPCDisabledFlag,
utils.IPCPathFlag, utils.IPCPathFlag,
utils.RPCEnabledFlag, utils.HTTPEnabledFlag,
utils.RPCListenAddrFlag, utils.HTTPListenAddrFlag,
utils.RPCPortFlag, utils.HTTPPortFlag,
utils.RPCApiFlag, utils.HTTPApiFlag,
utils.RPCGlobalGasCap, utils.HTTPCORSDomainFlag,
utils.RPCCORSDomainFlag, utils.HTTPVirtualHostsFlag,
utils.RPCVirtualHostsFlag,
utils.WSEnabledFlag, utils.WSEnabledFlag,
utils.WSListenAddrFlag, utils.WSListenAddrFlag,
utils.WSPortFlag, utils.WSPortFlag,
@ -174,6 +173,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.GraphQLPortFlag, utils.GraphQLPortFlag,
utils.GraphQLCORSDomainFlag, utils.GraphQLCORSDomainFlag,
utils.GraphQLVirtualHostsFlag, utils.GraphQLVirtualHostsFlag,
utils.RPCGlobalGasCap,
utils.JSpathFlag, utils.JSpathFlag,
utils.ExecFlag, utils.ExecFlag,
utils.PreloadJSFlag, utils.PreloadJSFlag,
@ -243,20 +243,28 @@ var AppHelpFlagGroups = []flagGroup{
Flags: whisperFlags, Flags: whisperFlags,
}, },
{ {
Name: "DEPRECATED", Name: "ALIASED (deprecated)",
Flags: []cli.Flag{ Flags: append([]cli.Flag{
utils.LegacyTestnetFlag, utils.LegacyRPCEnabledFlag,
utils.LightLegacyServFlag, utils.LegacyRPCListenAddrFlag,
utils.LightLegacyPeersFlag, utils.LegacyRPCPortFlag,
utils.MinerLegacyThreadsFlag, utils.LegacyRPCCORSDomainFlag,
utils.MinerLegacyGasTargetFlag, utils.LegacyRPCVirtualHostsFlag,
utils.MinerLegacyGasPriceFlag, utils.LegacyRPCApiFlag,
utils.MinerLegacyEtherbaseFlag, utils.LegacyWSListenAddrFlag,
utils.MinerLegacyExtraDataFlag, utils.LegacyWSPortFlag,
}, utils.LegacyWSAllowedOriginsFlag,
utils.LegacyWSApiFlag,
utils.LegacyGpoBlocksFlag,
utils.LegacyGpoPercentileFlag,
}, debug.DeprecatedFlags...),
}, },
{ {
Name: "MISC", Name: "MISC",
Flags: []cli.Flag{
utils.SnapshotFlag,
cli.HelpFlag,
},
}, },
} }
@ -314,10 +322,17 @@ func init() {
categorized[flag.String()] = struct{}{} categorized[flag.String()] = struct{}{}
} }
} }
deprecated := make(map[string]struct{})
for _, flag := range utils.DeprecatedFlags {
deprecated[flag.String()] = struct{}{}
}
// Only add uncategorized flags if they are not deprecated
var uncategorized []cli.Flag var uncategorized []cli.Flag
for _, flag := range data.(*cli.App).Flags { for _, flag := range data.(*cli.App).Flags {
if _, ok := categorized[flag.String()]; !ok { if _, ok := categorized[flag.String()]; !ok {
uncategorized = append(uncategorized, flag) if _, ok := deprecated[flag.String()]; !ok {
uncategorized = append(uncategorized, flag)
}
} }
} }
if len(uncategorized) > 0 { if len(uncategorized) > 0 {

View File

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

163
cmd/utils/flags_legacy.go Normal file
View File

@ -0,0 +1,163 @@
// Copyright 2020 The go-ethereum Authors
// This file is part of go-ethereum.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// go-ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
package utils
import (
"fmt"
"strings"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/node"
"gopkg.in/urfave/cli.v1"
)
var ShowDeprecated = cli.Command{
Action: showDeprecated,
Name: "show-deprecated-flags",
Usage: "Show flags that have been deprecated",
ArgsUsage: " ",
Category: "MISCELLANEOUS COMMANDS",
Description: "Show flags that have been deprecated and will soon be removed",
}
var DeprecatedFlags = []cli.Flag{
LegacyTestnetFlag,
LegacyLightServFlag,
LegacyLightPeersFlag,
LegacyMinerThreadsFlag,
LegacyMinerGasTargetFlag,
LegacyMinerGasPriceFlag,
LegacyMinerEtherbaseFlag,
LegacyMinerExtraDataFlag,
}
var (
// (Deprecated April 2018)
LegacyMinerThreadsFlag = cli.IntFlag{
Name: "minerthreads",
Usage: "Number of CPU threads to use for mining (deprecated, use --miner.threads)",
Value: 0,
}
LegacyMinerGasTargetFlag = cli.Uint64Flag{
Name: "targetgaslimit",
Usage: "Target gas floor for mined blocks (deprecated, use --miner.gastarget)",
Value: eth.DefaultConfig.Miner.GasFloor,
}
LegacyMinerGasPriceFlag = BigFlag{
Name: "gasprice",
Usage: "Minimum gas price for mining a transaction (deprecated, use --miner.gasprice)",
Value: eth.DefaultConfig.Miner.GasPrice,
}
LegacyMinerEtherbaseFlag = cli.StringFlag{
Name: "etherbase",
Usage: "Public address for block mining rewards (default = first account, deprecated, use --miner.etherbase)",
Value: "0",
}
LegacyMinerExtraDataFlag = cli.StringFlag{
Name: "extradata",
Usage: "Block extra data set by the miner (default = client version, deprecated, use --miner.extradata)",
}
// (Deprecated June 2019)
LegacyLightServFlag = cli.IntFlag{
Name: "lightserv",
Usage: "Maximum percentage of time allowed for serving LES requests (deprecated, use --light.serve)",
Value: eth.DefaultConfig.LightServ,
}
LegacyLightPeersFlag = cli.IntFlag{
Name: "lightpeers",
Usage: "Maximum number of light clients to serve, or light servers to attach to (deprecated, use --light.maxpeers)",
Value: eth.DefaultConfig.LightPeers,
}
// (Deprecated April 2020)
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.)",
}
LegacyRPCEnabledFlag = cli.BoolFlag{
Name: "rpc",
Usage: "Enable the HTTP-RPC server (deprecated, use --http)",
}
LegacyRPCListenAddrFlag = cli.StringFlag{
Name: "rpcaddr",
Usage: "HTTP-RPC server listening interface (deprecated, use --http.addr)",
Value: node.DefaultHTTPHost,
}
LegacyRPCPortFlag = cli.IntFlag{
Name: "rpcport",
Usage: "HTTP-RPC server listening port (deprecated, use --http.port)",
Value: node.DefaultHTTPPort,
}
LegacyRPCCORSDomainFlag = cli.StringFlag{
Name: "rpccorsdomain",
Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced) (deprecated, use --http.corsdomain)",
Value: "",
}
LegacyRPCVirtualHostsFlag = cli.StringFlag{
Name: "rpcvhosts",
Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (deprecated, use --http.vhosts)",
Value: strings.Join(node.DefaultConfig.HTTPVirtualHosts, ","),
}
LegacyRPCApiFlag = cli.StringFlag{
Name: "rpcapi",
Usage: "API's offered over the HTTP-RPC interface (deprecated, use --http.api)",
Value: "",
}
LegacyWSListenAddrFlag = cli.StringFlag{
Name: "wsaddr",
Usage: "WS-RPC server listening interface (deprecated, use --ws.addr)",
Value: node.DefaultWSHost,
}
LegacyWSPortFlag = cli.IntFlag{
Name: "wsport",
Usage: "WS-RPC server listening port (deprecated, use --ws.port)",
Value: node.DefaultWSPort,
}
LegacyWSApiFlag = cli.StringFlag{
Name: "wsapi",
Usage: "API's offered over the WS-RPC interface (deprecated, use --ws.api)",
Value: "",
}
LegacyWSAllowedOriginsFlag = cli.StringFlag{
Name: "wsorigins",
Usage: "Origins from which to accept websockets requests (deprecated, use --ws.origins)",
Value: "",
}
LegacyGpoBlocksFlag = cli.IntFlag{
Name: "gpoblocks",
Usage: "Number of recent blocks to check for gas prices (deprecated, use --gpo.blocks)",
Value: eth.DefaultConfig.GPO.Blocks,
}
LegacyGpoPercentileFlag = cli.IntFlag{
Name: "gpopercentile",
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices (deprecated, use --gpo.percentile)",
Value: eth.DefaultConfig.GPO.Percentile,
}
)
// showDeprecated displays deprecated flags that will be soon removed from the codebase.
func showDeprecated(*cli.Context) {
fmt.Println("--------------------------------------------------------------------")
fmt.Println("The following flags are deprecated and will be removed in the future!")
fmt.Println("--------------------------------------------------------------------")
fmt.Println()
for _, flag := range DeprecatedFlags {
fmt.Println(flag.String())
}
}

View File

@ -60,39 +60,68 @@ var (
Usage: "Enable the pprof HTTP server", Usage: "Enable the pprof HTTP server",
} }
pprofPortFlag = cli.IntFlag{ pprofPortFlag = cli.IntFlag{
Name: "pprofport", Name: "pprof.port",
Usage: "pprof HTTP server listening port", Usage: "pprof HTTP server listening port",
Value: 6060, Value: 6060,
} }
pprofAddrFlag = cli.StringFlag{ pprofAddrFlag = cli.StringFlag{
Name: "pprofaddr", Name: "pprof.addr",
Usage: "pprof HTTP server listening interface", Usage: "pprof HTTP server listening interface",
Value: "127.0.0.1", Value: "127.0.0.1",
} }
memprofilerateFlag = cli.IntFlag{ memprofilerateFlag = cli.IntFlag{
Name: "memprofilerate", Name: "pprof.memprofilerate",
Usage: "Turn on memory profiling with the given rate", Usage: "Turn on memory profiling with the given rate",
Value: runtime.MemProfileRate, Value: runtime.MemProfileRate,
} }
blockprofilerateFlag = cli.IntFlag{ blockprofilerateFlag = cli.IntFlag{
Name: "blockprofilerate", Name: "pprof.blockprofilerate",
Usage: "Turn on block profiling with the given rate", Usage: "Turn on block profiling with the given rate",
} }
cpuprofileFlag = cli.StringFlag{ cpuprofileFlag = cli.StringFlag{
Name: "cpuprofile", Name: "pprof.cpuprofile",
Usage: "Write CPU profile to the given file", Usage: "Write CPU profile to the given file",
} }
traceFlag = cli.StringFlag{ traceFlag = cli.StringFlag{
Name: "trace", Name: "trace",
Usage: "Write execution trace to the given file", Usage: "Write execution trace to the given file",
} }
// (Deprecated April 2020)
legacyPprofPortFlag = cli.IntFlag{
Name: "pprofport",
Usage: "pprof HTTP server listening port (deprecated, use --pprof.port)",
Value: 6060,
}
legacyPprofAddrFlag = cli.StringFlag{
Name: "pprofaddr",
Usage: "pprof HTTP server listening interface (deprecated, use --pprof.addr)",
Value: "127.0.0.1",
}
legacyMemprofilerateFlag = cli.IntFlag{
Name: "memprofilerate",
Usage: "Turn on memory profiling with the given rate (deprecated, use --pprof.memprofilerate)",
Value: runtime.MemProfileRate,
}
legacyBlockprofilerateFlag = cli.IntFlag{
Name: "blockprofilerate",
Usage: "Turn on block profiling with the given rate (deprecated, use --pprof.blockprofilerate)",
}
legacyCpuprofileFlag = cli.StringFlag{
Name: "cpuprofile",
Usage: "Write CPU profile to the given file (deprecated, use --pprof.cpuprofile)",
}
) )
// Flags holds all command-line flags required for debugging. // Flags holds all command-line flags required for debugging.
var Flags = []cli.Flag{ var Flags = []cli.Flag{
verbosityFlag, vmoduleFlag, backtraceAtFlag, debugFlag, verbosityFlag, vmoduleFlag, backtraceAtFlag, debugFlag,
pprofFlag, pprofAddrFlag, pprofPortFlag, pprofFlag, pprofAddrFlag, pprofPortFlag, memprofilerateFlag,
memprofilerateFlag, blockprofilerateFlag, cpuprofileFlag, traceFlag, blockprofilerateFlag, cpuprofileFlag, traceFlag,
}
var DeprecatedFlags = []cli.Flag{
legacyPprofPortFlag, legacyPprofAddrFlag, legacyMemprofilerateFlag,
legacyBlockprofilerateFlag, legacyCpuprofileFlag,
} }
var ( var (
@ -121,22 +150,51 @@ func Setup(ctx *cli.Context) error {
log.Root().SetHandler(glogger) log.Root().SetHandler(glogger)
// profiling, tracing // profiling, tracing
if ctx.GlobalIsSet(legacyMemprofilerateFlag.Name) {
runtime.MemProfileRate = ctx.GlobalInt(legacyMemprofilerateFlag.Name)
log.Warn("The flag --memprofilerate is deprecated and will be removed in the future, please use --pprof.memprofilerate")
}
runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name) runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name)
if ctx.GlobalIsSet(legacyBlockprofilerateFlag.Name) {
Handler.SetBlockProfileRate(ctx.GlobalInt(legacyBlockprofilerateFlag.Name))
log.Warn("The flag --blockprofilerate is deprecated and will be removed in the future, please use --pprof.blockprofilerate")
}
Handler.SetBlockProfileRate(ctx.GlobalInt(blockprofilerateFlag.Name)) Handler.SetBlockProfileRate(ctx.GlobalInt(blockprofilerateFlag.Name))
if traceFile := ctx.GlobalString(traceFlag.Name); traceFile != "" { if traceFile := ctx.GlobalString(traceFlag.Name); traceFile != "" {
if err := Handler.StartGoTrace(traceFile); err != nil { if err := Handler.StartGoTrace(traceFile); err != nil {
return err return err
} }
} }
if cpuFile := ctx.GlobalString(cpuprofileFlag.Name); cpuFile != "" { if cpuFile := ctx.GlobalString(cpuprofileFlag.Name); cpuFile != "" {
if err := Handler.StartCPUProfile(cpuFile); err != nil { if err := Handler.StartCPUProfile(cpuFile); err != nil {
return err return err
} }
} }
if cpuFile := ctx.GlobalString(legacyCpuprofileFlag.Name); cpuFile != "" {
log.Warn("The flag --cpuprofile is deprecated and will be removed in the future, please use --pprof.cpuprofile")
if err := Handler.StartCPUProfile(cpuFile); err != nil {
return err
}
}
// pprof server // pprof server
if ctx.GlobalBool(pprofFlag.Name) { if ctx.GlobalBool(pprofFlag.Name) {
address := fmt.Sprintf("%s:%d", ctx.GlobalString(pprofAddrFlag.Name), ctx.GlobalInt(pprofPortFlag.Name)) listenHost := ctx.GlobalString(pprofAddrFlag.Name)
if ctx.GlobalIsSet(legacyPprofAddrFlag.Name) && !ctx.GlobalIsSet(pprofAddrFlag.Name) {
listenHost = ctx.GlobalString(legacyPprofAddrFlag.Name)
log.Warn("The flag --pprofaddr is deprecated and will be removed in the future, please use --pprof.addr")
}
port := ctx.GlobalInt(pprofPortFlag.Name)
if ctx.GlobalIsSet(legacyPprofPortFlag.Name) && !ctx.GlobalIsSet(pprofPortFlag.Name) {
port = ctx.GlobalInt(legacyPprofPortFlag.Name)
log.Warn("The flag --pprofport is deprecated and will be removed in the future, please use --pprof.port")
}
address := fmt.Sprintf("%s:%d", listenHost, port)
StartPProf(address) StartPProf(address)
} }
return nil return nil