Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
  • Loading branch information
sandreim committed Dec 14, 2023
1 parent 4c86691 commit bd128b3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 44 deletions.
2 changes: 1 addition & 1 deletion polkadot/node/subsystem-bench/src/availability/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn prepare_test_inner(
};

let (collation_req_receiver, req_cfg) =
IncomingRequest::get_config_receiver(&ReqProtocolNames::new(&GENESIS_HASH, None));
IncomingRequest::get_config_receiver(&ReqProtocolNames::new(GENESIS_HASH, None));

let subsystem = if use_fast_path {
AvailabilityRecoverySubsystem::with_fast_path(
Expand Down
18 changes: 6 additions & 12 deletions polkadot/node/subsystem-bench/src/core/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl TestSequence {

impl TestSequence {
pub fn new_from_file(path: &Path) -> std::io::Result<TestSequence> {
let string = String::from_utf8(std::fs::read(&path)?).expect("File is valid UTF8");
let string = String::from_utf8(std::fs::read(path)?).expect("File is valid UTF8");
Ok(serde_yaml::from_str(&string).expect("File is valid test sequence YA"))
}
}
Expand Down Expand Up @@ -150,7 +150,7 @@ impl TestConfiguration {
/// Generates the authority keys we need for the network emulation.
pub fn generate_authorities(&self) -> TestAuthorities {
let keyrings = (0..self.n_validators)
.map(|peer_index| Keyring::new(format!("Node{}", peer_index).into()))
.map(|peer_index| Keyring::new(format!("Node{}", peer_index)))
.collect::<Vec<_>>();

// Generate `AuthorityDiscoveryId`` for each peer
Expand All @@ -162,8 +162,7 @@ impl TestConfiguration {
let validator_authority_id: Vec<AuthorityDiscoveryId> = keyrings
.iter()
.map(|keyring| keyring.clone().public().into())
.collect::<Vec<_>>()
.into();
.collect::<Vec<_>>();

TestAuthorities { keyrings, validator_public, validator_authority_id }
}
Expand Down Expand Up @@ -251,14 +250,9 @@ impl TestConfiguration {

/// Produce a randomized duration between `min` and `max`.
pub fn random_latency(maybe_peer_latency: Option<&PeerLatency>) -> Option<Duration> {
if let Some(peer_latency) = maybe_peer_latency {
Some(
Uniform::from(peer_latency.min_latency..=peer_latency.max_latency)
.sample(&mut thread_rng()),
)
} else {
None
}
maybe_peer_latency.map(|peer_latency| {
Uniform::from(peer_latency.min_latency..=peer_latency.max_latency).sample(&mut thread_rng())
})
}

/// Generate a random error based on `probability`.
Expand Down
8 changes: 4 additions & 4 deletions polkadot/node/subsystem-bench/src/core/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl MetricCollection {
/// Sums up all metrics with the given name in the collection
pub fn sum_by(&self, name: &str) -> f64 {
self.all()
.into_iter()
.iter()
.filter(|metric| &metric.name == name)
.map(|metric| metric.value)
.sum()
Expand Down Expand Up @@ -71,7 +71,7 @@ impl MetricCollection {

impl Display for MetricCollection {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "")?;
writeln!(f)?;
let metrics = self.all();
for metric in metrics {
writeln!(f, "{}", metric)?;
Expand Down Expand Up @@ -150,15 +150,15 @@ pub fn parse_metrics(registry: &Registry) -> MetricCollection {
},
MetricType::HISTOGRAM => {
let h = m.get_histogram();
let h_name = name.clone() + "_sum".into();
let h_name = name.clone() + "_sum";
test_metrics.push(TestMetric {
name: h_name,
label_names: label_names.clone(),
label_values: label_values.clone(),
value: h.get_sample_sum(),
});

let h_name = name.clone() + "_count".into();
let h_name = name.clone() + "_count";
test_metrics.push(TestMetric {
name: h_name,
label_names,
Expand Down
7 changes: 3 additions & 4 deletions polkadot/node/subsystem-bench/src/core/mock/av_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl MockAvailabilityStore {
let v = self
.state
.chunks
.get(*candidate_index as usize)
.get(*candidate_index)
.unwrap()
.iter()
.filter(|c| send_chunk(c.index.0 as usize))
Expand Down Expand Up @@ -123,9 +123,8 @@ impl MockAvailabilityStore {
.expect("candidate was generated previously; qed");
gum::debug!(target: LOG_TARGET, ?candidate_hash, candidate_index, "Candidate mapped to index");

let chunk_size = self.state.chunks.get(*candidate_index as usize).unwrap()
[0]
.encoded_size();
let chunk_size =
self.state.chunks.get(*candidate_index).unwrap()[0].encoded_size();
let _ = tx.send(Some(chunk_size));
},
_ => {
Expand Down
40 changes: 19 additions & 21 deletions polkadot/node/subsystem-bench/src/core/mock/network_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ impl MockNetworkBridgeTx {
.expect("candidate was generated previously; qed");
gum::warn!(target: LOG_TARGET, ?candidate_hash, candidate_index, "Candidate mapped to index");

let chunk: ChunkResponse =
self.availabilty.chunks.get(*candidate_index as usize).unwrap()
[validator_index]
.clone()
.into();
let chunk: ChunkResponse = self.availabilty.chunks.get(*candidate_index).unwrap()
[validator_index]
.clone()
.into();
let mut size = chunk.encoded_size();

let response = if random_error(self.config.error) {
Expand Down Expand Up @@ -206,7 +205,7 @@ impl MockNetworkBridgeTx {
.inc_received(outgoing_request.payload.encoded_size());

let available_data =
self.availabilty.available_data.get(*candidate_index as usize).unwrap().clone();
self.availabilty.available_data.get(*candidate_index).unwrap().clone();

let size = available_data.encoded_size();

Expand Down Expand Up @@ -267,22 +266,21 @@ impl MockNetworkBridgeTx {
let our_network = self.network.clone();

// This task will handle node messages receipt from the simulated network.
let _ = ctx
.spawn_blocking(
"network-receive",
async move {
while let Some(action) = ingress_rx.recv().await {
let size = action.size();

// account for our node receiving the data.
our_network.inc_received(size);
rx_limiter.reap(size).await;
action.run().await;
}
ctx.spawn_blocking(
"network-receive",
async move {
while let Some(action) = ingress_rx.recv().await {
let size = action.size();

// account for our node receiving the data.
our_network.inc_received(size);
rx_limiter.reap(size).await;
action.run().await;
}
.boxed(),
)
.expect("We never fail to spawn tasks");
}
.boxed(),
)
.expect("We never fail to spawn tasks");

// Main subsystem loop.
loop {
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/subsystem-bench/src/core/mock/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl MockRuntimeApi {
.map(|i| ValidatorIndex(i as _))
.collect::<Vec<_>>();

let validator_groups = all_validators.chunks(5).map(|x| Vec::from(x)).collect::<Vec<_>>();
let validator_groups = all_validators.chunks(5).map(Vec::from).collect::<Vec<_>>();

SessionInfo {
validators: self.state.authorities.validator_public.clone().into(),
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/subsystem-bench/src/subsystem-bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl BenchCli {

fn main() -> eyre::Result<()> {
color_eyre::install()?;
let _ = env_logger::builder()
env_logger::builder()
.filter(Some("hyper"), log::LevelFilter::Info)
// Avoid `Terminating due to subsystem exit subsystem` warnings
.filter(Some("polkadot_overseer"), log::LevelFilter::Error)
Expand Down

0 comments on commit bd128b3

Please sign in to comment.