Skip to content

Commit

Permalink
v2.0: Remove deprecated CommitmentLevel variants (backport of solana-…
Browse files Browse the repository at this point in the history
…labs#1903) (solana-labs#1989)

Remove deprecated CommitmentLevel variants (solana-labs#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 2e3c2c7)

Co-authored-by: Tyera <tyera@anza.xyz>
  • Loading branch information
mergify[bot] and CriesofCarrots authored Jul 8, 2024
1 parent bdf39e8 commit 3aee1ea
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 240 deletions.
126 changes: 28 additions & 98 deletions rpc-client/src/nonblocking/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -550,26 +550,6 @@ impl RpcClient {
self.config.commitment_config
}

async fn use_deprecated_commitment(&self) -> Result<bool, RpcError> {
Ok(self.get_node_version().await? < semver::Version::new(1, 5, 5))
}

async fn maybe_map_commitment(
&self,
requested_commitment: CommitmentConfig,
) -> Result<CommitmentConfig, RpcError> {
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,
Expand Down Expand Up @@ -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()
},
)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1844,11 +1818,8 @@ impl RpcClient {
&self,
commitment_config: CommitmentConfig,
) -> ClientResult<Slot> {
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].
Expand Down Expand Up @@ -1908,11 +1879,8 @@ impl RpcClient {
&self,
commitment_config: CommitmentConfig,
) -> ClientResult<u64> {
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.
Expand Down Expand Up @@ -2189,11 +2157,8 @@ impl RpcClient {
&self,
commitment_config: CommitmentConfig,
) -> RpcResult<RpcSupply> {
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.
Expand Down Expand Up @@ -2235,7 +2200,6 @@ impl RpcClient {
config: RpcLargestAccountsConfig,
) -> RpcResult<Vec<RpcAccountBalance>> {
let commitment = config.commitment.unwrap_or_default();
let commitment = self.maybe_map_commitment(commitment).await?;
let config = RpcLargestAccountsConfig {
commitment: Some(commitment),
..config
Expand Down Expand Up @@ -2305,7 +2269,7 @@ impl RpcClient {
commitment_config: CommitmentConfig,
) -> ClientResult<RpcVoteAccountStatus> {
self.get_vote_accounts_with_config(RpcGetVoteAccountsConfig {
commitment: Some(self.maybe_map_commitment(commitment_config).await?),
commitment: Some(commitment_config),
..RpcGetVoteAccountsConfig::default()
})
.await
Expand Down Expand Up @@ -2646,16 +2610,9 @@ impl RpcClient {
commitment_config: CommitmentConfig,
) -> ClientResult<Vec<Slot>> {
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
}
Expand Down Expand Up @@ -2750,11 +2707,7 @@ impl RpcClient {
) -> ClientResult<Vec<Slot>> {
self.send(
RpcRequest::GetBlocksWithLimit,
json!([
start_slot,
limit,
self.maybe_map_commitment(commitment_config).await?
]),
json!([start_slot, limit, commitment_config]),
)
.await
}
Expand Down Expand Up @@ -3095,11 +3048,8 @@ impl RpcClient {
&self,
commitment_config: CommitmentConfig,
) -> ClientResult<EpochInfo> {
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.
Expand Down Expand Up @@ -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()
},
)
Expand Down Expand Up @@ -3618,7 +3568,7 @@ impl RpcClient {
) -> RpcResult<Option<Account>> {
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,
};
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -4074,10 +4024,7 @@ impl RpcClient {
) -> RpcResult<u64> {
self.send(
RpcRequest::GetBalance,
json!([
pubkey.to_string(),
self.maybe_map_commitment(commitment_config).await?
]),
json!([pubkey.to_string(), commitment_config]),
)
.await
}
Expand Down Expand Up @@ -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?);
Expand Down Expand Up @@ -4266,7 +4212,7 @@ impl RpcClient {
Ok(self
.send::<Response<u64>>(
RpcRequest::GetStakeMinimumDelegation,
json!([self.maybe_map_commitment(commitment_config).await?]),
json!([commitment_config]),
)
.await?
.value)
Expand All @@ -4282,11 +4228,8 @@ impl RpcClient {
&self,
commitment_config: CommitmentConfig,
) -> ClientResult<u64> {
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<Slot> {
Expand Down Expand Up @@ -4325,7 +4268,7 @@ impl RpcClient {
) -> RpcResult<Option<UiTokenAccount>> {
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,
};
Expand Down Expand Up @@ -4388,10 +4331,7 @@ impl RpcClient {
) -> RpcResult<UiTokenAmount> {
self.send(
RpcRequest::GetTokenAccountBalance,
json!([
pubkey.to_string(),
self.maybe_map_commitment(commitment_config).await?
]),
json!([pubkey.to_string(), commitment_config]),
)
.await
}
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -4497,10 +4437,7 @@ impl RpcClient {
) -> RpcResult<Vec<RpcTokenAccountBalance>> {
self.send(
RpcRequest::GetTokenLargestAccounts,
json!([
mint.to_string(),
self.maybe_map_commitment(commitment_config).await?
]),
json!([mint.to_string(), commitment_config]),
)
.await
}
Expand All @@ -4519,10 +4456,7 @@ impl RpcClient {
) -> RpcResult<UiTokenAmount> {
self.send(
RpcRequest::GetTokenSupply,
json!([
mint.to_string(),
self.maybe_map_commitment(commitment_config).await?
]),
json!([mint.to_string(), commitment_config]),
)
.await
}
Expand Down Expand Up @@ -4563,7 +4497,6 @@ impl RpcClient {
config: RpcRequestAirdropConfig,
) -> ClientResult<Signature> {
let commitment = config.commitment.unwrap_or_default();
let commitment = self.maybe_map_commitment(commitment).await?;
let config = RpcRequestAirdropConfig {
commitment: Some(commitment),
..config
Expand Down Expand Up @@ -4786,10 +4719,7 @@ impl RpcClient {
blockhash,
last_valid_block_height,
} = self
.send::<Response<RpcBlockhash>>(
RpcRequest::GetLatestBlockhash,
json!([self.maybe_map_commitment(commitment).await?]),
)
.send::<Response<RpcBlockhash>>(RpcRequest::GetLatestBlockhash, json!([commitment]))
.await?
.value;
let blockhash = blockhash.parse().map_err(|_| {
Expand Down
16 changes: 3 additions & 13 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 3 additions & 8 deletions runtime/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down
Loading

0 comments on commit 3aee1ea

Please sign in to comment.