Update account manager config parsing

This commit is contained in:
Paul Hauner
2019-06-09 04:34:56 -04:00
parent 3487b16ce5
commit ab12787610
12 changed files with 66 additions and 96 deletions

View File

@@ -18,7 +18,6 @@ ssz = { path = "../eth2/utils/ssz" }
eth2_config = { path = "../eth2/utils/eth2_config" }
tree_hash = { path = "../eth2/utils/tree_hash" }
clap = "2.32.0"
dirs = "1.0.3"
grpcio = { version = "0.4", default-features = false, features = ["protobuf-codec"] }
protobuf = "2.0.2"
protos = { path = "../protos" }

View File

@@ -48,48 +48,8 @@ impl Config {
};
Ok(())
//
}
/*
/// Build a new configuration from defaults, which are overrided by arguments provided.
pub fn parse_args(args: &ArgMatches, log: &slog::Logger) -> Result<Self, Error> {
let mut config = Config::default();
// Use the specified datadir, or default in the home directory
if let Some(datadir) = args.value_of("datadir") {
config.data_dir = PathBuf::from(datadir);
info!(log, "Using custom data dir: {:?}", &config.data_dir);
};
fs::create_dir_all(&config.data_dir)
.unwrap_or_else(|_| panic!("Unable to create {:?}", &config.data_dir));
if let Some(srv) = args.value_of("server") {
//TODO: Validate the server value, to ensure it makes sense.
config.server = srv.to_string();
info!(log, "Using custom server: {:?}", &config.server);
};
// TODO: Permit loading a custom spec from file.
if let Some(spec_str) = args.value_of("spec") {
info!(log, "Using custom spec: {:?}", spec_str);
config.spec = match spec_str {
"mainnet" => MainnetEthSpec::default_spec(),
"minimal" => MinimalEthSpec::default_spec(),
// Should be impossible due to clap's `possible_values(..)` function.
_ => unreachable!(),
};
};
// Log configuration
info!(log, "";
"data_dir" => &config.data_dir.to_str(),
"server" => &config.server);
Ok(config)
}
*/
/// Try to load keys from validator_dir, returning None if none are found or an error.
#[allow(dead_code)]
pub fn fetch_keys(&self, log: &slog::Logger) -> Option<Vec<Keypair>> {

View File

@@ -7,10 +7,9 @@ mod service;
mod signer;
use crate::config::Config as ValidatorClientConfig;
use std::fs;
use crate::service::Service as ValidatorService;
use clap::{App, Arg, ArgMatches};
use eth2_config::{read_from_file, write_to_file, Eth2Config};
use clap::{App, Arg};
use eth2_config::{get_data_dir, read_from_file, write_to_file, Eth2Config};
use protos::services_grpc::ValidatorServiceClient;
use slog::{crit, error, info, o, Drain};
use std::path::PathBuf;
@@ -18,8 +17,8 @@ use types::{Keypair, MainnetEthSpec, MinimalEthSpec};
pub const DEFAULT_SPEC: &str = "minimal";
pub const DEFAULT_DATA_DIR: &str = ".lighthouse-validator";
pub const CLIENT_CONFIG_FILENAME: &str = "client_config.toml";
pub const ETH2_CONFIG_FILENAME: &str = "eth2_config.toml";
pub const CLIENT_CONFIG_FILENAME: &str = "client-config.toml";
pub const ETH2_CONFIG_FILENAME: &str = "eth2-config.toml";
fn main() {
// Logging
@@ -38,7 +37,7 @@ fn main() {
.long("datadir")
.value_name("DIR")
.help("Data directory for keys and databases.")
.takes_value(true)
.takes_value(true),
)
.arg(
Arg::with_name("eth-config")
@@ -68,11 +67,11 @@ fn main() {
)
.get_matches();
let data_dir = match get_data_dir(&matches) {
let data_dir = match get_data_dir(&matches, PathBuf::from(DEFAULT_DATA_DIR)) {
Ok(dir) => dir,
Err(e) => {
crit!(log, "Failed to initialize data dir"; "error" => format!("{:?}", e));
return
return;
}
};
@@ -119,9 +118,7 @@ fn main() {
// Attempt to load the `Eth2Config` from file.
//
// If the file doesn't exist, create a default one depending on the CLI flags.
let mut eth2_config = match read_from_file::<Eth2Config>(
eth2_config_path.clone()
) {
let mut eth2_config = match read_from_file::<Eth2Config>(eth2_config_path.clone()) {
Ok(Some(c)) => c,
Ok(None) => {
let default = match matches.value_of("spec-constants") {
@@ -181,15 +178,3 @@ fn main() {
Err(e) => crit!(log, "Validator client exited with error"; "error" => e.to_string()),
}
}
fn get_data_dir(args: &ArgMatches) -> Result<PathBuf, &'static str> {
if let Some(data_dir) = args.value_of("data_dir") {
Ok(PathBuf::from(data_dir))
} else {
let path = dirs::home_dir()
.ok_or_else(|| "Unable to locate home directory")?
.join(&DEFAULT_DATA_DIR);
fs::create_dir_all(&path).map_err(|_| "Unable to create data_dir")?;
Ok(path)
}
}