mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 11:41:51 +00:00
Directory restructure (#1532)
Closes #1487 Closes #1427 Directory restructure in accordance with #1487. Also has temporary migration code to move the old directories into new structure. Also extracts all default directory names and utility functions into a `directory` crate to avoid repetitio. ~Since `validator_definition.yaml` stores absolute paths, users will have to manually change the keystore paths or delete the file to get the validators picked up by the vc.~. `validator_definition.yaml` is migrated as well from the default directories. Co-authored-by: realbigsean <seananderson33@gmail.com> Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
committed by
Paul Hauner
parent
dffc56ef1d
commit
8e20176337
@@ -16,6 +16,19 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
||||
.default_value(&DEFAULT_HTTP_SERVER)
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("validators-dir")
|
||||
.long("validators-dir")
|
||||
.value_name("VALIDATORS_DIR")
|
||||
.help(
|
||||
"The directory which contains the validator keystores, deposit data for \
|
||||
each validator along with the common slashing protection database \
|
||||
and the validator_definitions.yml"
|
||||
)
|
||||
.takes_value(true)
|
||||
.conflicts_with("datadir")
|
||||
.requires("secrets-dir")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("secrets-dir")
|
||||
.long("secrets-dir")
|
||||
@@ -24,9 +37,11 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
||||
"The directory which contains the password to unlock the validator \
|
||||
voting keypairs. Each password should be contained in a file where the \
|
||||
name is the 0x-prefixed hex representation of the validators voting public \
|
||||
key. Defaults to ~/.lighthouse/secrets.",
|
||||
key. Defaults to ~/.lighthouse/{testnet}/secrets.",
|
||||
)
|
||||
.takes_value(true),
|
||||
.takes_value(true)
|
||||
.conflicts_with("datadir")
|
||||
.requires("validators-dir"),
|
||||
)
|
||||
.arg(Arg::with_name("auto-register").long("auto-register").help(
|
||||
"If present, the validator client will register any new signing keys with \
|
||||
@@ -48,6 +63,16 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
||||
that might also be using the same keystores."
|
||||
)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("strict-slashing-protection")
|
||||
.long("strict-slashing-protection")
|
||||
.help(
|
||||
"If present, do not create a new slashing database. This is to ensure that users \
|
||||
do not accidentally get slashed in case their slashing protection db ends up in the \
|
||||
wrong directory during directory restructure and vc creates a new empty db and \
|
||||
re-registers all validators."
|
||||
)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("disable-auto-discover")
|
||||
.long("disable-auto-discover")
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
use clap::ArgMatches;
|
||||
use clap_utils::{parse_optional, parse_path_with_default_in_home_dir};
|
||||
use clap_utils::{parse_optional, parse_required};
|
||||
use directory::{
|
||||
get_testnet_name, DEFAULT_HARDCODED_TESTNET, DEFAULT_ROOT_DIR, DEFAULT_SECRET_DIR,
|
||||
DEFAULT_VALIDATOR_DIR,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use types::{Graffiti, GRAFFITI_BYTES_LEN};
|
||||
|
||||
pub const DEFAULT_HTTP_SERVER: &str = "http://localhost:5052/";
|
||||
pub const DEFAULT_DATA_DIR: &str = ".lighthouse/validators";
|
||||
pub const DEFAULT_SECRETS_DIR: &str = ".lighthouse/secrets";
|
||||
/// Path to the slashing protection database within the datadir.
|
||||
pub const SLASHING_PROTECTION_FILENAME: &str = "slashing_protection.sqlite";
|
||||
|
||||
@@ -14,7 +16,7 @@ pub const SLASHING_PROTECTION_FILENAME: &str = "slashing_protection.sqlite";
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
/// The data directory, which stores all validator databases
|
||||
pub data_dir: PathBuf,
|
||||
pub validator_dir: PathBuf,
|
||||
/// The directory containing the passwords to unlock validator keystores.
|
||||
pub secrets_dir: PathBuf,
|
||||
/// The http endpoint of the beacon node API.
|
||||
@@ -28,6 +30,8 @@ pub struct Config {
|
||||
pub delete_lockfiles: bool,
|
||||
/// If true, don't scan the validators dir for new keystores.
|
||||
pub disable_auto_discover: bool,
|
||||
/// If true, don't re-register existing validators in definitions.yml for slashing protection.
|
||||
pub strict_slashing_protection: bool,
|
||||
/// Graffiti to be inserted everytime we create a block.
|
||||
pub graffiti: Option<Graffiti>,
|
||||
}
|
||||
@@ -35,19 +39,22 @@ pub struct Config {
|
||||
impl Default for Config {
|
||||
/// Build a new configuration from defaults.
|
||||
fn default() -> Self {
|
||||
let data_dir = dirs::home_dir()
|
||||
.map(|home| home.join(DEFAULT_DATA_DIR))
|
||||
.unwrap_or_else(|| PathBuf::from("."));
|
||||
let secrets_dir = dirs::home_dir()
|
||||
.map(|home| home.join(DEFAULT_SECRETS_DIR))
|
||||
.unwrap_or_else(|| PathBuf::from("."));
|
||||
// WARNING: these directory defaults should be always overrided with parameters
|
||||
// from cli for specific networks.
|
||||
let base_dir = dirs::home_dir()
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
.join(DEFAULT_ROOT_DIR)
|
||||
.join(DEFAULT_HARDCODED_TESTNET);
|
||||
let validator_dir = base_dir.join(DEFAULT_VALIDATOR_DIR);
|
||||
let secrets_dir = base_dir.join(DEFAULT_SECRET_DIR);
|
||||
Self {
|
||||
data_dir,
|
||||
validator_dir,
|
||||
secrets_dir,
|
||||
http_server: DEFAULT_HTTP_SERVER.to_string(),
|
||||
allow_unsynced_beacon_node: false,
|
||||
delete_lockfiles: false,
|
||||
disable_auto_discover: false,
|
||||
strict_slashing_protection: false,
|
||||
graffiti: None,
|
||||
}
|
||||
}
|
||||
@@ -59,16 +66,39 @@ impl Config {
|
||||
pub fn from_cli(cli_args: &ArgMatches) -> Result<Config, String> {
|
||||
let mut config = Config::default();
|
||||
|
||||
config.data_dir = parse_path_with_default_in_home_dir(
|
||||
cli_args,
|
||||
"datadir",
|
||||
PathBuf::from(".lighthouse").join("validators"),
|
||||
)?;
|
||||
let default_root_dir = dirs::home_dir()
|
||||
.map(|home| home.join(DEFAULT_ROOT_DIR))
|
||||
.unwrap_or_else(|| PathBuf::from("."));
|
||||
|
||||
if !config.data_dir.exists() {
|
||||
let (mut validator_dir, mut secrets_dir) = (None, None);
|
||||
if cli_args.value_of("datadir").is_some() {
|
||||
let base_dir: PathBuf = parse_required(cli_args, "datadir")?;
|
||||
validator_dir = Some(base_dir.join(DEFAULT_VALIDATOR_DIR));
|
||||
secrets_dir = Some(base_dir.join(DEFAULT_SECRET_DIR));
|
||||
}
|
||||
if cli_args.value_of("validators-dir").is_some()
|
||||
&& cli_args.value_of("secrets-dir").is_some()
|
||||
{
|
||||
validator_dir = Some(parse_required(cli_args, "validators-dir")?);
|
||||
secrets_dir = Some(parse_required(cli_args, "secrets-dir")?);
|
||||
}
|
||||
|
||||
config.validator_dir = validator_dir.unwrap_or_else(|| {
|
||||
default_root_dir
|
||||
.join(get_testnet_name(cli_args))
|
||||
.join(DEFAULT_VALIDATOR_DIR)
|
||||
});
|
||||
|
||||
config.secrets_dir = secrets_dir.unwrap_or_else(|| {
|
||||
default_root_dir
|
||||
.join(get_testnet_name(cli_args))
|
||||
.join(DEFAULT_SECRET_DIR)
|
||||
});
|
||||
|
||||
if !config.validator_dir.exists() {
|
||||
return Err(format!(
|
||||
"The directory for validator data (--datadir) does not exist: {:?}",
|
||||
config.data_dir
|
||||
"The directory for validator data does not exist: {:?}",
|
||||
config.validator_dir
|
||||
));
|
||||
}
|
||||
|
||||
@@ -79,10 +109,7 @@ impl Config {
|
||||
config.allow_unsynced_beacon_node = cli_args.is_present("allow-unsynced");
|
||||
config.delete_lockfiles = cli_args.is_present("delete-lockfiles");
|
||||
config.disable_auto_discover = cli_args.is_present("disable-auto-discover");
|
||||
|
||||
if let Some(secrets_dir) = parse_optional(cli_args, "secrets-dir")? {
|
||||
config.secrets_dir = secrets_dir;
|
||||
}
|
||||
config.strict_slashing_protection = cli_args.is_present("strict-slashing-protection");
|
||||
|
||||
if let Some(input_graffiti) = cli_args.value_of("graffiti") {
|
||||
let graffiti_bytes = input_graffiti.as_bytes();
|
||||
|
||||
@@ -68,18 +68,18 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
log,
|
||||
"Starting validator client";
|
||||
"beacon_node" => &config.http_server,
|
||||
"datadir" => format!("{:?}", config.data_dir),
|
||||
"validator_dir" => format!("{:?}", config.validator_dir),
|
||||
);
|
||||
|
||||
let mut validator_defs = ValidatorDefinitions::open_or_create(&config.data_dir)
|
||||
let mut validator_defs = ValidatorDefinitions::open_or_create(&config.validator_dir)
|
||||
.map_err(|e| format!("Unable to open or create validator definitions: {:?}", e))?;
|
||||
|
||||
if !config.disable_auto_discover {
|
||||
let new_validators = validator_defs
|
||||
.discover_local_keystores(&config.data_dir, &config.secrets_dir, &log)
|
||||
.discover_local_keystores(&config.validator_dir, &config.secrets_dir, &log)
|
||||
.map_err(|e| format!("Unable to discover local validator keystores: {:?}", e))?;
|
||||
validator_defs
|
||||
.save(&config.data_dir)
|
||||
.save(&config.validator_dir)
|
||||
.map_err(|e| format!("Unable to update validator definitions: {:?}", e))?;
|
||||
info!(
|
||||
log,
|
||||
@@ -90,7 +90,7 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
|
||||
let validators = InitializedValidators::from_definitions(
|
||||
validator_defs,
|
||||
config.data_dir.clone(),
|
||||
config.validator_dir.clone(),
|
||||
config.delete_lockfiles,
|
||||
log.clone(),
|
||||
)
|
||||
|
||||
@@ -62,14 +62,24 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
|
||||
fork_service: ForkService<T, E>,
|
||||
log: Logger,
|
||||
) -> Result<Self, String> {
|
||||
let slashing_db_path = config.data_dir.join(SLASHING_PROTECTION_FILENAME);
|
||||
let slashing_protection =
|
||||
let slashing_db_path = config.validator_dir.join(SLASHING_PROTECTION_FILENAME);
|
||||
let slashing_protection = if config.strict_slashing_protection {
|
||||
// Don't create a new slashing database if `strict_slashing_protection` is turned on.
|
||||
SlashingDatabase::open(&slashing_db_path).map_err(|e| {
|
||||
format!(
|
||||
"Failed to open slashing protection database: {:?}.
|
||||
Ensure that `slashing_protection.sqlite` is in {:?} folder",
|
||||
e, config.validator_dir
|
||||
)
|
||||
})?
|
||||
} else {
|
||||
SlashingDatabase::open_or_create(&slashing_db_path).map_err(|e| {
|
||||
format!(
|
||||
"Failed to open or create slashing protection database: {:?}",
|
||||
e
|
||||
)
|
||||
})?;
|
||||
})?
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
validators: Arc::new(RwLock::new(validators)),
|
||||
|
||||
Reference in New Issue
Block a user