Add custom rpc/tpu port options for ThinClient (#24842)

This commit is contained in:
sakridge 2022-05-01 00:14:47 -07:00 committed by GitHub
parent 88c16c0176
commit 0b0589eb11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 31 deletions

View File

@ -122,6 +122,26 @@ pub fn build_args<'a, 'b>(version: &'b str) -> App<'a, 'b> {
.validator(is_url) .validator(is_url)
.help("WebSocket URL for the solana cluster"), .help("WebSocket URL for the solana cluster"),
) )
.arg(
Arg::with_name("rpc_addr")
.long("rpc-addr")
.value_name("HOST:PORT")
.takes_value(true)
.conflicts_with("tpu_client")
.conflicts_with("rpc_client")
.requires("tpu_addr")
.help("Specify custom rpc_addr to create thin_client"),
)
.arg(
Arg::with_name("tpu_addr")
.long("tpu-addr")
.value_name("HOST:PORT")
.conflicts_with("tpu_client")
.conflicts_with("rpc_client")
.takes_value(true)
.requires("rpc_addr")
.help("Specify custom tpu_addr to create thin_client"),
)
.arg( .arg(
Arg::with_name("entrypoint") Arg::with_name("entrypoint")
.short("n") .short("n")

View File

@ -1,5 +1,6 @@
#![allow(clippy::integer_arithmetic)] #![allow(clippy::integer_arithmetic)]
use { use {
clap::value_t,
log::*, log::*,
solana_bench_tps::{ solana_bench_tps::{
bench::{do_bench_tps, generate_keypairs}, bench::{do_bench_tps, generate_keypairs},
@ -100,41 +101,60 @@ fn main() {
do_bench_tps(client, cli_config, keypairs); do_bench_tps(client, cli_config, keypairs);
} }
ExternalClientType::ThinClient => { ExternalClientType::ThinClient => {
let nodes = discover_cluster(entrypoint_addr, *num_nodes, SocketAddrSpace::Unspecified) let client = if let Ok(rpc_addr) = value_t!(matches, "rpc_addr", String) {
.unwrap_or_else(|err| { let rpc = rpc_addr.parse().unwrap_or_else(|e| {
eprintln!("Failed to discover {} nodes: {:?}", num_nodes, err); eprintln!("RPC address should parse as socketaddr {:?}", e);
exit(1); exit(1);
}); });
if *use_quic { let tpu = value_t!(matches, "tpu_addr", String)
connection_cache::set_use_quic(true); .unwrap()
} .parse()
let client = if *multi_client { .unwrap_or_else(|e| {
let (client, num_clients) = get_multi_client(&nodes, &SocketAddrSpace::Unspecified); eprintln!("TPU address should parse to a socket: {:?}", e);
if nodes.len() < num_clients { exit(1);
eprintln!( });
"Error: Insufficient nodes discovered. Expecting {} or more",
num_nodes solana_client::thin_client::create_client(rpc, tpu)
);
exit(1);
}
Arc::new(client)
} else if let Some(target_node) = target_node {
info!("Searching for target_node: {:?}", target_node);
let mut target_client = None;
for node in nodes {
if node.id == *target_node {
target_client =
Some(Arc::new(get_client(&[node], &SocketAddrSpace::Unspecified)));
break;
}
}
target_client.unwrap_or_else(|| {
eprintln!("Target node {} not found", target_node);
exit(1);
})
} else { } else {
Arc::new(get_client(&nodes, &SocketAddrSpace::Unspecified)) let nodes =
discover_cluster(entrypoint_addr, *num_nodes, SocketAddrSpace::Unspecified)
.unwrap_or_else(|err| {
eprintln!("Failed to discover {} nodes: {:?}", num_nodes, err);
exit(1);
});
if *use_quic {
connection_cache::set_use_quic(true);
}
if *multi_client {
let (client, num_clients) =
get_multi_client(&nodes, &SocketAddrSpace::Unspecified);
if nodes.len() < num_clients {
eprintln!(
"Error: Insufficient nodes discovered. Expecting {} or more",
num_nodes
);
exit(1);
}
client
} else if let Some(target_node) = target_node {
info!("Searching for target_node: {:?}", target_node);
let mut target_client = None;
for node in nodes {
if node.id == *target_node {
target_client =
Some(get_client(&[node], &SocketAddrSpace::Unspecified));
break;
}
}
target_client.unwrap_or_else(|| {
eprintln!("Target node {} not found", target_node);
exit(1);
})
} else {
get_client(&nodes, &SocketAddrSpace::Unspecified)
}
}; };
let client = Arc::new(client);
let keypairs = get_keypairs( let keypairs = get_keypairs(
client.clone(), client.clone(),
id, id,