mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 06:14:38 +00:00
Introduce validator definition file for VC (#1357)
## Issue Addressed
NA
## Proposed Changes
- Introduces the `valdiator_definitions.yml` file which serves as an explicit list of validators that should be run by the validator client.
- Removes `--strict` flag, split into `--strict-lockfiles` and `--disable-auto-discover`
- Adds a "Validator Management" page to the book.
- Adds the `common/account_utils` crate which contains some logic that was starting to duplicate across the codebase.
The new docs for this feature are the best description of it (apart from the code, I guess): 9cb87e93ce/book/src/validator-management.md
## API Changes
This change should be transparent for *most* existing users. If the `valdiator_definitions.yml` doesn't exist then it will be automatically generated using a method that will detect all the validators in their `validators_dir`.
Users will have issues if they are:
1. Using `--strict`.
1. Have keystores in their `~/.lighthouse/validators` directory that weren't being detected by the current keystore discovery method.
For users with (1), the VC will refuse to start because the `--strict` flag has been removed. They will be forced to review `--help` and choose an equivalent flag.
For users with (2), this seems fairly unlikely and since we're only in testnets there's no *real* value on the line here. I'm happy to take the risk, it would be a different case for mainnet.
## Additional Info
This PR adds functionality we will need for #1347.
## TODO
- [x] Reconsider flags
- [x] Move doc into a more reasonable chapter.
- [x] Check for compile warnings.
This commit is contained in:
@@ -1,25 +1,7 @@
|
||||
use clap::ArgMatches;
|
||||
use eth2_wallet::PlainText;
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
use std::fs::create_dir_all;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// The `Alphanumeric` crate only generates a-z, A-Z, 0-9, therefore it has a range of 62
|
||||
/// characters.
|
||||
///
|
||||
/// 62**48 is greater than 255**32, therefore this password has more bits of entropy than a byte
|
||||
/// array of length 32.
|
||||
const DEFAULT_PASSWORD_LEN: usize = 48;
|
||||
|
||||
pub fn random_password() -> PlainText {
|
||||
rand::thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(DEFAULT_PASSWORD_LEN)
|
||||
.collect::<String>()
|
||||
.into_bytes()
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn ensure_dir_exists<P: AsRef<Path>>(path: P) -> Result<(), String> {
|
||||
let path = path.as_ref();
|
||||
|
||||
@@ -37,56 +19,3 @@ pub fn base_wallet_dir(matches: &ArgMatches, arg: &'static str) -> Result<PathBu
|
||||
PathBuf::new().join(".lighthouse").join("wallets"),
|
||||
)
|
||||
}
|
||||
|
||||
/// Remove any number of newline or carriage returns from the end of a vector of bytes.
|
||||
pub fn strip_off_newlines(mut bytes: Vec<u8>) -> Vec<u8> {
|
||||
let mut strip_off = 0;
|
||||
for (i, byte) in bytes.iter().rev().enumerate() {
|
||||
if *byte == b'\n' || *byte == b'\r' {
|
||||
strip_off = i + 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
bytes.truncate(bytes.len() - strip_off);
|
||||
bytes
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::strip_off_newlines;
|
||||
|
||||
#[test]
|
||||
fn test_strip_off() {
|
||||
let expected = "hello world".as_bytes().to_vec();
|
||||
|
||||
assert_eq!(
|
||||
strip_off_newlines("hello world\n".as_bytes().to_vec()),
|
||||
expected
|
||||
);
|
||||
assert_eq!(
|
||||
strip_off_newlines("hello world\n\n\n\n".as_bytes().to_vec()),
|
||||
expected
|
||||
);
|
||||
assert_eq!(
|
||||
strip_off_newlines("hello world\r".as_bytes().to_vec()),
|
||||
expected
|
||||
);
|
||||
assert_eq!(
|
||||
strip_off_newlines("hello world\r\r\r\r\r".as_bytes().to_vec()),
|
||||
expected
|
||||
);
|
||||
assert_eq!(
|
||||
strip_off_newlines("hello world\r\n".as_bytes().to_vec()),
|
||||
expected
|
||||
);
|
||||
assert_eq!(
|
||||
strip_off_newlines("hello world\r\n\r\n".as_bytes().to_vec()),
|
||||
expected
|
||||
);
|
||||
assert_eq!(
|
||||
strip_off_newlines("hello world".as_bytes().to_vec()),
|
||||
expected
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use crate::{
|
||||
common::{ensure_dir_exists, random_password, strip_off_newlines},
|
||||
SECRETS_DIR_FLAG, VALIDATOR_DIR_FLAG,
|
||||
};
|
||||
use crate::{common::ensure_dir_exists, SECRETS_DIR_FLAG, VALIDATOR_DIR_FLAG};
|
||||
use account_utils::{random_password, strip_off_newlines};
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use environment::Environment;
|
||||
use eth2_wallet::PlainText;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use crate::{
|
||||
common::{random_password, strip_off_newlines},
|
||||
BASE_DIR_FLAG,
|
||||
};
|
||||
use crate::BASE_DIR_FLAG;
|
||||
use account_utils::{random_password, strip_off_newlines};
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use eth2_wallet::{
|
||||
bip39::{Language, Mnemonic, MnemonicType},
|
||||
|
||||
Reference in New Issue
Block a user