Rename CacheSlotInfo to CommitmentSlots (#11111)
This commit is contained in:
parent
d0d4d9b3d1
commit
a255b0fc86
|
@ -3,7 +3,7 @@ use solana_measure::measure::Measure;
|
|||
use solana_metrics::datapoint_info;
|
||||
use solana_runtime::{
|
||||
bank::Bank,
|
||||
commitment::{BlockCommitment, BlockCommitmentCache, CacheSlotInfo, VOTE_THRESHOLD_SIZE},
|
||||
commitment::{BlockCommitment, BlockCommitmentCache, CommitmentSlots, VOTE_THRESHOLD_SIZE},
|
||||
};
|
||||
use solana_sdk::clock::Slot;
|
||||
use solana_vote_program::vote_state::VoteState;
|
||||
|
@ -112,7 +112,7 @@ impl AggregateCommitmentService {
|
|||
let mut new_block_commitment = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
aggregation_data.total_stake,
|
||||
CacheSlotInfo {
|
||||
CommitmentSlots {
|
||||
slot: aggregation_data.bank.slot(),
|
||||
root: aggregation_data.root,
|
||||
highest_confirmed_slot: aggregation_data.root,
|
||||
|
@ -138,7 +138,7 @@ impl AggregateCommitmentService {
|
|||
// Triggers rpc_subscription notifications as soon as new commitment data is available,
|
||||
// sending just the commitment cache slot information that the notifications thread
|
||||
// needs
|
||||
subscriptions.notify_subscribers(w_block_commitment_cache.slot_info());
|
||||
subscriptions.notify_subscribers(w_block_commitment_cache.commitment_slots());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ use solana_runtime::{
|
|||
accounts::AccountAddressFilter,
|
||||
bank::Bank,
|
||||
bank_forks::BankForks,
|
||||
commitment::{BlockCommitmentArray, BlockCommitmentCache, CacheSlotInfo},
|
||||
commitment::{BlockCommitmentArray, BlockCommitmentCache, CommitmentSlots},
|
||||
log_collector::LogCollector,
|
||||
send_transaction_service::{SendTransactionService, TransactionInfo},
|
||||
};
|
||||
|
@ -192,7 +192,7 @@ impl JsonRpcRequestProcessor {
|
|||
block_commitment_cache: Arc::new(RwLock::new(BlockCommitmentCache::new(
|
||||
HashMap::new(),
|
||||
0,
|
||||
CacheSlotInfo {
|
||||
CommitmentSlots {
|
||||
slot: bank.slot(),
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
|
@ -1819,7 +1819,7 @@ pub mod tests {
|
|||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
10,
|
||||
CacheSlotInfo {
|
||||
CommitmentSlots {
|
||||
slot: bank.slot(),
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
|
@ -3334,7 +3334,7 @@ pub mod tests {
|
|||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
42,
|
||||
CacheSlotInfo {
|
||||
CommitmentSlots {
|
||||
slot: bank_forks.read().unwrap().highest_slot(),
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
|
@ -3863,7 +3863,7 @@ pub mod tests {
|
|||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
50,
|
||||
CacheSlotInfo {
|
||||
CommitmentSlots {
|
||||
slot: bank.slot(),
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
|
|
|
@ -359,7 +359,7 @@ mod tests {
|
|||
use solana_runtime::{
|
||||
bank::Bank,
|
||||
bank_forks::BankForks,
|
||||
commitment::{BlockCommitmentCache, CacheSlotInfo},
|
||||
commitment::{BlockCommitmentCache, CommitmentSlots},
|
||||
genesis_utils::{
|
||||
create_genesis_config, create_genesis_config_with_vote_accounts, GenesisConfigInfo,
|
||||
ValidatorVoteKeypairs,
|
||||
|
@ -392,9 +392,9 @@ mod tests {
|
|||
.get(current_slot)
|
||||
.unwrap()
|
||||
.process_transaction(tx)?;
|
||||
let mut cache_slot_info = CacheSlotInfo::default();
|
||||
cache_slot_info.slot = current_slot;
|
||||
subscriptions.notify_subscribers(cache_slot_info);
|
||||
let mut commitment_slots = CommitmentSlots::default();
|
||||
commitment_slots.slot = current_slot;
|
||||
subscriptions.notify_subscribers(commitment_slots);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -687,7 +687,7 @@ mod tests {
|
|||
.process_transaction(&tx)
|
||||
.unwrap();
|
||||
rpc.subscriptions
|
||||
.notify_subscribers(CacheSlotInfo::default());
|
||||
.notify_subscribers(CommitmentSlots::default());
|
||||
// allow 200ms for notification thread to wake
|
||||
std::thread::sleep(Duration::from_millis(200));
|
||||
let _panic = robust_poll_or_panic(receiver);
|
||||
|
@ -732,17 +732,17 @@ mod tests {
|
|||
.unwrap()
|
||||
.process_transaction(&tx)
|
||||
.unwrap();
|
||||
let mut cache_slot_info = CacheSlotInfo::default();
|
||||
cache_slot_info.slot = 1;
|
||||
rpc.subscriptions.notify_subscribers(cache_slot_info);
|
||||
let mut commitment_slots = CommitmentSlots::default();
|
||||
commitment_slots.slot = 1;
|
||||
rpc.subscriptions.notify_subscribers(commitment_slots);
|
||||
|
||||
let cache_slot_info = CacheSlotInfo {
|
||||
let commitment_slots = CommitmentSlots {
|
||||
slot: 2,
|
||||
root: 1,
|
||||
highest_confirmed_slot: 1,
|
||||
highest_confirmed_root: 1,
|
||||
};
|
||||
rpc.subscriptions.notify_subscribers(cache_slot_info);
|
||||
rpc.subscriptions.notify_subscribers(commitment_slots);
|
||||
let expected = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "accountNotification",
|
||||
|
|
|
@ -14,7 +14,7 @@ use solana_client::rpc_response::{
|
|||
use solana_runtime::{
|
||||
bank::Bank,
|
||||
bank_forks::BankForks,
|
||||
commitment::{BlockCommitmentCache, CacheSlotInfo},
|
||||
commitment::{BlockCommitmentCache, CommitmentSlots},
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
|
@ -60,7 +60,7 @@ enum NotificationEntry {
|
|||
Vote(Vote),
|
||||
Root(Slot),
|
||||
Frozen(Slot),
|
||||
Bank(CacheSlotInfo),
|
||||
Bank(CommitmentSlots),
|
||||
Gossip(Slot),
|
||||
}
|
||||
|
||||
|
@ -71,8 +71,8 @@ impl std::fmt::Debug for NotificationEntry {
|
|||
NotificationEntry::Frozen(slot) => write!(f, "Frozen({})", slot),
|
||||
NotificationEntry::Vote(vote) => write!(f, "Vote({:?})", vote),
|
||||
NotificationEntry::Slot(slot_info) => write!(f, "Slot({:?})", slot_info),
|
||||
NotificationEntry::Bank(cache_slot_info) => {
|
||||
write!(f, "Bank({{slot: {:?}}})", cache_slot_info.slot)
|
||||
NotificationEntry::Bank(commitment_slots) => {
|
||||
write!(f, "Bank({{slot: {:?}}})", commitment_slots.slot)
|
||||
}
|
||||
NotificationEntry::Gossip(slot) => write!(f, "Gossip({:?})", slot),
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ fn check_commitment_and_notify<K, S, B, F, X>(
|
|||
subscriptions: &HashMap<K, HashMap<SubscriptionId, SubscriptionData<Response<S>>>>,
|
||||
hashmap_key: &K,
|
||||
bank_forks: &Arc<RwLock<BankForks>>,
|
||||
cache_slot_info: &CacheSlotInfo,
|
||||
commitment_slots: &CommitmentSlots,
|
||||
bank_method: B,
|
||||
filter_results: F,
|
||||
notifier: &RpcNotifier,
|
||||
|
@ -173,11 +173,11 @@ where
|
|||
) in hashmap.iter()
|
||||
{
|
||||
let slot = match commitment.commitment {
|
||||
CommitmentLevel::Max => cache_slot_info.highest_confirmed_root,
|
||||
CommitmentLevel::Recent => cache_slot_info.slot,
|
||||
CommitmentLevel::Root => cache_slot_info.root,
|
||||
CommitmentLevel::Max => commitment_slots.highest_confirmed_root,
|
||||
CommitmentLevel::Recent => commitment_slots.slot,
|
||||
CommitmentLevel::Root => commitment_slots.root,
|
||||
CommitmentLevel::Single | CommitmentLevel::SingleGossip => {
|
||||
cache_slot_info.highest_confirmed_slot
|
||||
commitment_slots.highest_confirmed_slot
|
||||
}
|
||||
};
|
||||
let results = {
|
||||
|
@ -387,14 +387,14 @@ impl RpcSubscriptions {
|
|||
bank_forks: &Arc<RwLock<BankForks>>,
|
||||
account_subscriptions: Arc<RpcAccountSubscriptions>,
|
||||
notifier: &RpcNotifier,
|
||||
cache_slot_info: &CacheSlotInfo,
|
||||
commitment_slots: &CommitmentSlots,
|
||||
) {
|
||||
let subscriptions = account_subscriptions.read().unwrap();
|
||||
check_commitment_and_notify(
|
||||
&subscriptions,
|
||||
pubkey,
|
||||
bank_forks,
|
||||
cache_slot_info,
|
||||
commitment_slots,
|
||||
Bank::get_account_modified_slot,
|
||||
filter_account_result,
|
||||
notifier,
|
||||
|
@ -406,14 +406,14 @@ impl RpcSubscriptions {
|
|||
bank_forks: &Arc<RwLock<BankForks>>,
|
||||
program_subscriptions: Arc<RpcProgramSubscriptions>,
|
||||
notifier: &RpcNotifier,
|
||||
cache_slot_info: &CacheSlotInfo,
|
||||
commitment_slots: &CommitmentSlots,
|
||||
) {
|
||||
let subscriptions = program_subscriptions.read().unwrap();
|
||||
check_commitment_and_notify(
|
||||
&subscriptions,
|
||||
program_id,
|
||||
bank_forks,
|
||||
cache_slot_info,
|
||||
commitment_slots,
|
||||
Bank::get_program_accounts_modified_since_parent,
|
||||
filter_program_results,
|
||||
notifier,
|
||||
|
@ -425,14 +425,14 @@ impl RpcSubscriptions {
|
|||
bank_forks: &Arc<RwLock<BankForks>>,
|
||||
signature_subscriptions: Arc<RpcSignatureSubscriptions>,
|
||||
notifier: &RpcNotifier,
|
||||
cache_slot_info: &CacheSlotInfo,
|
||||
commitment_slots: &CommitmentSlots,
|
||||
) {
|
||||
let mut subscriptions = signature_subscriptions.write().unwrap();
|
||||
let notified_ids = check_commitment_and_notify(
|
||||
&subscriptions,
|
||||
signature,
|
||||
bank_forks,
|
||||
cache_slot_info,
|
||||
commitment_slots,
|
||||
Bank::get_signature_status_processed_since_parent,
|
||||
filter_signature_result,
|
||||
notifier,
|
||||
|
@ -605,8 +605,8 @@ impl RpcSubscriptions {
|
|||
|
||||
/// Notify subscribers of changes to any accounts or new signatures since
|
||||
/// the bank's last checkpoint.
|
||||
pub fn notify_subscribers(&self, cache_slot_info: CacheSlotInfo) {
|
||||
self.enqueue_notification(NotificationEntry::Bank(cache_slot_info));
|
||||
pub fn notify_subscribers(&self, commitment_slots: CommitmentSlots) {
|
||||
self.enqueue_notification(NotificationEntry::Bank(commitment_slots));
|
||||
}
|
||||
|
||||
/// Notify SingleGossip commitment-level subscribers of changes to any accounts or new
|
||||
|
@ -730,13 +730,13 @@ impl RpcSubscriptions {
|
|||
.filter(|&s| s > root)
|
||||
.collect();
|
||||
}
|
||||
NotificationEntry::Bank(cache_slot_info) => {
|
||||
NotificationEntry::Bank(commitment_slots) => {
|
||||
RpcSubscriptions::notify_accounts_programs_signatures(
|
||||
&subscriptions.account_subscriptions,
|
||||
&subscriptions.program_subscriptions,
|
||||
&subscriptions.signature_subscriptions,
|
||||
&bank_forks,
|
||||
&cache_slot_info,
|
||||
&commitment_slots,
|
||||
¬ifier,
|
||||
)
|
||||
}
|
||||
|
@ -805,16 +805,16 @@ impl RpcSubscriptions {
|
|||
|
||||
drop(last_checked_slots_lock);
|
||||
|
||||
let cache_slot_info = CacheSlotInfo {
|
||||
let commitment_slots = CommitmentSlots {
|
||||
highest_confirmed_slot: slot,
|
||||
..CacheSlotInfo::default()
|
||||
..CommitmentSlots::default()
|
||||
};
|
||||
RpcSubscriptions::notify_accounts_programs_signatures(
|
||||
&subscriptions.gossip_account_subscriptions,
|
||||
&subscriptions.gossip_program_subscriptions,
|
||||
&subscriptions.gossip_signature_subscriptions,
|
||||
&bank_forks,
|
||||
&cache_slot_info,
|
||||
&commitment_slots,
|
||||
¬ifier,
|
||||
);
|
||||
}
|
||||
|
@ -824,7 +824,7 @@ impl RpcSubscriptions {
|
|||
program_subscriptions: &Arc<RpcProgramSubscriptions>,
|
||||
signature_subscriptions: &Arc<RpcSignatureSubscriptions>,
|
||||
bank_forks: &Arc<RwLock<BankForks>>,
|
||||
cache_slot_info: &CacheSlotInfo,
|
||||
commitment_slots: &CommitmentSlots,
|
||||
notifier: &RpcNotifier,
|
||||
) {
|
||||
let pubkeys: Vec<_> = {
|
||||
|
@ -837,7 +837,7 @@ impl RpcSubscriptions {
|
|||
&bank_forks,
|
||||
account_subscriptions.clone(),
|
||||
¬ifier,
|
||||
&cache_slot_info,
|
||||
&commitment_slots,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -851,7 +851,7 @@ impl RpcSubscriptions {
|
|||
&bank_forks,
|
||||
program_subscriptions.clone(),
|
||||
¬ifier,
|
||||
&cache_slot_info,
|
||||
&commitment_slots,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -865,7 +865,7 @@ impl RpcSubscriptions {
|
|||
&bank_forks,
|
||||
signature_subscriptions.clone(),
|
||||
¬ifier,
|
||||
&cache_slot_info,
|
||||
&commitment_slots,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -988,9 +988,9 @@ pub(crate) mod tests {
|
|||
.unwrap()
|
||||
.process_transaction(&tx)
|
||||
.unwrap();
|
||||
let mut cache_slot_info = CacheSlotInfo::default();
|
||||
cache_slot_info.slot = 1;
|
||||
subscriptions.notify_subscribers(cache_slot_info);
|
||||
let mut commitment_slots = CommitmentSlots::default();
|
||||
commitment_slots.slot = 1;
|
||||
subscriptions.notify_subscribers(commitment_slots);
|
||||
let (response, _) = robust_poll_or_panic(transport_receiver);
|
||||
let expected = json!({
|
||||
"jsonrpc": "2.0",
|
||||
|
@ -1071,7 +1071,7 @@ pub(crate) mod tests {
|
|||
.unwrap()
|
||||
.contains_key(&solana_budget_program::id()));
|
||||
|
||||
subscriptions.notify_subscribers(CacheSlotInfo::default());
|
||||
subscriptions.notify_subscribers(CommitmentSlots::default());
|
||||
let (response, _) = robust_poll_or_panic(transport_receiver);
|
||||
let expected = json!({
|
||||
"jsonrpc": "2.0",
|
||||
|
@ -1153,7 +1153,7 @@ pub(crate) mod tests {
|
|||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
10,
|
||||
CacheSlotInfo {
|
||||
CommitmentSlots {
|
||||
slot: bank1.slot(),
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
|
@ -1210,9 +1210,9 @@ pub(crate) mod tests {
|
|||
assert!(sig_subs.contains_key(&unprocessed_tx.signatures[0]));
|
||||
assert!(sig_subs.contains_key(&processed_tx.signatures[0]));
|
||||
}
|
||||
let mut cache_slot_info = CacheSlotInfo::default();
|
||||
cache_slot_info.slot = 1;
|
||||
subscriptions.notify_subscribers(cache_slot_info);
|
||||
let mut commitment_slots = CommitmentSlots::default();
|
||||
commitment_slots.slot = 1;
|
||||
subscriptions.notify_subscribers(commitment_slots);
|
||||
let expected_res = RpcSignatureResult { err: None };
|
||||
|
||||
struct Notification {
|
||||
|
|
|
@ -43,7 +43,7 @@ pub struct BlockCommitmentCache {
|
|||
block_commitment: HashMap<Slot, BlockCommitment>,
|
||||
/// Cache slot details. Cluster data is calculated from the block_commitment map, and cached in
|
||||
/// the struct to avoid the expense of recalculating on every call.
|
||||
slot_info: CacheSlotInfo,
|
||||
commitment_slots: CommitmentSlots,
|
||||
/// Total stake active during the bank's epoch
|
||||
total_stake: u64,
|
||||
}
|
||||
|
@ -55,9 +55,9 @@ impl std::fmt::Debug for BlockCommitmentCache {
|
|||
.field("total_stake", &self.total_stake)
|
||||
.field(
|
||||
"bank",
|
||||
&format_args!("Bank({{current_slot: {:?}}})", self.slot_info.slot),
|
||||
&format_args!("Bank({{current_slot: {:?}}})", self.commitment_slots.slot),
|
||||
)
|
||||
.field("root", &self.slot_info.root)
|
||||
.field("root", &self.commitment_slots.root)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
@ -66,12 +66,12 @@ impl BlockCommitmentCache {
|
|||
pub fn new(
|
||||
block_commitment: HashMap<Slot, BlockCommitment>,
|
||||
total_stake: u64,
|
||||
slot_info: CacheSlotInfo,
|
||||
commitment_slots: CommitmentSlots,
|
||||
) -> Self {
|
||||
Self {
|
||||
block_commitment,
|
||||
total_stake,
|
||||
slot_info,
|
||||
commitment_slots,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,23 +84,23 @@ impl BlockCommitmentCache {
|
|||
}
|
||||
|
||||
pub fn slot(&self) -> Slot {
|
||||
self.slot_info.slot
|
||||
self.commitment_slots.slot
|
||||
}
|
||||
|
||||
pub fn root(&self) -> Slot {
|
||||
self.slot_info.root
|
||||
self.commitment_slots.root
|
||||
}
|
||||
|
||||
pub fn highest_confirmed_slot(&self) -> Slot {
|
||||
self.slot_info.highest_confirmed_slot
|
||||
self.commitment_slots.highest_confirmed_slot
|
||||
}
|
||||
|
||||
pub fn highest_confirmed_root(&self) -> Slot {
|
||||
self.slot_info.highest_confirmed_root
|
||||
self.commitment_slots.highest_confirmed_root
|
||||
}
|
||||
|
||||
pub fn slot_info(&self) -> CacheSlotInfo {
|
||||
self.slot_info
|
||||
pub fn commitment_slots(&self) -> CommitmentSlots {
|
||||
self.commitment_slots
|
||||
}
|
||||
|
||||
fn highest_slot_with_confirmation_count(&self, confirmation_count: usize) -> Slot {
|
||||
|
@ -112,7 +112,7 @@ impl BlockCommitmentCache {
|
|||
}
|
||||
}
|
||||
}
|
||||
self.slot_info.root
|
||||
self.commitment_slots.root
|
||||
}
|
||||
|
||||
pub fn calculate_highest_confirmed_slot(&self) -> Slot {
|
||||
|
@ -155,7 +155,7 @@ impl BlockCommitmentCache {
|
|||
Self {
|
||||
block_commitment,
|
||||
total_stake: 42,
|
||||
slot_info: CacheSlotInfo {
|
||||
commitment_slots: CommitmentSlots {
|
||||
slot,
|
||||
root,
|
||||
highest_confirmed_slot: root,
|
||||
|
@ -165,16 +165,16 @@ impl BlockCommitmentCache {
|
|||
}
|
||||
|
||||
pub fn set_highest_confirmed_slot(&mut self, slot: Slot) {
|
||||
self.slot_info.highest_confirmed_slot = slot;
|
||||
self.commitment_slots.highest_confirmed_slot = slot;
|
||||
}
|
||||
|
||||
pub fn set_highest_confirmed_root(&mut self, root: Slot) {
|
||||
self.slot_info.highest_confirmed_root = root;
|
||||
self.commitment_slots.highest_confirmed_root = root;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
pub struct CacheSlotInfo {
|
||||
pub struct CommitmentSlots {
|
||||
/// The slot of the bank from which all other slots were calculated.
|
||||
pub slot: Slot,
|
||||
/// The current node root
|
||||
|
@ -257,7 +257,7 @@ mod tests {
|
|||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
total_stake,
|
||||
CacheSlotInfo {
|
||||
CommitmentSlots {
|
||||
slot: bank_slot_5,
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
|
@ -275,7 +275,7 @@ mod tests {
|
|||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
total_stake,
|
||||
CacheSlotInfo {
|
||||
CommitmentSlots {
|
||||
slot: bank_slot_5,
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
|
@ -293,7 +293,7 @@ mod tests {
|
|||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
total_stake,
|
||||
CacheSlotInfo {
|
||||
CommitmentSlots {
|
||||
slot: bank_slot_5,
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
|
@ -311,7 +311,7 @@ mod tests {
|
|||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
total_stake,
|
||||
CacheSlotInfo {
|
||||
CommitmentSlots {
|
||||
slot: bank_slot_5,
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
|
@ -329,7 +329,7 @@ mod tests {
|
|||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
total_stake,
|
||||
CacheSlotInfo {
|
||||
CommitmentSlots {
|
||||
slot: bank_slot_5,
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
|
|
Loading…
Reference in New Issue