mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-01 20:04:41 +00:00
Migrate validator client to clap derive (#6300)
Partially #5900 Migrate the validator client cli to clap derive
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
use clap::Parser;
|
||||
use database_manager::cli::DatabaseManager;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator_client::cli::ValidatorClient;
|
||||
|
||||
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
|
||||
pub enum LighthouseSubcommands {
|
||||
#[clap(name = "database_manager")]
|
||||
DatabaseManager(DatabaseManager),
|
||||
DatabaseManager(Box<DatabaseManager>),
|
||||
#[clap(name = "validator_client")]
|
||||
ValidatorClient(Box<ValidatorClient>),
|
||||
}
|
||||
|
||||
@@ -399,10 +399,10 @@ fn main() {
|
||||
.action(ArgAction::HelpLong)
|
||||
.display_order(0)
|
||||
.help_heading(FLAG_HEADER)
|
||||
.global(true)
|
||||
)
|
||||
.subcommand(beacon_node::cli_app())
|
||||
.subcommand(boot_node::cli_app())
|
||||
.subcommand(validator_client::cli_app())
|
||||
.subcommand(account_manager::cli_app())
|
||||
.subcommand(validator_manager::cli_app());
|
||||
|
||||
@@ -673,12 +673,49 @@ fn run<E: EthSpec>(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Ok(LighthouseSubcommands::DatabaseManager(db_manager_config)) =
|
||||
LighthouseSubcommands::from_arg_matches(matches)
|
||||
{
|
||||
info!(log, "Running database manager for {} network", network_name);
|
||||
database_manager::run(matches, &db_manager_config, environment)?;
|
||||
return Ok(());
|
||||
match LighthouseSubcommands::from_arg_matches(matches) {
|
||||
Ok(LighthouseSubcommands::DatabaseManager(db_manager_config)) => {
|
||||
info!(log, "Running database manager for {} network", network_name);
|
||||
database_manager::run(matches, &db_manager_config, environment)?;
|
||||
return Ok(());
|
||||
}
|
||||
Ok(LighthouseSubcommands::ValidatorClient(validator_client_config)) => {
|
||||
let context = environment.core_context();
|
||||
let log = context.log().clone();
|
||||
let executor = context.executor.clone();
|
||||
let config = validator_client::Config::from_cli(
|
||||
matches,
|
||||
&validator_client_config,
|
||||
context.log(),
|
||||
)
|
||||
.map_err(|e| format!("Unable to initialize validator config: {}", e))?;
|
||||
// Dump configs if `dump-config` or `dump-chain-config` flags are set
|
||||
clap_utils::check_dump_configs::<_, E>(matches, &config, &context.eth2_config.spec)?;
|
||||
|
||||
let shutdown_flag = matches.get_flag("immediate-shutdown");
|
||||
if shutdown_flag {
|
||||
info!(log, "Validator client immediate shutdown triggered.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
executor.clone().spawn(
|
||||
async move {
|
||||
if let Err(e) = ProductionValidatorClient::new(context, config)
|
||||
.and_then(|mut vc| async move { vc.start_service().await })
|
||||
.await
|
||||
{
|
||||
crit!(log, "Failed to start validator client"; "reason" => e);
|
||||
// Ignore the error since it always occurs during normal operation when
|
||||
// shutting down.
|
||||
let _ = executor
|
||||
.shutdown_sender()
|
||||
.try_send(ShutdownReason::Failure("Failed to start validator client"));
|
||||
}
|
||||
},
|
||||
"validator_client",
|
||||
);
|
||||
}
|
||||
Err(_) => (),
|
||||
};
|
||||
|
||||
info!(log, "Lighthouse started"; "version" => VERSION);
|
||||
@@ -733,38 +770,9 @@ fn run<E: EthSpec>(
|
||||
"beacon_node",
|
||||
);
|
||||
}
|
||||
Some(("validator_client", matches)) => {
|
||||
let context = environment.core_context();
|
||||
let log = context.log().clone();
|
||||
let executor = context.executor.clone();
|
||||
let config = validator_client::Config::from_cli(matches, context.log())
|
||||
.map_err(|e| format!("Unable to initialize validator config: {}", e))?;
|
||||
// Dump configs if `dump-config` or `dump-chain-config` flags are set
|
||||
clap_utils::check_dump_configs::<_, E>(matches, &config, &context.eth2_config.spec)?;
|
||||
|
||||
let shutdown_flag = matches.get_flag("immediate-shutdown");
|
||||
if shutdown_flag {
|
||||
info!(log, "Validator client immediate shutdown triggered.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
executor.clone().spawn(
|
||||
async move {
|
||||
if let Err(e) = ProductionValidatorClient::new(context, config)
|
||||
.and_then(|mut vc| async move { vc.start_service().await })
|
||||
.await
|
||||
{
|
||||
crit!(log, "Failed to start validator client"; "reason" => e);
|
||||
// Ignore the error since it always occurs during normal operation when
|
||||
// shutting down.
|
||||
let _ = executor
|
||||
.shutdown_sender()
|
||||
.try_send(ShutdownReason::Failure("Failed to start validator client"));
|
||||
}
|
||||
},
|
||||
"validator_client",
|
||||
);
|
||||
}
|
||||
// TODO(clap-derive) delete this once we've fully migrated to clap derive.
|
||||
// Qt the moment this needs to exist so that we dont trigger a crit.
|
||||
Some(("validator_client", _)) => (),
|
||||
_ => {
|
||||
crit!(log, "No subcommand supplied. See --help .");
|
||||
return Err("No subcommand supplied.".into());
|
||||
|
||||
@@ -407,6 +407,13 @@ fn metrics_port_flag() {
|
||||
.with_config(|config| assert_eq!(config.http_metrics.listen_port, 9090));
|
||||
}
|
||||
#[test]
|
||||
fn metrics_port_flag_default() {
|
||||
CommandLineTest::new()
|
||||
.flag("metrics", None)
|
||||
.run()
|
||||
.with_config(|config| assert_eq!(config.http_metrics.listen_port, 5064));
|
||||
}
|
||||
#[test]
|
||||
fn metrics_allow_origin_flag() {
|
||||
CommandLineTest::new()
|
||||
.flag("metrics", None)
|
||||
@@ -458,7 +465,7 @@ fn no_doppelganger_protection_flag() {
|
||||
fn no_gas_limit_flag() {
|
||||
CommandLineTest::new()
|
||||
.run()
|
||||
.with_config(|config| assert!(config.validator_store.gas_limit.is_none()));
|
||||
.with_config(|config| assert!(config.validator_store.gas_limit == Some(30_000_000)));
|
||||
}
|
||||
#[test]
|
||||
fn gas_limit_flag() {
|
||||
@@ -560,7 +567,7 @@ fn broadcast_flag() {
|
||||
});
|
||||
// Other valid variants
|
||||
CommandLineTest::new()
|
||||
.flag("broadcast", Some("blocks, subscriptions"))
|
||||
.flag("broadcast", Some("blocks,subscriptions"))
|
||||
.run()
|
||||
.with_config(|config| {
|
||||
assert_eq!(
|
||||
@@ -605,7 +612,7 @@ fn beacon_nodes_sync_tolerances_flag() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Unknown API topic")]
|
||||
#[should_panic(expected = "invalid value")]
|
||||
fn wrong_broadcast_flag() {
|
||||
CommandLineTest::new()
|
||||
.flag("broadcast", Some("foo, subscriptions"))
|
||||
|
||||
Reference in New Issue
Block a user