Skip to content

Commit 54d0eeb

Browse files
authored
Merge pull request #19818 from rjl493456442/encap-les
cmd: encapsulate les relative cli options
2 parents 8c4bc4f + c705aac commit 54d0eeb

File tree

6 files changed

+112
-79
lines changed

6 files changed

+112
-79
lines changed

cmd/geth/main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ var (
9393
utils.SyncModeFlag,
9494
utils.ExitWhenSyncedFlag,
9595
utils.GCModeFlag,
96-
utils.LightServFlag,
97-
utils.LightBandwidthInFlag,
98-
utils.LightBandwidthOutFlag,
99-
utils.LightPeersFlag,
96+
utils.LightServeFlag,
97+
utils.LightLegacyServFlag,
98+
utils.LightIngressFlag,
99+
utils.LightEgressFlag,
100+
utils.LightMaxPeersFlag,
101+
utils.LightLegacyPeersFlag,
100102
utils.LightKDFFlag,
101103
utils.UltraLightServersFlag,
102104
utils.UltraLightFractionFlag,
@@ -336,7 +338,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
336338

337339
// Set contract backend for ethereum service if local node
338340
// is serving LES requests.
339-
if ctx.GlobalInt(utils.LightServFlag.Name) > 0 {
341+
if ctx.GlobalInt(utils.LightLegacyServFlag.Name) > 0 || ctx.GlobalInt(utils.LightServeFlag.Name) > 0 {
340342
var ethService *eth.Ethereum
341343
if err := stack.Service(&ethService); err != nil {
342344
utils.Fatalf("Failed to retrieve ethereum service: %v", err)

cmd/geth/usage.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,20 @@ var AppHelpFlagGroups = []flagGroup{
8282
utils.GCModeFlag,
8383
utils.EthStatsURLFlag,
8484
utils.IdentityFlag,
85-
utils.LightServFlag,
86-
utils.LightBandwidthInFlag,
87-
utils.LightBandwidthOutFlag,
88-
utils.LightPeersFlag,
85+
utils.LightKDFFlag,
86+
utils.WhitelistFlag,
87+
},
88+
},
89+
{
90+
Name: "LIGHT CLIENT",
91+
Flags: []cli.Flag{
92+
utils.LightServeFlag,
93+
utils.LightIngressFlag,
94+
utils.LightEgressFlag,
95+
utils.LightMaxPeersFlag,
8996
utils.UltraLightServersFlag,
9097
utils.UltraLightFractionFlag,
9198
utils.UltraLightOnlyAnnounceFlag,
92-
utils.LightKDFFlag,
93-
utils.WhitelistFlag,
9499
},
95100
},
96101
{
@@ -248,6 +253,8 @@ var AppHelpFlagGroups = []flagGroup{
248253
{
249254
Name: "DEPRECATED",
250255
Flags: []cli.Flag{
256+
utils.LightLegacyServFlag,
257+
utils.LightLegacyPeersFlag,
251258
utils.MinerLegacyThreadsFlag,
252259
utils.MinerLegacyGasTargetFlag,
253260
utils.MinerLegacyGasPriceFlag,

cmd/utils/flags.go

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,6 @@ var (
174174
Name: "exitwhensynced",
175175
Usage: "Exits after block synchronisation completes",
176176
}
177-
UltraLightServersFlag = cli.StringFlag{
178-
Name: "ulc.servers",
179-
Usage: "List of trusted ultra-light servers",
180-
Value: strings.Join(eth.DefaultConfig.UltraLightServers, ","),
181-
}
182-
UltraLightFractionFlag = cli.IntFlag{
183-
Name: "ulc.fraction",
184-
Usage: "Minimum % of trusted ultra-light servers required to announce a new head",
185-
Value: eth.DefaultConfig.UltraLightFraction,
186-
}
187-
UltraLightOnlyAnnounceFlag = cli.BoolFlag{
188-
Name: "ulc.onlyannounce",
189-
Usage: "Ultra light server sends announcements only",
190-
}
191177
IterativeOutputFlag = cli.BoolFlag{
192178
Name: "iterative",
193179
Usage: "Print streaming JSON iteratively, delimited by newlines",
@@ -215,33 +201,58 @@ var (
215201
Usage: `Blockchain garbage collection mode ("full", "archive")`,
216202
Value: "full",
217203
}
218-
LightServFlag = cli.IntFlag{
204+
LightKDFFlag = cli.BoolFlag{
205+
Name: "lightkdf",
206+
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
207+
}
208+
WhitelistFlag = cli.StringFlag{
209+
Name: "whitelist",
210+
Usage: "Comma separated block number-to-hash mappings to enforce (<number>=<hash>)",
211+
}
212+
// Light server and client settings
213+
LightLegacyServFlag = cli.IntFlag{ // Deprecated in favor of light.serve, remove in 2021
219214
Name: "lightserv",
215+
Usage: "Maximum percentage of time allowed for serving LES requests (deprecated, use --light.serve)",
216+
Value: eth.DefaultConfig.LightServ,
217+
}
218+
LightServeFlag = cli.IntFlag{
219+
Name: "light.serve",
220220
Usage: "Maximum percentage of time allowed for serving LES requests (multi-threaded processing allows values over 100)",
221-
Value: 0,
221+
Value: eth.DefaultConfig.LightServ,
222222
}
223-
LightBandwidthInFlag = cli.IntFlag{
224-
Name: "lightbwin",
225-
Usage: "Incoming bandwidth limit for light server (kilobytes/sec, 0 = unlimited)",
226-
Value: 0,
223+
LightIngressFlag = cli.IntFlag{
224+
Name: "light.ingress",
225+
Usage: "Incoming bandwidth limit for serving light clients (kilobytes/sec, 0 = unlimited)",
226+
Value: eth.DefaultConfig.LightIngress,
227227
}
228-
LightBandwidthOutFlag = cli.IntFlag{
229-
Name: "lightbwout",
230-
Usage: "Outgoing bandwidth limit for light server (kilobytes/sec, 0 = unlimited)",
231-
Value: 0,
228+
LightEgressFlag = cli.IntFlag{
229+
Name: "light.egress",
230+
Usage: "Outgoing bandwidth limit for serving light clients (kilobytes/sec, 0 = unlimited)",
231+
Value: eth.DefaultConfig.LightEgress,
232232
}
233-
LightPeersFlag = cli.IntFlag{
233+
LightLegacyPeersFlag = cli.IntFlag{ // Deprecated in favor of light.maxpeers, remove in 2021
234234
Name: "lightpeers",
235-
Usage: "Maximum number of LES client peers",
235+
Usage: "Maximum number of light clients to serve, or light servers to attach to (deprecated, use --light.maxpeers)",
236236
Value: eth.DefaultConfig.LightPeers,
237237
}
238-
LightKDFFlag = cli.BoolFlag{
239-
Name: "lightkdf",
240-
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
238+
LightMaxPeersFlag = cli.IntFlag{
239+
Name: "light.maxpeers",
240+
Usage: "Maximum number of light clients to serve, or light servers to attach to",
241+
Value: eth.DefaultConfig.LightPeers,
241242
}
242-
WhitelistFlag = cli.StringFlag{
243-
Name: "whitelist",
244-
Usage: "Comma separated block number-to-hash mappings to enforce (<number>=<hash>)",
243+
UltraLightServersFlag = cli.StringFlag{
244+
Name: "ulc.servers",
245+
Usage: "List of trusted ultra-light servers",
246+
Value: strings.Join(eth.DefaultConfig.UltraLightServers, ","),
247+
}
248+
UltraLightFractionFlag = cli.IntFlag{
249+
Name: "ulc.fraction",
250+
Usage: "Minimum % of trusted ultra-light servers required to announce a new head",
251+
Value: eth.DefaultConfig.UltraLightFraction,
252+
}
253+
UltraLightOnlyAnnounceFlag = cli.BoolFlag{
254+
Name: "ulc.onlyannounce",
255+
Usage: "Ultra light server sends announcements only",
245256
}
246257
// Dashboard settings
247258
DashboardEnabledFlag = cli.BoolFlag{
@@ -949,8 +960,26 @@ func setIPC(ctx *cli.Context, cfg *node.Config) {
949960
}
950961
}
951962

952-
// setUltraLight configures the ultra light client settings from the command line flags.
953-
func setUltraLight(ctx *cli.Context, cfg *eth.Config) {
963+
// setLes configures the les server and ultra light client settings from the command line flags.
964+
func setLes(ctx *cli.Context, cfg *eth.Config) {
965+
if ctx.GlobalIsSet(LightLegacyServFlag.Name) {
966+
cfg.LightServ = ctx.GlobalInt(LightLegacyServFlag.Name)
967+
}
968+
if ctx.GlobalIsSet(LightServeFlag.Name) {
969+
cfg.LightServ = ctx.GlobalInt(LightServeFlag.Name)
970+
}
971+
if ctx.GlobalIsSet(LightIngressFlag.Name) {
972+
cfg.LightIngress = ctx.GlobalInt(LightIngressFlag.Name)
973+
}
974+
if ctx.GlobalIsSet(LightEgressFlag.Name) {
975+
cfg.LightEgress = ctx.GlobalInt(LightEgressFlag.Name)
976+
}
977+
if ctx.GlobalIsSet(LightLegacyPeersFlag.Name) {
978+
cfg.LightPeers = ctx.GlobalInt(LightLegacyPeersFlag.Name)
979+
}
980+
if ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
981+
cfg.LightPeers = ctx.GlobalInt(LightMaxPeersFlag.Name)
982+
}
954983
if ctx.GlobalIsSet(UltraLightServersFlag.Name) {
955984
cfg.UltraLightServers = strings.Split(ctx.GlobalString(UltraLightServersFlag.Name), ",")
956985
}
@@ -1056,19 +1085,22 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
10561085
setBootstrapNodesV5(ctx, cfg)
10571086

10581087
lightClient := ctx.GlobalString(SyncModeFlag.Name) == "light"
1059-
lightServer := ctx.GlobalInt(LightServFlag.Name) != 0
1060-
lightPeers := ctx.GlobalInt(LightPeersFlag.Name)
1088+
lightServer := (ctx.GlobalInt(LightLegacyServFlag.Name) != 0 || ctx.GlobalInt(LightServeFlag.Name) != 0)
10611089

1090+
lightPeers := ctx.GlobalInt(LightLegacyPeersFlag.Name)
1091+
if ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
1092+
lightPeers = ctx.GlobalInt(LightMaxPeersFlag.Name)
1093+
}
10621094
if ctx.GlobalIsSet(MaxPeersFlag.Name) {
10631095
cfg.MaxPeers = ctx.GlobalInt(MaxPeersFlag.Name)
1064-
if lightServer && !ctx.GlobalIsSet(LightPeersFlag.Name) {
1096+
if lightServer && !ctx.GlobalIsSet(LightLegacyPeersFlag.Name) && !ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
10651097
cfg.MaxPeers += lightPeers
10661098
}
10671099
} else {
10681100
if lightServer {
10691101
cfg.MaxPeers += lightPeers
10701102
}
1071-
if lightClient && ctx.GlobalIsSet(LightPeersFlag.Name) && cfg.MaxPeers < lightPeers {
1103+
if lightClient && (ctx.GlobalIsSet(LightLegacyPeersFlag.Name) || ctx.GlobalIsSet(LightMaxPeersFlag.Name)) && cfg.MaxPeers < lightPeers {
10721104
cfg.MaxPeers = lightPeers
10731105
}
10741106
}
@@ -1366,9 +1398,9 @@ func SetShhConfig(ctx *cli.Context, stack *node.Node, cfg *whisper.Config) {
13661398
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
13671399
// Avoid conflicting network flags
13681400
CheckExclusive(ctx, DeveloperFlag, TestnetFlag, RinkebyFlag, GoerliFlag)
1369-
CheckExclusive(ctx, LightServFlag, SyncModeFlag, "light")
1370-
// Can't use both ephemeral unlocked and external signer
1371-
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag)
1401+
CheckExclusive(ctx, LightLegacyServFlag, LightServeFlag, SyncModeFlag, "light")
1402+
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
1403+
13721404
var ks *keystore.KeyStore
13731405
if keystores := stack.AccountManager().Backends(keystore.KeyStoreType); len(keystores) > 0 {
13741406
ks = keystores[0].(*keystore.KeyStore)
@@ -1379,19 +1411,11 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
13791411
setEthash(ctx, cfg)
13801412
setMiner(ctx, &cfg.Miner)
13811413
setWhitelist(ctx, cfg)
1382-
setUltraLight(ctx, cfg)
1414+
setLes(ctx, cfg)
13831415

13841416
if ctx.GlobalIsSet(SyncModeFlag.Name) {
13851417
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
13861418
}
1387-
if ctx.GlobalIsSet(LightServFlag.Name) {
1388-
cfg.LightServ = ctx.GlobalInt(LightServFlag.Name)
1389-
}
1390-
cfg.LightBandwidthIn = ctx.GlobalInt(LightBandwidthInFlag.Name)
1391-
cfg.LightBandwidthOut = ctx.GlobalInt(LightBandwidthOutFlag.Name)
1392-
if ctx.GlobalIsSet(LightPeersFlag.Name) {
1393-
cfg.LightPeers = ctx.GlobalInt(LightPeersFlag.Name)
1394-
}
13951419
if ctx.GlobalIsSet(NetworkIdFlag.Name) {
13961420
cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
13971421
}

eth/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ type Config struct {
102102
Whitelist map[uint64]common.Hash `toml:"-"`
103103

104104
// Light client options
105-
LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
106-
LightBandwidthIn int `toml:",omitempty"` // Incoming bandwidth limit for light servers
107-
LightBandwidthOut int `toml:",omitempty"` // Outgoing bandwidth limit for light servers
108-
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
105+
LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
106+
LightIngress int `toml:",omitempty"` // Incoming bandwidth limit for light servers
107+
LightEgress int `toml:",omitempty"` // Outgoing bandwidth limit for light servers
108+
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
109109

110110
// Ultra Light client options
111111
UltraLightServers []string `toml:",omitempty"` // List of trusted ultra light servers

eth/gen_config.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

les/costtracker.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ func newCostTracker(db ethdb.Database, config *eth.Config) (*costTracker, uint64
139139
reqInfoCh: make(chan reqInfo, 100),
140140
utilTarget: utilTarget,
141141
}
142-
if config.LightBandwidthIn > 0 {
143-
ct.inSizeFactor = utilTarget / float64(config.LightBandwidthIn)
142+
if config.LightIngress > 0 {
143+
ct.inSizeFactor = utilTarget / float64(config.LightIngress)
144144
}
145-
if config.LightBandwidthOut > 0 {
146-
ct.outSizeFactor = utilTarget / float64(config.LightBandwidthOut)
145+
if config.LightEgress > 0 {
146+
ct.outSizeFactor = utilTarget / float64(config.LightEgress)
147147
}
148148
if makeCostStats {
149149
ct.stats = make(map[uint64][]uint64)

0 commit comments

Comments
 (0)