Skip to content

Commit

Permalink
clippy: address some of the pedantic lints
Browse files Browse the repository at this point in the history
  • Loading branch information
dknopik committed Oct 11, 2024
1 parent 7fb0cc6 commit a6e1c00
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 53 deletions.
3 changes: 2 additions & 1 deletion lib/src/clients/blobssss.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use crate::clients::Client;
use crate::config::shadow::Process;
use crate::node::{NodeInfo, SimulationContext};
Expand Down Expand Up @@ -32,7 +33,7 @@ impl Client for Blobssss {
self.private_key,
ctx.el_http_endpoints().iter().join(","),
),
environment: Default::default(),
environment: HashMap::default(),
expected_final_state: "running".into(),
start_time: self.start_time.clone().into(),
})
Expand Down
2 changes: 1 addition & 1 deletion lib/src/clients/lighthouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Default for Lighthouse {
fn default() -> Self {
Self {
executable: "lighthouse".into(),
extra_args: "".into(),
extra_args: String::new(),
lower_target_peers: true,
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/clients/lighthouse_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::fs::create_dir;
#[serde(default)]
pub struct LighthouseValidatorClient {
pub executable: CowStr,
pub validators: Option<u64>,
pub validators: Option<usize>,
}

impl Default for LighthouseValidatorClient {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/clients/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum ValidatorDemand {
Any,
/// We want validators, and the slice will have exactly this amount of elements. Generation
/// fails if we can not satisfy this.
Count(u64),
Count(usize),
}

#[typetag::deserialize(tag = "type")]
Expand Down
2 changes: 1 addition & 1 deletion lib/src/clients/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Client for Prometheus {
dir.to_str().ok_or(Error::NonUTF8Path)?,
config_file.to_str().ok_or(Error::NonUTF8Path)?,
),
environment: Default::default(),
environment: HashMap::default(),
expected_final_state: "running".into(),
start_time: "10s".into(),
})
Expand Down
24 changes: 12 additions & 12 deletions lib/src/config/ethshadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct EthShadowConfig {
nodes: Vec<SugaredNode>,
pub locations: HashMap<CowStr, Location>,
pub reliabilities: HashMap<CowStr, Reliability>,
pub validators: Option<u64>,
pub validators: Option<usize>,
pub clients: HashMap<CowStr, Box<dyn Client>>,
#[serde(default = "default_clients")]
pub default_clients: HashMap<CowStr, CowStr>,
Expand All @@ -36,7 +36,7 @@ pub struct EthShadowConfig {
#[derive(Deserialize, Clone, Debug)]
#[serde(untagged)]
enum NodeConfig {
Simple(u64),
Simple(usize),
Detailed(Vec<SugaredNode>),
}

Expand Down Expand Up @@ -83,17 +83,17 @@ struct SugaredNode {
}

impl SugaredNode {
fn combinations(&self) -> u64 {
self.locations.len() as u64
* self.reliabilities.len() as u64
fn combinations(&self) -> usize {
self.locations.len()
* self.reliabilities.len()
* self
.clients
.values()
.map(|clients| clients.len())
.product::<usize>() as u64
.map(OneOrMany::len)
.product::<usize>()
}

fn count_per_combination(&self) -> Result<u64, Error> {
fn count_per_combination(&self) -> Result<usize, Error> {
match self.count {
NodeCount::CountPerCombination(count) => Ok(count),
NodeCount::TotalCount(count) => {
Expand All @@ -110,9 +110,9 @@ impl SugaredNode {
#[derive(Deserialize, Clone, Copy, Debug)]
enum NodeCount {
#[serde(rename = "per_combination")]
CountPerCombination(u64),
CountPerCombination(usize),
#[serde(rename = "total")]
TotalCount(u64),
TotalCount(usize),
}

impl Default for NodeCount {
Expand Down Expand Up @@ -400,7 +400,7 @@ impl EthShadowConfig {
.map(|client| {
self.clients
.get(client.as_str())
.map(|b| b.as_ref())
.map(AsRef::as_ref)
.ok_or_else(|| Error::UnknownClient(client.clone()))
})
.try_collect()
Expand Down Expand Up @@ -445,7 +445,7 @@ pub struct Node<'a> {
pub location: &'a str,
pub reliability: &'a str,
pub clients: Vec<&'a dyn Client>,
pub count: u64,
pub count: usize,
pub tag: Option<&'a str>,
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/config/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<'a> Iterator for HostsMut<'a> {
fn next(&mut self) -> Option<Self::Item> {
self.hosts
.as_mut()
.and_then(|hosts| hosts.next())
.and_then(Iterator::next)
.map(|(_, host)| {
host.as_mapping_mut()
.ok_or_else(|| Error::ExpectedOtherType("host".to_string()))
Expand Down
4 changes: 2 additions & 2 deletions lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum Error {
#[error("Unknown client \"{0}\"")]
UnknownClient(String),
#[error("You have specified {0} total validators, but VCs have requested {1}")]
MoreValidatorsRequested(u64, u64),
MoreValidatorsRequested(usize, usize),
#[error(
"You have configured all validator clients to take a specific number of validators \
and it disagrees with the configured total number of validators"
Expand All @@ -41,7 +41,7 @@ pub enum Error {
"The specified number of nodes ({0}) must be divisible by the number of possible \
combinations ({1})"
)]
InconsistentCount(u64, u64),
InconsistentCount(usize, usize),
#[error("Missing env var: {0}")]
MissingEnvVar(#[from] VarError),
#[error("Output data folder already exists")]
Expand Down
6 changes: 3 additions & 3 deletions lib/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ pub fn write_config(
export(
file,
"ELECTRA_FORK_EPOCH",
genesis.electra_epoch.unwrap_or(9999999),
genesis.electra_epoch.unwrap_or(9_999_999),
)?;
export(file, "EIP7594_FORK_VERSION", "0x70000000")?;
export(
file,
"EIP7594_FORK_EPOCH",
genesis.eip7594_epoch.unwrap_or(99999999),
genesis.eip7594_epoch.unwrap_or(99_999_999),
)?;
export(file, "WITHDRAWAL_TYPE", "0x01")?;
export(
Expand All @@ -80,7 +80,7 @@ pub fn write_config(
export(
file,
"GENESIS_GASLIMIT",
genesis.gaslimit.unwrap_or(25000000),
genesis.gaslimit.unwrap_or(25_000_000),
)?;
export_optional(
file,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/gml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<W: Write> Drop for Gml<W> {
}

impl NetworkNode {
pub fn id(&self) -> u64 {
pub fn id(self) -> u64 {
self.id
}
}
2 changes: 1 addition & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn generate<T: TryInto<FullConfig, Error = Error>>(
// postprocessing given shadow config values: overwrite string network ids
for host in shadow_config.hosts_mut()? {
if let Some(node_id) = host?.network_node_id_mut() {
if let Some((location, reliability)) = node_id.as_str().and_then(|s| s.split_once("-"))
if let Some((location, reliability)) = node_id.as_str().and_then(|s| s.split_once('-'))
{
let node = network_graph.assign_network_node(location, reliability)?;
*node_id = Value::Number(node.id().into());
Expand Down
10 changes: 5 additions & 5 deletions lib/src/network_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl SimpleNetworkGraph<'_> {
let mut gml = String::new();
let mut gml_builder = Gml::new(&mut gml, true)?;
for location_name in config.locations.keys() {
for (reliability_name, reliability) in config.reliabilities.iter() {
for (reliability_name, reliability) in &config.reliabilities {
let node = gml_builder.add_node(
&reliability.bandwidth_up,
&reliability.bandwidth_down,
Expand All @@ -49,12 +49,12 @@ impl SimpleNetworkGraph<'_> {
.insert(reliability_name, node);
}
}
for (src_location_name, src_location) in config.locations.iter() {
for (src_reliability_name, src_reliability) in config.reliabilities.iter() {
for (src_location_name, src_location) in &config.locations {
for (src_reliability_name, src_reliability) in &config.reliabilities {
let src_node =
network_graph.get_network_node(src_location_name, src_reliability_name)?;
for dest_location_name in config.locations.keys() {
for (dest_reliability_name, dest_reliability) in config.reliabilities.iter() {
for (dest_reliability_name, dest_reliability) in &config.reliabilities {
let dest_node = network_graph
.get_network_node(dest_location_name, dest_reliability_name)?;
let mut latency = src_location
Expand Down Expand Up @@ -89,7 +89,7 @@ impl SimpleNetworkGraph<'_> {
"{src_location_name}-{src_reliability_name} to \
{dest_location_name}-{dest_reliability_name}"
)),
)?
)?;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl<'c, 'n> NodeManager<'c, 'n> {
rng,
base_dir.join("metadata"),
base_dir.join("jwt/jwtsecret"),
num_el_clients as usize,
num_cl_clients as usize,
num_el_clients,
num_cl_clients,
);
Self {
ctx,
Expand Down
39 changes: 18 additions & 21 deletions lib/src/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,22 @@ impl ValidatorManager {
}
}

match config.validators {
Some(validators) => {
let Some(remaining) = validators.checked_sub(requested) else {
return Err(Error::MoreValidatorsRequested(validators, requested));
};
validator_count = validators;
if anys != 0 {
val_for_each_any = remaining / anys;
remainder = remaining % anys;
} else if remaining != 0 {
return Err(Error::LeftoverValidators);
}
if let Some(validators) = config.validators {
let Some(remaining) = validators.checked_sub(requested) else {
return Err(Error::MoreValidatorsRequested(validators, requested));
};
validator_count = validators;
if anys != 0 {
val_for_each_any = remaining / anys;
remainder = remaining % anys;
} else if remaining != 0 {
return Err(Error::LeftoverValidators);
}
None => {
if anys != 0 {
return Err(Error::MissingValidatorCount);
}
validator_count = requested;
} else {
if anys != 0 {
return Err(Error::MissingValidatorCount);
}
validator_count = requested;
};

info!("Generating {validator_count} validators");
Expand All @@ -75,13 +72,13 @@ impl ValidatorManager {
.mnemonic
.as_deref()
.unwrap_or(DEFAULT_MNEMONIC),
validator_count as usize,
validator_count,
)?;

Ok(ValidatorManager {
validators,
val_for_each_any: val_for_each_any as usize,
remainder: remainder as usize,
val_for_each_any,
remainder,
already_assigned: 0,
})
}
Expand All @@ -97,7 +94,7 @@ impl ValidatorManager {
self.val_for_each_any
}
}
ValidatorDemand::Count(count) => count as usize,
ValidatorDemand::Count(count) => count,
};
let start = self.already_assigned;
let end = start + count;
Expand Down

0 comments on commit a6e1c00

Please sign in to comment.