Skip to content

Commit

Permalink
Add ping cli option to use CommitmentLevel::Max, instead of Commitmen…
Browse files Browse the repository at this point in the history
…tLevel::Recent
  • Loading branch information
CriesofCarrots committed Nov 6, 2019
1 parent 0ace799 commit 7ec2704
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
12 changes: 11 additions & 1 deletion cli/src/cli.rs
Expand Up @@ -15,6 +15,7 @@ use solana_drone::drone::request_airdrop_transaction;
use solana_drone::drone_mock::request_airdrop_transaction;
use solana_sdk::{
bpf_loader,
commitment_config::CommitmentConfig,
fee_calculator::FeeCalculator,
hash::Hash,
instruction::InstructionError,
Expand Down Expand Up @@ -56,6 +57,7 @@ pub enum CliCommand {
interval: Duration,
count: Option<u64>,
timeout: Duration,
commitment_config: CommitmentConfig,
},
ShowValidators {
use_lamports_unit: bool,
Expand Down Expand Up @@ -824,7 +826,15 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
interval,
count,
timeout,
} => process_ping(&rpc_client, config, interval, count, timeout),
commitment_config,
} => process_ping(
&rpc_client,
config,
interval,
count,
timeout,
commitment_config,
),
CliCommand::ShowValidators { use_lamports_unit } => {
process_show_validators(&rpc_client, *use_lamports_unit)
}
Expand Down
32 changes: 28 additions & 4 deletions cli/src/cluster_query.rs
Expand Up @@ -75,6 +75,14 @@ impl ClusterQuerySubCommands for App<'_, '_> {
.takes_value(true)
.default_value("15")
.help("Wait up to timeout seconds for transaction confirmation"),
)
.arg(
Arg::with_name("confirmed")
.long("confirmed")
.takes_value(false)
.help(
"Wait until the transaction is confirmed at maximum-lockout commitment level",
),
),
)
.subcommand(
Expand All @@ -98,11 +106,17 @@ pub fn parse_cluster_ping(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, Cl
None
};
let timeout = Duration::from_secs(value_t_or_exit!(matches, "timeout", u64));
let commitment_config = if matches.is_present("confirmed") {
CommitmentConfig::default()
} else {
CommitmentConfig::recent()
};
Ok(CliCommandInfo {
command: CliCommand::Ping {
interval,
count,
timeout,
commitment_config,
},
require_keypair: true,
})
Expand Down Expand Up @@ -193,6 +207,7 @@ pub fn process_ping(
interval: &Duration,
count: &Option<u64>,
timeout: &Duration,
commitment_config: &CommitmentConfig,
) -> ProcessResult {
let to = Keypair::new().pubkey();

Expand Down Expand Up @@ -224,7 +239,7 @@ pub fn process_ping(
loop {
let signature_status = rpc_client.get_signature_status_with_commitment(
&signature,
CommitmentConfig::recent(),
commitment_config.clone(),
)?;
let elapsed_time = Instant::now().duration_since(transaction_sent);
if let Some(transaction_status) = signature_status {
Expand Down Expand Up @@ -481,16 +496,25 @@ mod tests {
}
);

let test_ping = test_commands
.clone()
.get_matches_from(vec!["test", "ping", "-i", "1", "-c", "2", "-t", "3"]);
let test_ping = test_commands.clone().get_matches_from(vec![
"test",
"ping",
"-i",
"1",
"-c",
"2",
"-t",
"3",
"--confirmed",
]);
assert_eq!(
parse_command(&test_ping).unwrap(),
CliCommandInfo {
command: CliCommand::Ping {
interval: Duration::from_secs(1),
count: Some(2),
timeout: Duration::from_secs(3),
commitment_config: CommitmentConfig::default(),
},
require_keypair: true
}
Expand Down

0 comments on commit 7ec2704

Please sign in to comment.