diff --git a/account_manager/src/lib.rs b/account_manager/src/lib.rs index 719d5728a..101c7634e 100644 --- a/account_manager/src/lib.rs +++ b/account_manager/src/lib.rs @@ -87,9 +87,53 @@ fn run_new_validator_subcommand( datadir: PathBuf, mut env: Environment, ) -> Result<(), String> { - let context = env.core_context(); + let mut context = env.core_context(); let log = context.log.clone(); + // Load the testnet configuration from disk, or use the default testnet. + let eth2_testnet_config: Eth2TestnetConfig = + if let Some(testnet_dir_str) = matches.value_of("testnet-dir") { + let testnet_dir = testnet_dir_str + .parse::() + .map_err(|e| format!("Unable to parse testnet-dir: {}", e))?; + + if !testnet_dir.exists() { + return Err(format!( + "Testnet directory at {:?} does not exist", + testnet_dir + )); + } + + info!( + log, + "Loading deposit contract address"; + "testnet_dir" => format!("{:?}", &testnet_dir) + ); + + Eth2TestnetConfig::load(testnet_dir.clone()) + .map_err(|e| format!("Failed to load testnet dir at {:?}: {}", testnet_dir, e))? + } else { + info!( + log, + "Using Lighthouse testnet deposit contract"; + ); + + Eth2TestnetConfig::hard_coded() + .map_err(|e| format!("Failed to load hard_coded testnet dir: {}", e))? + }; + + context.eth2_config.spec = eth2_testnet_config + .yaml_config + .as_ref() + .ok_or_else(|| "The testnet directory must contain a spec config".to_string())? + .apply_to_chain_spec::(&context.eth2_config.spec) + .ok_or_else(|| { + format!( + "The loaded config is not compatible with the {} spec", + &context.eth2_config.spec_constants + ) + })?; + let methods: Vec = match matches.subcommand() { ("insecure", Some(matches)) => { let first = matches @@ -130,7 +174,7 @@ fn run_new_validator_subcommand( &methods, deposit_value, &context.eth2_config.spec, - &env.core_context().log, + &log, )?; if matches.is_present("send-deposits") { @@ -173,39 +217,6 @@ fn run_new_validator_subcommand( "eth1_node_http_endpoint" => eth1_endpoint ); - // Load the testnet configuration from disk, or use the default testnet. - let eth2_testnet_config: Eth2TestnetConfig = if let Some(testnet_dir_str) = - matches.value_of("testnet-dir") - { - let testnet_dir = testnet_dir_str - .parse::() - .map_err(|e| format!("Unable to parse testnet-dir: {}", e))?; - - if !testnet_dir.exists() { - return Err(format!( - "Testnet directory at {:?} does not exist", - testnet_dir - )); - } - - info!( - log, - "Loading deposit contract address"; - "testnet_dir" => format!("{:?}", &testnet_dir) - ); - - Eth2TestnetConfig::load(testnet_dir.clone()) - .map_err(|e| format!("Failed to load testnet dir at {:?}: {}", testnet_dir, e))? - } else { - info!( - log, - "Using Lighthouse testnet deposit contract"; - ); - - Eth2TestnetConfig::hard_coded() - .map_err(|e| format!("Failed to load hard_coded testnet dir: {}", e))? - }; - // Convert from `types::Address` to `web3::types::Address`. let deposit_contract = Address::from_slice( eth2_testnet_config diff --git a/eth2/types/src/chain_spec.rs b/eth2/types/src/chain_spec.rs index fe3990e09..188d5842a 100644 --- a/eth2/types/src/chain_spec.rs +++ b/eth2/types/src/chain_spec.rs @@ -612,7 +612,7 @@ impl YamlConfig { domain_deposit: self.domain_deposit, domain_voluntary_exit: self.domain_voluntary_exit, boot_nodes: chain_spec.boot_nodes.clone(), - genesis_fork_version: chain_spec.genesis_fork_version.clone(), + genesis_fork_version: self.genesis_fork_version.clone(), eth1_follow_distance: self.eth1_follow_distance, ..*chain_spec })