Reduce duplication of keypair generation

This commit is contained in:
Paul Hauner
2019-11-24 07:42:13 +11:00
parent e94c265036
commit 07681612d0
4 changed files with 34 additions and 32 deletions

View File

@@ -1,6 +1,5 @@
use clap::ArgMatches;
use serde_derive::{Deserialize, Serialize};
use std::ops::Range;
use std::path::PathBuf;
pub const DEFAULT_HTTP_SERVER: &str = "http://localhost:5052/";
@@ -11,7 +10,7 @@ pub enum KeySource {
/// Load the keypairs from disk.
Disk,
/// Generate the keypairs (insecure, generates predictable keys).
TestingKeypairRange(Range<usize>),
InsecureKeypairs(Vec<usize>),
}
impl Default for KeySource {
@@ -93,7 +92,7 @@ fn process_testnet_subcommand(cli_args: &ArgMatches, mut config: Config) -> Resu
return Err("Cannot supply a last validator less than the first".to_string());
}
KeySource::TestingKeypairRange(first..last)
KeySource::InsecureKeypairs((first..last).collect())
}
_ => KeySource::Disk,
};

View File

@@ -9,12 +9,11 @@ mod validator_store;
pub mod validator_directory;
pub use cli::cli_app;
pub use config::Config;
pub use config::{Config, KeySource};
use attestation_service::{AttestationService, AttestationServiceBuilder};
use block_service::{BlockService, BlockServiceBuilder};
use clap::ArgMatches;
use config::KeySource;
use duties_service::{DutiesService, DutiesServiceBuilder};
use environment::RuntimeContext;
use exit_future::Signal;
@@ -37,7 +36,7 @@ use validator_store::ValidatorStore;
/// The interval between attempts to contact the beacon node during startup.
const RETRY_DELAY: Duration = Duration::from_secs(2);
/// The global timeout for HTTP events.
/// The global timeout for HTTP requests to the beacon node.
const HTTP_TIMEOUT: Duration = Duration::from_secs(12);
#[derive(Clone)]
@@ -144,9 +143,9 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
// Generate ephemeral insecure keypairs for testing purposes.
//
// Do not use in production.
KeySource::TestingKeypairRange(range) => {
KeySource::InsecureKeypairs(indices) => {
ValidatorStore::insecure_ephemeral_validators(
range.clone(),
&indices,
context.eth2_config.spec.clone(),
fork_service.clone(),
log_3.clone(),

View File

@@ -8,7 +8,6 @@ use std::collections::HashMap;
use std::fs::read_dir;
use std::iter::FromIterator;
use std::marker::PhantomData;
use std::ops::Range;
use std::path::PathBuf;
use std::sync::Arc;
use tempdir::TempDir;
@@ -74,7 +73,7 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
}
pub fn insecure_ephemeral_validators(
range: Range<usize>,
validator_indices: &[usize],
spec: ChainSpec,
fork_service: ForkService<T, E>,
log: Logger,
@@ -83,8 +82,7 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
.map_err(|e| format!("Unable to create temp dir: {:?}", e))?;
let data_dir = PathBuf::from(temp_dir.path());
let validators = range
.collect::<Vec<_>>()
let validators = validator_indices
.par_iter()
.map(|index| {
ValidatorDirectoryBuilder::default()