From 11c4968ea02c2d7423df163566d5a97fb933231a Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 25 Nov 2020 02:00:11 +1100 Subject: [PATCH] DO spec check before waiting for genesis (#1962) --- validator_client/src/lib.rs | 41 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/validator_client/src/lib.rs b/validator_client/src/lib.rs index f9604dc309..e614fd1361 100644 --- a/validator_client/src/lib.rs +++ b/validator_client/src/lib.rs @@ -37,7 +37,7 @@ use std::net::SocketAddr; use std::sync::Arc; use std::time::{SystemTime, UNIX_EPOCH}; use tokio::time::{delay_for, Duration}; -use types::{EthSpec, Hash256, YamlConfig}; +use types::{EthSpec, Hash256}; use validator_store::ValidatorStore; /// The interval between attempts to contact the beacon node during startup. @@ -181,23 +181,10 @@ impl ProductionValidatorClient { BeaconNodeHttpClient::from_components(beacon_node_url, beacon_node_http_client); // Perform some potentially long-running initialization tasks. - let (yaml_config, genesis_time, genesis_validators_root) = tokio::select! { + let (genesis_time, genesis_validators_root) = tokio::select! { tuple = init_from_beacon_node(&beacon_node, &context) => tuple?, () = context.executor.exit() => return Err("Shutting down".to_string()) }; - let beacon_node_spec = yaml_config.apply_to_chain_spec::(&T::default_spec()) - .ok_or_else(|| - "The minimal/mainnet spec type of the beacon node does not match the validator client. \ - See the --network command.".to_string() - )?; - - if context.eth2_config.spec != beacon_node_spec { - return Err( - "The beacon node is using a different Eth2 specification to this validator client. \ - See the --network command." - .to_string(), - ); - } let slot_clock = SystemTimeSlotClock::new( context.eth2_config.spec.genesis_slot, @@ -331,7 +318,7 @@ impl ProductionValidatorClient { async fn init_from_beacon_node( beacon_node: &BeaconNodeHttpClient, context: &RuntimeContext, -) -> Result<(YamlConfig, u64, Hash256), String> { +) -> Result<(u64, Hash256), String> { // Wait for the beacon node to come online. wait_for_node(beacon_node, context.log()).await?; @@ -341,6 +328,22 @@ async fn init_from_beacon_node( .map_err(|e| format!("Unable to read spec from beacon node: {:?}", e))? .data; + let beacon_node_spec = yaml_config + .apply_to_chain_spec::(&E::default_spec()) + .ok_or_else(|| { + "The minimal/mainnet spec type of the beacon node does not match the validator client. \ + See the --network command." + .to_string() + })?; + + if context.eth2_config.spec != beacon_node_spec { + return Err( + "The beacon node is using a different Eth2 specification to this validator client. \ + See the --network command." + .to_string(), + ); + } + let genesis = loop { match beacon_node.get_beacon_genesis().await { Ok(genesis) => break genesis.data, @@ -401,11 +404,7 @@ async fn init_from_beacon_node( ); } - Ok(( - yaml_config, - genesis.genesis_time, - genesis.genesis_validators_root, - )) + Ok((genesis.genesis_time, genesis.genesis_validators_root)) } /// Request the version from the node, looping back and trying again on failure. Exit once the node