diff --git a/account_manager/src/cli.rs b/account_manager/src/cli.rs index d417e1ecf0..38b289ff32 100644 --- a/account_manager/src/cli.rs +++ b/account_manager/src/cli.rs @@ -2,7 +2,7 @@ use clap::{App, Arg, SubCommand}; pub fn cli_app<'a, 'b>() -> App<'a, 'b> { App::new("account_manager") - .visible_aliases(&["am", "account", "account_manager"]) + .visible_aliases(&["a", "am", "account", "account_manager"]) .about("Utilities for generating and managing Ethereum 2.0 accounts.") .subcommand( SubCommand::with_name("validator") diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index e7f727b305..8592cd1a27 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -1,8 +1,8 @@ use clap::{App, Arg, SubCommand}; pub fn cli_app<'a, 'b>() -> App<'a, 'b> { - App::new("Beacon Node") - .visible_aliases(&["b", "bn", "beacon", "beacon_node"]) + App::new("beacon_node") + .visible_aliases(&["b", "bn", "beacon"]) .version(crate_version!()) .author("Sigma Prime ") .about("Eth 2.0 Client") diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index 5bbd2c66e4..63e466f12f 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -158,7 +158,7 @@ fn run( None }; - let validator_client = if let Some(sub_matches) = matches.subcommand_matches("Validator Client") + let validator_client = if let Some(sub_matches) = matches.subcommand_matches("validator_client") { let runtime_context = environment.core_context(); diff --git a/validator_client/Cargo.toml b/validator_client/Cargo.toml index 43ce4923d9..02eea884b4 100644 --- a/validator_client/Cargo.toml +++ b/validator_client/Cargo.toml @@ -34,7 +34,6 @@ environment = { path = "../lighthouse/environment" } parking_lot = "0.7" exit-future = "0.1.4" libc = "0.2.65" -lazy_static = "1.4.0" eth2_ssz_derive = { path = "../eth2/utils/ssz_derive" } hex = "0.4" deposit_contract = { path = "../eth2/utils/deposit_contract" } diff --git a/validator_client/src/cli.rs b/validator_client/src/cli.rs index 6c1f192a8b..bd5a93f6fa 100644 --- a/validator_client/src/cli.rs +++ b/validator_client/src/cli.rs @@ -1,18 +1,5 @@ -use crate::config::Config; +use crate::config::DEFAULT_HTTP_SERVER; use clap::{App, Arg, SubCommand}; -use lazy_static::lazy_static; - -lazy_static! { - /// The default configuration. Is in lazy_static because clap requires references, therefore we - /// can't initialize the defaults in the `cli_app` function - static ref DEFAULTS: Config = { - Config::default() - }; - - static ref DEFAULT_SERVER_HTTP_PORT: String = { - format!("{}", DEFAULTS.server_http_port) - }; -} pub fn cli_app<'a, 'b>() -> App<'a, 'b> { App::new("validator_client") @@ -23,16 +10,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { .long("server") .value_name("NETWORK_ADDRESS") .help("Address to connect to BeaconNode.") - .default_value(&DEFAULTS.server) - .takes_value(true), - ) - .arg( - Arg::with_name("server-http-port") - .long("server-http-port") - .short("h") - .value_name("PORT") - .help("Port to use for HTTP API connection to the server.") - .default_value(&DEFAULT_SERVER_HTTP_PORT) + .default_value(&DEFAULT_HTTP_SERVER) .takes_value(true), ) /* diff --git a/validator_client/src/config.rs b/validator_client/src/config.rs index 847c07ed50..c94673a468 100644 --- a/validator_client/src/config.rs +++ b/validator_client/src/config.rs @@ -2,8 +2,10 @@ use clap::ArgMatches; use serde_derive::{Deserialize, Serialize}; use std::ops::Range; use std::path::PathBuf; -use types::{EthSpec, MainnetEthSpec}; +pub const DEFAULT_HTTP_SERVER: &str = "http://localhost:5052/"; + +/// Specifies a method for obtaining validator keypairs. #[derive(Clone)] pub enum KeySource { /// Load the keypairs from disk. @@ -23,17 +25,13 @@ impl Default for KeySource { pub struct Config { /// The data directory, which stores all validator databases pub data_dir: PathBuf, - /// The source for loading keypairs + /// Specifies how the validator client should load keypairs. #[serde(skip)] pub key_source: KeySource, - /// The path where the logs will be outputted - pub log_file: PathBuf, - /// The server at which the Beacon Node can be contacted - pub server: String, - /// The HTTP port on the server, for the REST API. - pub server_http_port: u16, - /// The number of slots per epoch. - pub slots_per_epoch: u64, + /// The http endpoint of the beacon node API. + /// + /// Should be similar to `http://localhost:8080` + pub http_server: String, } impl Default for Config { @@ -42,10 +40,7 @@ impl Default for Config { Self { data_dir: PathBuf::from(".lighthouse/validators"), key_source: <_>::default(), - log_file: PathBuf::from(""), - server: "localhost".into(), - server_http_port: 5052, - slots_per_epoch: MainnetEthSpec::slots_per_epoch(), + http_server: DEFAULT_HTTP_SERVER.to_string(), } } } @@ -53,23 +48,13 @@ impl Default for Config { impl Config { /// Parses the CLI arguments and attempts to load the client configuration. pub fn from_cli(cli_args: &ArgMatches) -> Result { - let mut client_config = Config::default(); - - if let Some(datadir) = cli_args.value_of("datadir") { - client_config.data_dir = PathBuf::from(datadir); - }; + let mut config = Config::default(); if let Some(server) = cli_args.value_of("server") { - client_config.server = server.to_string(); + config.http_server = server.to_string(); } - if let Some(port) = cli_args.value_of("server-http-port") { - client_config.server_http_port = port - .parse::() - .map_err(|e| format!("Unable to parse HTTP port: {:?}", e))?; - } - - let client_config = match cli_args.subcommand() { + let config = match cli_args.subcommand() { ("testnet", Some(sub_cli_args)) => { if cli_args.is_present("eth2-config") && sub_cli_args.is_present("bootstrap") { return Err( @@ -78,21 +63,18 @@ impl Config { .into(), ); } - process_testnet_subcommand(sub_cli_args, client_config) + process_testnet_subcommand(sub_cli_args, config) } _ => return Err("You must use the testnet command. See '--help'.".into()), }?; - Ok(client_config) + Ok(config) } } /// Parses the `testnet` CLI subcommand. -fn process_testnet_subcommand( - cli_args: &ArgMatches, - mut client_config: Config, -) -> Result { - client_config.key_source = match cli_args.subcommand() { +fn process_testnet_subcommand(cli_args: &ArgMatches, mut config: Config) -> Result { + config.key_source = match cli_args.subcommand() { ("insecure", Some(sub_cli_args)) => { let first = sub_cli_args .value_of("first_validator") @@ -114,5 +96,5 @@ fn process_testnet_subcommand( _ => KeySource::Disk, }; - Ok(client_config) + Ok(config) } diff --git a/validator_client/src/lib.rs b/validator_client/src/lib.rs index ecc370ce56..1ceb527d4a 100644 --- a/validator_client/src/lib.rs +++ b/validator_client/src/lib.rs @@ -14,7 +14,7 @@ pub use config::Config; use attestation_service::{AttestationService, AttestationServiceBuilder}; use block_service::{BlockService, BlockServiceBuilder}; use clap::ArgMatches; -use config::{Config as ClientConfig, KeySource}; +use config::KeySource; use duties_service::{DutiesService, DutiesServiceBuilder}; use environment::RuntimeContext; use exit_future::Signal; @@ -53,35 +53,30 @@ impl ProductionValidatorClient { context: RuntimeContext, cli_args: &ArgMatches, ) -> impl Future { - ClientConfig::from_cli(&cli_args) + Config::from_cli(&cli_args) .into_future() .map_err(|e| format!("Unable to initialize config: {}", e)) - .and_then(|client_config| Self::new(context, client_config)) + .and_then(|config| Self::new(context, config)) } /// Instantiates the validator client, _without_ starting the timers to trigger block /// and attestation production. pub fn new( mut context: RuntimeContext, - client_config: ClientConfig, + config: Config, ) -> impl Future { let log_1 = context.log.clone(); let log_2 = context.log.clone(); let log_3 = context.log.clone(); - let http_server_addr = format!( - "http://{}:{}", - client_config.server, client_config.server_http_port - ); - info!( log_1, "Starting validator client"; - "beacon_node" => &http_server_addr, - "datadir" => format!("{:?}", client_config.data_dir), + "beacon_node" => &config.http_server, + "datadir" => format!("{:?}", config.data_dir), ); - RemoteBeaconNode::new(http_server_addr) + RemoteBeaconNode::new(config.http_server.clone()) .map_err(|e| format!("Unable to init beacon node http client: {}", e)) .into_future() .and_then(move |beacon_node| wait_for_node(beacon_node, log_2)) @@ -125,12 +120,12 @@ impl ProductionValidatorClient { Duration::from_millis(context.eth2_config.spec.milliseconds_per_slot), ); - let validator_store: ValidatorStore = match &client_config.key_source { + let validator_store: ValidatorStore = match &config.key_source { // Load pre-existing validators from the data dir. // // Use the `account_manager` to generate these files. KeySource::Disk => ValidatorStore::load_from_disk( - client_config.data_dir.clone(), + config.data_dir.clone(), context.eth2_config.spec.clone(), log_3.clone(), )?,