Skip to content

Commit

Permalink
Deprecate commitment variants (solana-labs#14797)
Browse files Browse the repository at this point in the history
* Deprecate commitment variants

* Add new CommitmentConfig builders

* Add helpers to avoid allowing deprecated variants

* Remove deprecated transaction-status code

* Include new commitment variants in runtime commitment; allow deprecated as long as old variants persist

* Remove deprecated banks code

* Remove deprecated variants in core; allow deprecated in rpc/rpc-subscriptions for now

* Heavier hand with rpc/rpc-subscription commitment

* Remove deprecated variants from local-cluster

* Remove deprecated variants from various tools

* Remove deprecated variants from validator

* Update docs

* Remove deprecated client code

* Add new variants to cli; remove deprecated variants as possible

* Don't send new commitment variants to old clusters

* Retain deprecated method in test_validator_saves_tower

* Fix clippy matches! suggestion for BPF solana-sdk legacy compile test

* Refactor node version check to handle commitment variants and transaction encoding

* Hide deprecated variants from cli help

* Add cli App comments
  • Loading branch information
CriesofCarrots authored Jan 26, 2021
1 parent e08d2e6 commit ffa5c7d
Show file tree
Hide file tree
Showing 37 changed files with 540 additions and 322 deletions.
4 changes: 2 additions & 2 deletions banks-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl BanksClient {
pub fn get_fees(
&mut self,
) -> impl Future<Output = io::Result<(FeeCalculator, Hash, Slot)>> + '_ {
self.get_fees_with_commitment_and_context(context::current(), CommitmentLevel::Root)
self.get_fees_with_commitment_and_context(context::current(), CommitmentLevel::default())
}

/// Return the cluster rent
Expand Down Expand Up @@ -196,7 +196,7 @@ impl BanksClient {
/// Return the most recent rooted slot height. All transactions at or below this height
/// are said to be finalized. The cluster will not fork to a higher slot height.
pub fn get_root_slot(&mut self) -> impl Future<Output = io::Result<Slot>> + '_ {
self.get_slot_with_context(context::current(), CommitmentLevel::Root)
self.get_slot_with_context(context::current(), CommitmentLevel::default())
}

/// Return the account at the given address at the slot corresponding to the given
Expand Down
4 changes: 2 additions & 2 deletions banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ impl Banks for BanksServer {
_: Context,
signature: Signature,
) -> Option<TransactionStatus> {
let bank = self.bank(CommitmentLevel::Recent);
let bank = self.bank(CommitmentLevel::Processed);
let (slot, status) = bank.get_signature_status_slot(&signature)?;
let r_block_commitment_cache = self.block_commitment_cache.read().unwrap();

let optimistically_confirmed_bank = self.bank(CommitmentLevel::SingleGossip);
let optimistically_confirmed_bank = self.bank(CommitmentLevel::Confirmed);
let optimistically_confirmed =
optimistically_confirmed_bank.get_signature_status_slot(&signature);

Expand Down
26 changes: 13 additions & 13 deletions bench-exchange/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ fn swapper<T>(
while client
.get_balance_with_commitment(
&trade_infos[trade_index].trade_account,
CommitmentConfig::recent(),
CommitmentConfig::processed(),
)
.unwrap_or(0)
== 0
Expand Down Expand Up @@ -445,7 +445,7 @@ fn swapper<T>(
account_group = (account_group + 1) % account_groups as usize;

let (blockhash, _fee_calculator, _last_valid_slot) = client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.get_recent_blockhash_with_commitment(CommitmentConfig::processed())
.expect("Failed to get blockhash");
let to_swap_txs: Vec<_> = to_swap
.par_iter()
Expand Down Expand Up @@ -571,7 +571,7 @@ fn trader<T>(
account_group = (account_group + 1) % account_groups as usize;

let (blockhash, _fee_calculator, _last_valid_slot) = client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.get_recent_blockhash_with_commitment(CommitmentConfig::processed())
.expect("Failed to get blockhash");

trades.chunks(chunk_size).for_each(|chunk| {
Expand Down Expand Up @@ -658,7 +658,7 @@ where
{
for s in &tx.signatures {
if let Ok(Some(r)) =
sync_client.get_signature_status_with_commitment(s, CommitmentConfig::recent())
sync_client.get_signature_status_with_commitment(s, CommitmentConfig::processed())
{
match r {
Ok(_) => {
Expand All @@ -681,7 +681,7 @@ fn verify_funding_transfer<T: SyncClient + ?Sized>(
if verify_transaction(client, tx) {
for a in &tx.message().account_keys[1..] {
if client
.get_balance_with_commitment(a, CommitmentConfig::recent())
.get_balance_with_commitment(a, CommitmentConfig::processed())
.unwrap_or(0)
>= amount
{
Expand Down Expand Up @@ -764,7 +764,7 @@ pub fn fund_keys<T: Client>(client: &T, source: &Keypair, dests: &[Arc<Keypair>]
);

let (blockhash, _fee_calculator, _last_valid_slot) = client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.get_recent_blockhash_with_commitment(CommitmentConfig::processed())
.expect("blockhash");
to_fund_txs.par_iter_mut().for_each(|(k, tx)| {
tx.sign(&[*k], blockhash);
Expand Down Expand Up @@ -803,7 +803,7 @@ pub fn fund_keys<T: Client>(client: &T, source: &Keypair, dests: &[Arc<Keypair>]
funded.append(&mut new_funded);
funded.retain(|(k, b)| {
client
.get_balance_with_commitment(&k.pubkey(), CommitmentConfig::recent())
.get_balance_with_commitment(&k.pubkey(), CommitmentConfig::processed())
.unwrap_or(0)
> lamports
&& *b > lamports
Expand Down Expand Up @@ -857,7 +857,7 @@ pub fn create_token_accounts<T: Client>(
let mut retries = 0;
while !to_create_txs.is_empty() {
let (blockhash, _fee_calculator, _last_valid_slot) = client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.get_recent_blockhash_with_commitment(CommitmentConfig::processed())
.expect("Failed to get blockhash");
to_create_txs
.par_iter_mut()
Expand Down Expand Up @@ -903,7 +903,7 @@ pub fn create_token_accounts<T: Client>(
let mut new_notfunded: Vec<(&Arc<Keypair>, &Keypair)> = vec![];
for f in &notfunded {
if client
.get_balance_with_commitment(&f.1.pubkey(), CommitmentConfig::recent())
.get_balance_with_commitment(&f.1.pubkey(), CommitmentConfig::processed())
.unwrap_or(0)
== 0
{
Expand Down Expand Up @@ -968,7 +968,7 @@ pub fn airdrop_lamports<T: Client>(
id: &Keypair,
amount: u64,
) {
let balance = client.get_balance_with_commitment(&id.pubkey(), CommitmentConfig::recent());
let balance = client.get_balance_with_commitment(&id.pubkey(), CommitmentConfig::processed());
let balance = balance.unwrap_or(0);
if balance >= amount {
return;
Expand All @@ -986,7 +986,7 @@ pub fn airdrop_lamports<T: Client>(
let mut tries = 0;
loop {
let (blockhash, _fee_calculator, _last_valid_slot) = client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.get_recent_blockhash_with_commitment(CommitmentConfig::processed())
.expect("Failed to get blockhash");
match request_airdrop_transaction(&faucet_addr, &id.pubkey(), amount_to_drop, blockhash) {
Ok(transaction) => {
Expand All @@ -995,14 +995,14 @@ pub fn airdrop_lamports<T: Client>(
for _ in 0..30 {
if let Ok(Some(_)) = client.get_signature_status_with_commitment(
&signature,
CommitmentConfig::recent(),
CommitmentConfig::processed(),
) {
break;
}
sleep(Duration::from_millis(100));
}
if client
.get_balance_with_commitment(&id.pubkey(), CommitmentConfig::recent())
.get_balance_with_commitment(&id.pubkey(), CommitmentConfig::processed())
.unwrap_or(0)
>= amount
{
Expand Down
8 changes: 4 additions & 4 deletions bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub type SharedTransactions = Arc<RwLock<VecDeque<Vec<(Transaction, u64)>>>>;

fn get_recent_blockhash<T: Client>(client: &T) -> (Hash, FeeCalculator) {
loop {
match client.get_recent_blockhash_with_commitment(CommitmentConfig::recent()) {
match client.get_recent_blockhash_with_commitment(CommitmentConfig::processed()) {
Ok((blockhash, fee_calculator, _last_valid_slot)) => {
return (blockhash, fee_calculator)
}
Expand Down Expand Up @@ -496,7 +496,7 @@ fn do_tx_transfers<T: Client>(

fn verify_funding_transfer<T: Client>(client: &Arc<T>, tx: &Transaction, amount: u64) -> bool {
for a in &tx.message().account_keys[1..] {
match client.get_balance_with_commitment(a, CommitmentConfig::recent()) {
match client.get_balance_with_commitment(a, CommitmentConfig::processed()) {
Ok(balance) => return balance >= amount,
Err(err) => error!("failed to get balance {:?}", err),
}
Expand Down Expand Up @@ -761,7 +761,7 @@ pub fn airdrop_lamports<T: Client>(
};

let current_balance = client
.get_balance_with_commitment(&id.pubkey(), CommitmentConfig::recent())
.get_balance_with_commitment(&id.pubkey(), CommitmentConfig::processed())
.unwrap_or_else(|e| {
info!("airdrop error {}", e);
starting_balance
Expand Down Expand Up @@ -966,7 +966,7 @@ mod tests {
for kp in &keypairs {
assert_eq!(
client
.get_balance_with_commitment(&kp.pubkey(), CommitmentConfig::recent())
.get_balance_with_commitment(&kp.pubkey(), CommitmentConfig::processed())
.unwrap(),
lamports
);
Expand Down
2 changes: 1 addition & 1 deletion cli-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Default for Config {
"System Program".to_string(),
);

let commitment = "singleGossip".to_string();
let commitment = "confirmed".to_string();

Self {
json_rpc_url,
Expand Down
8 changes: 4 additions & 4 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl CliConfig<'_> {
}

fn default_commitment() -> CommitmentConfig {
CommitmentConfig::single_gossip()
CommitmentConfig::confirmed()
}

fn first_nonempty_setting(
Expand Down Expand Up @@ -532,10 +532,10 @@ impl CliConfig<'_> {

pub fn recent_for_tests() -> Self {
Self {
commitment: CommitmentConfig::recent(),
commitment: CommitmentConfig::processed(),
send_transaction_config: RpcSendTransactionConfig {
skip_preflight: true,
preflight_commitment: Some(CommitmentConfig::recent().commitment),
preflight_commitment: Some(CommitmentConfig::processed().commitment),
..RpcSendTransactionConfig::default()
},
..Self::default()
Expand All @@ -558,7 +558,7 @@ impl Default for CliConfig<'_> {
rpc_timeout: Duration::from_secs(u64::from_str(DEFAULT_RPC_TIMEOUT_SECONDS).unwrap()),
verbose: false,
output_format: OutputFormat::Display,
commitment: CommitmentConfig::single_gossip(),
commitment: CommitmentConfig::confirmed(),
send_transaction_config: RpcSendTransactionConfig::default(),
address_labels: HashMap::new(),
}
Expand Down
8 changes: 4 additions & 4 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ pub fn process_get_block(
let slot = if let Some(slot) = slot {
slot
} else {
rpc_client.get_slot_with_commitment(CommitmentConfig::max())?
rpc_client.get_slot_with_commitment(CommitmentConfig::finalized())?
};

let mut block =
Expand Down Expand Up @@ -980,7 +980,7 @@ pub fn process_get_block_time(
let slot = if let Some(slot) = slot {
slot
} else {
rpc_client.get_slot_with_commitment(CommitmentConfig::max())?
rpc_client.get_slot_with_commitment(CommitmentConfig::finalized())?
};
let timestamp = rpc_client.get_block_time(slot)?;
let block_time = CliBlockTime { slot, timestamp };
Expand Down Expand Up @@ -1029,7 +1029,7 @@ pub fn process_show_block_production(
slot_limit: Option<u64>,
) -> ProcessResult {
let epoch_schedule = rpc_client.get_epoch_schedule()?;
let epoch_info = rpc_client.get_epoch_info_with_commitment(CommitmentConfig::max())?;
let epoch_info = rpc_client.get_epoch_info_with_commitment(CommitmentConfig::finalized())?;

let epoch = epoch.unwrap_or(epoch_info.epoch);
if epoch > epoch_info.epoch {
Expand Down Expand Up @@ -1088,7 +1088,7 @@ pub fn process_show_block_production(

progress_bar.set_message(&format!("Fetching leader schedule for epoch {}...", epoch));
let leader_schedule = rpc_client
.get_leader_schedule_with_commitment(Some(start_slot), CommitmentConfig::root())?;
.get_leader_schedule_with_commitment(Some(start_slot), CommitmentConfig::finalized())?;
if leader_schedule.is_none() {
return Err(format!("Unable to fetch leader schedule for slot {}", start_slot).into());
}
Expand Down
14 changes: 12 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,20 @@ fn main() -> Result<(), Box<dyn error::Error>> {
Arg::with_name("commitment")
.long("commitment")
.takes_value(true)
.possible_values(&["recent", "single", "singleGossip", "root", "max"])
.possible_values(&[
"processed",
"confirmed",
"finalized",
"recent", // Deprecated as of v1.5.5
"single", // Deprecated as of v1.5.5
"singleGossip", // Deprecated as of v1.5.5
"root", // Deprecated as of v1.5.5
"max", // Deprecated as of v1.5.5
])
.value_name("COMMITMENT_LEVEL")
.hide_possible_values(true)
.global(true)
.help("Return information at the selected commitment level"),
.help("Return information at the selected commitment level [possible values: processed, confirmed, finalized]"),
)
.arg(
Arg::with_name("verbose")
Expand Down
4 changes: 2 additions & 2 deletions cli/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{thread::sleep, time::Duration};
pub fn check_recent_balance(expected_balance: u64, client: &RpcClient, pubkey: &Pubkey) {
(0..5).for_each(|tries| {
let balance = client
.get_balance_with_commitment(pubkey, CommitmentConfig::recent())
.get_balance_with_commitment(pubkey, CommitmentConfig::processed())
.unwrap()
.value;
if balance == expected_balance {
Expand All @@ -20,7 +20,7 @@ pub fn check_recent_balance(expected_balance: u64, client: &RpcClient, pubkey: &

pub fn check_ready(rpc_client: &RpcClient) {
while rpc_client
.get_slot_with_commitment(CommitmentConfig::recent())
.get_slot_with_commitment(CommitmentConfig::processed())
.unwrap()
< 5
{
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn full_battery_tests(
let faucet_addr = receiver.recv().unwrap();

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
let json_rpc_url = test_validator.rpc_url();

let mut config_payer = CliConfig::recent_for_tests();
Expand Down Expand Up @@ -230,7 +230,7 @@ fn test_create_account_with_seed() {

// Setup accounts
let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
request_and_confirm_airdrop(
&rpc_client,
&faucet_addr,
Expand Down Expand Up @@ -280,7 +280,7 @@ fn test_create_account_with_seed() {
let nonce_hash = nonce_utils::get_account_with_commitment(
&rpc_client,
&nonce_address,
CommitmentConfig::recent(),
CommitmentConfig::processed(),
)
.and_then(|ref a| nonce_utils::data_from_account(a))
.unwrap()
Expand Down
10 changes: 5 additions & 5 deletions cli/tests/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn test_cli_program_deploy_non_upgradeable() {
let faucet_addr = receiver.recv().unwrap();

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());

let mut file = File::open(pathbuf.to_str().unwrap()).unwrap();
let mut program_data = Vec::new();
Expand Down Expand Up @@ -155,7 +155,7 @@ fn test_cli_program_deploy_no_authority() {
let faucet_addr = receiver.recv().unwrap();

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());

let mut file = File::open(pathbuf.to_str().unwrap()).unwrap();
let mut program_data = Vec::new();
Expand Down Expand Up @@ -243,7 +243,7 @@ fn test_cli_program_deploy_with_authority() {
let faucet_addr = receiver.recv().unwrap();

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());

let mut file = File::open(pathbuf.to_str().unwrap()).unwrap();
let mut program_data = Vec::new();
Expand Down Expand Up @@ -574,7 +574,7 @@ fn test_cli_program_write_buffer() {
let faucet_addr = receiver.recv().unwrap();

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());

let mut file = File::open(pathbuf.to_str().unwrap()).unwrap();
let mut program_data = Vec::new();
Expand Down Expand Up @@ -829,7 +829,7 @@ fn test_cli_program_set_buffer_authority() {
let faucet_addr = receiver.recv().unwrap();

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());

let mut file = File::open(pathbuf.to_str().unwrap()).unwrap();
let mut program_data = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/request_airdrop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn test_cli_request_airdrop() {
sig_response.unwrap();

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::recent());
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());

let balance = rpc_client
.get_balance(&bob_config.signers[0].pubkey())
Expand Down
Loading

0 comments on commit ffa5c7d

Please sign in to comment.