mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 04:48:21 +00:00
Tidy validator config, CLIs
This commit is contained in:
@@ -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<Config, String> {
|
||||
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::<u16>()
|
||||
.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<Config, String> {
|
||||
client_config.key_source = match cli_args.subcommand() {
|
||||
fn process_testnet_subcommand(cli_args: &ArgMatches, mut config: Config) -> Result<Config, String> {
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user