mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 09:16:00 +00:00
Remove intermediate file from move
This commit is contained in:
@@ -10,8 +10,7 @@ use eth2::{
|
|||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::fs;
|
use std::path::PathBuf;
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
@@ -21,7 +20,6 @@ pub const MOVE_DIR_NAME: &str = "lighthouse-validator-move";
|
|||||||
pub const VALIDATOR_SPECIFICATION_FILE: &str = "validator-specification.json";
|
pub const VALIDATOR_SPECIFICATION_FILE: &str = "validator-specification.json";
|
||||||
|
|
||||||
pub const CMD: &str = "move";
|
pub const CMD: &str = "move";
|
||||||
pub const WORKING_DIRECTORY_FLAG: &str = "working-directory";
|
|
||||||
pub const SRC_VALIDATOR_CLIENT_URL_FLAG: &str = "src-validator-client-url";
|
pub const SRC_VALIDATOR_CLIENT_URL_FLAG: &str = "src-validator-client-url";
|
||||||
pub const SRC_VALIDATOR_CLIENT_TOKEN_FLAG: &str = "src-validator-client-token";
|
pub const SRC_VALIDATOR_CLIENT_TOKEN_FLAG: &str = "src-validator-client-token";
|
||||||
pub const DEST_VALIDATOR_CLIENT_URL_FLAG: &str = "dest-validator-client-url";
|
pub const DEST_VALIDATOR_CLIENT_URL_FLAG: &str = "dest-validator-client-url";
|
||||||
@@ -42,18 +40,6 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
|||||||
are defined in a JSON file which can be generated using the \"create-validators\" \
|
are defined in a JSON file which can be generated using the \"create-validators\" \
|
||||||
command.",
|
command.",
|
||||||
)
|
)
|
||||||
.arg(
|
|
||||||
Arg::with_name(WORKING_DIRECTORY_FLAG)
|
|
||||||
.long(WORKING_DIRECTORY_FLAG)
|
|
||||||
.value_name("PATH_TO_DIRECTORY")
|
|
||||||
.help(
|
|
||||||
"The path to a directory where the application can write files.\
|
|
||||||
Under certain failure scenarios this directory may contain files which \
|
|
||||||
can be used to recover validators.",
|
|
||||||
)
|
|
||||||
.required(true)
|
|
||||||
.takes_value(true),
|
|
||||||
)
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(SRC_VALIDATOR_CLIENT_URL_FLAG)
|
Arg::with_name(SRC_VALIDATOR_CLIENT_URL_FLAG)
|
||||||
.long(SRC_VALIDATOR_CLIENT_URL_FLAG)
|
.long(SRC_VALIDATOR_CLIENT_URL_FLAG)
|
||||||
@@ -162,7 +148,6 @@ impl FromStr for Validators {
|
|||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
|
||||||
pub struct MoveConfig {
|
pub struct MoveConfig {
|
||||||
pub working_directory_path: PathBuf,
|
|
||||||
pub src_vc_url: SensitiveUrl,
|
pub src_vc_url: SensitiveUrl,
|
||||||
pub src_vc_token_path: PathBuf,
|
pub src_vc_token_path: PathBuf,
|
||||||
pub dest_vc_url: SensitiveUrl,
|
pub dest_vc_url: SensitiveUrl,
|
||||||
@@ -176,7 +161,6 @@ pub struct MoveConfig {
|
|||||||
impl MoveConfig {
|
impl MoveConfig {
|
||||||
fn from_cli(matches: &ArgMatches) -> Result<Self, String> {
|
fn from_cli(matches: &ArgMatches) -> Result<Self, String> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
working_directory_path: clap_utils::parse_required(matches, WORKING_DIRECTORY_FLAG)?,
|
|
||||||
src_vc_url: clap_utils::parse_required(matches, SRC_VALIDATOR_CLIENT_URL_FLAG)?,
|
src_vc_url: clap_utils::parse_required(matches, SRC_VALIDATOR_CLIENT_URL_FLAG)?,
|
||||||
src_vc_token_path: clap_utils::parse_required(
|
src_vc_token_path: clap_utils::parse_required(
|
||||||
matches,
|
matches,
|
||||||
@@ -209,7 +193,6 @@ pub async fn cli_run<'a>(
|
|||||||
|
|
||||||
async fn run<'a>(config: MoveConfig) -> Result<(), String> {
|
async fn run<'a>(config: MoveConfig) -> Result<(), String> {
|
||||||
let MoveConfig {
|
let MoveConfig {
|
||||||
working_directory_path,
|
|
||||||
src_vc_url,
|
src_vc_url,
|
||||||
src_vc_token_path,
|
src_vc_token_path,
|
||||||
dest_vc_url,
|
dest_vc_url,
|
||||||
@@ -220,26 +203,6 @@ async fn run<'a>(config: MoveConfig) -> Result<(), String> {
|
|||||||
gas_limit,
|
gas_limit,
|
||||||
} = config;
|
} = config;
|
||||||
|
|
||||||
if !working_directory_path.exists() {
|
|
||||||
return Err(format!("{:?} does not exist", working_directory_path));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Append another directory to the "working directory" provided by the user. By creating a new
|
|
||||||
// directory we can prove (to some degree) that we can write in the given directory.
|
|
||||||
//
|
|
||||||
// It also allows us to easily detect when another identical process is running or the previous
|
|
||||||
// run failed by checking to see if the directory already exists.
|
|
||||||
let working_directory_path = working_directory_path.join(MOVE_DIR_NAME);
|
|
||||||
if working_directory_path.exists() {
|
|
||||||
return Err(format!(
|
|
||||||
"{:?} already exists, exiting",
|
|
||||||
working_directory_path
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
fs::create_dir(&working_directory_path)
|
|
||||||
.map_err(|e| format!("Failed to create {:?}: {:?}", working_directory_path, e))?;
|
|
||||||
|
|
||||||
// Moving validators between the same VC is unlikely to be useful and probably indicates a user
|
// Moving validators between the same VC is unlikely to be useful and probably indicates a user
|
||||||
// error.
|
// error.
|
||||||
if src_vc_url == dest_vc_url {
|
if src_vc_url == dest_vc_url {
|
||||||
@@ -509,47 +472,6 @@ async fn sleep_with_retry_message(pubkey: &PublicKeyBytes, path: Option<&str>) {
|
|||||||
sleep(UPLOAD_RETRY_WAIT).await
|
sleep(UPLOAD_RETRY_WAIT).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn backup_validator<P: AsRef<Path>>(
|
|
||||||
validator_specification: &ValidatorSpecification,
|
|
||||||
working_directory_path: P,
|
|
||||||
dest_vc_url: &SensitiveUrl,
|
|
||||||
dest_vc_token_path: P,
|
|
||||||
) {
|
|
||||||
use crate::validators::import_validators::{
|
|
||||||
CMD, VALIDATORS_FILE_FLAG, VALIDATOR_CLIENT_TOKEN_FLAG, VALIDATOR_CLIENT_URL_FLAG,
|
|
||||||
};
|
|
||||||
|
|
||||||
let validator_specification_path = working_directory_path
|
|
||||||
.as_ref()
|
|
||||||
.join(VALIDATOR_SPECIFICATION_FILE);
|
|
||||||
if let Err(e) = write_to_json_file(&validator_specification_path, &validator_specification) {
|
|
||||||
eprintln!(
|
|
||||||
"A validator was removed from the source validator client but it could not be \
|
|
||||||
saved to disk after an upload failure. The validator may need to be recovered \
|
|
||||||
from a backup or mnemonic. Error was {:?}",
|
|
||||||
e
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
eprintln!(
|
|
||||||
"It may be possible to recover this validator by running the following command: \n\n\
|
|
||||||
lighthouse {} {} {} --{} {:?} --{} {} --{} {:?} \n\n\
|
|
||||||
The {:?} directory contains a backup of the validator that was unable to be uploaded. \
|
|
||||||
That backup contains the unencrypted validator secret key and should not be shared with \
|
|
||||||
anyone. If the recovery command (above) succeeds, it is safe to remove that directory.",
|
|
||||||
crate::CMD,
|
|
||||||
crate::validators::CMD,
|
|
||||||
CMD,
|
|
||||||
VALIDATORS_FILE_FLAG,
|
|
||||||
validator_specification_path.as_os_str(),
|
|
||||||
VALIDATOR_CLIENT_URL_FLAG,
|
|
||||||
dest_vc_url.full,
|
|
||||||
VALIDATOR_CLIENT_TOKEN_FLAG,
|
|
||||||
dest_vc_token_path.as_ref().as_os_str(),
|
|
||||||
working_directory_path.as_ref().as_os_str(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The tests use crypto and are too slow in debug.
|
// The tests use crypto and are too slow in debug.
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -616,7 +538,6 @@ mod test {
|
|||||||
fs::write(&dest_vc_token_path, &dest_vc.api_token).unwrap();
|
fs::write(&dest_vc_token_path, &dest_vc.api_token).unwrap();
|
||||||
|
|
||||||
let move_config = MoveConfig {
|
let move_config = MoveConfig {
|
||||||
working_directory_path: self.dir.path().into(),
|
|
||||||
src_vc_url: src_vc.url.clone(),
|
src_vc_url: src_vc.url.clone(),
|
||||||
src_vc_token_path,
|
src_vc_token_path,
|
||||||
dest_vc_url: dest_vc.url.clone(),
|
dest_vc_url: dest_vc.url.clone(),
|
||||||
|
|||||||
Reference in New Issue
Block a user