From b3ed3c7c748c4514bb922b117306ea917aaeeae6 Mon Sep 17 00:00:00 2001 From: Tyera Date: Wed, 3 Jul 2024 10:40:54 -0600 Subject: [PATCH] Remove deprecated CommitmentLevel variants (#1903) * Remove deprecated CommitmentLevel variants and CommitmentConfig methods * Remove deprecated variants from BlockCommitmentCache usage * Remove deprecated variants from rpc * Remove maybe_map_commitment from RpcClient (cherry picked from commit 2e3c2c78e94fc7614dbf5899c5dc27a20e60f4c9) --- rpc-client/src/nonblocking/rpc_client.rs | 126 +++++----------------- rpc/src/rpc.rs | 16 +-- runtime/src/commitment.rs | 11 +- sdk/src/commitment_config.rs | 129 ++--------------------- 4 files changed, 42 insertions(+), 240 deletions(-) diff --git a/rpc-client/src/nonblocking/rpc_client.rs b/rpc-client/src/nonblocking/rpc_client.rs index 624e4ba183a62a..bcaf3e16f41d0b 100644 --- a/rpc-client/src/nonblocking/rpc_client.rs +++ b/rpc-client/src/nonblocking/rpc_client.rs @@ -39,7 +39,7 @@ use { solana_sdk::{ account::Account, clock::{Epoch, Slot, UnixTimestamp, DEFAULT_MS_PER_SLOT}, - commitment_config::{CommitmentConfig, CommitmentLevel}, + commitment_config::CommitmentConfig, epoch_info::EpochInfo, epoch_schedule::EpochSchedule, hash::Hash, @@ -550,26 +550,6 @@ impl RpcClient { self.config.commitment_config } - async fn use_deprecated_commitment(&self) -> Result { - Ok(self.get_node_version().await? < semver::Version::new(1, 5, 5)) - } - - async fn maybe_map_commitment( - &self, - requested_commitment: CommitmentConfig, - ) -> Result { - if matches!( - requested_commitment.commitment, - CommitmentLevel::Finalized | CommitmentLevel::Confirmed | CommitmentLevel::Processed - ) && self.use_deprecated_commitment().await? - { - return Ok(CommitmentConfig::use_deprecated_commitment( - requested_commitment, - )); - } - Ok(requested_commitment) - } - #[allow(deprecated)] async fn maybe_map_filters( &self, @@ -822,11 +802,7 @@ impl RpcClient { self.send_transaction_with_config( transaction, RpcSendTransactionConfig { - preflight_commitment: Some( - self.maybe_map_commitment(self.commitment()) - .await? - .commitment, - ), + preflight_commitment: Some(self.commitment().commitment), ..RpcSendTransactionConfig::default() }, ) @@ -927,7 +903,6 @@ impl RpcClient { let preflight_commitment = CommitmentConfig { commitment: config.preflight_commitment.unwrap_or_default(), }; - let preflight_commitment = self.maybe_map_commitment(preflight_commitment).await?; let config = RpcSendTransactionConfig { encoding: Some(encoding), preflight_commitment: Some(preflight_commitment.commitment), @@ -1375,7 +1350,6 @@ impl RpcClient { self.default_cluster_transaction_encoding().await? }; let commitment = config.commitment.unwrap_or_default(); - let commitment = self.maybe_map_commitment(commitment).await?; let config = RpcSimulateTransactionConfig { encoding: Some(encoding), commitment: Some(commitment), @@ -1844,11 +1818,8 @@ impl RpcClient { &self, commitment_config: CommitmentConfig, ) -> ClientResult { - self.send( - RpcRequest::GetSlot, - json!([self.maybe_map_commitment(commitment_config).await?]), - ) - .await + self.send(RpcRequest::GetSlot, json!([commitment_config])) + .await } /// Returns the block height that has reached the configured [commitment level][cl]. @@ -1908,11 +1879,8 @@ impl RpcClient { &self, commitment_config: CommitmentConfig, ) -> ClientResult { - self.send( - RpcRequest::GetBlockHeight, - json!([self.maybe_map_commitment(commitment_config).await?]), - ) - .await + self.send(RpcRequest::GetBlockHeight, json!([commitment_config])) + .await } /// Returns the slot leaders for a given slot range. @@ -2189,11 +2157,8 @@ impl RpcClient { &self, commitment_config: CommitmentConfig, ) -> RpcResult { - self.send( - RpcRequest::GetSupply, - json!([self.maybe_map_commitment(commitment_config).await?]), - ) - .await + self.send(RpcRequest::GetSupply, json!([commitment_config])) + .await } /// Returns the 20 largest accounts, by lamport balance. @@ -2235,7 +2200,6 @@ impl RpcClient { config: RpcLargestAccountsConfig, ) -> RpcResult> { let commitment = config.commitment.unwrap_or_default(); - let commitment = self.maybe_map_commitment(commitment).await?; let config = RpcLargestAccountsConfig { commitment: Some(commitment), ..config @@ -2305,7 +2269,7 @@ impl RpcClient { commitment_config: CommitmentConfig, ) -> ClientResult { self.get_vote_accounts_with_config(RpcGetVoteAccountsConfig { - commitment: Some(self.maybe_map_commitment(commitment_config).await?), + commitment: Some(commitment_config), ..RpcGetVoteAccountsConfig::default() }) .await @@ -2646,16 +2610,9 @@ impl RpcClient { commitment_config: CommitmentConfig, ) -> ClientResult> { let json = if end_slot.is_some() { - json!([ - start_slot, - end_slot, - self.maybe_map_commitment(commitment_config).await? - ]) + json!([start_slot, end_slot, commitment_config]) } else { - json!([ - start_slot, - self.maybe_map_commitment(commitment_config).await? - ]) + json!([start_slot, commitment_config]) }; self.send(RpcRequest::GetBlocks, json).await } @@ -2750,11 +2707,7 @@ impl RpcClient { ) -> ClientResult> { self.send( RpcRequest::GetBlocksWithLimit, - json!([ - start_slot, - limit, - self.maybe_map_commitment(commitment_config).await? - ]), + json!([start_slot, limit, commitment_config]), ) .await } @@ -3095,11 +3048,8 @@ impl RpcClient { &self, commitment_config: CommitmentConfig, ) -> ClientResult { - self.send( - RpcRequest::GetEpochInfo, - json!([self.maybe_map_commitment(commitment_config).await?]), - ) - .await + self.send(RpcRequest::GetEpochInfo, json!([commitment_config])) + .await } /// Returns the leader schedule for an epoch. @@ -3172,7 +3122,7 @@ impl RpcClient { self.get_leader_schedule_with_config( slot, RpcLeaderScheduleConfig { - commitment: Some(self.maybe_map_commitment(commitment_config).await?), + commitment: Some(commitment_config), ..RpcLeaderScheduleConfig::default() }, ) @@ -3618,7 +3568,7 @@ impl RpcClient { ) -> RpcResult> { let config = RpcAccountInfoConfig { encoding: Some(UiAccountEncoding::Base64Zstd), - commitment: Some(self.maybe_map_commitment(commitment_config).await?), + commitment: Some(commitment_config), data_slice: None, min_context_slot: None, }; @@ -3845,7 +3795,7 @@ impl RpcClient { pubkeys, RpcAccountInfoConfig { encoding: Some(UiAccountEncoding::Base64Zstd), - commitment: Some(self.maybe_map_commitment(commitment_config).await?), + commitment: Some(commitment_config), data_slice: None, min_context_slot: None, }, @@ -4074,10 +4024,7 @@ impl RpcClient { ) -> RpcResult { self.send( RpcRequest::GetBalance, - json!([ - pubkey.to_string(), - self.maybe_map_commitment(commitment_config).await? - ]), + json!([pubkey.to_string(), commitment_config]), ) .await } @@ -4197,7 +4144,6 @@ impl RpcClient { .account_config .commitment .unwrap_or_else(|| self.commitment()); - let commitment = self.maybe_map_commitment(commitment).await?; config.account_config.commitment = Some(commitment); if let Some(filters) = config.filters { config.filters = Some(self.maybe_map_filters(filters).await?); @@ -4266,7 +4212,7 @@ impl RpcClient { Ok(self .send::>( RpcRequest::GetStakeMinimumDelegation, - json!([self.maybe_map_commitment(commitment_config).await?]), + json!([commitment_config]), ) .await? .value) @@ -4282,11 +4228,8 @@ impl RpcClient { &self, commitment_config: CommitmentConfig, ) -> ClientResult { - self.send( - RpcRequest::GetTransactionCount, - json!([self.maybe_map_commitment(commitment_config).await?]), - ) - .await + self.send(RpcRequest::GetTransactionCount, json!([commitment_config])) + .await } pub async fn get_first_available_block(&self) -> ClientResult { @@ -4325,7 +4268,7 @@ impl RpcClient { ) -> RpcResult> { let config = RpcAccountInfoConfig { encoding: Some(UiAccountEncoding::JsonParsed), - commitment: Some(self.maybe_map_commitment(commitment_config).await?), + commitment: Some(commitment_config), data_slice: None, min_context_slot: None, }; @@ -4388,10 +4331,7 @@ impl RpcClient { ) -> RpcResult { self.send( RpcRequest::GetTokenAccountBalance, - json!([ - pubkey.to_string(), - self.maybe_map_commitment(commitment_config).await? - ]), + json!([pubkey.to_string(), commitment_config]), ) .await } @@ -4426,7 +4366,7 @@ impl RpcClient { let config = RpcAccountInfoConfig { encoding: Some(UiAccountEncoding::JsonParsed), - commitment: Some(self.maybe_map_commitment(commitment_config).await?), + commitment: Some(commitment_config), data_slice: None, min_context_slot: None, }; @@ -4468,7 +4408,7 @@ impl RpcClient { let config = RpcAccountInfoConfig { encoding: Some(UiAccountEncoding::JsonParsed), - commitment: Some(self.maybe_map_commitment(commitment_config).await?), + commitment: Some(commitment_config), data_slice: None, min_context_slot: None, }; @@ -4497,10 +4437,7 @@ impl RpcClient { ) -> RpcResult> { self.send( RpcRequest::GetTokenLargestAccounts, - json!([ - mint.to_string(), - self.maybe_map_commitment(commitment_config).await? - ]), + json!([mint.to_string(), commitment_config]), ) .await } @@ -4519,10 +4456,7 @@ impl RpcClient { ) -> RpcResult { self.send( RpcRequest::GetTokenSupply, - json!([ - mint.to_string(), - self.maybe_map_commitment(commitment_config).await? - ]), + json!([mint.to_string(), commitment_config]), ) .await } @@ -4563,7 +4497,6 @@ impl RpcClient { config: RpcRequestAirdropConfig, ) -> ClientResult { let commitment = config.commitment.unwrap_or_default(); - let commitment = self.maybe_map_commitment(commitment).await?; let config = RpcRequestAirdropConfig { commitment: Some(commitment), ..config @@ -4786,10 +4719,7 @@ impl RpcClient { blockhash, last_valid_block_height, } = self - .send::>( - RpcRequest::GetLatestBlockhash, - json!([self.maybe_map_commitment(commitment).await?]), - ) + .send::>(RpcRequest::GetLatestBlockhash, json!([commitment])) .await? .value; let blockhash = blockhash.parse().map_err(|_| { diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 51c651b481aa71..2fa8a036cfc201 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -269,23 +269,13 @@ impl JsonRpcRequestProcessor { .slot_with_commitment(commitment.commitment); match commitment.commitment { - // Recent variant is deprecated - CommitmentLevel::Recent | CommitmentLevel::Processed => { + CommitmentLevel::Processed => { debug!("RPC using the heaviest slot: {:?}", slot); } - // Root variant is deprecated - CommitmentLevel::Root => { - debug!("RPC using node root: {:?}", slot); - } - // Single variant is deprecated - CommitmentLevel::Single => { - debug!("RPC using confirmed slot: {:?}", slot); - } - // Max variant is deprecated - CommitmentLevel::Max | CommitmentLevel::Finalized => { + CommitmentLevel::Finalized => { debug!("RPC using block: {:?}", slot); } - CommitmentLevel::SingleGossip | CommitmentLevel::Confirmed => unreachable!(), // SingleGossip variant is deprecated + CommitmentLevel::Confirmed => unreachable!(), // SingleGossip variant is deprecated }; let r_bank_forks = self.bank_forks.read().unwrap(); diff --git a/runtime/src/commitment.rs b/runtime/src/commitment.rs index 3f600a9401ae9b..632e4bda3d8505 100644 --- a/runtime/src/commitment.rs +++ b/runtime/src/commitment.rs @@ -111,16 +111,11 @@ impl BlockCommitmentCache { self.highest_confirmed_slot() } - #[allow(deprecated)] pub fn slot_with_commitment(&self, commitment_level: CommitmentLevel) -> Slot { match commitment_level { - CommitmentLevel::Recent | CommitmentLevel::Processed => self.slot(), - CommitmentLevel::Root => self.root(), - CommitmentLevel::Single => self.highest_confirmed_slot(), - CommitmentLevel::SingleGossip | CommitmentLevel::Confirmed => { - self.highest_gossip_confirmed_slot() - } - CommitmentLevel::Max | CommitmentLevel::Finalized => self.highest_super_majority_root(), + CommitmentLevel::Processed => self.slot(), + CommitmentLevel::Confirmed => self.highest_gossip_confirmed_slot(), + CommitmentLevel::Finalized => self.highest_super_majority_root(), } } diff --git a/sdk/src/commitment_config.rs b/sdk/src/commitment_config.rs index f0068659f4d7b4..7aca56b8947dbd 100644 --- a/sdk/src/commitment_config.rs +++ b/sdk/src/commitment_config.rs @@ -1,6 +1,5 @@ //! Definitions of commitment levels. -#![allow(deprecated)] #![cfg(feature = "full")] use {std::str::FromStr, thiserror::Error}; @@ -12,56 +11,6 @@ pub struct CommitmentConfig { } impl CommitmentConfig { - #[deprecated( - since = "1.5.5", - note = "Please use CommitmentConfig::processed() instead" - )] - pub fn recent() -> Self { - Self { - commitment: CommitmentLevel::Recent, - } - } - - #[deprecated( - since = "1.5.5", - note = "Please use CommitmentConfig::finalized() instead" - )] - pub fn max() -> Self { - Self { - commitment: CommitmentLevel::Max, - } - } - - #[deprecated( - since = "1.5.5", - note = "Please use CommitmentConfig::finalized() instead" - )] - pub fn root() -> Self { - Self { - commitment: CommitmentLevel::Root, - } - } - - #[deprecated( - since = "1.5.5", - note = "Please use CommitmentConfig::confirmed() instead" - )] - pub fn single() -> Self { - Self { - commitment: CommitmentLevel::Single, - } - } - - #[deprecated( - since = "1.5.5", - note = "Please use CommitmentConfig::confirmed() instead" - )] - pub fn single_gossip() -> Self { - Self { - commitment: CommitmentLevel::SingleGossip, - } - } - pub const fn finalized() -> Self { Self { commitment: CommitmentLevel::Finalized, @@ -89,37 +38,27 @@ impl CommitmentConfig { } pub fn is_finalized(&self) -> bool { - matches!( - &self.commitment, - CommitmentLevel::Finalized | CommitmentLevel::Max | CommitmentLevel::Root - ) + self.commitment == CommitmentLevel::Finalized } pub fn is_confirmed(&self) -> bool { - matches!( - &self.commitment, - CommitmentLevel::Confirmed | CommitmentLevel::SingleGossip | CommitmentLevel::Single - ) + self.commitment == CommitmentLevel::Confirmed } pub fn is_processed(&self) -> bool { - matches!( - &self.commitment, - CommitmentLevel::Processed | CommitmentLevel::Recent - ) + self.commitment == CommitmentLevel::Processed } pub fn is_at_least_confirmed(&self) -> bool { self.is_confirmed() || self.is_finalized() } + #[deprecated( + since = "2.0.2", + note = "Returns self. Please do not use. Will be removed in the future." + )] pub fn use_deprecated_commitment(commitment: CommitmentConfig) -> Self { - match commitment.commitment { - CommitmentLevel::Finalized => CommitmentConfig::max(), - CommitmentLevel::Confirmed => CommitmentConfig::single_gossip(), - CommitmentLevel::Processed => CommitmentConfig::recent(), - _ => commitment, - } + commitment } } @@ -138,48 +77,6 @@ impl FromStr for CommitmentConfig { /// finalized. When querying the ledger state, use lower levels of commitment to report progress and higher /// levels to ensure state changes will not be rolled back. pub enum CommitmentLevel { - /// (DEPRECATED) The highest slot having reached max vote lockout, as recognized by a supermajority of the cluster. - #[deprecated( - since = "1.5.5", - note = "Please use CommitmentLevel::Finalized instead" - )] - Max, - - /// (DEPRECATED) The highest slot of the heaviest fork. Ledger state at this slot is not derived from a finalized - /// block, but if multiple forks are present, is from the fork the validator believes is most likely - /// to finalize. - #[deprecated( - since = "1.5.5", - note = "Please use CommitmentLevel::Processed instead" - )] - Recent, - - /// (DEPRECATED) The highest slot having reached max vote lockout. - #[deprecated( - since = "1.5.5", - note = "Please use CommitmentLevel::Finalized instead" - )] - Root, - - /// (DEPRECATED) The highest slot having reached 1 confirmation by supermajority of the cluster. - #[deprecated( - since = "1.5.5", - note = "Please use CommitmentLevel::Confirmed instead" - )] - Single, - - /// (DEPRECATED) The highest slot that has been voted on by supermajority of the cluster - /// This differs from `single` in that: - /// 1) It incorporates votes from gossip and replay. - /// 2) It does not count votes on descendants of a block, only direct votes on that block. - /// 3) This confirmation level also upholds "optimistic confirmation" guarantees in - /// release 1.3 and onwards. - #[deprecated( - since = "1.5.5", - note = "Please use CommitmentLevel::Confirmed instead" - )] - SingleGossip, - /// The highest slot of the heaviest fork processed by the node. Ledger state at this slot is /// not derived from a confirmed or finalized block, but if multiple forks are present, is from /// the fork the validator believes is most likely to finalize. @@ -207,11 +104,6 @@ impl FromStr for CommitmentLevel { fn from_str(s: &str) -> Result { match s { - "max" => Ok(CommitmentLevel::Max), - "recent" => Ok(CommitmentLevel::Recent), - "root" => Ok(CommitmentLevel::Root), - "single" => Ok(CommitmentLevel::Single), - "singleGossip" => Ok(CommitmentLevel::SingleGossip), "processed" => Ok(CommitmentLevel::Processed), "confirmed" => Ok(CommitmentLevel::Confirmed), "finalized" => Ok(CommitmentLevel::Finalized), @@ -223,11 +115,6 @@ impl FromStr for CommitmentLevel { impl std::fmt::Display for CommitmentLevel { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { let s = match self { - CommitmentLevel::Max => "max", - CommitmentLevel::Recent => "recent", - CommitmentLevel::Root => "root", - CommitmentLevel::Single => "single", - CommitmentLevel::SingleGossip => "singleGossip", CommitmentLevel::Processed => "processed", CommitmentLevel::Confirmed => "confirmed", CommitmentLevel::Finalized => "finalized",