From f0ea69120813638277d12117a2fbddffd2877d35 Mon Sep 17 00:00:00 2001 From: thojest Date: Fri, 1 Mar 2019 18:19:08 +0100 Subject: [PATCH 1/3] now possible to select ChainSpec by using CLI flag (lighthouse-252) --- validator_client/src/config.rs | 9 ++++++++- validator_client/src/main.rs | 27 ++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/validator_client/src/config.rs b/validator_client/src/config.rs index 104a4bbe6..68405ed2f 100644 --- a/validator_client/src/config.rs +++ b/validator_client/src/config.rs @@ -1,11 +1,13 @@ use std::fs; use std::path::PathBuf; +use types::ChainSpec; /// Stores the core configuration for this validator instance. #[derive(Clone)] pub struct ClientConfig { pub data_dir: PathBuf, pub server: String, + pub spec: ChainSpec, } const DEFAULT_LIGHTHOUSE_DIR: &str = ".lighthouse-validators"; @@ -20,6 +22,11 @@ impl ClientConfig { fs::create_dir_all(&data_dir) .unwrap_or_else(|_| panic!("Unable to create {:?}", &data_dir)); let server = "localhost:50051".to_string(); - Self { data_dir, server } + let spec = ChainSpec::foundation(); + Self { + data_dir, + server, + spec, + } } } diff --git a/validator_client/src/main.rs b/validator_client/src/main.rs index c835300b5..e9a7b15a3 100644 --- a/validator_client/src/main.rs +++ b/validator_client/src/main.rs @@ -43,6 +43,15 @@ fn main() { .help("Address to connect to BeaconNode.") .takes_value(true), ) + .arg( + Arg::with_name("spec") + .long("spec") + .value_name("spec") + .short("s") + .help("Configuration of Beacon Chain") + .takes_value(true) + .possible_values(&["foundation", "few_validators"]), + ) .get_matches(); let mut config = ClientConfig::default(); @@ -62,6 +71,17 @@ fn main() { } } + // TODO: Permit loading a custom spec from file. + // Custom spec + if let Some(spec_str) = matches.value_of("spec") { + match spec_str { + "foundation" => config.spec = ChainSpec::foundation(), + "few_validators" => config.spec = ChainSpec::few_validators(), + // Should be impossible + _ => error!(log, "Invalid spec defined"; "spec" => format!("{:?}", config.spec)), + }; + } + // Log configuration info!(log, ""; "data_dir" => &config.data_dir.to_str(), @@ -81,11 +101,8 @@ fn main() { Arc::new(ValidatorServiceClient::new(ch)) }; - // Ethereum - // - // TODO: Permit loading a custom spec from file. - // https://github.com/sigp/lighthouse/issues/160 - let spec = Arc::new(ChainSpec::foundation()); + // Spec + let spec = Arc::new(config.spec.clone()); // Clock for determining the present slot. // TODO: this shouldn't be a static time, instead it should be pulled from the beacon node. From ed7a0810080475fabffdd7cd01e35edfabddb049 Mon Sep 17 00:00:00 2001 From: thojest Date: Fri, 1 Mar 2019 18:23:25 +0100 Subject: [PATCH 2/3] slightly adapted impossible error for validator_client (lighthouse-252) --- validator_client/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/validator_client/src/main.rs b/validator_client/src/main.rs index e9a7b15a3..f81c3e40c 100644 --- a/validator_client/src/main.rs +++ b/validator_client/src/main.rs @@ -78,7 +78,10 @@ fn main() { "foundation" => config.spec = ChainSpec::foundation(), "few_validators" => config.spec = ChainSpec::few_validators(), // Should be impossible - _ => error!(log, "Invalid spec defined"; "spec" => format!("{:?}", config.spec)), + _ => { + error!(log, "Invalid ChainSpec defined"; "spec" => spec_str); + return; + } }; } From c28c07c17d40f7c5f8a647ee40f3bf14e535a075 Mon Sep 17 00:00:00 2001 From: thojest Date: Sun, 3 Mar 2019 14:15:00 +0100 Subject: [PATCH 3/3] validator_client: added default_value for spec; used unreachable macro for custom spec (lighthouse-252) --- validator_client/src/main.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/validator_client/src/main.rs b/validator_client/src/main.rs index f81c3e40c..4344bc16e 100644 --- a/validator_client/src/main.rs +++ b/validator_client/src/main.rs @@ -50,7 +50,8 @@ fn main() { .short("s") .help("Configuration of Beacon Chain") .takes_value(true) - .possible_values(&["foundation", "few_validators"]), + .possible_values(&["foundation", "few_validators"]) + .default_value("foundation"), ) .get_matches(); @@ -77,11 +78,8 @@ fn main() { match spec_str { "foundation" => config.spec = ChainSpec::foundation(), "few_validators" => config.spec = ChainSpec::few_validators(), - // Should be impossible - _ => { - error!(log, "Invalid ChainSpec defined"; "spec" => spec_str); - return; - } + // Should be impossible due to clap's `possible_values(..)` function. + _ => unreachable!(), }; }