diff --git a/lib/src/genesis.rs b/lib/src/genesis.rs index d09fc76..01e2cf9 100644 --- a/lib/src/genesis.rs +++ b/lib/src/genesis.rs @@ -1,5 +1,4 @@ -use crate::config::ethshadow::DEFAULT_MNEMONIC; -use crate::config::EthShadowConfig; +use crate::config::ethshadow::{Genesis, DEFAULT_MNEMONIC}; use crate::error::Error; use crate::utils::log_and_wait; use std::ffi::OsString; @@ -12,8 +11,11 @@ use users::get_current_uid; pub const GENESIS_FORK_VERSION: &str = "0x10000000"; -pub fn write_config(config: &EthShadowConfig, mut output_path: PathBuf) -> Result<(), Error> { - let genesis = &config.genesis; +pub fn write_config( + genesis: &Genesis, + num_validators: usize, + mut output_path: PathBuf, +) -> Result<(), Error> { output_path.push("values.env"); let mut file = BufWriter::new(File::create_new(output_path)?); let file = &mut file; @@ -44,11 +46,7 @@ pub fn write_config(config: &EthShadowConfig, mut output_path: PathBuf) -> Resul "DEPOSIT_CONTRACT_BLOCK", "0x0000000000000000000000000000000000000000000000000000000000000000", )?; - export( - file, - "NUMBER_OF_VALIDATORS", - config.validators.unwrap_or(80), - )?; + export(file, "NUMBER_OF_VALIDATORS", num_validators)?; export(file, "GENESIS_FORK_VERSION", "0x10000000")?; export(file, "ALTAIR_FORK_VERSION", "0x20000000")?; export(file, "BELLATRIX_FORK_VERSION", "0x30000000")?; diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 4be1544..12d186e 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,9 +1,9 @@ +use crate::config::ethshadow::DEFAULT_GENESIS_GEN_IMAGE; use crate::config::FullConfig; use crate::error::Error; use crate::network_graph::{generate_network_graph, GeneratedNetworkGraph}; use crate::node::NodeManager; use crate::validators::ValidatorManager; -use config::ethshadow; use log::{debug, info}; use serde_yaml::Value; use std::borrow::Cow; @@ -73,14 +73,24 @@ pub fn generate>( output_path = output_path.canonicalize()?; let dir_path = output_path.clone().into_os_string(); + debug!("Desugaring node config"); + let nodes = ethshadow_config.desugar_nodes()?; + + debug!("Computing validators"); + let validators = ValidatorManager::new(ðshadow_config, &nodes, &output_path)?; + info!("Generating genesis information"); - genesis::write_config(ðshadow_config, output_path.clone())?; + genesis::write_config( + ðshadow_config.genesis, + validators.total_count(), + output_path.clone(), + )?; genesis::generate( ethshadow_config .genesis .generator_image .as_deref() - .unwrap_or(ethshadow::DEFAULT_GENESIS_GEN_IMAGE), + .unwrap_or(DEFAULT_GENESIS_GEN_IMAGE), dir_path, )?; @@ -104,11 +114,6 @@ pub fn generate>( } } - let nodes = ethshadow_config.desugar_nodes()?; - - debug!("Computing validators"); - let validators = ValidatorManager::new(ðshadow_config, &nodes, &output_path)?; - info!("Generating nodes"); let mut node_manager = NodeManager::new( output_path.clone(), diff --git a/lib/src/validators.rs b/lib/src/validators.rs index a7c397b..026b862 100644 --- a/lib/src/validators.rs +++ b/lib/src/validators.rs @@ -104,6 +104,10 @@ impl ValidatorManager { self.already_assigned = end; &self.validators[start..end] } + + pub fn total_count(&self) -> usize { + self.validators.len() + } } fn generate(