From 2e3c2c78e94fc7614dbf5899c5dc27a20e60f4c9 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 --- 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 9194012224d4f0..8282dbfd5b5cf8 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. @@ -2187,11 +2155,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. @@ -2233,7 +2198,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 @@ -2303,7 +2267,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 @@ -2644,16 +2608,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 } @@ -2748,11 +2705,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 } @@ -3093,11 +3046,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. @@ -3170,7 +3120,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() }, ) @@ -3616,7 +3566,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, }; @@ -3843,7 +3793,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, }, @@ -4072,10 +4022,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 } @@ -4195,7 +4142,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?); @@ -4264,7 +4210,7 @@ impl RpcClient { Ok(self .send::>( RpcRequest::GetStakeMinimumDelegation, - json!([self.maybe_map_commitment(commitment_config).await?]), + json!([commitment_config]), ) .await? .value) @@ -4280,11 +4226,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 { @@ -4323,7 +4266,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, }; @@ -4386,10 +4329,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 } @@ -4424,7 +4364,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, }; @@ -4466,7 +4406,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, }; @@ -4495,10 +4435,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 } @@ -4517,10 +4454,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 } @@ -4561,7 +4495,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 @@ -4784,10 +4717,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",