Cli: default to single gossip (#14673)

* Init cli RpcClient with chosen commitment; default to single_gossip

* Fill in missing client methods

* Cli tests: make RpcClient commitment specific

* Simply rpc_client calls, using configured commitment

* Check validator vote account with single-gossip commitment
This commit is contained in:
Tyera Eulberg
2021-01-19 15:33:03 -07:00
committed by GitHub
parent fba4e51171
commit 4964b0fe61
16 changed files with 179 additions and 384 deletions

View File

@ -522,7 +522,7 @@ impl Default for CliConfig<'_> {
rpc_timeout: Duration::from_secs(u64::from_str(DEFAULT_RPC_TIMEOUT_SECONDS).unwrap()), rpc_timeout: Duration::from_secs(u64::from_str(DEFAULT_RPC_TIMEOUT_SECONDS).unwrap()),
verbose: false, verbose: false,
output_format: OutputFormat::Display, output_format: OutputFormat::Display,
commitment: CommitmentConfig::default(), commitment: CommitmentConfig::single_gossip(),
send_transaction_config: RpcSendTransactionConfig::default(), send_transaction_config: RpcSendTransactionConfig::default(),
address_labels: HashMap::new(), address_labels: HashMap::new(),
} }
@ -934,9 +934,7 @@ fn process_balance(
} else { } else {
config.pubkey()? config.pubkey()?
}; };
let balance = rpc_client let balance = rpc_client.get_balance(&pubkey)?;
.get_balance_with_commitment(&pubkey, config.commitment)?
.value;
Ok(build_balance_message(balance, use_lamports_unit, true)) Ok(build_balance_message(balance, use_lamports_unit, true))
} }
@ -1102,11 +1100,7 @@ fn process_transfer(
let result = if no_wait { let result = if no_wait {
rpc_client.send_transaction(&tx) rpc_client.send_transaction(&tx)
} else { } else {
rpc_client.send_and_confirm_transaction_with_spinner_and_config( rpc_client.send_and_confirm_transaction_with_spinner(&tx)
&tx,
config.commitment,
config.send_transaction_config,
)
}; };
log_instruction_custom_error::<SystemError>(result, &config) log_instruction_custom_error::<SystemError>(result, &config)
} }
@ -1123,8 +1117,11 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
let mut _rpc_client; let mut _rpc_client;
let rpc_client = if config.rpc_client.is_none() { let rpc_client = if config.rpc_client.is_none() {
_rpc_client = _rpc_client = RpcClient::new_with_timeout_and_commitment(
RpcClient::new_with_timeout(config.json_rpc_url.to_string(), config.rpc_timeout); config.json_rpc_url.to_string(),
config.rpc_timeout,
config.commitment,
);
&_rpc_client &_rpc_client
} else { } else {
// Primarily for testing // Primarily for testing
@ -1752,8 +1749,7 @@ pub fn request_and_confirm_airdrop(
} }
}?; }?;
let tx = keypair.airdrop_transaction(); let tx = keypair.airdrop_transaction();
let result = let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
rpc_client.send_and_confirm_transaction_with_spinner_and_commitment(&tx, config.commitment);
log_instruction_custom_error::<SystemError>(result, &config) log_instruction_custom_error::<SystemError>(result, &config)
} }
@ -1856,7 +1852,7 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
.takes_value(false) .takes_value(false)
.help("Display balance in lamports instead of SOL"), .help("Display balance in lamports instead of SOL"),
) )
.arg(commitment_arg_with_default("max")), .arg(commitment_arg_with_default("singleGossip")),
) )
.subcommand( .subcommand(
SubCommand::with_name("confirm") SubCommand::with_name("confirm")

View File

@ -127,12 +127,15 @@ impl ClusterQuerySubCommands for App<'_, '_> {
.subcommand( .subcommand(
SubCommand::with_name("cluster-date") SubCommand::with_name("cluster-date")
.about("Get current cluster date, computed from genesis creation time and network time") .about("Get current cluster date, computed from genesis creation time and network time")
.arg(commitment_arg()),
) )
.subcommand( .subcommand(
SubCommand::with_name("cluster-version") SubCommand::with_name("cluster-version")
.about("Get the version of the cluster entrypoint"), .about("Get the version of the cluster entrypoint"),
) )
.subcommand(SubCommand::with_name("fees").about("Display current cluster fees")) .subcommand(SubCommand::with_name("fees").about("Display current cluster fees")
.arg(commitment_arg()),
)
.subcommand( .subcommand(
SubCommand::with_name("first-available-block") SubCommand::with_name("first-available-block")
.about("Get the first available block in the storage"), .about("Get the first available block in the storage"),
@ -786,8 +789,7 @@ pub fn process_catchup(
} }
pub fn process_cluster_date(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { pub fn process_cluster_date(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult {
let result = rpc_client let result = rpc_client.get_account_with_commitment(&sysvar::clock::id(), config.commitment)?;
.get_account_with_commitment(&sysvar::clock::id(), CommitmentConfig::default())?;
if let Some(clock_account) = result.value { if let Some(clock_account) = result.value {
let clock: Clock = from_account(&clock_account).ok_or_else(|| { let clock: Clock = from_account(&clock_account).ok_or_else(|| {
CliError::RpcRequestError("Failed to deserialize clock sysvar".to_string()) CliError::RpcRequestError("Failed to deserialize clock sysvar".to_string())
@ -813,7 +815,7 @@ pub fn process_cluster_version(rpc_client: &RpcClient, config: &CliConfig) -> Pr
} }
pub fn process_fees(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { pub fn process_fees(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult {
let result = rpc_client.get_recent_blockhash_with_commitment(CommitmentConfig::default())?; let result = rpc_client.get_recent_blockhash_with_commitment(config.commitment)?;
let (recent_blockhash, fee_calculator, last_valid_slot) = result.value; let (recent_blockhash, fee_calculator, last_valid_slot) = result.value;
let fees = CliFees { let fees = CliFees {
slot: result.context.slot, slot: result.context.slot,
@ -978,15 +980,13 @@ pub fn process_get_block_time(
Ok(config.output_format.formatted_string(&block_time)) Ok(config.output_format.formatted_string(&block_time))
} }
pub fn process_get_epoch(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { pub fn process_get_epoch(rpc_client: &RpcClient, _config: &CliConfig) -> ProcessResult {
let epoch_info = rpc_client.get_epoch_info_with_commitment(config.commitment)?; let epoch_info = rpc_client.get_epoch_info()?;
Ok(epoch_info.epoch.to_string()) Ok(epoch_info.epoch.to_string())
} }
pub fn process_get_epoch_info(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { pub fn process_get_epoch_info(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult {
let epoch_info: CliEpochInfo = rpc_client let epoch_info: CliEpochInfo = rpc_client.get_epoch_info()?.into();
.get_epoch_info_with_commitment(config.commitment)?
.into();
Ok(config.output_format.formatted_string(&epoch_info)) Ok(config.output_format.formatted_string(&epoch_info))
} }
@ -995,15 +995,13 @@ pub fn process_get_genesis_hash(rpc_client: &RpcClient) -> ProcessResult {
Ok(genesis_hash.to_string()) Ok(genesis_hash.to_string())
} }
pub fn process_get_slot(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { pub fn process_get_slot(rpc_client: &RpcClient, _config: &CliConfig) -> ProcessResult {
let slot = rpc_client.get_slot_with_commitment(config.commitment)?; let slot = rpc_client.get_slot()?;
Ok(slot.to_string()) Ok(slot.to_string())
} }
pub fn process_get_block_height(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { pub fn process_get_block_height(rpc_client: &RpcClient, _config: &CliConfig) -> ProcessResult {
let epoch_info: CliEpochInfo = rpc_client let epoch_info: CliEpochInfo = rpc_client.get_epoch_info()?.into();
.get_epoch_info_with_commitment(config.commitment)?
.into();
Ok(epoch_info.epoch_info.block_height.to_string()) Ok(epoch_info.epoch_info.block_height.to_string())
} }
@ -1189,19 +1187,19 @@ pub fn process_supply(
config: &CliConfig, config: &CliConfig,
print_accounts: bool, print_accounts: bool,
) -> ProcessResult { ) -> ProcessResult {
let supply_response = rpc_client.supply_with_commitment(config.commitment)?; let supply_response = rpc_client.supply()?;
let mut supply: CliSupply = supply_response.value.into(); let mut supply: CliSupply = supply_response.value.into();
supply.print_accounts = print_accounts; supply.print_accounts = print_accounts;
Ok(config.output_format.formatted_string(&supply)) Ok(config.output_format.formatted_string(&supply))
} }
pub fn process_total_supply(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { pub fn process_total_supply(rpc_client: &RpcClient, _config: &CliConfig) -> ProcessResult {
let total_supply = rpc_client.total_supply_with_commitment(config.commitment)?; let total_supply = rpc_client.total_supply()?;
Ok(format!("{} SOL", lamports_to_sol(total_supply))) Ok(format!("{} SOL", lamports_to_sol(total_supply)))
} }
pub fn process_get_transaction_count(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { pub fn process_get_transaction_count(rpc_client: &RpcClient, _config: &CliConfig) -> ProcessResult {
let transaction_count = rpc_client.get_transaction_count_with_commitment(config.commitment)?; let transaction_count = rpc_client.get_transaction_count()?;
Ok(transaction_count.to_string()) Ok(transaction_count.to_string())
} }
@ -1292,8 +1290,7 @@ pub fn process_ping(
Ok(signature) => { Ok(signature) => {
let transaction_sent = Instant::now(); let transaction_sent = Instant::now();
loop { loop {
let signature_status = rpc_client let signature_status = rpc_client.get_signature_status(&signature)?;
.get_signature_status_with_commitment(&signature, config.commitment)?;
let elapsed_time = Instant::now().duration_since(transaction_sent); let elapsed_time = Instant::now().duration_since(transaction_sent);
if let Some(transaction_status) = signature_status { if let Some(transaction_status) = signature_status {
match transaction_status { match transaction_status {
@ -1695,8 +1692,8 @@ pub fn process_show_validators(
config: &CliConfig, config: &CliConfig,
use_lamports_unit: bool, use_lamports_unit: bool,
) -> ProcessResult { ) -> ProcessResult {
let epoch_info = rpc_client.get_epoch_info_with_commitment(config.commitment)?; let epoch_info = rpc_client.get_epoch_info()?;
let vote_accounts = rpc_client.get_vote_accounts_with_commitment(config.commitment)?; let vote_accounts = rpc_client.get_vote_accounts()?;
let mut node_version = HashMap::new(); let mut node_version = HashMap::new();
let unknown_version = "unknown".to_string(); let unknown_version = "unknown".to_string();

View File

@ -19,6 +19,7 @@ use solana_cli_config::{Config, CONFIG_FILE};
use solana_cli_output::{display::println_name_value, OutputFormat}; use solana_cli_output::{display::println_name_value, OutputFormat};
use solana_client::rpc_config::RpcSendTransactionConfig; use solana_client::rpc_config::RpcSendTransactionConfig;
use solana_remote_wallet::remote_wallet::RemoteWalletManager; use solana_remote_wallet::remote_wallet::RemoteWalletManager;
use solana_sdk::commitment_config::CommitmentConfig;
use std::{collections::HashMap, error, path::PathBuf, sync::Arc, time::Duration}; use std::{collections::HashMap, error, path::PathBuf, sync::Arc, time::Duration};
pub fn println_name_value_or(name: &str, value: &str, setting_type: SettingType) { pub fn println_name_value_or(name: &str, value: &str, setting_type: SettingType) {
@ -191,7 +192,7 @@ pub fn parse_args<'a>(
} }
commitment_of(sub_matches, COMMITMENT_ARG.long) commitment_of(sub_matches, COMMITMENT_ARG.long)
} }
.unwrap_or_default(); .unwrap_or_else(CommitmentConfig::single_gossip);
let address_labels = if matches.is_present("no_address_labels") { let address_labels = if matches.is_present("no_address_labels") {
HashMap::new() HashMap::new()

View File

@ -332,9 +332,7 @@ pub fn process_authorize_nonce_account(
nonce_authority: SignerIndex, nonce_authority: SignerIndex,
new_authority: &Pubkey, new_authority: &Pubkey,
) -> ProcessResult { ) -> ProcessResult {
let (recent_blockhash, fee_calculator, _) = rpc_client let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let nonce_authority = config.signers[nonce_authority]; let nonce_authority = config.signers[nonce_authority];
let ix = authorize_nonce_account(nonce_account, &nonce_authority.pubkey(), new_authority); let ix = authorize_nonce_account(nonce_account, &nonce_authority.pubkey(), new_authority);
@ -349,11 +347,7 @@ pub fn process_authorize_nonce_account(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<NonceError>(result, &config) log_instruction_custom_error::<NonceError>(result, &config)
} }
@ -400,9 +394,7 @@ pub fn process_create_nonce_account(
Message::new(&ixs, Some(&config.signers[0].pubkey())) Message::new(&ixs, Some(&config.signers[0].pubkey()))
}; };
let (recent_blockhash, fee_calculator, _) = rpc_client let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let (message, lamports) = resolve_spend_tx_and_check_account_balance( let (message, lamports) = resolve_spend_tx_and_check_account_balance(
rpc_client, rpc_client,
@ -414,9 +406,7 @@ pub fn process_create_nonce_account(
config.commitment, config.commitment,
)?; )?;
if let Ok(nonce_account) = if let Ok(nonce_account) = get_account(rpc_client, &nonce_account_address) {
get_account_with_commitment(rpc_client, &nonce_account_address, config.commitment)
{
let err_msg = if state_from_account(&nonce_account).is_ok() { let err_msg = if state_from_account(&nonce_account).is_ok() {
format!("Nonce account {} already exists", nonce_account_address) format!("Nonce account {} already exists", nonce_account_address)
} else { } else {
@ -439,11 +429,7 @@ pub fn process_create_nonce_account(
let mut tx = Transaction::new_unsigned(message); let mut tx = Transaction::new_unsigned(message);
tx.try_sign(&config.signers, recent_blockhash)?; tx.try_sign(&config.signers, recent_blockhash)?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<SystemError>(result, &config) log_instruction_custom_error::<SystemError>(result, &config)
} }
@ -471,9 +457,8 @@ pub fn process_new_nonce(
(&nonce_account, "nonce_account_pubkey".to_string()), (&nonce_account, "nonce_account_pubkey".to_string()),
)?; )?;
let nonce_account_check = let nonce_account_check = rpc_client.get_account(&nonce_account);
rpc_client.get_account_with_commitment(&nonce_account, config.commitment); if nonce_account_check.is_err() {
if nonce_account_check.is_err() || nonce_account_check.unwrap().value.is_none() {
return Err(CliError::BadParameter( return Err(CliError::BadParameter(
"Unable to create new nonce, no nonce account found".to_string(), "Unable to create new nonce, no nonce account found".to_string(),
) )
@ -482,9 +467,7 @@ pub fn process_new_nonce(
let nonce_authority = config.signers[nonce_authority]; let nonce_authority = config.signers[nonce_authority];
let ix = advance_nonce_account(&nonce_account, &nonce_authority.pubkey()); let ix = advance_nonce_account(&nonce_account, &nonce_authority.pubkey());
let (recent_blockhash, fee_calculator, _) = rpc_client let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let message = Message::new(&[ix], Some(&config.signers[0].pubkey())); let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
let mut tx = Transaction::new_unsigned(message); let mut tx = Transaction::new_unsigned(message);
tx.try_sign(&config.signers, recent_blockhash)?; tx.try_sign(&config.signers, recent_blockhash)?;
@ -495,11 +478,7 @@ pub fn process_new_nonce(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<SystemError>(result, &config) log_instruction_custom_error::<SystemError>(result, &config)
} }
@ -541,9 +520,7 @@ pub fn process_withdraw_from_nonce_account(
destination_account_pubkey: &Pubkey, destination_account_pubkey: &Pubkey,
lamports: u64, lamports: u64,
) -> ProcessResult { ) -> ProcessResult {
let (recent_blockhash, fee_calculator, _) = rpc_client let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let nonce_authority = config.signers[nonce_authority]; let nonce_authority = config.signers[nonce_authority];
let ix = withdraw_nonce_account( let ix = withdraw_nonce_account(
@ -562,11 +539,7 @@ pub fn process_withdraw_from_nonce_account(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<NonceError>(result, &config) log_instruction_custom_error::<NonceError>(result, &config)
} }

View File

@ -271,6 +271,7 @@ impl ProgramSubCommands for App<'_, '_> {
.required(true) .required(true)
.help("Public key of the account to query") .help("Public key of the account to query")
) )
.arg(commitment_arg_with_default("singleGossip")),
) )
) )
} }
@ -856,9 +857,7 @@ fn process_set_authority(
}; };
trace!("Set a new authority"); trace!("Set a new authority");
let (blockhash, _, _) = rpc_client let (blockhash, _) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let mut tx = if let Some(pubkey) = program_pubkey { let mut tx = if let Some(pubkey) = program_pubkey {
Transaction::new_unsigned(Message::new( Transaction::new_unsigned(Message::new(
@ -1349,9 +1348,7 @@ fn check_payer(
balance_needed: u64, balance_needed: u64,
messages: &[&Message], messages: &[&Message],
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
let (_, fee_calculator, _) = rpc_client let (_, fee_calculator) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
// Does the payer have enough? // Does the payer have enough?
check_account_for_spend_multiple_fees_with_commitment( check_account_for_spend_multiple_fees_with_commitment(
@ -1379,9 +1376,7 @@ fn send_deploy_messages(
if let Some(message) = initial_message { if let Some(message) = initial_message {
if let Some(initial_signer) = initial_signer { if let Some(initial_signer) = initial_signer {
trace!("Preparing the required accounts"); trace!("Preparing the required accounts");
let (blockhash, _, _) = rpc_client let (blockhash, _) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let mut initial_transaction = Transaction::new_unsigned(message.clone()); let mut initial_transaction = Transaction::new_unsigned(message.clone());
// Most of the initial_transaction combinations require both the fee-payer and new program // Most of the initial_transaction combinations require both the fee-payer and new program
@ -1393,11 +1388,7 @@ fn send_deploy_messages(
} else { } else {
initial_transaction.try_sign(&[payer_signer], blockhash)?; initial_transaction.try_sign(&[payer_signer], blockhash)?;
} }
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&initial_transaction);
&initial_transaction,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<SystemError>(result, &config) log_instruction_custom_error::<SystemError>(result, &config)
.map_err(|err| format!("Account allocation failed: {}", err))?; .map_err(|err| format!("Account allocation failed: {}", err))?;
} else { } else {
@ -1432,9 +1423,7 @@ fn send_deploy_messages(
if let Some(message) = final_message { if let Some(message) = final_message {
if let Some(final_signer) = final_signer { if let Some(final_signer) = final_signer {
trace!("Deploying program"); trace!("Deploying program");
let (blockhash, _, _) = rpc_client let (blockhash, _) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let mut final_tx = Transaction::new_unsigned(message.clone()); let mut final_tx = Transaction::new_unsigned(message.clone());
final_tx.try_sign(&[payer_signer, final_signer], blockhash)?; final_tx.try_sign(&[payer_signer, final_signer], blockhash)?;
@ -1513,10 +1502,9 @@ fn send_and_confirm_transactions_with_spinner<T: Signers>(
let mut status_retries = 15; let mut status_retries = 15;
progress_bar.set_message("Finding leader node..."); progress_bar.set_message("Finding leader node...");
let epoch_info = rpc_client.get_epoch_info_with_commitment(commitment)?; let epoch_info = rpc_client.get_epoch_info()?;
if epoch_info.epoch > leader_schedule_epoch || leader_schedule.is_none() { if epoch_info.epoch > leader_schedule_epoch || leader_schedule.is_none() {
leader_schedule = rpc_client leader_schedule = rpc_client.get_leader_schedule(Some(epoch_info.absolute_slot))?;
.get_leader_schedule_with_commitment(Some(epoch_info.absolute_slot), commitment)?;
leader_schedule_epoch = epoch_info.epoch; leader_schedule_epoch = epoch_info.epoch;
} }
let tpu_address = get_leader_tpu( let tpu_address = get_leader_tpu(
@ -1598,7 +1586,7 @@ fn send_and_confirm_transactions_with_spinner<T: Signers>(
return Ok(()); return Ok(());
} }
let slot = rpc_client.get_slot_with_commitment(commitment)?; let slot = rpc_client.get_slot()?;
if slot > last_valid_slot { if slot > last_valid_slot {
break; break;
} }

View File

@ -10,6 +10,7 @@ use crate::{
use chrono::{Local, TimeZone}; use chrono::{Local, TimeZone};
use clap::{App, Arg, ArgGroup, ArgMatches, SubCommand}; use clap::{App, Arg, ArgGroup, ArgMatches, SubCommand};
use solana_clap_utils::{ use solana_clap_utils::{
commitment::commitment_arg_with_default,
fee_payer::{fee_payer_arg, FEE_PAYER_ARG}, fee_payer::{fee_payer_arg, FEE_PAYER_ARG},
input_parsers::*, input_parsers::*,
input_validators::*, input_validators::*,
@ -404,6 +405,7 @@ impl StakeSubCommands for App<'_, '_> {
.takes_value(false) .takes_value(false)
.help("Display balance in lamports instead of SOL") .help("Display balance in lamports instead of SOL")
) )
.arg(commitment_arg_with_default("singleGossip")),
) )
.subcommand( .subcommand(
SubCommand::with_name("stake-history") SubCommand::with_name("stake-history")
@ -959,11 +961,7 @@ pub fn process_create_stake_account(
return_signers(&tx, &config.output_format) return_signers(&tx, &config.output_format)
} else { } else {
tx.try_sign(&config.signers, recent_blockhash)?; tx.try_sign(&config.signers, recent_blockhash)?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<SystemError>(result, &config) log_instruction_custom_error::<SystemError>(result, &config)
} }
} }
@ -1033,11 +1031,7 @@ pub fn process_stake_authorize(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<StakeError>(result, &config) log_instruction_custom_error::<StakeError>(result, &config)
} }
} }
@ -1096,11 +1090,7 @@ pub fn process_deactivate_stake_account(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<StakeError>(result, &config) log_instruction_custom_error::<StakeError>(result, &config)
} }
} }
@ -1168,11 +1158,7 @@ pub fn process_withdraw_stake(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<SystemError>(result, &config) log_instruction_custom_error::<SystemError>(result, &config)
} }
} }
@ -1311,11 +1297,7 @@ pub fn process_split_stake(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<StakeError>(result, &config) log_instruction_custom_error::<StakeError>(result, &config)
} }
} }
@ -1479,11 +1461,7 @@ pub fn process_stake_set_lockup(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<StakeError>(result, &config) log_instruction_custom_error::<StakeError>(result, &config)
} }
} }
@ -1792,23 +1770,15 @@ pub fn process_delegate_stake(
if !sign_only { if !sign_only {
// Sanity check the vote account to ensure it is attached to a validator that has recently // Sanity check the vote account to ensure it is attached to a validator that has recently
// voted at the tip of the ledger // voted at the tip of the ledger
let vote_account = rpc_client let vote_account_data = rpc_client
.get_account_with_commitment(vote_account_pubkey, config.commitment) .get_account(vote_account_pubkey)
.map_err(|_| { .map_err(|_| {
CliError::RpcRequestError(format!( CliError::RpcRequestError(format!(
"Vote account not found: {}", "Vote account not found: {}",
vote_account_pubkey vote_account_pubkey
)) ))
})?; })?
let vote_account_data = if let Some(account) = vote_account.value { .data;
account.data
} else {
return Err(CliError::RpcRequestError(format!(
"Vote account not found: {}",
vote_account_pubkey
))
.into());
};
let vote_state = VoteState::deserialize(&vote_account_data).map_err(|_| { let vote_state = VoteState::deserialize(&vote_account_data).map_err(|_| {
CliError::RpcRequestError( CliError::RpcRequestError(
@ -1888,11 +1858,7 @@ pub fn process_delegate_stake(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<StakeError>(result, &config) log_instruction_custom_error::<StakeError>(result, &config)
} }
} }

View File

@ -20,7 +20,6 @@ use solana_config_program::{config_instruction, get_config_data, ConfigKeys, Con
use solana_remote_wallet::remote_wallet::RemoteWalletManager; use solana_remote_wallet::remote_wallet::RemoteWalletManager;
use solana_sdk::{ use solana_sdk::{
account::Account, account::Account,
commitment_config::CommitmentConfig,
message::Message, message::Message,
pubkey::Pubkey, pubkey::Pubkey,
signature::{Keypair, Signer}, signature::{Keypair, Signer},
@ -288,9 +287,7 @@ pub fn process_set_validator_info(
}; };
// Check existence of validator-info account // Check existence of validator-info account
let balance = rpc_client let balance = rpc_client.get_balance(&info_pubkey).unwrap_or(0);
.poll_get_balance_with_commitment(&info_pubkey, CommitmentConfig::default())
.unwrap_or(0);
let lamports = let lamports =
rpc_client.get_minimum_balance_for_rent_exemption(ValidatorInfo::max_space() as usize)?; rpc_client.get_minimum_balance_for_rent_exemption(ValidatorInfo::max_space() as usize)?;

View File

@ -8,7 +8,7 @@ use crate::{
}; };
use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand}; use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand};
use solana_clap_utils::{ use solana_clap_utils::{
commitment::commitment_arg, commitment::commitment_arg_with_default,
input_parsers::*, input_parsers::*,
input_validators::*, input_validators::*,
keypair::{DefaultSigner, SignerIndex}, keypair::{DefaultSigner, SignerIndex},
@ -209,7 +209,7 @@ impl VoteSubCommands for App<'_, '_> {
.takes_value(false) .takes_value(false)
.help("Display balance in lamports instead of SOL"), .help("Display balance in lamports instead of SOL"),
) )
.arg(commitment_arg()), .arg(commitment_arg_with_default("singleGossip")),
) )
.subcommand( .subcommand(
SubCommand::with_name("withdraw-from-vote-account") SubCommand::with_name("withdraw-from-vote-account")
@ -494,9 +494,7 @@ pub fn process_create_vote_account(
} }
} }
let (recent_blockhash, fee_calculator, _) = rpc_client let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let (message, _) = resolve_spend_tx_and_check_account_balance( let (message, _) = resolve_spend_tx_and_check_account_balance(
rpc_client, rpc_client,
@ -509,11 +507,7 @@ pub fn process_create_vote_account(
)?; )?;
let mut tx = Transaction::new_unsigned(message); let mut tx = Transaction::new_unsigned(message);
tx.try_sign(&config.signers, recent_blockhash)?; tx.try_sign(&config.signers, recent_blockhash)?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<SystemError>(result, &config) log_instruction_custom_error::<SystemError>(result, &config)
} }
@ -536,9 +530,7 @@ pub fn process_vote_authorize(
(&authorized.pubkey(), "authorized_account".to_string()), (&authorized.pubkey(), "authorized_account".to_string()),
(new_authorized_pubkey, "new_authorized_pubkey".to_string()), (new_authorized_pubkey, "new_authorized_pubkey".to_string()),
)?; )?;
let (recent_blockhash, fee_calculator, _) = rpc_client let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let ixs = vec![vote_instruction::authorize( let ixs = vec![vote_instruction::authorize(
vote_account_pubkey, // vote account to update vote_account_pubkey, // vote account to update
&authorized.pubkey(), // current authorized &authorized.pubkey(), // current authorized
@ -556,11 +548,7 @@ pub fn process_vote_authorize(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<VoteError>(result, &config) log_instruction_custom_error::<VoteError>(result, &config)
} }
@ -578,9 +566,7 @@ pub fn process_vote_update_validator(
(vote_account_pubkey, "vote_account_pubkey".to_string()), (vote_account_pubkey, "vote_account_pubkey".to_string()),
(&new_identity_pubkey, "new_identity_account".to_string()), (&new_identity_pubkey, "new_identity_account".to_string()),
)?; )?;
let (recent_blockhash, fee_calculator, _) = rpc_client let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let ixs = vec![vote_instruction::update_validator_identity( let ixs = vec![vote_instruction::update_validator_identity(
vote_account_pubkey, vote_account_pubkey,
&authorized_withdrawer.pubkey(), &authorized_withdrawer.pubkey(),
@ -597,11 +583,7 @@ pub fn process_vote_update_validator(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<VoteError>(result, &config) log_instruction_custom_error::<VoteError>(result, &config)
} }
@ -613,9 +595,7 @@ pub fn process_vote_update_commission(
withdraw_authority: SignerIndex, withdraw_authority: SignerIndex,
) -> ProcessResult { ) -> ProcessResult {
let authorized_withdrawer = config.signers[withdraw_authority]; let authorized_withdrawer = config.signers[withdraw_authority];
let (recent_blockhash, fee_calculator, _) = rpc_client let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let ixs = vec![vote_instruction::update_commission( let ixs = vec![vote_instruction::update_commission(
vote_account_pubkey, vote_account_pubkey,
&authorized_withdrawer.pubkey(), &authorized_withdrawer.pubkey(),
@ -632,11 +612,7 @@ pub fn process_vote_update_commission(
&tx.message, &tx.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<VoteError>(result, &config) log_instruction_custom_error::<VoteError>(result, &config)
} }
@ -733,14 +709,10 @@ pub fn process_withdraw_from_vote_account(
withdraw_amount: SpendAmount, withdraw_amount: SpendAmount,
destination_account_pubkey: &Pubkey, destination_account_pubkey: &Pubkey,
) -> ProcessResult { ) -> ProcessResult {
let (recent_blockhash, fee_calculator, _) = rpc_client let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
.get_recent_blockhash_with_commitment(config.commitment)?
.value;
let withdraw_authority = config.signers[withdraw_authority]; let withdraw_authority = config.signers[withdraw_authority];
let current_balance = rpc_client let current_balance = rpc_client.get_balance(&vote_account_pubkey)?;
.get_balance_with_commitment(&vote_account_pubkey, config.commitment)?
.value;
let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(VoteState::size_of())?; let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(VoteState::size_of())?;
let lamports = match withdraw_amount { let lamports = match withdraw_amount {
@ -773,11 +745,7 @@ pub fn process_withdraw_from_vote_account(
&transaction.message, &transaction.message,
config.commitment, config.commitment,
)?; )?;
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config( let result = rpc_client.send_and_confirm_transaction_with_spinner(&transaction);
&transaction,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<VoteError>(result, &config) log_instruction_custom_error::<VoteError>(result, &config)
} }

View File

@ -63,7 +63,8 @@ fn full_battery_tests(
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let json_rpc_url = test_validator.rpc_url(); let json_rpc_url = test_validator.rpc_url();
let mut config_payer = CliConfig::recent_for_tests(); let mut config_payer = CliConfig::recent_for_tests();
@ -228,7 +229,8 @@ fn test_create_account_with_seed() {
let config = CliConfig::recent_for_tests(); let config = CliConfig::recent_for_tests();
// Setup accounts // Setup accounts
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
request_and_confirm_airdrop( request_and_confirm_airdrop(
&rpc_client, &rpc_client,
&faucet_addr, &faucet_addr,

View File

@ -33,7 +33,8 @@ fn test_cli_program_deploy_non_upgradeable() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let mut file = File::open(pathbuf.to_str().unwrap()).unwrap(); let mut file = File::open(pathbuf.to_str().unwrap()).unwrap();
let mut program_data = Vec::new(); let mut program_data = Vec::new();
@ -70,11 +71,7 @@ fn test_cli_program_deploy_non_upgradeable() {
.as_str() .as_str()
.unwrap(); .unwrap();
let program_id = Pubkey::from_str(&program_id_str).unwrap(); let program_id = Pubkey::from_str(&program_id_str).unwrap();
let account0 = rpc_client let account0 = rpc_client.get_account(&program_id).unwrap();
.get_account_with_commitment(&program_id, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!(account0.lamports, minimum_balance_for_rent_exemption); assert_eq!(account0.lamports, minimum_balance_for_rent_exemption);
assert_eq!(account0.owner, bpf_loader::id()); assert_eq!(account0.owner, bpf_loader::id());
assert_eq!(account0.executable, true); assert_eq!(account0.executable, true);
@ -94,9 +91,7 @@ fn test_cli_program_deploy_non_upgradeable() {
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let account1 = rpc_client let account1 = rpc_client
.get_account_with_commitment(&custom_address_keypair.pubkey(), CommitmentConfig::recent()) .get_account(&custom_address_keypair.pubkey())
.unwrap()
.value
.unwrap(); .unwrap();
assert_eq!(account1.lamports, minimum_balance_for_rent_exemption); assert_eq!(account1.lamports, minimum_balance_for_rent_exemption);
assert_eq!(account1.owner, bpf_loader::id()); assert_eq!(account1.owner, bpf_loader::id());
@ -134,9 +129,7 @@ fn test_cli_program_deploy_non_upgradeable() {
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let account2 = rpc_client let account2 = rpc_client
.get_account_with_commitment(&custom_address_keypair.pubkey(), CommitmentConfig::recent()) .get_account(&custom_address_keypair.pubkey())
.unwrap()
.value
.unwrap(); .unwrap();
assert_eq!(account2.lamports, 2 * minimum_balance_for_rent_exemption); assert_eq!(account2.lamports, 2 * minimum_balance_for_rent_exemption);
assert_eq!(account2.owner, bpf_loader::id()); assert_eq!(account2.owner, bpf_loader::id());
@ -161,7 +154,8 @@ fn test_cli_program_deploy_no_authority() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let mut file = File::open(pathbuf.to_str().unwrap()).unwrap(); let mut file = File::open(pathbuf.to_str().unwrap()).unwrap();
let mut program_data = Vec::new(); let mut program_data = Vec::new();
@ -248,7 +242,8 @@ fn test_cli_program_deploy_with_authority() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let mut file = File::open(pathbuf.to_str().unwrap()).unwrap(); let mut file = File::open(pathbuf.to_str().unwrap()).unwrap();
let mut program_data = Vec::new(); let mut program_data = Vec::new();
@ -304,11 +299,7 @@ fn test_cli_program_deploy_with_authority() {
program_keypair.pubkey(), program_keypair.pubkey(),
Pubkey::from_str(&program_pubkey_str).unwrap() Pubkey::from_str(&program_pubkey_str).unwrap()
); );
let program_account = rpc_client let program_account = rpc_client.get_account(&program_keypair.pubkey()).unwrap();
.get_account_with_commitment(&program_keypair.pubkey(), CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!(program_account.lamports, minimum_balance_for_program); assert_eq!(program_account.lamports, minimum_balance_for_program);
assert_eq!(program_account.owner, bpf_loader_upgradeable::id()); assert_eq!(program_account.owner, bpf_loader_upgradeable::id());
assert_eq!(program_account.executable, true); assert_eq!(program_account.executable, true);
@ -316,11 +307,7 @@ fn test_cli_program_deploy_with_authority() {
&[program_keypair.pubkey().as_ref()], &[program_keypair.pubkey().as_ref()],
&bpf_loader_upgradeable::id(), &bpf_loader_upgradeable::id(),
); );
let programdata_account = rpc_client let programdata_account = rpc_client.get_account(&programdata_pubkey).unwrap();
.get_account_with_commitment(&programdata_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!( assert_eq!(
programdata_account.lamports, programdata_account.lamports,
minimum_balance_for_programdata minimum_balance_for_programdata
@ -356,21 +343,13 @@ fn test_cli_program_deploy_with_authority() {
.as_str() .as_str()
.unwrap(); .unwrap();
let program_pubkey = Pubkey::from_str(&program_pubkey_str).unwrap(); let program_pubkey = Pubkey::from_str(&program_pubkey_str).unwrap();
let program_account = rpc_client let program_account = rpc_client.get_account(&program_pubkey).unwrap();
.get_account_with_commitment(&program_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!(program_account.lamports, minimum_balance_for_program); assert_eq!(program_account.lamports, minimum_balance_for_program);
assert_eq!(program_account.owner, bpf_loader_upgradeable::id()); assert_eq!(program_account.owner, bpf_loader_upgradeable::id());
assert_eq!(program_account.executable, true); assert_eq!(program_account.executable, true);
let (programdata_pubkey, _) = let (programdata_pubkey, _) =
Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id()); Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id());
let programdata_account = rpc_client let programdata_account = rpc_client.get_account(&programdata_pubkey).unwrap();
.get_account_with_commitment(&programdata_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!( assert_eq!(
programdata_account.lamports, programdata_account.lamports,
minimum_balance_for_programdata minimum_balance_for_programdata
@ -397,21 +376,13 @@ fn test_cli_program_deploy_with_authority() {
max_len: Some(max_len), max_len: Some(max_len),
}); });
process_command(&config).unwrap(); process_command(&config).unwrap();
let program_account = rpc_client let program_account = rpc_client.get_account(&program_pubkey).unwrap();
.get_account_with_commitment(&program_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!(program_account.lamports, minimum_balance_for_program); assert_eq!(program_account.lamports, minimum_balance_for_program);
assert_eq!(program_account.owner, bpf_loader_upgradeable::id()); assert_eq!(program_account.owner, bpf_loader_upgradeable::id());
assert_eq!(program_account.executable, true); assert_eq!(program_account.executable, true);
let (programdata_pubkey, _) = let (programdata_pubkey, _) =
Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id()); Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id());
let programdata_account = rpc_client let programdata_account = rpc_client.get_account(&programdata_pubkey).unwrap();
.get_account_with_commitment(&programdata_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!( assert_eq!(
programdata_account.lamports, programdata_account.lamports,
minimum_balance_for_programdata minimum_balance_for_programdata
@ -460,21 +431,13 @@ fn test_cli_program_deploy_with_authority() {
max_len: None, max_len: None,
}); });
process_command(&config).unwrap(); process_command(&config).unwrap();
let program_account = rpc_client let program_account = rpc_client.get_account(&program_pubkey).unwrap();
.get_account_with_commitment(&program_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!(program_account.lamports, minimum_balance_for_program); assert_eq!(program_account.lamports, minimum_balance_for_program);
assert_eq!(program_account.owner, bpf_loader_upgradeable::id()); assert_eq!(program_account.owner, bpf_loader_upgradeable::id());
assert_eq!(program_account.executable, true); assert_eq!(program_account.executable, true);
let (programdata_pubkey, _) = let (programdata_pubkey, _) =
Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id()); Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id());
let programdata_account = rpc_client let programdata_account = rpc_client.get_account(&programdata_pubkey).unwrap();
.get_account_with_commitment(&programdata_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!( assert_eq!(
programdata_account.lamports, programdata_account.lamports,
minimum_balance_for_programdata minimum_balance_for_programdata
@ -565,11 +528,7 @@ fn test_cli_program_deploy_with_authority() {
let program_pubkey = Pubkey::from_str(&program_pubkey_str).unwrap(); let program_pubkey = Pubkey::from_str(&program_pubkey_str).unwrap();
let (programdata_pubkey, _) = let (programdata_pubkey, _) =
Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id()); Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id());
let programdata_account = rpc_client let programdata_account = rpc_client.get_account(&programdata_pubkey).unwrap();
.get_account_with_commitment(&programdata_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
if let UpgradeableLoaderState::ProgramData { if let UpgradeableLoaderState::ProgramData {
slot: _, slot: _,
upgrade_authority_address, upgrade_authority_address,
@ -614,7 +573,8 @@ fn test_cli_program_write_buffer() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let mut file = File::open(pathbuf.to_str().unwrap()).unwrap(); let mut file = File::open(pathbuf.to_str().unwrap()).unwrap();
let mut program_data = Vec::new(); let mut program_data = Vec::new();
@ -663,11 +623,7 @@ fn test_cli_program_write_buffer() {
.as_str() .as_str()
.unwrap(); .unwrap();
let new_buffer_pubkey = Pubkey::from_str(&buffer_pubkey_str).unwrap(); let new_buffer_pubkey = Pubkey::from_str(&buffer_pubkey_str).unwrap();
let buffer_account = rpc_client let buffer_account = rpc_client.get_account(&new_buffer_pubkey).unwrap();
.get_account_with_commitment(&new_buffer_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!(buffer_account.lamports, minimum_balance_for_buffer_default); assert_eq!(buffer_account.lamports, minimum_balance_for_buffer_default);
assert_eq!(buffer_account.owner, bpf_loader_upgradeable::id()); assert_eq!(buffer_account.owner, bpf_loader_upgradeable::id());
if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() { if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() {
@ -704,11 +660,7 @@ fn test_cli_program_write_buffer() {
buffer_keypair.pubkey(), buffer_keypair.pubkey(),
Pubkey::from_str(&buffer_pubkey_str).unwrap() Pubkey::from_str(&buffer_pubkey_str).unwrap()
); );
let buffer_account = rpc_client let buffer_account = rpc_client.get_account(&buffer_keypair.pubkey()).unwrap();
.get_account_with_commitment(&buffer_keypair.pubkey(), CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!(buffer_account.lamports, minimum_balance_for_buffer); assert_eq!(buffer_account.lamports, minimum_balance_for_buffer);
assert_eq!(buffer_account.owner, bpf_loader_upgradeable::id()); assert_eq!(buffer_account.owner, bpf_loader_upgradeable::id());
if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() { if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() {
@ -765,11 +717,7 @@ fn test_cli_program_write_buffer() {
buffer_keypair.pubkey(), buffer_keypair.pubkey(),
Pubkey::from_str(&buffer_pubkey_str).unwrap() Pubkey::from_str(&buffer_pubkey_str).unwrap()
); );
let buffer_account = rpc_client let buffer_account = rpc_client.get_account(&buffer_keypair.pubkey()).unwrap();
.get_account_with_commitment(&buffer_keypair.pubkey(), CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!(buffer_account.lamports, minimum_balance_for_buffer_default); assert_eq!(buffer_account.lamports, minimum_balance_for_buffer_default);
assert_eq!(buffer_account.owner, bpf_loader_upgradeable::id()); assert_eq!(buffer_account.owner, bpf_loader_upgradeable::id());
if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() { if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() {
@ -804,11 +752,7 @@ fn test_cli_program_write_buffer() {
.as_str() .as_str()
.unwrap(); .unwrap();
let buffer_pubkey = Pubkey::from_str(&buffer_pubkey_str).unwrap(); let buffer_pubkey = Pubkey::from_str(&buffer_pubkey_str).unwrap();
let buffer_account = rpc_client let buffer_account = rpc_client.get_account(&buffer_pubkey).unwrap();
.get_account_with_commitment(&buffer_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
assert_eq!(buffer_account.lamports, minimum_balance_for_buffer_default); assert_eq!(buffer_account.lamports, minimum_balance_for_buffer_default);
assert_eq!(buffer_account.owner, bpf_loader_upgradeable::id()); assert_eq!(buffer_account.owner, bpf_loader_upgradeable::id());
if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() { if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() {
@ -843,11 +787,7 @@ fn test_cli_program_write_buffer() {
.as_str() .as_str()
.unwrap(); .unwrap();
let buffer_pubkey = Pubkey::from_str(&buffer_pubkey_str).unwrap(); let buffer_pubkey = Pubkey::from_str(&buffer_pubkey_str).unwrap();
let buffer_account = rpc_client let buffer_account = rpc_client.get_account(&buffer_pubkey).unwrap();
.get_account_with_commitment(&buffer_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() { if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() {
assert_eq!(authority_address, None); assert_eq!(authority_address, None);
} else { } else {
@ -888,7 +828,8 @@ fn test_cli_program_set_buffer_authority() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let mut file = File::open(pathbuf.to_str().unwrap()).unwrap(); let mut file = File::open(pathbuf.to_str().unwrap()).unwrap();
let mut program_data = Vec::new(); let mut program_data = Vec::new();
@ -924,11 +865,7 @@ fn test_cli_program_set_buffer_authority() {
max_len: None, max_len: None,
}); });
process_command(&config).unwrap(); process_command(&config).unwrap();
let buffer_account = rpc_client let buffer_account = rpc_client.get_account(&buffer_keypair.pubkey()).unwrap();
.get_account_with_commitment(&buffer_keypair.pubkey(), CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() { if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() {
assert_eq!(authority_address, Some(keypair.pubkey())); assert_eq!(authority_address, Some(keypair.pubkey()));
} else { } else {
@ -956,11 +893,7 @@ fn test_cli_program_set_buffer_authority() {
Pubkey::from_str(&new_buffer_authority_str).unwrap(), Pubkey::from_str(&new_buffer_authority_str).unwrap(),
new_buffer_authority.pubkey() new_buffer_authority.pubkey()
); );
let buffer_account = rpc_client let buffer_account = rpc_client.get_account(&buffer_keypair.pubkey()).unwrap();
.get_account_with_commitment(&buffer_keypair.pubkey(), CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() { if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() {
assert_eq!(authority_address, Some(new_buffer_authority.pubkey())); assert_eq!(authority_address, Some(new_buffer_authority.pubkey()));
} else { } else {
@ -987,11 +920,7 @@ fn test_cli_program_set_buffer_authority() {
Pubkey::from_str(&buffer_authority_str).unwrap(), Pubkey::from_str(&buffer_authority_str).unwrap(),
buffer_keypair.pubkey() buffer_keypair.pubkey()
); );
let buffer_account = rpc_client let buffer_account = rpc_client.get_account(&buffer_keypair.pubkey()).unwrap();
.get_account_with_commitment(&buffer_keypair.pubkey(), CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() { if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() {
assert_eq!(authority_address, Some(buffer_keypair.pubkey())); assert_eq!(authority_address, Some(buffer_keypair.pubkey()));
} else { } else {
@ -1015,11 +944,7 @@ fn test_cli_program_set_buffer_authority() {
.as_str() .as_str()
.unwrap(); .unwrap();
assert_eq!(buffer_authority_str, "None"); assert_eq!(buffer_authority_str, "None");
let buffer_account = rpc_client let buffer_account = rpc_client.get_account(&buffer_keypair.pubkey()).unwrap();
.get_account_with_commitment(&buffer_keypair.pubkey(), CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() { if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() {
assert_eq!(authority_address, None); assert_eq!(authority_address, None);
} else { } else {

View File

@ -31,11 +31,11 @@ fn test_cli_request_airdrop() {
let sig_response = process_command(&bob_config); let sig_response = process_command(&bob_config);
sig_response.unwrap(); sig_response.unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let balance = rpc_client let balance = rpc_client
.get_balance_with_commitment(&bob_config.signers[0].pubkey(), CommitmentConfig::recent()) .get_balance(&bob_config.signers[0].pubkey())
.unwrap() .unwrap();
.value;
assert_eq!(balance, 50); assert_eq!(balance, 50);
} }

View File

@ -32,7 +32,8 @@ fn test_stake_delegation_force() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let default_signer = Keypair::new(); let default_signer = Keypair::new();
let mut config = CliConfig::recent_for_tests(); let mut config = CliConfig::recent_for_tests();
@ -120,7 +121,8 @@ fn test_seed_stake_delegation_and_deactivation() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let validator_keypair = keypair_from_seed(&[0u8; 32]).unwrap(); let validator_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
let mut config_validator = CliConfig::recent_for_tests(); let mut config_validator = CliConfig::recent_for_tests();
@ -199,7 +201,8 @@ fn test_stake_delegation_and_deactivation() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let validator_keypair = Keypair::new(); let validator_keypair = Keypair::new();
let mut config_validator = CliConfig::recent_for_tests(); let mut config_validator = CliConfig::recent_for_tests();
@ -274,7 +277,8 @@ fn test_offline_stake_delegation_and_deactivation() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let mut config_validator = CliConfig::recent_for_tests(); let mut config_validator = CliConfig::recent_for_tests();
config_validator.json_rpc_url = test_validator.rpc_url(); config_validator.json_rpc_url = test_validator.rpc_url();
@ -406,7 +410,8 @@ fn test_nonced_stake_delegation_and_deactivation() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let config_keypair = keypair_from_seed(&[0u8; 32]).unwrap(); let config_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
let mut config = CliConfig::recent_for_tests(); let mut config = CliConfig::recent_for_tests();
@ -520,7 +525,8 @@ fn test_stake_authorize() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let default_signer = Keypair::new(); let default_signer = Keypair::new();
let mut config = CliConfig::recent_for_tests(); let mut config = CliConfig::recent_for_tests();
@ -588,11 +594,7 @@ fn test_stake_authorize() {
fee_payer: 0, fee_payer: 0,
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let stake_account = rpc_client let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
let stake_state: StakeState = stake_account.state().unwrap(); let stake_state: StakeState = stake_account.state().unwrap();
let current_authority = match stake_state { let current_authority = match stake_state {
StakeState::Initialized(meta) => meta.authorized.staker, StakeState::Initialized(meta) => meta.authorized.staker,
@ -619,11 +621,7 @@ fn test_stake_authorize() {
fee_payer: 0, fee_payer: 0,
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let stake_account = rpc_client let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
let stake_state: StakeState = stake_account.state().unwrap(); let stake_state: StakeState = stake_account.state().unwrap();
let (current_staker, current_withdrawer) = match stake_state { let (current_staker, current_withdrawer) = match stake_state {
StakeState::Initialized(meta) => (meta.authorized.staker, meta.authorized.withdrawer), StakeState::Initialized(meta) => (meta.authorized.staker, meta.authorized.withdrawer),
@ -645,11 +643,7 @@ fn test_stake_authorize() {
fee_payer: 0, fee_payer: 0,
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let stake_account = rpc_client let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
let stake_state: StakeState = stake_account.state().unwrap(); let stake_state: StakeState = stake_account.state().unwrap();
let current_authority = match stake_state { let current_authority = match stake_state {
StakeState::Initialized(meta) => meta.authorized.staker, StakeState::Initialized(meta) => meta.authorized.staker,
@ -660,10 +654,7 @@ fn test_stake_authorize() {
// Offline assignment of new nonced stake authority // Offline assignment of new nonced stake authority
let nonced_authority = Keypair::new(); let nonced_authority = Keypair::new();
let nonced_authority_pubkey = nonced_authority.pubkey(); let nonced_authority_pubkey = nonced_authority.pubkey();
let (blockhash, _, _) = rpc_client let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.unwrap()
.value;
config_offline.command = CliCommand::StakeAuthorize { config_offline.command = CliCommand::StakeAuthorize {
stake_account_pubkey, stake_account_pubkey,
new_authorizations: vec![(StakeAuthorize::Staker, nonced_authority_pubkey, 0)], new_authorizations: vec![(StakeAuthorize::Staker, nonced_authority_pubkey, 0)],
@ -689,11 +680,7 @@ fn test_stake_authorize() {
fee_payer: 0, fee_payer: 0,
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let stake_account = rpc_client let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
let stake_state: StakeState = stake_account.state().unwrap(); let stake_state: StakeState = stake_account.state().unwrap();
let current_authority = match stake_state { let current_authority = match stake_state {
StakeState::Initialized(meta) => meta.authorized.staker, StakeState::Initialized(meta) => meta.authorized.staker,
@ -758,11 +745,7 @@ fn test_stake_authorize() {
fee_payer: 0, fee_payer: 0,
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let stake_account = rpc_client let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
let stake_state: StakeState = stake_account.state().unwrap(); let stake_state: StakeState = stake_account.state().unwrap();
let current_authority = match stake_state { let current_authority = match stake_state {
StakeState::Initialized(meta) => meta.authorized.staker, StakeState::Initialized(meta) => meta.authorized.staker,
@ -792,7 +775,8 @@ fn test_stake_authorize_with_fee_payer() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let default_signer = Keypair::new(); let default_signer = Keypair::new();
let default_pubkey = default_signer.pubkey(); let default_pubkey = default_signer.pubkey();
@ -870,10 +854,7 @@ fn test_stake_authorize_with_fee_payer() {
check_recent_balance(100_000 - SIG_FEE - SIG_FEE, &rpc_client, &payer_pubkey); check_recent_balance(100_000 - SIG_FEE - SIG_FEE, &rpc_client, &payer_pubkey);
// Assign authority with offline fee payer // Assign authority with offline fee payer
let (blockhash, _, _) = rpc_client let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.unwrap()
.value;
config_offline.command = CliCommand::StakeAuthorize { config_offline.command = CliCommand::StakeAuthorize {
stake_account_pubkey, stake_account_pubkey,
new_authorizations: vec![(StakeAuthorize::Staker, payer_pubkey, 0)], new_authorizations: vec![(StakeAuthorize::Staker, payer_pubkey, 0)],
@ -916,7 +897,8 @@ fn test_stake_split() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let default_signer = Keypair::new(); let default_signer = Keypair::new();
let offline_signer = Keypair::new(); let offline_signer = Keypair::new();
@ -1059,7 +1041,8 @@ fn test_stake_set_lockup() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let default_signer = Keypair::new(); let default_signer = Keypair::new();
let offline_signer = Keypair::new(); let offline_signer = Keypair::new();
@ -1142,11 +1125,7 @@ fn test_stake_set_lockup() {
fee_payer: 0, fee_payer: 0,
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let stake_account = rpc_client let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
let stake_state: StakeState = stake_account.state().unwrap(); let stake_state: StakeState = stake_account.state().unwrap();
let current_lockup = match stake_state { let current_lockup = match stake_state {
StakeState::Initialized(meta) => meta.lockup, StakeState::Initialized(meta) => meta.lockup,
@ -1197,11 +1176,7 @@ fn test_stake_set_lockup() {
fee_payer: 0, fee_payer: 0,
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let stake_account = rpc_client let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
let stake_state: StakeState = stake_account.state().unwrap(); let stake_state: StakeState = stake_account.state().unwrap();
let current_lockup = match stake_state { let current_lockup = match stake_state {
StakeState::Initialized(meta) => meta.lockup, StakeState::Initialized(meta) => meta.lockup,
@ -1294,11 +1269,7 @@ fn test_stake_set_lockup() {
fee_payer: 0, fee_payer: 0,
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let stake_account = rpc_client let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
.unwrap()
.value
.unwrap();
let stake_state: StakeState = stake_account.state().unwrap(); let stake_state: StakeState = stake_account.state().unwrap();
let current_lockup = match stake_state { let current_lockup = match stake_state {
StakeState::Initialized(meta) => meta.lockup, StakeState::Initialized(meta) => meta.lockup,
@ -1322,7 +1293,8 @@ fn test_offline_nonced_create_stake_account_and_withdraw() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let mut config = CliConfig::recent_for_tests(); let mut config = CliConfig::recent_for_tests();
let default_signer = keypair_from_seed(&[1u8; 32]).unwrap(); let default_signer = keypair_from_seed(&[1u8; 32]).unwrap();
config.signers = vec![&default_signer]; config.signers = vec![&default_signer];

View File

@ -29,7 +29,8 @@ fn test_transfer() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let default_signer = Keypair::new(); let default_signer = Keypair::new();
let default_offline_signer = Keypair::new(); let default_offline_signer = Keypair::new();
@ -92,10 +93,7 @@ fn test_transfer() {
check_recent_balance(50, &rpc_client, &offline_pubkey); check_recent_balance(50, &rpc_client, &offline_pubkey);
// Offline transfer // Offline transfer
let (blockhash, _, _) = rpc_client let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.unwrap()
.value;
offline.command = CliCommand::Transfer { offline.command = CliCommand::Transfer {
amount: SpendAmount::Some(10), amount: SpendAmount::Some(10),
to: recipient_pubkey, to: recipient_pubkey,
@ -256,7 +254,8 @@ fn test_transfer_multisession_signing() {
let config = CliConfig::recent_for_tests(); let config = CliConfig::recent_for_tests();
// Setup accounts // Setup accounts
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
request_and_confirm_airdrop( request_and_confirm_airdrop(
&rpc_client, &rpc_client,
&faucet_addr, &faucet_addr,
@ -279,10 +278,7 @@ fn test_transfer_multisession_signing() {
check_ready(&rpc_client); check_ready(&rpc_client);
let (blockhash, _, _) = rpc_client let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.unwrap()
.value;
// Offline fee-payer signs first // Offline fee-payer signs first
let mut fee_payer_config = CliConfig::recent_for_tests(); let mut fee_payer_config = CliConfig::recent_for_tests();
@ -368,7 +364,8 @@ fn test_transfer_all() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let default_signer = Keypair::new(); let default_signer = Keypair::new();

View File

@ -25,7 +25,8 @@ fn test_vote_authorize_and_withdraw() {
run_local_faucet(mint_keypair, sender, None); run_local_faucet(mint_keypair, sender, None);
let faucet_addr = receiver.recv().unwrap(); let faucet_addr = receiver.recv().unwrap();
let rpc_client = RpcClient::new(test_validator.rpc_url()); let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
let default_signer = Keypair::new(); let default_signer = Keypair::new();
let mut config = CliConfig::recent_for_tests(); let mut config = CliConfig::recent_for_tests();
@ -55,9 +56,7 @@ fn test_vote_authorize_and_withdraw() {
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let vote_account = rpc_client let vote_account = rpc_client
.get_account_with_commitment(&vote_account_keypair.pubkey(), CommitmentConfig::recent()) .get_account(&vote_account_keypair.pubkey())
.unwrap()
.value
.unwrap(); .unwrap();
let vote_state: VoteStateVersions = vote_account.state().unwrap(); let vote_state: VoteStateVersions = vote_account.state().unwrap();
let authorized_withdrawer = vote_state.convert_to_current().authorized_withdrawer; let authorized_withdrawer = vote_state.convert_to_current().authorized_withdrawer;
@ -95,9 +94,7 @@ fn test_vote_authorize_and_withdraw() {
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();
let vote_account = rpc_client let vote_account = rpc_client
.get_account_with_commitment(&vote_account_keypair.pubkey(), CommitmentConfig::recent()) .get_account(&vote_account_keypair.pubkey())
.unwrap()
.value
.unwrap(); .unwrap();
let vote_state: VoteStateVersions = vote_account.state().unwrap(); let vote_state: VoteStateVersions = vote_account.state().unwrap();
let authorized_withdrawer = vote_state.convert_to_current().authorized_withdrawer; let authorized_withdrawer = vote_state.convert_to_current().authorized_withdrawer;

View File

@ -97,6 +97,17 @@ impl RpcClient {
) )
} }
pub fn new_with_timeout_and_commitment(
url: String,
timeout: Duration,
commitment_config: CommitmentConfig,
) -> Self {
Self::new_sender(
HttpSender::new_with_timeout(url, timeout),
commitment_config,
)
}
pub fn new_mock(url: String) -> Self { pub fn new_mock(url: String) -> Self {
Self::new_sender(MockSender::new(url), CommitmentConfig::default()) Self::new_sender(MockSender::new(url), CommitmentConfig::default())
} }
@ -350,6 +361,10 @@ impl RpcClient {
self.send(RpcRequest::GetSlot, json!([commitment_config])) self.send(RpcRequest::GetSlot, json!([commitment_config]))
} }
pub fn supply(&self) -> RpcResult<RpcSupply> {
self.supply_with_commitment(self.commitment_config)
}
pub fn supply_with_commitment( pub fn supply_with_commitment(
&self, &self,
commitment_config: CommitmentConfig, commitment_config: CommitmentConfig,
@ -771,6 +786,7 @@ impl RpcClient {
filters: None, filters: None,
account_config: RpcAccountInfoConfig { account_config: RpcAccountInfoConfig {
encoding: Some(UiAccountEncoding::Base64), encoding: Some(UiAccountEncoding::Base64),
commitment: Some(self.commitment_config),
..RpcAccountInfoConfig::default() ..RpcAccountInfoConfig::default()
}, },
}, },

View File

@ -323,7 +323,7 @@ fn check_vote_account(
authorized_voter_pubkeys: &[Pubkey], authorized_voter_pubkeys: &[Pubkey],
) -> Result<(), String> { ) -> Result<(), String> {
let vote_account = rpc_client let vote_account = rpc_client
.get_account_with_commitment(vote_account_address, CommitmentConfig::root()) .get_account_with_commitment(vote_account_address, CommitmentConfig::single_gossip())
.map_err(|err| format!("failed to fetch vote account: {}", err.to_string()))? .map_err(|err| format!("failed to fetch vote account: {}", err.to_string()))?
.value .value
.ok_or_else(|| format!("vote account does not exist: {}", vote_account_address))?; .ok_or_else(|| format!("vote account does not exist: {}", vote_account_address))?;
@ -336,7 +336,7 @@ fn check_vote_account(
} }
let identity_account = rpc_client let identity_account = rpc_client
.get_account_with_commitment(identity_pubkey, CommitmentConfig::root()) .get_account_with_commitment(identity_pubkey, CommitmentConfig::single_gossip())
.map_err(|err| format!("failed to fetch identity account: {}", err.to_string()))? .map_err(|err| format!("failed to fetch identity account: {}", err.to_string()))?
.value .value
.ok_or_else(|| format!("identity account does not exist: {}", identity_pubkey))?; .ok_or_else(|| format!("identity account does not exist: {}", identity_pubkey))?;