From 5e3da4c590805154b85ea05dcf8e896738d04c6a Mon Sep 17 00:00:00 2001 From: Daniel Knopik Date: Thu, 10 Oct 2024 13:15:47 +0200 Subject: [PATCH] add defaults for usual performance config values --- .gitignore | 2 ++ ethshadow.yaml | 67 ------------------------------------- lib/src/config/ethshadow.rs | 9 +++++ lib/src/config/shadow.rs | 39 +++++++++++++++++++++ lib/src/lib.rs | 1 + 5 files changed, 51 insertions(+), 67 deletions(-) delete mode 100644 ethshadow.yaml diff --git a/.gitignore b/.gitignore index f76491a..8398e14 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ data* target .idea *.swp +/*.yaml +/*.yml \ No newline at end of file diff --git a/ethshadow.yaml b/ethshadow.yaml deleted file mode 100644 index f1983a6..0000000 --- a/ethshadow.yaml +++ /dev/null @@ -1,67 +0,0 @@ -general: - model_unblocked_syscall_latency: true - stop_time: 1h - progress: true - heartbeat_interval: 1m - -experimental: - runahead: 20ms - use_memory_manager: true - host_heartbeat_interval: 1m - -ethereum: - validators: 160 - nodes: - - location: europe - reliability: reliable - tag: boot - clients: - el: geth_bootnode - cl: lighthouse_bootnode - - locations: - - europe - - na_east - - na_west - reliabilities: - - reliable - - home - count: - per_combination: 4 - clients: - el: geth - cl: lighthouse - vc: lighthouse_vc - - locations: - - east_asia - - australia - - west_asia - reliabilities: - - reliable - - home - count: - per_combination: 2 - clients: - el: reth - cl: lighthouse - vc: lighthouse_vc - - location: europe - reliability: reliable - tag: monitoring - clients: - monitoring: prometheus - - location: europe - reliability: reliable - tag: spammer - clients: - spamming: spammer - clients: - spammer: - type: simple_blob_spammer - executable: blobssss - private_key: "087e1e65a8127930dc08bc7cfcf2dd19400112910e40247dfe71a1d82365958d" - min_per_slot: 2 - max_per_slot: 4 - start_time: 330s - genesis: - premine: - 5E015fB7fdD3882dd62C5A7fDc41E02cAE6ce459: 1000000ETH diff --git a/lib/src/config/ethshadow.rs b/lib/src/config/ethshadow.rs index b6ef407..ed5b708 100644 --- a/lib/src/config/ethshadow.rs +++ b/lib/src/config/ethshadow.rs @@ -376,6 +376,15 @@ impl EthShadowConfig { self.clients.entry(name.into()).or_insert(Box::new(client)); } + pub fn minimum_latency(&self) -> Duration { + self.locations + .values() + .flat_map(|loc| loc.latency_to.values()) + .map(|latency| latency.into_inner()) + .min() + .expect("latencies should be specified at this point") + } + pub fn desugar_nodes(&self) -> Result, Error> { let mut result = vec![]; diff --git a/lib/src/config/shadow.rs b/lib/src/config/shadow.rs index 5387175..0fd04a2 100644 --- a/lib/src/config/shadow.rs +++ b/lib/src/config/shadow.rs @@ -4,6 +4,7 @@ use serde::Serialize; use serde_yaml::mapping::IterMut; use serde_yaml::{to_value, Mapping, Value}; use std::collections::HashMap; +use std::time::Duration; /// A light wrapper around a yaml mapping representing the root of a shadow config with some useful /// setters and getters @@ -30,6 +31,22 @@ pub struct Process { } impl ShadowConfig { + pub fn general_mut(&mut self) -> Result<&mut Mapping, Error> { + self.0 + .entry("general".into()) + .or_insert(Mapping::new().into()) + .as_mapping_mut() + .ok_or_else(|| Error::ExpectedOtherType("general".into())) + } + + pub fn experimental_mut(&mut self) -> Result<&mut Mapping, Error> { + self.0 + .entry("experimental".into()) + .or_insert(Mapping::new().into()) + .as_mapping_mut() + .ok_or_else(|| Error::ExpectedOtherType("experimental".into())) + } + pub fn seed(&self) -> u64 { self.0 .get("general") @@ -83,6 +100,28 @@ impl ShadowConfig { .map(|h| h.iter_mut()), }) } + + pub fn apply_defaults(&mut self, runahead: Duration) -> Result<(), Error> { + let general = self.general_mut()?; + general + .entry("model_unblocked_syscall_latency".into()) + .or_insert(Value::Bool(true)); + general + .entry("heartbeat_interval".into()) + .or_insert_with(|| Value::String("1m".into())); + let experimental = self.experimental_mut()?; + // todo: warn user if they override runahead with a value larger than the min latency + experimental + .entry("runahead".into()) + .or_insert_with(|| format!("{}ns", runahead.as_nanos()).into()); + experimental + .entry("use_memory_manager".into()) + .or_insert(Value::Bool(true)); + experimental + .entry("host_heartbeat_interval".into()) + .or_insert_with(|| Value::String("1m".into())); + Ok(()) + } } pub struct HostsMut<'a> { diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 30477ba..879a769 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -60,6 +60,7 @@ pub fn generate>( mut shadow_config, } = config.try_into()?; ethshadow_config.add_default_builtins(); + shadow_config.apply_defaults(ethshadow_config.minimum_latency())?; create_dir(&output_path).map_err(|e| match e.kind() { ErrorKind::AlreadyExists => Error::OutputFolderExists,