Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Mar 28, 2024
1 parent 632daa5 commit a135ed6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
38 changes: 28 additions & 10 deletions bench/src/benches/confirmation_rate.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use crate::{create_rng, generate_txs, BenchmarkTransactionParams};
use anyhow::Context;
use itertools::Itertools;
use log::{debug, info, trace, warn};
use std::ops::Add;
use std::path::Path;
use std::sync::Arc;
use std::time::Duration;
use itertools::Itertools;

use crate::benches::rpc_interface::{
send_and_confirm_bulk_transactions, ConfirmationResponseFromRpc,
};
use solana_lite_rpc_util::histogram_percentiles::calculate_percentiles;
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::signature::{read_keypair_file, Keypair, Signature, Signer};
use solana_lite_rpc_util::histogram_nbuckets::histogram;
use solana_lite_rpc_util::histogram_percentiles::calculate_percentiles;

#[derive(Clone, Debug, Default, serde::Serialize)]
pub struct Metric {
Expand Down Expand Up @@ -142,22 +140,37 @@ pub async fn send_bulk_txs_and_wait(
}

let histogram_confirmation_time_ms = {
let confirmation_times = vec_confirmation_time.iter().map(|d| d.as_secs_f64() * 1000.0)
let confirmation_times = vec_confirmation_time
.iter()
.map(|d| d.as_secs_f64() * 1000.0)
.sorted_by(|a, b| a.partial_cmp(b).unwrap())
.collect_vec();
let histogram_confirmation_time = calculate_percentiles(&confirmation_times);
debug!("Confirmation time percentiles: {}", histogram_confirmation_time);
histogram_confirmation_time.v.iter().map(|d| *d as f32).collect()
debug!(
"Confirmation time percentiles: {}",
histogram_confirmation_time
);
histogram_confirmation_time
.v
.iter()
.map(|d| *d as f32)
.collect()
};
let average_confirmation_time_ms = if tx_confirmed > 0 {
vec_confirmation_time.iter().map(|d| d.as_secs_f32() * 1000.0).sum::<f32>()
vec_confirmation_time
.iter()
.map(|d| d.as_secs_f32() * 1000.0)
.sum::<f32>()
/ tx_confirmed as f32
} else {
0.0
};
let average_slot_confirmation_time = if tx_confirmed > 0 {
vec_slot_confirmation_time.iter().map(|d| *d as f32)
.sum::<f32>() / tx_confirmed as f32
vec_slot_confirmation_time
.iter()
.map(|d| *d as f32)
.sum::<f32>()
/ tx_confirmed as f32
} else {
0.0
};
Expand All @@ -176,12 +189,17 @@ pub async fn send_bulk_txs_and_wait(
fn calc_stats_avg(stats: &[Metric]) -> Metric {
let len = stats.len();

if len == 1 {
return stats[0].clone();
}

let mut avg = Metric {
txs_sent: 0,
txs_send_errors: 0,
txs_confirmed: 0,
txs_un_confirmed: 0,
average_confirmation_time: 0.0,
// TODO add support for histogram average (requires to keep all values for all runs)
histogram_confirmation_time: vec![],
average_slot_confirmation_time: 0.0,
};
Expand Down
45 changes: 22 additions & 23 deletions bench/src/benches/rpc_interface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{bail, Context, Error};
use futures::future::join_all;
use futures::{FutureExt, TryFutureExt};
use futures::TryFutureExt;
use itertools::Itertools;
use log::{debug, trace, warn};
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
Expand All @@ -12,7 +12,7 @@ use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::signature::Signature;
use solana_sdk::transaction::Transaction;
use solana_transaction_status::TransactionConfirmationStatus;
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use std::iter::zip;
use std::sync::Arc;
use std::time::Duration;
Expand All @@ -35,6 +35,7 @@ pub enum ConfirmationResponseFromRpc {
}

#[derive(Clone)]
#[allow(dead_code)]
struct RpcSendData {
pub signature: Signature,
pub sent_duration: Duration,
Expand Down Expand Up @@ -155,7 +156,7 @@ pub async fn send_and_confirm_bulk_transactions(
num_sent_ok,
"Items must move between pending+result"
);
let tx_batch = pending_status_map.iter().map(|(tx_sig, _)| tx_sig).cloned().collect_vec();
let tx_batch = pending_status_map.keys().cloned().collect_vec();
debug!(
"Request status for batch of remaining {} transactions in iteration {}",
tx_batch.len(),
Expand All @@ -168,7 +169,7 @@ pub async fn send_and_confirm_bulk_transactions(
for chunk in tx_batch.chunks(256) {
// fail hard if not possible to poll status
let chunk_responses = rpc_client
.get_signature_statuses(&chunk)
.get_signature_statuses(chunk)
.await
.expect("get signature statuses");
batch_status.extend(chunk_responses.value);
Expand Down Expand Up @@ -242,33 +243,31 @@ pub async fn send_and_confirm_bulk_transactions(
let total_time_elapsed_polling = started_at.elapsed();

// all transactions which remain in pending list are considered timed out
for (tx_sig, rpcsend_data) in pending_status_map.clone() {
pending_status_map.remove(&tx_sig);
for tx_sig in pending_status_map.keys() {
result_status_map.insert(
tx_sig,
*tx_sig,
ConfirmationResponseFromRpc::Timeout(total_time_elapsed_polling),
);
}
drop(pending_status_map);

let result_as_vec = batch_rpcsend_or_fails
.into_iter()
.enumerate()
.map(|(i, sig_or_fail)| {
match sig_or_fail {
Ok(rpcsend_data) => {
let tx_sig = rpcsend_data.signature;
let confirmation = result_status_map
.get(&tx_sig)
.expect("consistent map with all tx")
.clone()
.to_owned();
(tx_sig, confirmation)
}
Err(send_error) => {
let tx_sig = txs[i].get_signature();
let confirmation = ConfirmationResponseFromRpc::SendError(Arc::new(send_error));
(*tx_sig, confirmation)
}
.map(|(i, sig_or_fail)| match sig_or_fail {
Ok(rpcsend_data) => {
let tx_sig = rpcsend_data.signature;
let confirmation = result_status_map
.get(&tx_sig)
.expect("consistent map with all tx")
.clone()
.to_owned();
(tx_sig, confirmation)
}
Err(send_error) => {
let tx_sig = txs[i].get_signature();
let confirmation = ConfirmationResponseFromRpc::SendError(Arc::new(send_error));
(*tx_sig, confirmation)
}
})
.collect_vec();
Expand Down
2 changes: 1 addition & 1 deletion bench/src/benchnew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn initialize_logger() {
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy()
.from_env_lossy(),
)
.with_thread_ids(true)
.with_line_number(true)
Expand Down

0 comments on commit a135ed6

Please sign in to comment.