Skip to content

Commit

Permalink
add defaults for usual performance config values
Browse files Browse the repository at this point in the history
  • Loading branch information
dknopik committed Oct 10, 2024
1 parent 1a38984 commit 5e3da4c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ data*
target
.idea
*.swp
/*.yaml
/*.yml
67 changes: 0 additions & 67 deletions ethshadow.yaml

This file was deleted.

9 changes: 9 additions & 0 deletions lib/src/config/ethshadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Node>, Error> {
let mut result = vec![];

Expand Down
39 changes: 39 additions & 0 deletions lib/src/config/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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> {
Expand Down
1 change: 1 addition & 0 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub fn generate<T: TryInto<FullConfig, Error = Error>>(
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,
Expand Down

0 comments on commit 5e3da4c

Please sign in to comment.