Skip to content

Commit 7e4b27c

Browse files
authored
Migrate validator client to clap derive (#6300)
Partially #5900 Migrate the validator client cli to clap derive
1 parent 95cec45 commit 7e4b27c

File tree

18 files changed

+654
-774
lines changed

18 files changed

+654
-774
lines changed

Cargo.lock

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

account_manager/src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ mod common;
22
pub mod validator;
33
pub mod wallet;
44

5-
use clap::Arg;
6-
use clap::ArgAction;
75
use clap::ArgMatches;
86
use clap::Command;
9-
use clap_utils::FLAG_HEADER;
107
use environment::Environment;
118
use types::EthSpec;
129

@@ -21,15 +18,6 @@ pub fn cli_app() -> Command {
2118
.visible_aliases(["a", "am", "account"])
2219
.about("Utilities for generating and managing Ethereum 2.0 accounts.")
2320
.display_order(0)
24-
.arg(
25-
Arg::new("help")
26-
.long("help")
27-
.short('h')
28-
.help("Prints help information")
29-
.action(ArgAction::HelpLong)
30-
.display_order(0)
31-
.help_heading(FLAG_HEADER),
32-
)
3321
.subcommand(wallet::cli_app())
3422
.subcommand(validator::cli_app())
3523
}

account_manager/src/validator/mod.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub mod slashing_protection;
88

99
use crate::{VALIDATOR_DIR_FLAG, VALIDATOR_DIR_FLAG_ALIAS};
1010
use clap::{Arg, ArgAction, ArgMatches, Command};
11-
use clap_utils::FLAG_HEADER;
1211
use directory::{parse_path_or_default_with_flag, DEFAULT_VALIDATOR_DIR};
1312
use environment::Environment;
1413
use std::path::PathBuf;
@@ -20,16 +19,6 @@ pub fn cli_app() -> Command {
2019
Command::new(CMD)
2120
.display_order(0)
2221
.about("Provides commands for managing Eth2 validators.")
23-
.arg(
24-
Arg::new("help")
25-
.long("help")
26-
.short('h')
27-
.help("Prints help information")
28-
.action(ArgAction::HelpLong)
29-
.display_order(0)
30-
.help_heading(FLAG_HEADER)
31-
.global(true),
32-
)
3322
.arg(
3423
Arg::new(VALIDATOR_DIR_FLAG)
3524
.long(VALIDATOR_DIR_FLAG)

account_manager/src/wallet/mod.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub mod recover;
44

55
use crate::WALLETS_DIR_FLAG;
66
use clap::{Arg, ArgAction, ArgMatches, Command};
7-
use clap_utils::FLAG_HEADER;
87
use directory::{parse_path_or_default_with_flag, DEFAULT_WALLET_DIR};
98
use std::fs::create_dir_all;
109
use std::path::PathBuf;
@@ -15,16 +14,6 @@ pub fn cli_app() -> Command {
1514
Command::new(CMD)
1615
.about("Manage wallets, from which validator keys can be derived.")
1716
.display_order(0)
18-
.arg(
19-
Arg::new("help")
20-
.long("help")
21-
.short('h')
22-
.help("Prints help information")
23-
.action(ArgAction::HelpLong)
24-
.display_order(0)
25-
.help_heading(FLAG_HEADER)
26-
.global(true)
27-
)
2817
.arg(
2918
Arg::new(WALLETS_DIR_FLAG)
3019
.long(WALLETS_DIR_FLAG)

beacon_node/src/cli.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ pub fn cli_app() -> Command {
1818
/*
1919
* Configuration directory locations.
2020
*/
21-
.arg(
22-
Arg::new("help")
23-
.long("help")
24-
.short('h')
25-
.help("Prints help information")
26-
.action(ArgAction::HelpLong)
27-
.display_order(0)
28-
.help_heading(FLAG_HEADER)
29-
)
3021
.arg(
3122
Arg::new("network-dir")
3223
.long("network-dir")

book/src/help_vc.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ Options:
1818
certificate path.
1919
--broadcast <API_TOPICS>
2020
Comma-separated list of beacon API topics to broadcast to all beacon
21-
nodes. Possible values are: none, attestations, blocks, subscriptions,
22-
sync-committee. Default (when flag is omitted) is to broadcast
23-
subscriptions only.
21+
nodes. Default (when flag is omitted) is to broadcast subscriptions
22+
only. [possible values: none, attestations, blocks, subscriptions,
23+
sync-committee]
2424
--builder-boost-factor <UINT64>
2525
Defines the boost factor, a percentage multiplier to apply to the
2626
builder's payload value when choosing between a builder payload header
2727
and payload from the local execution node.
28-
--builder-registration-timestamp-override <builder-registration-timestamp-override>
28+
--builder-registration-timestamp-override <UNIX-TIMESTAMP>
2929
This flag takes a unix timestamp value that will be used to override
30-
the timestamp used in the builder api registration
30+
the timestamp used in the builder api registration.
3131
-d, --datadir <DIR>
3232
Used to specify a custom root data directory for lighthouse keys and
3333
databases. Defaults to $HOME/.lighthouse/{network} where network is
@@ -41,7 +41,7 @@ Options:
4141
The gas limit to be used in all builder proposals for all validators
4242
managed by this validator client. Note this will not necessarily be
4343
used if the gas limit set here moves too far from the previous block's
44-
gas limit. [default: 30,000,000]
44+
gas limit. [default: 30000000]
4545
--genesis-state-url <URL>
4646
A URL of a beacon-API compatible server from which to download the
4747
genesis state. Checkpoint sync server URLs can generally be used with
@@ -68,7 +68,8 @@ Options:
6868
is supplied, the CORS allowed origin is set to the listen address of
6969
this server (e.g., http://localhost:5062).
7070
--http-port <PORT>
71-
Set the listen TCP port for the RESTful HTTP API server.
71+
Set the listen TCP port for the RESTful HTTP API server. [default:
72+
5062]
7273
--http-token-path <HTTP_TOKEN_PATH>
7374
Path to file containing the HTTP API token for validator client
7475
authentication. If not specified, defaults to
@@ -96,13 +97,15 @@ Options:
9697
set to 0, background file logging is disabled. [default: 200]
9798
--metrics-address <ADDRESS>
9899
Set the listen address for the Prometheus metrics HTTP server.
100+
[default: 127.0.0.1]
99101
--metrics-allow-origin <ORIGIN>
100102
Set the value of the Access-Control-Allow-Origin response HTTP header.
101103
Use * to allow any origin (not recommended in production). If no value
102104
is supplied, the CORS allowed origin is set to the listen address of
103105
this server (e.g., http://localhost:5064).
104106
--metrics-port <PORT>
105107
Set the listen TCP port for the Prometheus metrics HTTP server.
108+
[default: 5064]
106109
--monitoring-endpoint <ADDRESS>
107110
Enables the monitoring service for sending system metrics to a remote
108111
endpoint. This can be used to monitor your setup on certain services
@@ -113,7 +116,7 @@ Options:
113116
provide an untrusted URL.
114117
--monitoring-endpoint-period <SECONDS>
115118
Defines how many seconds to wait between each message sent to the
116-
monitoring-endpoint. Default: 60s
119+
monitoring-endpoint. [default: 60]
117120
--network <network>
118121
Name of the Eth2 chain Lighthouse will sync and follow. [possible
119122
values: mainnet, gnosis, chiado, sepolia, holesky]
@@ -145,8 +148,8 @@ Options:
145148
each validator along with the common slashing protection database and
146149
the validator_definitions.yml
147150
--web3-signer-keep-alive-timeout <MILLIS>
148-
Keep-alive timeout for each web3signer connection. Set to 'null' to
149-
never timeout [default: 20000]
151+
Keep-alive timeout for each web3signer connection. Set to '0' to never
152+
timeout. [default: 20000]
150153
--web3-signer-max-idle-connections <COUNT>
151154
Maximum number of idle connections to maintain per web3signer host.
152155
Default is unlimited.

boot_node/src/cli.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ pub fn cli_app() -> Command {
1313
surface compared to a full beacon node.")
1414
.styles(get_color_style())
1515
.display_order(0)
16-
.arg(
17-
Arg::new("help")
18-
.long("help")
19-
.short('h')
20-
.help("Prints help information")
21-
.action(ArgAction::HelpLong)
22-
.display_order(0)
23-
.help_heading(FLAG_HEADER)
24-
)
2516
.arg(
2617
Arg::new("enr-address")
2718
.long("enr-address")

database_manager/src/cli.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@ pub struct DatabaseManager {
6666
)]
6767
pub backend: store::config::DatabaseBackend,
6868

69-
#[clap(
70-
long,
71-
global = true,
72-
help = "Prints help information",
73-
action = clap::ArgAction::HelpLong,
74-
display_order = 0,
75-
help_heading = FLAG_HEADER
76-
)]
77-
help: Option<bool>,
78-
7969
#[clap(subcommand)]
8070
pub subcommand: DatabaseManagerSubcommand,
8171
}

lighthouse/src/cli.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use clap::Parser;
22
use database_manager::cli::DatabaseManager;
33
use serde::{Deserialize, Serialize};
4+
use validator_client::cli::ValidatorClient;
45

56
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
67
pub enum LighthouseSubcommands {
78
#[clap(name = "database_manager")]
8-
DatabaseManager(DatabaseManager),
9+
DatabaseManager(Box<DatabaseManager>),
10+
#[clap(name = "validator_client")]
11+
ValidatorClient(Box<ValidatorClient>),
912
}

lighthouse/src/main.rs

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ fn main() {
399399
.action(ArgAction::HelpLong)
400400
.display_order(0)
401401
.help_heading(FLAG_HEADER)
402+
.global(true)
402403
)
403404
.subcommand(beacon_node::cli_app())
404405
.subcommand(boot_node::cli_app())
405-
.subcommand(validator_client::cli_app())
406406
.subcommand(account_manager::cli_app())
407407
.subcommand(validator_manager::cli_app());
408408

@@ -673,12 +673,49 @@ fn run<E: EthSpec>(
673673
return Ok(());
674674
}
675675

676-
if let Ok(LighthouseSubcommands::DatabaseManager(db_manager_config)) =
677-
LighthouseSubcommands::from_arg_matches(matches)
678-
{
679-
info!(log, "Running database manager for {} network", network_name);
680-
database_manager::run(matches, &db_manager_config, environment)?;
681-
return Ok(());
676+
match LighthouseSubcommands::from_arg_matches(matches) {
677+
Ok(LighthouseSubcommands::DatabaseManager(db_manager_config)) => {
678+
info!(log, "Running database manager for {} network", network_name);
679+
database_manager::run(matches, &db_manager_config, environment)?;
680+
return Ok(());
681+
}
682+
Ok(LighthouseSubcommands::ValidatorClient(validator_client_config)) => {
683+
let context = environment.core_context();
684+
let log = context.log().clone();
685+
let executor = context.executor.clone();
686+
let config = validator_client::Config::from_cli(
687+
matches,
688+
&validator_client_config,
689+
context.log(),
690+
)
691+
.map_err(|e| format!("Unable to initialize validator config: {}", e))?;
692+
// Dump configs if `dump-config` or `dump-chain-config` flags are set
693+
clap_utils::check_dump_configs::<_, E>(matches, &config, &context.eth2_config.spec)?;
694+
695+
let shutdown_flag = matches.get_flag("immediate-shutdown");
696+
if shutdown_flag {
697+
info!(log, "Validator client immediate shutdown triggered.");
698+
return Ok(());
699+
}
700+
701+
executor.clone().spawn(
702+
async move {
703+
if let Err(e) = ProductionValidatorClient::new(context, config)
704+
.and_then(|mut vc| async move { vc.start_service().await })
705+
.await
706+
{
707+
crit!(log, "Failed to start validator client"; "reason" => e);
708+
// Ignore the error since it always occurs during normal operation when
709+
// shutting down.
710+
let _ = executor
711+
.shutdown_sender()
712+
.try_send(ShutdownReason::Failure("Failed to start validator client"));
713+
}
714+
},
715+
"validator_client",
716+
);
717+
}
718+
Err(_) => (),
682719
};
683720

684721
info!(log, "Lighthouse started"; "version" => VERSION);
@@ -733,38 +770,9 @@ fn run<E: EthSpec>(
733770
"beacon_node",
734771
);
735772
}
736-
Some(("validator_client", matches)) => {
737-
let context = environment.core_context();
738-
let log = context.log().clone();
739-
let executor = context.executor.clone();
740-
let config = validator_client::Config::from_cli(matches, context.log())
741-
.map_err(|e| format!("Unable to initialize validator config: {}", e))?;
742-
// Dump configs if `dump-config` or `dump-chain-config` flags are set
743-
clap_utils::check_dump_configs::<_, E>(matches, &config, &context.eth2_config.spec)?;
744-
745-
let shutdown_flag = matches.get_flag("immediate-shutdown");
746-
if shutdown_flag {
747-
info!(log, "Validator client immediate shutdown triggered.");
748-
return Ok(());
749-
}
750-
751-
executor.clone().spawn(
752-
async move {
753-
if let Err(e) = ProductionValidatorClient::new(context, config)
754-
.and_then(|mut vc| async move { vc.start_service().await })
755-
.await
756-
{
757-
crit!(log, "Failed to start validator client"; "reason" => e);
758-
// Ignore the error since it always occurs during normal operation when
759-
// shutting down.
760-
let _ = executor
761-
.shutdown_sender()
762-
.try_send(ShutdownReason::Failure("Failed to start validator client"));
763-
}
764-
},
765-
"validator_client",
766-
);
767-
}
773+
// TODO(clap-derive) delete this once we've fully migrated to clap derive.
774+
// Qt the moment this needs to exist so that we dont trigger a crit.
775+
Some(("validator_client", _)) => (),
768776
_ => {
769777
crit!(log, "No subcommand supplied. See --help .");
770778
return Err("No subcommand supplied.".into());

lighthouse/tests/validator_client.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@ fn metrics_port_flag() {
407407
.with_config(|config| assert_eq!(config.http_metrics.listen_port, 9090));
408408
}
409409
#[test]
410+
fn metrics_port_flag_default() {
411+
CommandLineTest::new()
412+
.flag("metrics", None)
413+
.run()
414+
.with_config(|config| assert_eq!(config.http_metrics.listen_port, 5064));
415+
}
416+
#[test]
410417
fn metrics_allow_origin_flag() {
411418
CommandLineTest::new()
412419
.flag("metrics", None)
@@ -458,7 +465,7 @@ fn no_doppelganger_protection_flag() {
458465
fn no_gas_limit_flag() {
459466
CommandLineTest::new()
460467
.run()
461-
.with_config(|config| assert!(config.validator_store.gas_limit.is_none()));
468+
.with_config(|config| assert!(config.validator_store.gas_limit == Some(30_000_000)));
462469
}
463470
#[test]
464471
fn gas_limit_flag() {
@@ -560,7 +567,7 @@ fn broadcast_flag() {
560567
});
561568
// Other valid variants
562569
CommandLineTest::new()
563-
.flag("broadcast", Some("blocks, subscriptions"))
570+
.flag("broadcast", Some("blocks,subscriptions"))
564571
.run()
565572
.with_config(|config| {
566573
assert_eq!(
@@ -605,7 +612,7 @@ fn beacon_nodes_sync_tolerances_flag() {
605612
}
606613

607614
#[test]
608-
#[should_panic(expected = "Unknown API topic")]
615+
#[should_panic(expected = "invalid value")]
609616
fn wrong_broadcast_flag() {
610617
CommandLineTest::new()
611618
.flag("broadcast", Some("foo, subscriptions"))

validator_client/beacon_node_fallback/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ name = "beacon_node_fallback"
99
path = "src/lib.rs"
1010

1111
[dependencies]
12+
clap = { workspace = true }
1213
environment = { workspace = true }
1314
eth2 = { workspace = true }
1415
futures = { workspace = true }

0 commit comments

Comments
 (0)