Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Lykov committed Feb 17, 2023
1 parent d2ee563 commit 255f846
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
10 changes: 5 additions & 5 deletions bench-tps/src/cli.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"),
)
}

Expand Down Expand Up @@ -536,18 +537,17 @@ 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)
});
}
let (_, node_id_path) = ConfigInput::compute_keypair_path_setting(
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
Expand Down
25 changes: 14 additions & 11 deletions bench-tps/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RpcClient>,
node_id: Pubkey,
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 255f846

Please sign in to comment.