From 255f8469288d44bfbd296f3ee2fe796950a1dd1a Mon Sep 17 00:00:00 2001 From: Kirill Lykov Date: Mon, 13 Feb 2023 23:04:07 +0100 Subject: [PATCH] address PR comments --- bench-tps/src/cli.rs | 10 +++++----- bench-tps/src/main.rs | 25 ++++++++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/bench-tps/src/cli.rs b/bench-tps/src/cli.rs index 9e31bddb978109..06ad95c44ef8eb 100644 --- a/bench-tps/src/cli.rs +++ b/bench-tps/src/cli.rs @@ -1,7 +1,7 @@ use { crate::spl_convert::FromOtherSolana, clap::{crate_description, crate_name, App, Arg, ArgMatches}, - solana_clap_utils::input_validators::{is_url, is_url_or_moniker, is_within_range}, + solana_clap_utils::input_validators::{is_keypair, is_url, is_url_or_moniker, is_within_range}, solana_cli_config::{ConfigInput, CONFIG_FILE}, solana_sdk::{ fee_calculator::FeeRateGovernor, @@ -372,7 +372,8 @@ pub fn build_args<'a>(version: &'_ str) -> App<'a, '_> { .value_name("PATH") .takes_value(true) .requires("json_rpc_url") - .help("File containing a node id (keypair) of a validator with active stake. This allows communicating with network using staked connection"), + .validator(is_keypair) + .help("File containing the node id (keypair) of a validator with active stake. This allows communicating with network using staked connection"), ) } @@ -536,7 +537,7 @@ pub fn extract_args(matches: &ArgMatches) -> Config { if let Some(addr) = matches.value_of("bind_address") { args.bind_address = solana_net_utils::parse_host(addr).unwrap_or_else(|e| { - eprintln!("failed to parse bind_address address: {e}"); + eprintln!("Failed to parse bind_address: {e}"); exit(1) }); } @@ -544,10 +545,9 @@ pub fn extract_args(matches: &ArgMatches) -> Config { matches.value_of("client_node_id").unwrap_or(""), &config.keypair_path, ); + // error is checked by arg validator if let Ok(node_id) = read_keypair_file(node_id_path) { args.client_node_id = Some(node_id); - } else if matches.is_present("client_node_id") { - panic!("could not parse identity path"); } args diff --git a/bench-tps/src/main.rs b/bench-tps/src/main.rs index ec941e40336753..9b2803dac4b752 100644 --- a/bench-tps/src/main.rs +++ b/bench-tps/src/main.rs @@ -39,6 +39,10 @@ use { /// Number of signatures for all transactions in ~1 week at ~100K TPS pub const NUM_SIGNATURES_FOR_TXS: u64 = 100_000 * 60 * 60 * 24 * 7; +/// Request information about node's stake +/// If fail to get requested information, return error +/// Otherwise return stake of the node +/// along with total activated stake of the network fn find_node_activated_stake( rpc_client: Arc, node_id: Pubkey, @@ -59,13 +63,17 @@ fn find_node_activated_stake( .sum(); let node_id_as_str = node_id.to_string(); - vote_accounts + let find_result = vote_accounts .current .iter() - .find(|&vote_account| vote_account.node_pubkey == node_id_as_str) - .map_or(Err(()), |value| { - Ok((value.activated_stake, total_active_stake)) - }) + .find(|&vote_account| vote_account.node_pubkey == node_id_as_str); + match find_result { + Some(value) => Ok((value.activated_stake, total_active_stake)), + None => { + error!("failed to find stake for requested node"); + Err(()) + } + } } fn create_connection_cache( @@ -79,12 +87,7 @@ fn create_connection_cache( return ConnectionCache::with_udp(tpu_connection_pool_size); } if client_node_id.is_none() { - return ConnectionCache::new_with_client_options( - tpu_connection_pool_size, - None, - None, - None, - ); + return ConnectionCache::new(tpu_connection_pool_size); } let rpc_client = Arc::new(RpcClient::new_with_commitment(