Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify BlockCommitmentCache slot info #11106

Merged
merged 2 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions core/src/commitment_service.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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());
}
}

Expand Down
42 changes: 25 additions & 17 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 7 additions & 7 deletions core/src/rpc_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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!({
Expand Down
42 changes: 22 additions & 20 deletions core/src/rpc_subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
}
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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!({
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 };

Expand Down
Loading