Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Plumb CommitmentConfig through bench-tps client types (#35282)
Browse files Browse the repository at this point in the history
* use --commitment-config <commitment-level> for setting blockhash commitment level for sending transactions with rpc-client

* clarify default

* leave get_balance_with_commitment at processed()

* rm unused variable

* refactor commitment_config flag read in

* update cli and change send_batch's get_latest_blockhash() to get_latest_blockhash_with_client_commitment() and use client's internal commitment level

* change fix some nits based on PR comments

* rm unused import
  • Loading branch information
Greg Cusack authored Feb 23, 2024
1 parent 72734a9 commit fe571bb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions bench-tps/src/bench_tps_client/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl BenchTpsClient for RpcClient {
fn send_transaction(&self, transaction: Transaction) -> Result<Signature> {
RpcClient::send_transaction(self, &transaction).map_err(|err| err.into())
}

fn send_batch(&self, transactions: Vec<Transaction>) -> Result<()> {
for transaction in transactions {
BenchTpsClient::send_transaction(self, transaction)?;
Expand Down
15 changes: 14 additions & 1 deletion bench-tps/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use {
clap::{crate_description, crate_name, App, Arg, ArgMatches},
clap::{crate_description, crate_name, value_t_or_exit, App, Arg, ArgMatches},
solana_clap_utils::{
hidden_unless_forced,
input_validators::{is_keypair, is_url, is_url_or_moniker, is_within_range},
},
solana_cli_config::{ConfigInput, CONFIG_FILE},
solana_sdk::{
commitment_config::CommitmentConfig,
fee_calculator::FeeRateGovernor,
pubkey::Pubkey,
signature::{read_keypair_file, Keypair},
Expand Down Expand Up @@ -80,6 +81,7 @@ pub struct Config {
pub num_conflict_groups: Option<usize>,
pub bind_address: IpAddr,
pub client_node_id: Option<Keypair>,
pub commitment_config: CommitmentConfig,
}

impl Eq for Config {}
Expand Down Expand Up @@ -115,6 +117,7 @@ impl Default for Config {
num_conflict_groups: None,
bind_address: IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
client_node_id: None,
commitment_config: CommitmentConfig::confirmed(),
}
}
}
Expand Down Expand Up @@ -396,6 +399,14 @@ pub fn build_args<'a>(version: &'_ str) -> App<'a, '_> {
.validator(is_keypair)
.help("File containing the node identity (keypair) of a validator with active stake. This allows communicating with network using staked connection"),
)
.arg(
Arg::with_name("commitment_config")
.long("commitment-config")
.takes_value(true)
.possible_values(&["processed", "confirmed", "finalized"])
.default_value("confirmed")
.help("Block commitment config for getting latest blockhash"),
)
}

/// Parses a clap `ArgMatches` structure into a `Config`
Expand Down Expand Up @@ -577,6 +588,8 @@ pub fn parse_args(matches: &ArgMatches) -> Result<Config, &'static str> {
args.client_node_id = Some(client_node_id);
}

args.commitment_config = value_t_or_exit!(matches, "commitment_config", CommitmentConfig);

Ok(args)
}

Expand Down
11 changes: 8 additions & 3 deletions bench-tps/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ fn create_connection_cache(
use_quic: bool,
bind_address: IpAddr,
client_node_id: Option<&Keypair>,
commitment_config: CommitmentConfig,
) -> ConnectionCache {
if !use_quic {
return ConnectionCache::with_udp(
Expand All @@ -97,7 +98,7 @@ fn create_connection_cache(

let rpc_client = Arc::new(RpcClient::new_with_commitment(
json_rpc_url.to_string(),
CommitmentConfig::confirmed(),
commitment_config,
));

let client_node_id = client_node_id.unwrap();
Expand Down Expand Up @@ -132,11 +133,12 @@ fn create_client(
num_nodes: usize,
target_node: Option<Pubkey>,
connection_cache: ConnectionCache,
commitment_config: CommitmentConfig,
) -> Arc<dyn BenchTpsClient + Send + Sync> {
match external_client_type {
ExternalClientType::RpcClient => Arc::new(RpcClient::new_with_commitment(
json_rpc_url.to_string(),
CommitmentConfig::confirmed(),
commitment_config,
)),
ExternalClientType::ThinClient => {
let connection_cache = Arc::new(connection_cache);
Expand Down Expand Up @@ -188,7 +190,7 @@ fn create_client(
ExternalClientType::TpuClient => {
let rpc_client = Arc::new(RpcClient::new_with_commitment(
json_rpc_url.to_string(),
CommitmentConfig::confirmed(),
commitment_config,
));
match connection_cache {
ConnectionCache::Udp(cache) => Arc::new(
Expand Down Expand Up @@ -256,6 +258,7 @@ fn main() {
instruction_padding_config,
bind_address,
client_node_id,
commitment_config,
..
} = &cli_config;

Expand Down Expand Up @@ -317,6 +320,7 @@ fn main() {
*use_quic,
*bind_address,
client_node_id.as_ref(),
*commitment_config,
);
let client = create_client(
external_client_type,
Expand All @@ -328,6 +332,7 @@ fn main() {
*num_nodes,
*target_node,
connection_cache,
*commitment_config,
);
if let Some(instruction_padding_config) = instruction_padding_config {
info!(
Expand Down
4 changes: 2 additions & 2 deletions bench-tps/src/send_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use {

pub fn get_latest_blockhash<T: BenchTpsClient + ?Sized>(client: &T) -> Hash {
loop {
match client.get_latest_blockhash_with_commitment(CommitmentConfig::processed()) {
Ok((blockhash, _)) => return blockhash,
match client.get_latest_blockhash() {
Ok(blockhash) => return blockhash,
Err(err) => {
info!("Couldn't get last blockhash: {:?}", err);
sleep(Duration::from_secs(1));
Expand Down

0 comments on commit fe571bb

Please sign in to comment.