Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate validator client to clap derive #6300

Open
wants to merge 48 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4513851
add derive cli definitions
eserilev Aug 19, 2024
bea2b48
update
eserilev Aug 19, 2024
3768588
change cli
eserilev Aug 19, 2024
1e19018
fix test
eserilev Aug 23, 2024
1a9ad30
cli docs
eserilev Aug 23, 2024
a80452b
fmt
eserilev Aug 23, 2024
99007eb
fix lint issue
eserilev Aug 23, 2024
5f4bf78
fix flag name
eserilev Aug 26, 2024
a944744
fix cli
eserilev Aug 26, 2024
9e7bed2
Merge branch 'unstable' of https://github.com/sigp/lighthouse into cl…
eserilev Aug 26, 2024
49da4e9
reintroduce deprecated flag
eserilev Aug 26, 2024
e8b7996
fix test
eserilev Aug 26, 2024
d986f84
cli fix
eserilev Aug 26, 2024
c90d977
fix test
eserilev Aug 26, 2024
5e96273
fix another test
eserilev Aug 26, 2024
e98f0d9
Merge branch 'unstable' of https://github.com/sigp/lighthouse into cl…
eserilev Aug 29, 2024
461cc22
fix test
eserilev Sep 3, 2024
4344953
fix test
eserilev Sep 4, 2024
9117690
linting
eserilev Sep 4, 2024
41e0c1a
fix validator crash
eserilev Sep 4, 2024
ea322d2
add additional test
eserilev Sep 4, 2024
8d3c91e
fix vc
eserilev Oct 16, 2024
1fc4429
resolve merge conflicts
eserilev Oct 16, 2024
d0929b9
Fix test
eserilev Oct 16, 2024
68fb7bd
Lint
eserilev Oct 16, 2024
c016661
Fix tests
eserilev Oct 16, 2024
e484019
fix
eserilev Oct 16, 2024
f4fcb77
fix
eserilev Oct 16, 2024
ef9165b
Fix tests
eserilev Oct 16, 2024
bb06e14
Fix tests
eserilev Oct 16, 2024
a273157
Fix tests
eserilev Oct 16, 2024
09920aa
resolve conflicts
eserilev Oct 22, 2024
63b8d60
fix
eserilev Oct 22, 2024
9efccb0
fix
eserilev Oct 23, 2024
26708ac
Merge branch 'unstable' of https://github.com/sigp/lighthouse into cl…
eserilev Oct 23, 2024
80bb142
Fix tests
eserilev Oct 23, 2024
3901113
fix tests
eserilev Oct 24, 2024
7ae2e2a
make gas limit config value non optional
eserilev Oct 26, 2024
258d96f
fix test
eserilev Nov 1, 2024
54a2d44
Merge branch 'clap-derive-validator-manager' of https://github.com/es…
eserilev Nov 7, 2024
cb8125e
Merge branch 'unstable' of https://github.com/sigp/lighthouse into cl…
eserilev Nov 7, 2024
02e305a
remove non global help flags, and other misc fixes
eserilev Nov 7, 2024
ee8a519
liniting
eserilev Nov 7, 2024
74ce49b
resolve merge conflicts
eserilev Nov 8, 2024
28fa46b
fix test
eserilev Nov 8, 2024
2b21122
Merge branch 'unstable' of https://github.com/sigp/lighthouse into cl…
eserilev Nov 18, 2024
71eed11
resolve merge conflicts
eserilev Jan 16, 2025
9620ff1
run make cli
eserilev Jan 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions account_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ mod common;
pub mod validator;
pub mod wallet;

use clap::Arg;
use clap::ArgAction;
use clap::ArgMatches;
use clap::Command;
use clap_utils::FLAG_HEADER;
use environment::Environment;
use types::EthSpec;

Expand All @@ -21,15 +18,6 @@ pub fn cli_app() -> Command {
.visible_aliases(["a", "am", "account"])
.about("Utilities for generating and managing Ethereum 2.0 accounts.")
.display_order(0)
.arg(
Arg::new("help")
.long("help")
.short('h')
.help("Prints help information")
.action(ArgAction::HelpLong)
.display_order(0)
.help_heading(FLAG_HEADER),
)
.subcommand(wallet::cli_app())
.subcommand(validator::cli_app())
}
Expand Down
11 changes: 0 additions & 11 deletions account_manager/src/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub mod slashing_protection;

use crate::{VALIDATOR_DIR_FLAG, VALIDATOR_DIR_FLAG_ALIAS};
use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER;
use directory::{parse_path_or_default_with_flag, DEFAULT_VALIDATOR_DIR};
use environment::Environment;
use std::path::PathBuf;
Expand All @@ -20,16 +19,6 @@ pub fn cli_app() -> Command {
Command::new(CMD)
.display_order(0)
.about("Provides commands for managing Eth2 validators.")
.arg(
Arg::new("help")
.long("help")
.short('h')
.help("Prints help information")
.action(ArgAction::HelpLong)
.display_order(0)
.help_heading(FLAG_HEADER)
.global(true),
)
.arg(
Arg::new(VALIDATOR_DIR_FLAG)
.long(VALIDATOR_DIR_FLAG)
Expand Down
11 changes: 0 additions & 11 deletions account_manager/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub mod recover;

use crate::WALLETS_DIR_FLAG;
use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_utils::FLAG_HEADER;
use directory::{ensure_dir_exists, parse_path_or_default_with_flag, DEFAULT_WALLET_DIR};
use std::path::PathBuf;

Expand All @@ -14,16 +13,6 @@ pub fn cli_app() -> Command {
Command::new(CMD)
.about("Manage wallets, from which validator keys can be derived.")
.display_order(0)
.arg(
Arg::new("help")
.long("help")
.short('h')
.help("Prints help information")
.action(ArgAction::HelpLong)
.display_order(0)
.help_heading(FLAG_HEADER)
.global(true)
)
.arg(
Arg::new(WALLETS_DIR_FLAG)
.long(WALLETS_DIR_FLAG)
Expand Down
9 changes: 0 additions & 9 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ pub fn cli_app() -> Command {
/*
* Configuration directory locations.
*/
.arg(
Arg::new("help")
.long("help")
.short('h')
.help("Prints help information")
.action(ArgAction::HelpLong)
.display_order(0)
.help_heading(FLAG_HEADER)
)
.arg(
Arg::new("network-dir")
.long("network-dir")
Expand Down
23 changes: 13 additions & 10 deletions book/src/help_vc.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ Options:
certificate path.
--broadcast <API_TOPICS>
Comma-separated list of beacon API topics to broadcast to all beacon
nodes. Possible values are: none, attestations, blocks, subscriptions,
sync-committee. Default (when flag is omitted) is to broadcast
subscriptions only.
nodes. Default (when flag is omitted) is to broadcast subscriptions
only. [possible values: none, attestations, blocks, subscriptions,
sync-committee]
--builder-boost-factor <UINT64>
Defines the boost factor, a percentage multiplier to apply to the
builder's payload value when choosing between a builder payload header
and payload from the local execution node.
--builder-registration-timestamp-override <builder-registration-timestamp-override>
--builder-registration-timestamp-override <UNIX-TIMESTAMP>
This flag takes a unix timestamp value that will be used to override
the timestamp used in the builder api registration
the timestamp used in the builder api registration.
-d, --datadir <DIR>
Used to specify a custom root data directory for lighthouse keys and
databases. Defaults to $HOME/.lighthouse/{network} where network is
Expand All @@ -41,7 +41,7 @@ Options:
The gas limit to be used in all builder proposals for all validators
managed by this validator client. Note this will not necessarily be
used if the gas limit set here moves too far from the previous block's
gas limit. [default: 30,000,000]
gas limit. [default: 30000000]
--genesis-state-url <URL>
A URL of a beacon-API compatible server from which to download the
genesis state. Checkpoint sync server URLs can generally be used with
Expand All @@ -68,7 +68,8 @@ Options:
is supplied, the CORS allowed origin is set to the listen address of
this server (e.g., http://localhost:5062).
--http-port <PORT>
Set the listen TCP port for the RESTful HTTP API server.
Set the listen TCP port for the RESTful HTTP API server. [default:
5062]
--log-format <FORMAT>
Specifies the log format used when emitting logs to the terminal.
[possible values: JSON]
Expand All @@ -92,13 +93,15 @@ Options:
set to 0, background file logging is disabled. [default: 200]
--metrics-address <ADDRESS>
Set the listen address for the Prometheus metrics HTTP server.
[default: 127.0.0.1]
--metrics-allow-origin <ORIGIN>
Set the value of the Access-Control-Allow-Origin response HTTP header.
Use * to allow any origin (not recommended in production). If no value
is supplied, the CORS allowed origin is set to the listen address of
this server (e.g., http://localhost:5064).
--metrics-port <PORT>
Set the listen TCP port for the Prometheus metrics HTTP server.
[default: 5064]
--monitoring-endpoint <ADDRESS>
Enables the monitoring service for sending system metrics to a remote
endpoint. This can be used to monitor your setup on certain services
Expand All @@ -109,7 +112,7 @@ Options:
provide an untrusted URL.
--monitoring-endpoint-period <SECONDS>
Defines how many seconds to wait between each message sent to the
monitoring-endpoint. Default: 60s
monitoring-endpoint. [default: 60]
--network <network>
Name of the Eth2 chain Lighthouse will sync and follow. [possible
values: mainnet, gnosis, chiado, sepolia, holesky]
Expand Down Expand Up @@ -141,8 +144,8 @@ Options:
each validator along with the common slashing protection database and
the validator_definitions.yml
--web3-signer-keep-alive-timeout <MILLIS>
Keep-alive timeout for each web3signer connection. Set to 'null' to
never timeout [default: 20000]
Keep-alive timeout for each web3signer connection. Set to '0' to never
timeout. [default: 20000]
--web3-signer-max-idle-connections <COUNT>
Maximum number of idle connections to maintain per web3signer host.
Default is unlimited.
Expand Down
9 changes: 0 additions & 9 deletions boot_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ pub fn cli_app() -> Command {
surface compared to a full beacon node.")
.styles(get_color_style())
.display_order(0)
.arg(
Arg::new("help")
.long("help")
.short('h')
.help("Prints help information")
.action(ArgAction::HelpLong)
.display_order(0)
.help_heading(FLAG_HEADER)
)
.arg(
Arg::new("enr-address")
.long("enr-address")
Expand Down
10 changes: 0 additions & 10 deletions database_manager/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ pub struct DatabaseManager {
)]
pub blobs_dir: Option<PathBuf>,

#[clap(
long,
global = true,
help = "Prints help information",
action = clap::ArgAction::HelpLong,
display_order = 0,
help_heading = FLAG_HEADER
)]
help: Option<bool>,

#[clap(subcommand)]
pub subcommand: DatabaseManagerSubcommand,
}
Expand Down
5 changes: 4 additions & 1 deletion lighthouse/src/cli.rs
Original file line number Diff line number Diff line change
@@ -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>),
}
86 changes: 47 additions & 39 deletions lighthouse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ fn main() {
.action(ArgAction::HelpLong)
.display_order(0)
.help_heading(FLAG_HEADER)
.global(true)
eserilev marked this conversation as resolved.
Show resolved Hide resolved
)
.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());

Expand Down Expand Up @@ -669,12 +669,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);
Expand Down Expand Up @@ -729,38 +766,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());
Expand Down
13 changes: 10 additions & 3 deletions lighthouse/tests/validator_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,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)
Expand Down Expand Up @@ -430,7 +437,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() {
Expand Down Expand Up @@ -532,7 +539,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!(
Expand Down Expand Up @@ -577,7 +584,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"))
Expand Down
1 change: 1 addition & 0 deletions validator_client/beacon_node_fallback/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ path = "src/lib.rs"

[dependencies]
environment = { workspace = true }
clap = { workspace = true }
eth2 = { workspace = true }
futures = { workspace = true }
itertools = { workspace = true }
Expand Down
Loading
Loading