Skip to content

Commit 23ba3fb

Browse files
jxsWoodpile37
authored andcommitted
require http and metrics for respective flags (sigp#4674)
## Issue Addressed following discussion on sigp#4639 (comment) this PR makes the `http` and `metrics` sub-flags to require those main flags enabled
1 parent dd87fd2 commit 23ba3fb

File tree

4 files changed

+90
-64
lines changed

4 files changed

+90
-64
lines changed

beacon_node/src/cli.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clap::{App, Arg};
1+
use clap::{App, Arg, ArgGroup};
22
use strum::VariantNames;
33
use types::ProgressiveBalancesMode;
44

@@ -362,22 +362,25 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
362362
.arg(
363363
Arg::with_name("http-address")
364364
.long("http-address")
365+
.requires("enable_http")
365366
.value_name("ADDRESS")
366367
.help("Set the listen address for the RESTful HTTP API server.")
367-
.default_value("127.0.0.1")
368+
.default_value_if("enable_http", None, "127.0.0.1")
368369
.takes_value(true),
369370
)
370371
.arg(
371372
Arg::with_name("http-port")
372373
.long("http-port")
374+
.requires("enable_http")
373375
.value_name("PORT")
374376
.help("Set the listen TCP port for the RESTful HTTP API server.")
375-
.default_value("5052")
377+
.default_value_if("enable_http", None, "5052")
376378
.takes_value(true),
377379
)
378380
.arg(
379381
Arg::with_name("http-allow-origin")
380382
.long("http-allow-origin")
383+
.requires("enable_http")
381384
.value_name("ORIGIN")
382385
.help("Set the value of the Access-Control-Allow-Origin response HTTP header. \
383386
Use * to allow any origin (not recommended in production). \
@@ -388,11 +391,13 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
388391
.arg(
389392
Arg::with_name("http-disable-legacy-spec")
390393
.long("http-disable-legacy-spec")
394+
.requires("enable_http")
391395
.hidden(true)
392396
)
393397
.arg(
394398
Arg::with_name("http-spec-fork")
395399
.long("http-spec-fork")
400+
.requires("enable_http")
396401
.value_name("FORK")
397402
.help("Serve the spec for a specific hard fork on /eth/v1/config/spec. It should \
398403
not be necessary to set this flag.")
@@ -410,52 +415,58 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
410415
.arg(
411416
Arg::with_name("http-tls-cert")
412417
.long("http-tls-cert")
418+
.requires("enable_http")
413419
.help("The path of the certificate to be used when serving the HTTP API server \
414420
over TLS.")
415421
.takes_value(true)
416422
)
417423
.arg(
418424
Arg::with_name("http-tls-key")
419425
.long("http-tls-key")
426+
.requires("enable_http")
420427
.help("The path of the private key to be used when serving the HTTP API server \
421428
over TLS. Must not be password-protected.")
422429
.takes_value(true)
423430
)
424431
.arg(
425432
Arg::with_name("http-allow-sync-stalled")
426433
.long("http-allow-sync-stalled")
434+
.requires("enable_http")
427435
.help("Forces the HTTP to indicate that the node is synced when sync is actually \
428436
stalled. This is useful for very small testnets. TESTING ONLY. DO NOT USE ON \
429437
MAINNET.")
430438
)
431439
.arg(
432440
Arg::with_name("http-sse-capacity-multiplier")
433441
.long("http-sse-capacity-multiplier")
442+
.requires("enable_http")
434443
.takes_value(true)
435-
.default_value("1")
444+
.default_value_if("enable_http", None, "1")
436445
.value_name("N")
437446
.help("Multiplier to apply to the length of HTTP server-sent-event (SSE) channels. \
438447
Increasing this value can prevent messages from being dropped.")
439448
)
440449
.arg(
441450
Arg::with_name("http-duplicate-block-status")
442451
.long("http-duplicate-block-status")
452+
.requires("enable_http")
443453
.takes_value(true)
444-
.default_value("202")
454+
.default_value_if("enable_http", None, "202")
445455
.value_name("STATUS_CODE")
446456
.help("Status code to send when a block that is already known is POSTed to the \
447457
HTTP API.")
448458
)
449459
.arg(
450460
Arg::with_name("http-enable-beacon-processor")
451461
.long("http-enable-beacon-processor")
462+
.requires("enable_http")
452463
.value_name("BOOLEAN")
453464
.help("The beacon processor is a scheduler which provides quality-of-service and \
454465
DoS protection. When set to \"true\", HTTP API requests will be queued and scheduled \
455466
alongside other tasks. When set to \"false\", HTTP API responses will be executed \
456467
immediately.")
457468
.takes_value(true)
458-
.default_value("true")
469+
.default_value_if("enable_http", None, "true")
459470
)
460471
/* Prometheus metrics HTTP server related arguments */
461472
.arg(
@@ -468,22 +479,25 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
468479
Arg::with_name("metrics-address")
469480
.long("metrics-address")
470481
.value_name("ADDRESS")
482+
.requires("metrics")
471483
.help("Set the listen address for the Prometheus metrics HTTP server.")
472-
.default_value("127.0.0.1")
484+
.default_value_if("metrics", None, "127.0.0.1")
473485
.takes_value(true),
474486
)
475487
.arg(
476488
Arg::with_name("metrics-port")
477489
.long("metrics-port")
490+
.requires("metrics")
478491
.value_name("PORT")
479492
.help("Set the listen TCP port for the Prometheus metrics HTTP server.")
480-
.default_value("5054")
493+
.default_value_if("metrics", None, "5054")
481494
.takes_value(true),
482495
)
483496
.arg(
484497
Arg::with_name("metrics-allow-origin")
485498
.long("metrics-allow-origin")
486499
.value_name("ORIGIN")
500+
.requires("metrics")
487501
.help("Set the value of the Access-Control-Allow-Origin response HTTP header. \
488502
Use * to allow any origin (not recommended in production). \
489503
If no value is supplied, the CORS allowed origin is set to the listen \
@@ -1301,4 +1315,5 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
13011315
.default_value("64")
13021316
.takes_value(true)
13031317
)
1318+
.group(ArgGroup::with_name("enable_http").args(&["http", "gui", "staking"]))
13041319
}

beacon_node/src/config.rs

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -95,69 +95,69 @@ pub fn get_config<E: EthSpec>(
9595
* Http API server
9696
*/
9797

98-
if cli_args.is_present("http") {
98+
if cli_args.is_present("enable_http") {
9999
client_config.http_api.enabled = true;
100-
}
101100

102-
if let Some(address) = cli_args.value_of("http-address") {
103-
client_config.http_api.listen_addr = address
104-
.parse::<IpAddr>()
105-
.map_err(|_| "http-address is not a valid IP address.")?;
106-
}
101+
if let Some(address) = cli_args.value_of("http-address") {
102+
client_config.http_api.listen_addr = address
103+
.parse::<IpAddr>()
104+
.map_err(|_| "http-address is not a valid IP address.")?;
105+
}
107106

108-
if let Some(port) = cli_args.value_of("http-port") {
109-
client_config.http_api.listen_port = port
110-
.parse::<u16>()
111-
.map_err(|_| "http-port is not a valid u16.")?;
112-
}
107+
if let Some(port) = cli_args.value_of("http-port") {
108+
client_config.http_api.listen_port = port
109+
.parse::<u16>()
110+
.map_err(|_| "http-port is not a valid u16.")?;
111+
}
113112

114-
if let Some(allow_origin) = cli_args.value_of("http-allow-origin") {
115-
// Pre-validate the config value to give feedback to the user on node startup, instead of
116-
// as late as when the first API response is produced.
117-
hyper::header::HeaderValue::from_str(allow_origin)
118-
.map_err(|_| "Invalid allow-origin value")?;
113+
if let Some(allow_origin) = cli_args.value_of("http-allow-origin") {
114+
// Pre-validate the config value to give feedback to the user on node startup, instead of
115+
// as late as when the first API response is produced.
116+
hyper::header::HeaderValue::from_str(allow_origin)
117+
.map_err(|_| "Invalid allow-origin value")?;
119118

120-
client_config.http_api.allow_origin = Some(allow_origin.to_string());
121-
}
119+
client_config.http_api.allow_origin = Some(allow_origin.to_string());
120+
}
122121

123-
if cli_args.is_present("http-disable-legacy-spec") {
124-
warn!(
125-
log,
126-
"The flag --http-disable-legacy-spec is deprecated and will be removed"
127-
);
128-
}
122+
if cli_args.is_present("http-disable-legacy-spec") {
123+
warn!(
124+
log,
125+
"The flag --http-disable-legacy-spec is deprecated and will be removed"
126+
);
127+
}
129128

130-
if let Some(fork_name) = clap_utils::parse_optional(cli_args, "http-spec-fork")? {
131-
client_config.http_api.spec_fork_name = Some(fork_name);
132-
}
129+
if let Some(fork_name) = clap_utils::parse_optional(cli_args, "http-spec-fork")? {
130+
client_config.http_api.spec_fork_name = Some(fork_name);
131+
}
133132

134-
if cli_args.is_present("http-enable-tls") {
135-
client_config.http_api.tls_config = Some(TlsConfig {
136-
cert: cli_args
137-
.value_of("http-tls-cert")
138-
.ok_or("--http-tls-cert was not provided.")?
139-
.parse::<PathBuf>()
140-
.map_err(|_| "http-tls-cert is not a valid path name.")?,
141-
key: cli_args
142-
.value_of("http-tls-key")
143-
.ok_or("--http-tls-key was not provided.")?
144-
.parse::<PathBuf>()
145-
.map_err(|_| "http-tls-key is not a valid path name.")?,
146-
});
147-
}
133+
if cli_args.is_present("http-enable-tls") {
134+
client_config.http_api.tls_config = Some(TlsConfig {
135+
cert: cli_args
136+
.value_of("http-tls-cert")
137+
.ok_or("--http-tls-cert was not provided.")?
138+
.parse::<PathBuf>()
139+
.map_err(|_| "http-tls-cert is not a valid path name.")?,
140+
key: cli_args
141+
.value_of("http-tls-key")
142+
.ok_or("--http-tls-key was not provided.")?
143+
.parse::<PathBuf>()
144+
.map_err(|_| "http-tls-key is not a valid path name.")?,
145+
});
146+
}
148147

149-
if cli_args.is_present("http-allow-sync-stalled") {
150-
client_config.http_api.allow_sync_stalled = true;
151-
}
148+
if cli_args.is_present("http-allow-sync-stalled") {
149+
client_config.http_api.allow_sync_stalled = true;
150+
}
152151

153-
client_config.http_api.sse_capacity_multiplier =
154-
parse_required(cli_args, "http-sse-capacity-multiplier")?;
152+
client_config.http_api.sse_capacity_multiplier =
153+
parse_required(cli_args, "http-sse-capacity-multiplier")?;
155154

156-
client_config.http_api.enable_beacon_processor =
157-
parse_required(cli_args, "http-enable-beacon-processor")?;
155+
client_config.http_api.enable_beacon_processor =
156+
parse_required(cli_args, "http-enable-beacon-processor")?;
158157

159-
client_config.http_api.duplicate_block_status_code =
160-
parse_required(cli_args, "http-duplicate-block-status")?;
158+
client_config.http_api.duplicate_block_status_code =
159+
parse_required(cli_args, "http-duplicate-block-status")?;
160+
}
161161

162162
if let Some(cache_size) = clap_utils::parse_optional(cli_args, "shuffling-cache-size")? {
163163
client_config.chain.shuffling_cache_size = cache_size;

lighthouse/tests/beacon_node.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,7 @@ fn http_flag() {
14661466
fn http_address_flag() {
14671467
let addr = "127.0.0.99".parse::<IpAddr>().unwrap();
14681468
CommandLineTest::new()
1469+
.flag("http", None)
14691470
.flag("http-address", Some("127.0.0.99"))
14701471
.run_with_zero_port()
14711472
.with_config(|config| assert_eq!(config.http_api.listen_addr, addr));
@@ -1474,6 +1475,7 @@ fn http_address_flag() {
14741475
fn http_address_ipv6_flag() {
14751476
let addr = "::1".parse::<IpAddr>().unwrap();
14761477
CommandLineTest::new()
1478+
.flag("http", None)
14771479
.flag("http-address", Some("::1"))
14781480
.run_with_zero_port()
14791481
.with_config(|config| assert_eq!(config.http_api.listen_addr, addr));
@@ -1483,6 +1485,7 @@ fn http_port_flag() {
14831485
let port1 = unused_tcp4_port().expect("Unable to find unused port.");
14841486
let port2 = unused_tcp4_port().expect("Unable to find unused port.");
14851487
CommandLineTest::new()
1488+
.flag("http", None)
14861489
.flag("http-port", Some(port1.to_string().as_str()))
14871490
.flag("port", Some(port2.to_string().as_str()))
14881491
.run()
@@ -2485,6 +2488,7 @@ fn http_sse_capacity_multiplier_default() {
24852488
#[test]
24862489
fn http_sse_capacity_multiplier_override() {
24872490
CommandLineTest::new()
2491+
.flag("http", None)
24882492
.flag("http-sse-capacity-multiplier", Some("10"))
24892493
.run_with_zero_port()
24902494
.with_config(|config| assert_eq!(config.http_api.sse_capacity_multiplier, 10));
@@ -2502,6 +2506,7 @@ fn http_duplicate_block_status_default() {
25022506
#[test]
25032507
fn http_duplicate_block_status_override() {
25042508
CommandLineTest::new()
2509+
.flag("http", None)
25052510
.flag("http-duplicate-block-status", Some("301"))
25062511
.run_with_zero_port()
25072512
.with_config(|config| {

validator_client/src/cli.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
170170
.arg(
171171
Arg::with_name("http-address")
172172
.long("http-address")
173+
.requires("http")
173174
.value_name("ADDRESS")
174175
.help("Set the address for the HTTP address. The HTTP server is not encrypted \
175176
and therefore it is unsafe to publish on a public network. When this \
@@ -189,14 +190,16 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
189190
.arg(
190191
Arg::with_name("http-port")
191192
.long("http-port")
193+
.requires("http")
192194
.value_name("PORT")
193195
.help("Set the listen TCP port for the RESTful HTTP API server.")
194-
.default_value("5062")
196+
.default_value_if("http", None, "5062")
195197
.takes_value(true),
196198
)
197199
.arg(
198200
Arg::with_name("http-allow-origin")
199201
.long("http-allow-origin")
202+
.requires("http")
200203
.value_name("ORIGIN")
201204
.help("Set the value of the Access-Control-Allow-Origin response HTTP header. \
202205
Use * to allow any origin (not recommended in production). \
@@ -207,21 +210,21 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
207210
.arg(
208211
Arg::with_name("http-allow-keystore-export")
209212
.long("http-allow-keystore-export")
213+
.requires("http")
210214
.help("If present, allow access to the DELETE /lighthouse/keystores HTTP \
211215
API method, which allows exporting keystores and passwords to HTTP API \
212216
consumers who have access to the API token. This method is useful for \
213217
exporting validators, however it should be used with caution since it \
214218
exposes private key data to authorized users.")
215-
.required(false)
216219
.takes_value(false),
217220
)
218221
.arg(
219222
Arg::with_name("http-store-passwords-in-secrets-dir")
220223
.long("http-store-passwords-in-secrets-dir")
224+
.requires("http")
221225
.help("If present, any validators created via the HTTP will have keystore \
222226
passwords stored in the secrets-dir rather than the validator \
223227
definitions file.")
224-
.required(false)
225228
.takes_value(false),
226229
)
227230
/* Prometheus metrics HTTP server related arguments */
@@ -234,22 +237,25 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
234237
.arg(
235238
Arg::with_name("metrics-address")
236239
.long("metrics-address")
240+
.requires("metrics")
237241
.value_name("ADDRESS")
238242
.help("Set the listen address for the Prometheus metrics HTTP server.")
239-
.default_value("127.0.0.1")
243+
.default_value_if("metrics", None, "127.0.0.1")
240244
.takes_value(true),
241245
)
242246
.arg(
243247
Arg::with_name("metrics-port")
244248
.long("metrics-port")
249+
.requires("metrics")
245250
.value_name("PORT")
246251
.help("Set the listen TCP port for the Prometheus metrics HTTP server.")
247-
.default_value("5064")
252+
.default_value_if("metrics", None, "5064")
248253
.takes_value(true),
249254
)
250255
.arg(
251256
Arg::with_name("metrics-allow-origin")
252257
.long("metrics-allow-origin")
258+
.requires("metrics")
253259
.value_name("ORIGIN")
254260
.help("Set the value of the Access-Control-Allow-Origin response HTTP header. \
255261
Use * to allow any origin (not recommended in production). \

0 commit comments

Comments
 (0)