diff --git a/validator_client/src/lib.rs b/validator_client/src/lib.rs index c7afbd7c4..e09ce1568 100644 --- a/validator_client/src/lib.rs +++ b/validator_client/src/lib.rs @@ -26,6 +26,7 @@ use slot_clock::SystemTimeSlotClock; use std::time::{SystemTime, UNIX_EPOCH}; use tokio::time::{delay_for, Duration}; use types::EthSpec; +use validator_dir::Manager as ValidatorManager; use validator_store::ValidatorStore; /// The interval between attempts to contact the beacon node during startup. @@ -58,13 +59,10 @@ impl ProductionValidatorClient { /// Instantiates the validator client, _without_ starting the timers to trigger block /// and attestation production. pub async fn new(mut context: RuntimeContext, config: Config) -> Result { - let log_1 = context.log().clone(); - let log_2 = context.log().clone(); - let log_3 = context.log().clone(); - let log_4 = context.log().clone(); + let log = context.log().clone(); info!( - log_1, + log, "Starting validator client"; "beacon_node" => &config.http_server, "datadir" => format!("{:?}", config.data_dir), @@ -72,18 +70,29 @@ impl ProductionValidatorClient { if !config.data_dir.join(SLASHING_PROTECTION_FILENAME).exists() && !config.auto_register { warn!( - log_1, + log, "Will not register any validators"; "msg" => "strongly consider using --auto-register on the first use", ); } + let validators = ValidatorManager::open(&config.data_dir) + .map_err(|e| format!("unable to read data_dir: {:?}", e))? + .decrypt_all_validators(config.secrets_dir.clone(), Some(&log)) + .map_err(|e| format!("unable to decrypt all validator directories: {:?}", e))?; + + info!( + log, + "Decrypted validator keystores"; + "count" => validators.len(), + ); + let beacon_node = RemoteBeaconNode::new_with_timeout(config.http_server.clone(), HTTP_TIMEOUT) .map_err(|e| format!("Unable to init beacon node http client: {}", e))?; // TODO: check if all logs in wait_for_node are produed while awaiting - let beacon_node = wait_for_node(beacon_node, log_2).await?; + let beacon_node = wait_for_node(beacon_node, &log).await?; let eth2_config = beacon_node .http .spec() @@ -99,7 +108,6 @@ impl ProductionValidatorClient { let now = SystemTime::now() .duration_since(UNIX_EPOCH) .map_err(|e| format!("Unable to read system time: {:?}", e))?; - let log = log_3.clone(); let genesis = Duration::from_secs(genesis_time); // If the time now is less than (prior to) genesis, then delay until the @@ -133,7 +141,6 @@ impl ProductionValidatorClient { e ) })?; - let log = log_4.clone(); // Do not permit a connection to a beacon node using different spec constants. if context.eth2_config.spec_constants != eth2_config.spec_constants { @@ -164,14 +171,14 @@ impl ProductionValidatorClient { .runtime_context(context.service_context("fork".into())) .build()?; - let validator_store: ValidatorStore = - ValidatorStore::load_from_disk( - &config, - genesis_validators_root, - context.eth2_config.spec.clone(), - fork_service.clone(), - log.clone(), - )?; + let validator_store: ValidatorStore = ValidatorStore::new( + validators, + &config, + genesis_validators_root, + context.eth2_config.spec.clone(), + fork_service.clone(), + log.clone(), + )?; info!( log, @@ -250,7 +257,7 @@ impl ProductionValidatorClient { /// has been contacted. async fn wait_for_node( beacon_node: RemoteBeaconNode, - log: Logger, + log: &Logger, ) -> Result, String> { // Try to get the version string from the node, looping until success is returned. loop { diff --git a/validator_client/src/validator_store.rs b/validator_client/src/validator_store.rs index c7e0d97ec..8e93ef584 100644 --- a/validator_client/src/validator_store.rs +++ b/validator_client/src/validator_store.rs @@ -13,7 +13,7 @@ use types::{ Attestation, BeaconBlock, ChainSpec, Domain, Epoch, EthSpec, Fork, Hash256, Keypair, PublicKey, SelectionProof, Signature, SignedAggregateAndProof, SignedBeaconBlock, SignedRoot, Slot, }; -use validator_dir::{Manager as ValidatorManager, ValidatorDir}; +use validator_dir::ValidatorDir; struct LocalValidator { validator_dir: ValidatorDir, @@ -53,7 +53,8 @@ pub struct ValidatorStore { } impl ValidatorStore { - pub fn load_from_disk( + pub fn new( + validators: Vec<(Keypair, ValidatorDir)>, config: &Config, genesis_validators_root: Hash256, spec: ChainSpec, @@ -69,20 +70,15 @@ impl ValidatorStore { ) })?; - let validator_key_values = ValidatorManager::open(&config.data_dir) - .map_err(|e| format!("unable to read data_dir: {:?}", e))? - .decrypt_all_validators(config.secrets_dir.clone(), Some(&log)) - .map_err(|e| format!("unable to decrypt all validator directories: {:?}", e))? - .into_iter() - .map(|(kp, dir)| { - ( - kp.pk.clone(), - LocalValidator { - validator_dir: dir, - voting_keypair: kp, - }, - ) - }); + let validator_key_values = validators.into_iter().map(|(kp, dir)| { + ( + kp.pk.clone(), + LocalValidator { + validator_dir: dir, + voting_keypair: kp, + }, + ) + }); Ok(Self { validators: Arc::new(RwLock::new(HashMap::from_iter(validator_key_values))),