Simplify BlockCommitmentCache slot info (#11106)

* Refactor BlockCommitmentCache, store a CacheSlotInfo

* Comma
This commit is contained in:
Tyera Eulberg
2020-07-17 09:24:51 -06:00
committed by GitHub
parent 25728baeac
commit fdff681bcc
5 changed files with 170 additions and 101 deletions

View File

@ -1,12 +1,9 @@
use crate::{
consensus::Stake,
rpc_subscriptions::{CacheSlotInfo, RpcSubscriptions},
};
use crate::{consensus::Stake, rpc_subscriptions::RpcSubscriptions};
use solana_measure::measure::Measure;
use solana_metrics::datapoint_info;
use solana_runtime::{
bank::Bank,
commitment::{BlockCommitment, BlockCommitmentCache, VOTE_THRESHOLD_SIZE},
commitment::{BlockCommitment, BlockCommitmentCache, CacheSlotInfo, VOTE_THRESHOLD_SIZE},
};
use solana_sdk::clock::Slot;
use solana_vote_program::vote_state::VoteState;
@ -114,14 +111,16 @@ impl AggregateCommitmentService {
let mut new_block_commitment = BlockCommitmentCache::new(
block_commitment,
highest_confirmed_root,
aggregation_data.total_stake,
aggregation_data.bank.slot(),
aggregation_data.root,
aggregation_data.root,
CacheSlotInfo {
slot: aggregation_data.bank.slot(),
root: aggregation_data.root,
highest_confirmed_slot: aggregation_data.root,
highest_confirmed_root,
},
);
new_block_commitment.highest_confirmed_slot =
new_block_commitment.calculate_highest_confirmed_slot();
let highest_confirmed_slot = new_block_commitment.calculate_highest_confirmed_slot();
new_block_commitment.set_highest_confirmed_slot(highest_confirmed_slot);
let mut w_block_commitment_cache = block_commitment_cache.write().unwrap();
@ -136,12 +135,10 @@ impl AggregateCommitmentService {
)
);
subscriptions.notify_subscribers(CacheSlotInfo {
current_slot: w_block_commitment_cache.slot(),
node_root: w_block_commitment_cache.root(),
highest_confirmed_root: w_block_commitment_cache.highest_confirmed_root(),
highest_confirmed_slot: w_block_commitment_cache.highest_confirmed_slot(),
});
// 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());
}
}

View File

@ -27,7 +27,7 @@ use solana_runtime::{
accounts::AccountAddressFilter,
bank::Bank,
bank_forks::BankForks,
commitment::{BlockCommitmentArray, BlockCommitmentCache},
commitment::{BlockCommitmentArray, BlockCommitmentCache, CacheSlotInfo},
log_collector::LogCollector,
send_transaction_service::{SendTransactionService, TransactionInfo},
};
@ -192,10 +192,12 @@ impl JsonRpcRequestProcessor {
block_commitment_cache: Arc::new(RwLock::new(BlockCommitmentCache::new(
HashMap::new(),
0,
0,
bank.slot(),
0,
0,
CacheSlotInfo {
slot: bank.slot(),
root: 0,
highest_confirmed_slot: 0,
highest_confirmed_root: 0,
},
))),
blockstore,
validator_exit: create_validator_exit(&exit),
@ -1816,11 +1818,13 @@ pub mod tests {
block_commitment.entry(1).or_insert(commitment_slot1);
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::new(
block_commitment,
0,
10,
bank.slot(),
0,
0,
CacheSlotInfo {
slot: bank.slot(),
root: 0,
highest_confirmed_slot: 0,
highest_confirmed_root: 0,
},
)));
// Add timestamp vote to blockstore
@ -3329,11 +3333,13 @@ pub mod tests {
.or_insert_with(|| commitment_slot1.clone());
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::new(
block_commitment,
0,
42,
bank_forks.read().unwrap().highest_slot(),
0,
0,
CacheSlotInfo {
slot: bank_forks.read().unwrap().highest_slot(),
root: 0,
highest_confirmed_slot: 0,
highest_confirmed_root: 0,
},
)));
let mut config = JsonRpcConfig::default();
@ -3856,11 +3862,13 @@ pub mod tests {
let highest_confirmed_root = 1;
let block_commitment_cache = BlockCommitmentCache::new(
block_commitment,
highest_confirmed_root,
50,
bank.slot(),
0,
0,
CacheSlotInfo {
slot: bank.slot(),
root: 0,
highest_confirmed_slot: 0,
highest_confirmed_root,
},
);
assert!(is_confirmed_rooted(

View File

@ -349,7 +349,7 @@ mod tests {
use super::*;
use crate::{
cluster_info_vote_listener::{ClusterInfoVoteListener, VoteTracker},
rpc_subscriptions::{tests::robust_poll_or_panic, CacheSlotInfo},
rpc_subscriptions::tests::robust_poll_or_panic,
};
use crossbeam_channel::unbounded;
use jsonrpc_core::{futures::sync::mpsc, Response};
@ -359,7 +359,7 @@ mod tests {
use solana_runtime::{
bank::Bank,
bank_forks::BankForks,
commitment::BlockCommitmentCache,
commitment::{BlockCommitmentCache, CacheSlotInfo},
genesis_utils::{
create_genesis_config, create_genesis_config_with_vote_accounts, GenesisConfigInfo,
ValidatorVoteKeypairs,
@ -393,7 +393,7 @@ mod tests {
.unwrap()
.process_transaction(tx)?;
let mut cache_slot_info = CacheSlotInfo::default();
cache_slot_info.current_slot = current_slot;
cache_slot_info.slot = current_slot;
subscriptions.notify_subscribers(cache_slot_info);
Ok(())
}
@ -733,14 +733,14 @@ mod tests {
.process_transaction(&tx)
.unwrap();
let mut cache_slot_info = CacheSlotInfo::default();
cache_slot_info.current_slot = 1;
cache_slot_info.slot = 1;
rpc.subscriptions.notify_subscribers(cache_slot_info);
let cache_slot_info = CacheSlotInfo {
current_slot: 2,
node_root: 1,
highest_confirmed_root: 1,
slot: 2,
root: 1,
highest_confirmed_slot: 1,
highest_confirmed_root: 1,
};
rpc.subscriptions.notify_subscribers(cache_slot_info);
let expected = json!({

View File

@ -11,7 +11,11 @@ use solana_account_decoder::{UiAccount, UiAccountEncoding};
use solana_client::rpc_response::{
Response, RpcKeyedAccount, RpcResponseContext, RpcSignatureResult,
};
use solana_runtime::{bank::Bank, bank_forks::BankForks, commitment::BlockCommitmentCache};
use solana_runtime::{
bank::Bank,
bank_forks::BankForks,
commitment::{BlockCommitmentCache, CacheSlotInfo},
};
use solana_sdk::{
account::Account,
clock::{Slot, UnixTimestamp},
@ -43,14 +47,6 @@ pub struct SlotInfo {
pub root: Slot,
}
#[derive(Default)]
pub struct CacheSlotInfo {
pub current_slot: Slot,
pub node_root: Slot,
pub highest_confirmed_root: Slot,
pub highest_confirmed_slot: Slot,
}
// A more human-friendly version of Vote, with the bank state signature base58 encoded.
#[derive(Serialize, Deserialize, Debug)]
pub struct RpcVote {
@ -75,11 +71,9 @@ 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({{current_slot: {:?}}})",
cache_slot_info.current_slot
),
NotificationEntry::Bank(cache_slot_info) => {
write!(f, "Bank({{slot: {:?}}})", cache_slot_info.slot)
}
NotificationEntry::Gossip(slot) => write!(f, "Gossip({:?})", slot),
}
}
@ -180,8 +174,8 @@ where
{
let slot = match commitment.commitment {
CommitmentLevel::Max => cache_slot_info.highest_confirmed_root,
CommitmentLevel::Recent => cache_slot_info.current_slot,
CommitmentLevel::Root => cache_slot_info.node_root,
CommitmentLevel::Recent => cache_slot_info.slot,
CommitmentLevel::Root => cache_slot_info.root,
CommitmentLevel::Single | CommitmentLevel::SingleGossip => {
cache_slot_info.highest_confirmed_slot
}
@ -995,7 +989,7 @@ pub(crate) mod tests {
.process_transaction(&tx)
.unwrap();
let mut cache_slot_info = CacheSlotInfo::default();
cache_slot_info.current_slot = 1;
cache_slot_info.slot = 1;
subscriptions.notify_subscribers(cache_slot_info);
let (response, _) = robust_poll_or_panic(transport_receiver);
let expected = json!({
@ -1156,8 +1150,16 @@ pub(crate) mod tests {
let mut block_commitment = HashMap::new();
block_commitment.entry(0).or_insert(cache0);
block_commitment.entry(1).or_insert(cache1);
let block_commitment_cache =
BlockCommitmentCache::new(block_commitment, 0, 10, bank1.slot(), 0, 0);
let block_commitment_cache = BlockCommitmentCache::new(
block_commitment,
10,
CacheSlotInfo {
slot: bank1.slot(),
root: 0,
highest_confirmed_slot: 0,
highest_confirmed_root: 0,
},
);
let exit = Arc::new(AtomicBool::new(false));
let subscriptions = RpcSubscriptions::new(
@ -1209,7 +1211,7 @@ pub(crate) mod tests {
assert!(sig_subs.contains_key(&processed_tx.signatures[0]));
}
let mut cache_slot_info = CacheSlotInfo::default();
cache_slot_info.current_slot = 1;
cache_slot_info.slot = 1;
subscriptions.notify_subscribers(cache_slot_info);
let expected_res = RpcSignatureResult { err: None };