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