Skip to content

Commit

Permalink
genesis: fix number of initial validators when omitting total validat…
Browse files Browse the repository at this point in the history
…or count
  • Loading branch information
dknopik committed Oct 11, 2024
1 parent 42e12f0 commit 0d1ab93
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
16 changes: 7 additions & 9 deletions lib/src/genesis.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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")?;
Expand Down
21 changes: 13 additions & 8 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -73,14 +73,24 @@ pub fn generate<T: TryInto<FullConfig, Error = Error>>(
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(&ethshadow_config, &nodes, &output_path)?;

info!("Generating genesis information");
genesis::write_config(&ethshadow_config, output_path.clone())?;
genesis::write_config(
&ethshadow_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,
)?;

Expand All @@ -104,11 +114,6 @@ pub fn generate<T: TryInto<FullConfig, Error = Error>>(
}
}

let nodes = ethshadow_config.desugar_nodes()?;

debug!("Computing validators");
let validators = ValidatorManager::new(&ethshadow_config, &nodes, &output_path)?;

info!("Generating nodes");
let mut node_manager = NodeManager::new(
output_path.clone(),
Expand Down
4 changes: 4 additions & 0 deletions lib/src/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0d1ab93

Please sign in to comment.