cmd: encapsulate les relative cli options

This commit is contained in:
rjl493456442 2019-07-10 10:08:59 +08:00 committed by Péter Szilágyi
parent 8c4bc4f7ef
commit c6a9616cfd
No known key found for this signature in database
GPG Key ID: E9AE538CEDF8293D
2 changed files with 43 additions and 33 deletions

@ -82,6 +82,13 @@ var AppHelpFlagGroups = []flagGroup{
utils.GCModeFlag, utils.GCModeFlag,
utils.EthStatsURLFlag, utils.EthStatsURLFlag,
utils.IdentityFlag, utils.IdentityFlag,
utils.LightKDFFlag,
utils.WhitelistFlag,
},
},
{
Name: "LES",
Flags: []cli.Flag{
utils.LightServFlag, utils.LightServFlag,
utils.LightBandwidthInFlag, utils.LightBandwidthInFlag,
utils.LightBandwidthOutFlag, utils.LightBandwidthOutFlag,
@ -89,8 +96,6 @@ var AppHelpFlagGroups = []flagGroup{
utils.UltraLightServersFlag, utils.UltraLightServersFlag,
utils.UltraLightFractionFlag, utils.UltraLightFractionFlag,
utils.UltraLightOnlyAnnounceFlag, utils.UltraLightOnlyAnnounceFlag,
utils.LightKDFFlag,
utils.WhitelistFlag,
}, },
}, },
{ {

@ -174,20 +174,6 @@ var (
Name: "exitwhensynced", Name: "exitwhensynced",
Usage: "Exits after block synchronisation completes", Usage: "Exits after block synchronisation completes",
} }
UltraLightServersFlag = cli.StringFlag{
Name: "ulc.servers",
Usage: "List of trusted ultra-light servers",
Value: strings.Join(eth.DefaultConfig.UltraLightServers, ","),
}
UltraLightFractionFlag = cli.IntFlag{
Name: "ulc.fraction",
Usage: "Minimum % of trusted ultra-light servers required to announce a new head",
Value: eth.DefaultConfig.UltraLightFraction,
}
UltraLightOnlyAnnounceFlag = cli.BoolFlag{
Name: "ulc.onlyannounce",
Usage: "Ultra light server sends announcements only",
}
IterativeOutputFlag = cli.BoolFlag{ IterativeOutputFlag = cli.BoolFlag{
Name: "iterative", Name: "iterative",
Usage: "Print streaming JSON iteratively, delimited by newlines", Usage: "Print streaming JSON iteratively, delimited by newlines",
@ -215,6 +201,15 @@ var (
Usage: `Blockchain garbage collection mode ("full", "archive")`, Usage: `Blockchain garbage collection mode ("full", "archive")`,
Value: "full", Value: "full",
} }
LightKDFFlag = cli.BoolFlag{
Name: "lightkdf",
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
}
WhitelistFlag = cli.StringFlag{
Name: "whitelist",
Usage: "Comma separated block number-to-hash mappings to enforce (<number>=<hash>)",
}
// LES settings
LightServFlag = cli.IntFlag{ LightServFlag = cli.IntFlag{
Name: "lightserv", Name: "lightserv",
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)",
@ -235,13 +230,19 @@ var (
Usage: "Maximum number of LES client peers", Usage: "Maximum number of LES client peers",
Value: eth.DefaultConfig.LightPeers, Value: eth.DefaultConfig.LightPeers,
} }
LightKDFFlag = cli.BoolFlag{ UltraLightServersFlag = cli.StringFlag{
Name: "lightkdf", Name: "ulc.servers",
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength", Usage: "List of trusted ultra-light servers",
Value: strings.Join(eth.DefaultConfig.UltraLightServers, ","),
} }
WhitelistFlag = cli.StringFlag{ UltraLightFractionFlag = cli.IntFlag{
Name: "whitelist", Name: "ulc.fraction",
Usage: "Comma separated block number-to-hash mappings to enforce (<number>=<hash>)", Usage: "Minimum % of trusted ultra-light servers required to announce a new head",
Value: eth.DefaultConfig.UltraLightFraction,
}
UltraLightOnlyAnnounceFlag = cli.BoolFlag{
Name: "ulc.onlyannounce",
Usage: "Ultra light server sends announcements only",
} }
// Dashboard settings // Dashboard settings
DashboardEnabledFlag = cli.BoolFlag{ DashboardEnabledFlag = cli.BoolFlag{
@ -949,8 +950,20 @@ func setIPC(ctx *cli.Context, cfg *node.Config) {
} }
} }
// setUltraLight configures the 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 setUltraLight(ctx *cli.Context, cfg *eth.Config) { func setLes(ctx *cli.Context, cfg *eth.Config) {
if ctx.GlobalIsSet(LightServFlag.Name) {
cfg.LightServ = ctx.GlobalInt(LightServFlag.Name)
}
if ctx.GlobalIsSet(LightBandwidthInFlag.Name) {
cfg.LightBandwidthIn = ctx.GlobalInt(LightBandwidthInFlag.Name)
}
if ctx.GlobalIsSet(LightBandwidthOutFlag.Name) {
cfg.LightBandwidthOut = ctx.GlobalInt(LightBandwidthOutFlag.Name)
}
if ctx.GlobalIsSet(LightPeersFlag.Name) {
cfg.LightPeers = ctx.GlobalInt(LightPeersFlag.Name)
}
if ctx.GlobalIsSet(UltraLightServersFlag.Name) { if ctx.GlobalIsSet(UltraLightServersFlag.Name) {
cfg.UltraLightServers = strings.Split(ctx.GlobalString(UltraLightServersFlag.Name), ",") cfg.UltraLightServers = strings.Split(ctx.GlobalString(UltraLightServersFlag.Name), ",")
} }
@ -1379,19 +1392,11 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
setEthash(ctx, cfg) setEthash(ctx, cfg)
setMiner(ctx, &cfg.Miner) setMiner(ctx, &cfg.Miner)
setWhitelist(ctx, cfg) setWhitelist(ctx, cfg)
setUltraLight(ctx, cfg) setLes(ctx, cfg)
if ctx.GlobalIsSet(SyncModeFlag.Name) { if ctx.GlobalIsSet(SyncModeFlag.Name) {
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode) cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
} }
if ctx.GlobalIsSet(LightServFlag.Name) {
cfg.LightServ = ctx.GlobalInt(LightServFlag.Name)
}
cfg.LightBandwidthIn = ctx.GlobalInt(LightBandwidthInFlag.Name)
cfg.LightBandwidthOut = ctx.GlobalInt(LightBandwidthOutFlag.Name)
if ctx.GlobalIsSet(LightPeersFlag.Name) {
cfg.LightPeers = ctx.GlobalInt(LightPeersFlag.Name)
}
if ctx.GlobalIsSet(NetworkIdFlag.Name) { if ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name) cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
} }