Deprecate commitment variants (#14797)

* 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
This commit is contained in:
Tyera Eulberg
2021-01-26 12:23:07 -07:00
committed by GitHub
parent e08d2e6fcc
commit ffa5c7dcc8
37 changed files with 540 additions and 322 deletions

View File

@ -139,16 +139,14 @@ pub struct JsonRpcRequestProcessor {
impl Metadata for JsonRpcRequestProcessor {}
impl JsonRpcRequestProcessor {
#[allow(deprecated)]
fn bank(&self, commitment: Option<CommitmentConfig>) -> Arc<Bank> {
debug!("RPC commitment_config: {:?}", commitment);
let r_bank_forks = self.bank_forks.read().unwrap();
let commitment_level = match commitment {
None => CommitmentLevel::Max,
Some(config) => config.commitment,
};
let commitment = commitment.unwrap_or_default();
if commitment_level == CommitmentLevel::SingleGossip {
if commitment.is_confirmed() {
let bank = self
.optimistically_confirmed_bank
.read()
@ -163,22 +161,26 @@ impl JsonRpcRequestProcessor {
.block_commitment_cache
.read()
.unwrap()
.slot_with_commitment(commitment_level);
.slot_with_commitment(commitment.commitment);
match commitment_level {
CommitmentLevel::Recent => {
match commitment.commitment {
// Recent variant is deprecated
CommitmentLevel::Recent | 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);
}
CommitmentLevel::Max => {
// Max variant is deprecated
CommitmentLevel::Max | CommitmentLevel::Finalized => {
debug!("RPC using block: {:?}", slot);
}
CommitmentLevel::SingleGossip => unreachable!(),
CommitmentLevel::SingleGossip | CommitmentLevel::Confirmed => unreachable!(), // SingleGossip variant is deprecated
};
r_bank_forks.get(slot).cloned().unwrap_or_else(|| {
@ -195,7 +197,7 @@ impl JsonRpcRequestProcessor {
// For more information, see https://github.com/solana-labs/solana/issues/11078
warn!(
"Bank with {:?} not found at slot: {:?}",
commitment_level, slot
commitment.commitment, slot
);
r_bank_forks.root_bank()
})
@ -380,7 +382,7 @@ impl JsonRpcRequestProcessor {
pub fn get_epoch_schedule(&self) -> EpochSchedule {
// Since epoch schedule data comes from the genesis config, any commitment level should be
// fine
let bank = self.bank(Some(CommitmentConfig::root()));
let bank = self.bank(Some(CommitmentConfig::finalized()));
*bank.epoch_schedule()
}
@ -873,7 +875,7 @@ impl JsonRpcRequestProcessor {
let search_transaction_history = config
.map(|x| x.search_transaction_history)
.unwrap_or(false);
let bank = self.bank(Some(CommitmentConfig::recent()));
let bank = self.bank(Some(CommitmentConfig::processed()));
for signature in signatures {
let status = if let Some(status) = self.get_transaction_status(signature, &bank) {
@ -925,7 +927,7 @@ impl JsonRpcRequestProcessor {
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(Some(CommitmentConfig::single_gossip()));
let optimistically_confirmed_bank = self.bank(Some(CommitmentConfig::confirmed()));
let optimistically_confirmed =
optimistically_confirmed_bank.get_signature_status_slot(&signature);
@ -5376,7 +5378,7 @@ pub mod tests {
let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getVoteAccounts","params":{}}}"#,
json!([CommitmentConfig::recent()])
json!([CommitmentConfig::processed()])
);
let res = io.handle_request_sync(&req, meta.clone());
@ -5422,7 +5424,7 @@ pub mod tests {
{
let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getVoteAccounts","params":{}}}"#,
json!([CommitmentConfig::recent()])
json!([CommitmentConfig::processed()])
);
let res = io.handle_request_sync(&req, meta);
@ -6110,7 +6112,8 @@ pub mod tests {
let mut io = MetaIoHandler::default();
io.extend_with(RpcSolImpl.to_delegate());
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment":"singleGossip"}]}"#;
let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment":"confirmed"}]}"#;
let res = io.handle_request_sync(req, meta.clone());
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
let slot: Slot = serde_json::from_value(json["result"].clone()).unwrap();
@ -6123,7 +6126,8 @@ pub mod tests {
&subscriptions,
&mut pending_optimistically_confirmed_banks,
);
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "singleGossip"}]}"#;
let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
let res = io.handle_request_sync(&req, meta.clone());
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
let slot: Slot = serde_json::from_value(json["result"].clone()).unwrap();
@ -6137,7 +6141,8 @@ pub mod tests {
&subscriptions,
&mut pending_optimistically_confirmed_banks,
);
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "singleGossip"}]}"#;
let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
let res = io.handle_request_sync(&req, meta.clone());
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
let slot: Slot = serde_json::from_value(json["result"].clone()).unwrap();
@ -6151,7 +6156,8 @@ pub mod tests {
&subscriptions,
&mut pending_optimistically_confirmed_banks,
);
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "singleGossip"}]}"#;
let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
let res = io.handle_request_sync(&req, meta.clone());
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
let slot: Slot = serde_json::from_value(json["result"].clone()).unwrap();
@ -6166,7 +6172,8 @@ pub mod tests {
&subscriptions,
&mut pending_optimistically_confirmed_banks,
);
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "singleGossip"}]}"#;
let req =
r#"{"jsonrpc":"2.0","id":1,"method":"getSlot","params":[{"commitment": "confirmed"}]}"#;
let res = io.handle_request_sync(&req, meta);
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
let slot: Slot = serde_json::from_value(json["result"].clone()).unwrap();

View File

@ -579,7 +579,7 @@ mod tests {
subscriber,
tx.signatures[0].to_string(),
Some(RpcSignatureSubscribeConfig {
commitment: Some(CommitmentConfig::single()),
commitment: Some(CommitmentConfig::finalized()),
..RpcSignatureSubscribeConfig::default()
}),
);
@ -612,7 +612,7 @@ mod tests {
subscriber,
tx.signatures[0].to_string(),
Some(RpcSignatureSubscribeConfig {
commitment: Some(CommitmentConfig::single()),
commitment: Some(CommitmentConfig::finalized()),
enable_received_notification: Some(true),
}),
);
@ -721,7 +721,7 @@ mod tests {
subscriber,
stake_account.pubkey().to_string(),
Some(RpcAccountInfoConfig {
commitment: Some(CommitmentConfig::recent()),
commitment: Some(CommitmentConfig::processed()),
encoding: None,
data_slice: None,
}),
@ -830,7 +830,7 @@ mod tests {
subscriber,
nonce_account.pubkey().to_string(),
Some(RpcAccountInfoConfig {
commitment: Some(CommitmentConfig::recent()),
commitment: Some(CommitmentConfig::processed()),
encoding: Some(UiAccountEncoding::JsonParsed),
data_slice: None,
}),
@ -952,7 +952,7 @@ mod tests {
subscriber,
bob.pubkey().to_string(),
Some(RpcAccountInfoConfig {
commitment: Some(CommitmentConfig::root()),
commitment: Some(CommitmentConfig::finalized()),
encoding: None,
data_slice: None,
}),
@ -1006,7 +1006,7 @@ mod tests {
subscriber,
bob.pubkey().to_string(),
Some(RpcAccountInfoConfig {
commitment: Some(CommitmentConfig::root()),
commitment: Some(CommitmentConfig::finalized()),
encoding: None,
data_slice: None,
}),

View File

@ -31,7 +31,7 @@ use solana_runtime::{
use solana_sdk::{
account::Account,
clock::{Slot, UnixTimestamp},
commitment_config::{CommitmentConfig, CommitmentLevel},
commitment_config::CommitmentConfig,
pubkey::Pubkey,
signature::Signature,
transaction,
@ -227,14 +227,14 @@ where
},
) in hashmap.iter()
{
let slot = match commitment.commitment {
CommitmentLevel::Max => commitment_slots.highest_confirmed_root,
CommitmentLevel::Recent => commitment_slots.slot,
CommitmentLevel::Root => commitment_slots.root,
CommitmentLevel::Single | CommitmentLevel::SingleGossip => {
commitment_slots.highest_confirmed_slot
}
let slot = if commitment.is_finalized() {
commitment_slots.highest_confirmed_root
} else if commitment.is_confirmed() {
commitment_slots.highest_confirmed_slot
} else {
commitment_slots.slot
};
if let Some(bank) = bank_forks.read().unwrap().get(slot).cloned() {
let results = bank_method(&bank, hashmap_key);
let mut w_last_notified_slot = last_notified_slot.write().unwrap();
@ -636,28 +636,23 @@ impl RpcSubscriptions {
let config = config.unwrap_or_default();
let commitment = config
.commitment
.unwrap_or_else(CommitmentConfig::single_gossip);
.unwrap_or_else(CommitmentConfig::confirmed);
let slot = match commitment.commitment {
CommitmentLevel::Max => self
.block_commitment_cache
let slot = if commitment.is_finalized() {
self.block_commitment_cache
.read()
.unwrap()
.highest_confirmed_root(),
CommitmentLevel::Recent => self.block_commitment_cache.read().unwrap().slot(),
CommitmentLevel::Root => self.block_commitment_cache.read().unwrap().root(),
CommitmentLevel::Single => self
.block_commitment_cache
.read()
.unwrap()
.highest_confirmed_slot(),
CommitmentLevel::SingleGossip => self
.optimistically_confirmed_bank
.highest_confirmed_root()
} else if commitment.is_confirmed() {
self.optimistically_confirmed_bank
.read()
.unwrap()
.bank
.slot(),
.slot()
} else {
self.block_commitment_cache.read().unwrap().slot()
};
let last_notified_slot = if let Some((_account, slot)) = self
.bank_forks
.read()
@ -670,7 +665,7 @@ impl RpcSubscriptions {
0
};
let mut subscriptions = if commitment.commitment == CommitmentLevel::SingleGossip {
let mut subscriptions = if commitment.is_confirmed() {
self.subscriptions
.gossip_account_subscriptions
.write()
@ -715,9 +710,9 @@ impl RpcSubscriptions {
let commitment = config
.account_config
.commitment
.unwrap_or_else(CommitmentConfig::single_gossip);
.unwrap_or_else(CommitmentConfig::confirmed);
let mut subscriptions = if commitment.commitment == CommitmentLevel::SingleGossip {
let mut subscriptions = if commitment.is_confirmed() {
self.subscriptions
.gossip_program_subscriptions
.write()
@ -762,10 +757,10 @@ impl RpcSubscriptions {
sub_id: SubscriptionId,
subscriber: Subscriber<Response<RpcLogsResponse>>,
) {
let commitment = commitment.unwrap_or_else(CommitmentConfig::single_gossip);
let commitment = commitment.unwrap_or_else(CommitmentConfig::confirmed);
{
let mut subscriptions = if commitment.commitment == CommitmentLevel::SingleGossip {
let mut subscriptions = if commitment.is_confirmed() {
self.subscriptions
.gossip_logs_subscriptions
.write()
@ -873,9 +868,9 @@ impl RpcSubscriptions {
.map(|config| (config.commitment, config.enable_received_notification))
.unwrap_or_default();
let commitment = commitment.unwrap_or_else(CommitmentConfig::single_gossip);
let commitment = commitment.unwrap_or_else(CommitmentConfig::confirmed);
let mut subscriptions = if commitment.commitment == CommitmentLevel::SingleGossip {
let mut subscriptions = if commitment.is_confirmed() {
self.subscriptions
.gossip_signature_subscriptions
.write()
@ -915,7 +910,7 @@ impl RpcSubscriptions {
self.enqueue_notification(NotificationEntry::Bank(commitment_slots));
}
/// Notify SingleGossip commitment-level subscribers of changes to any accounts or new
/// Notify Confirmed commitment-level subscribers of changes to any accounts or new
/// signatures.
pub fn notify_gossip_subscribers(&self, slot: Slot) {
self.enqueue_notification(NotificationEntry::Gossip(slot));
@ -1374,7 +1369,7 @@ pub(crate) mod tests {
subscriptions.add_account_subscription(
alice.pubkey(),
Some(RpcAccountInfoConfig {
commitment: Some(CommitmentConfig::recent()),
commitment: Some(CommitmentConfig::processed()),
encoding: None,
data_slice: None,
}),
@ -1433,7 +1428,7 @@ pub(crate) mod tests {
subscriptions.add_account_subscription(
alice.pubkey(),
Some(RpcAccountInfoConfig {
commitment: Some(CommitmentConfig::recent()),
commitment: Some(CommitmentConfig::processed()),
encoding: None,
data_slice: None,
}),
@ -1529,7 +1524,7 @@ pub(crate) mod tests {
solana_stake_program::id(),
Some(RpcProgramAccountsConfig {
account_config: RpcAccountInfoConfig {
commitment: Some(CommitmentConfig::recent()),
commitment: Some(CommitmentConfig::processed()),
..RpcAccountInfoConfig::default()
},
..RpcProgramAccountsConfig::default()
@ -1658,7 +1653,7 @@ pub(crate) mod tests {
subscriptions.add_signature_subscription(
past_bank_tx.signatures[0],
Some(RpcSignatureSubscribeConfig {
commitment: Some(CommitmentConfig::recent()),
commitment: Some(CommitmentConfig::processed()),
enable_received_notification: Some(false),
}),
SubscriptionId::Number(1),
@ -1667,7 +1662,7 @@ pub(crate) mod tests {
subscriptions.add_signature_subscription(
past_bank_tx.signatures[0],
Some(RpcSignatureSubscribeConfig {
commitment: Some(CommitmentConfig::root()),
commitment: Some(CommitmentConfig::finalized()),
enable_received_notification: Some(false),
}),
SubscriptionId::Number(2),
@ -1676,7 +1671,7 @@ pub(crate) mod tests {
subscriptions.add_signature_subscription(
processed_tx.signatures[0],
Some(RpcSignatureSubscribeConfig {
commitment: Some(CommitmentConfig::recent()),
commitment: Some(CommitmentConfig::processed()),
enable_received_notification: Some(false),
}),
SubscriptionId::Number(3),
@ -1685,7 +1680,7 @@ pub(crate) mod tests {
subscriptions.add_signature_subscription(
unprocessed_tx.signatures[0],
Some(RpcSignatureSubscribeConfig {
commitment: Some(CommitmentConfig::recent()),
commitment: Some(CommitmentConfig::processed()),
enable_received_notification: Some(false),
}),
SubscriptionId::Number(4),
@ -1695,7 +1690,7 @@ pub(crate) mod tests {
subscriptions.add_signature_subscription(
unprocessed_tx.signatures[0],
Some(RpcSignatureSubscribeConfig {
commitment: Some(CommitmentConfig::recent()),
commitment: Some(CommitmentConfig::processed()),
enable_received_notification: Some(true),
}),
SubscriptionId::Number(5),
@ -1892,7 +1887,7 @@ pub(crate) mod tests {
fn test_add_and_remove_subscription() {
let mut subscriptions: HashMap<u64, HashMap<SubscriptionId, SubscriptionData<(), ()>>> =
HashMap::new();
let commitment = CommitmentConfig::single_gossip();
let commitment = CommitmentConfig::confirmed();
let num_keys = 5;
for key in 0..num_keys {
@ -1982,7 +1977,7 @@ pub(crate) mod tests {
subscriptions.add_account_subscription(
alice.pubkey(),
Some(RpcAccountInfoConfig {
commitment: Some(CommitmentConfig::single_gossip()),
commitment: Some(CommitmentConfig::confirmed()),
encoding: None,
data_slice: None,
}),
@ -2063,7 +2058,7 @@ pub(crate) mod tests {
subscriptions.add_account_subscription(
alice.pubkey(),
Some(RpcAccountInfoConfig {
commitment: Some(CommitmentConfig::single_gossip()),
commitment: Some(CommitmentConfig::confirmed()),
encoding: None,
data_slice: None,
}),

View File

@ -416,7 +416,7 @@ impl TestValidator {
// due to a bug in the Bank)
{
let rpc_client =
RpcClient::new_with_commitment(rpc_url.clone(), CommitmentConfig::recent());
RpcClient::new_with_commitment(rpc_url.clone(), CommitmentConfig::processed());
let fee_rate_governor = rpc_client
.get_fee_rate_governor()
.expect("get_fee_rate_governor")
@ -475,7 +475,7 @@ impl TestValidator {
/// associated fee calculator
pub fn rpc_client(&self) -> (RpcClient, Hash, FeeCalculator) {
let rpc_client =
RpcClient::new_with_commitment(self.rpc_url.clone(), CommitmentConfig::recent());
RpcClient::new_with_commitment(self.rpc_url.clone(), CommitmentConfig::processed());
let (recent_blockhash, fee_calculator) = rpc_client
.get_recent_blockhash()
.expect("get_recent_blockhash");

View File

@ -498,7 +498,7 @@ impl Validator {
};
if config.dev_halt_at_slot.is_some() {
// Simulate a confirmed root to avoid RPC errors with CommitmentConfig::max() and
// Simulate a confirmed root to avoid RPC errors with CommitmentConfig::finalized() and
// to ensure RPC endpoints like getConfirmedBlock, which require a confirmed root, work
block_commitment_cache
.write()