Drop bank from BlockCommitmentCache (#10959)
* Remove bank reference from BlockCommitmentCache * Don't use a Bank to create BlockCommitmentCache * Rename recent_slot to slot
This commit is contained in:
parent
841ecfd927
commit
ebadbce920
|
@ -116,7 +116,7 @@ impl AggregateCommitmentService {
|
||||||
block_commitment,
|
block_commitment,
|
||||||
highest_confirmed_root,
|
highest_confirmed_root,
|
||||||
aggregation_data.total_stake,
|
aggregation_data.total_stake,
|
||||||
aggregation_data.bank,
|
aggregation_data.bank.slot(),
|
||||||
aggregation_data.root,
|
aggregation_data.root,
|
||||||
aggregation_data.root,
|
aggregation_data.root,
|
||||||
);
|
);
|
||||||
|
|
|
@ -183,7 +183,7 @@ impl JsonRpcRequestProcessor {
|
||||||
HashMap::new(),
|
HashMap::new(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
bank.clone(),
|
bank.slot(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
))),
|
))),
|
||||||
|
@ -1798,7 +1798,7 @@ pub mod tests {
|
||||||
block_commitment,
|
block_commitment,
|
||||||
0,
|
0,
|
||||||
10,
|
10,
|
||||||
bank.clone(),
|
bank.slot(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
)));
|
)));
|
||||||
|
@ -3326,7 +3326,7 @@ pub mod tests {
|
||||||
block_commitment,
|
block_commitment,
|
||||||
0,
|
0,
|
||||||
42,
|
42,
|
||||||
bank_forks.read().unwrap().working_bank(),
|
bank_forks.read().unwrap().highest_slot(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
)));
|
)));
|
||||||
|
@ -3830,7 +3830,7 @@ pub mod tests {
|
||||||
block_commitment,
|
block_commitment,
|
||||||
highest_confirmed_root,
|
highest_confirmed_root,
|
||||||
50,
|
50,
|
||||||
bank.clone(),
|
bank.slot(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
|
@ -525,9 +525,8 @@ mod tests {
|
||||||
subscriptions: Arc::new(RpcSubscriptions::new(
|
subscriptions: Arc::new(RpcSubscriptions::new(
|
||||||
&Arc::new(AtomicBool::new(false)),
|
&Arc::new(AtomicBool::new(false)),
|
||||||
bank_forks.clone(),
|
bank_forks.clone(),
|
||||||
Arc::new(RwLock::new(BlockCommitmentCache::new_for_tests_with_bank(
|
Arc::new(RwLock::new(BlockCommitmentCache::new_for_tests_with_slots(
|
||||||
bank_forks.read().unwrap().get(1).unwrap().clone(),
|
1, 1,
|
||||||
1,
|
|
||||||
))),
|
))),
|
||||||
)),
|
)),
|
||||||
uid: Arc::new(atomic::AtomicUsize::default()),
|
uid: Arc::new(atomic::AtomicUsize::default()),
|
||||||
|
|
|
@ -961,9 +961,8 @@ pub(crate) mod tests {
|
||||||
let subscriptions = RpcSubscriptions::new(
|
let subscriptions = RpcSubscriptions::new(
|
||||||
&exit,
|
&exit,
|
||||||
bank_forks.clone(),
|
bank_forks.clone(),
|
||||||
Arc::new(RwLock::new(BlockCommitmentCache::new_for_tests_with_bank(
|
Arc::new(RwLock::new(BlockCommitmentCache::new_for_tests_with_slots(
|
||||||
bank_forks.read().unwrap().get(1).unwrap().clone(),
|
1, 1,
|
||||||
1,
|
|
||||||
))),
|
))),
|
||||||
);
|
);
|
||||||
subscriptions.add_account_subscription(
|
subscriptions.add_account_subscription(
|
||||||
|
@ -1158,7 +1157,7 @@ pub(crate) mod tests {
|
||||||
block_commitment.entry(0).or_insert(cache0);
|
block_commitment.entry(0).or_insert(cache0);
|
||||||
block_commitment.entry(1).or_insert(cache1);
|
block_commitment.entry(1).or_insert(cache1);
|
||||||
let block_commitment_cache =
|
let block_commitment_cache =
|
||||||
BlockCommitmentCache::new(block_commitment, 0, 10, bank1, 0, 0);
|
BlockCommitmentCache::new(block_commitment, 0, 10, bank1.slot(), 0, 0);
|
||||||
|
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
let subscriptions = RpcSubscriptions::new(
|
let subscriptions = RpcSubscriptions::new(
|
||||||
|
@ -1433,9 +1432,8 @@ pub(crate) mod tests {
|
||||||
let subscriptions = RpcSubscriptions::new(
|
let subscriptions = RpcSubscriptions::new(
|
||||||
&exit,
|
&exit,
|
||||||
bank_forks.clone(),
|
bank_forks.clone(),
|
||||||
Arc::new(RwLock::new(BlockCommitmentCache::new_for_tests_with_bank(
|
Arc::new(RwLock::new(BlockCommitmentCache::new_for_tests_with_slots(
|
||||||
bank_forks.read().unwrap().get(1).unwrap().clone(),
|
1, 1,
|
||||||
1,
|
|
||||||
))),
|
))),
|
||||||
);
|
);
|
||||||
let sub_id0 = SubscriptionId::Number(0 as u64);
|
let sub_id0 = SubscriptionId::Number(0 as u64);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::bank::Bank;
|
|
||||||
use solana_sdk::clock::Slot;
|
use solana_sdk::clock::Slot;
|
||||||
use solana_vote_program::vote_state::MAX_LOCKOUT_HISTORY;
|
use solana_vote_program::vote_state::MAX_LOCKOUT_HISTORY;
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub const VOTE_THRESHOLD_SIZE: f64 = 2f64 / 3f64;
|
pub const VOTE_THRESHOLD_SIZE: f64 = 2f64 / 3f64;
|
||||||
|
|
||||||
|
@ -41,7 +40,8 @@ pub struct BlockCommitmentCache {
|
||||||
block_commitment: HashMap<Slot, BlockCommitment>,
|
block_commitment: HashMap<Slot, BlockCommitment>,
|
||||||
highest_confirmed_root: Slot,
|
highest_confirmed_root: Slot,
|
||||||
total_stake: u64,
|
total_stake: u64,
|
||||||
bank: Arc<Bank>,
|
/// The slot of the bank from which all other slots were calculated.
|
||||||
|
slot: Slot,
|
||||||
root: Slot,
|
root: Slot,
|
||||||
pub highest_confirmed_slot: Slot,
|
pub highest_confirmed_slot: Slot,
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ impl std::fmt::Debug for BlockCommitmentCache {
|
||||||
.field("total_stake", &self.total_stake)
|
.field("total_stake", &self.total_stake)
|
||||||
.field(
|
.field(
|
||||||
"bank",
|
"bank",
|
||||||
&format_args!("Bank({{current_slot: {:?}}})", self.bank.slot()),
|
&format_args!("Bank({{current_slot: {:?}}})", self.slot),
|
||||||
)
|
)
|
||||||
.field("root", &self.root)
|
.field("root", &self.root)
|
||||||
.finish()
|
.finish()
|
||||||
|
@ -65,7 +65,7 @@ impl BlockCommitmentCache {
|
||||||
block_commitment: HashMap<Slot, BlockCommitment>,
|
block_commitment: HashMap<Slot, BlockCommitment>,
|
||||||
highest_confirmed_root: Slot,
|
highest_confirmed_root: Slot,
|
||||||
total_stake: u64,
|
total_stake: u64,
|
||||||
bank: Arc<Bank>,
|
slot: Slot,
|
||||||
root: Slot,
|
root: Slot,
|
||||||
highest_confirmed_slot: Slot,
|
highest_confirmed_slot: Slot,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -73,7 +73,7 @@ impl BlockCommitmentCache {
|
||||||
block_commitment,
|
block_commitment,
|
||||||
highest_confirmed_root,
|
highest_confirmed_root,
|
||||||
total_stake,
|
total_stake,
|
||||||
bank,
|
slot,
|
||||||
root,
|
root,
|
||||||
highest_confirmed_slot,
|
highest_confirmed_slot,
|
||||||
}
|
}
|
||||||
|
@ -91,12 +91,8 @@ impl BlockCommitmentCache {
|
||||||
self.total_stake
|
self.total_stake
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bank(&self) -> Arc<Bank> {
|
|
||||||
self.bank.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn slot(&self) -> Slot {
|
pub fn slot(&self) -> Slot {
|
||||||
self.bank.slot()
|
self.slot
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root(&self) -> Slot {
|
pub fn root(&self) -> Slot {
|
||||||
|
@ -153,14 +149,14 @@ impl BlockCommitmentCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_for_tests_with_bank(bank: Arc<Bank>, root: Slot) -> Self {
|
pub fn new_for_tests_with_slots(slot: Slot, root: Slot) -> Self {
|
||||||
let mut block_commitment: HashMap<Slot, BlockCommitment> = HashMap::new();
|
let mut block_commitment: HashMap<Slot, BlockCommitment> = HashMap::new();
|
||||||
block_commitment.insert(0, BlockCommitment::default());
|
block_commitment.insert(0, BlockCommitment::default());
|
||||||
Self {
|
Self {
|
||||||
block_commitment,
|
block_commitment,
|
||||||
total_stake: 42,
|
total_stake: 42,
|
||||||
highest_confirmed_root: root,
|
highest_confirmed_root: root,
|
||||||
bank,
|
slot,
|
||||||
root,
|
root,
|
||||||
highest_confirmed_slot: root,
|
highest_confirmed_slot: root,
|
||||||
}
|
}
|
||||||
|
@ -174,7 +170,6 @@ impl BlockCommitmentCache {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_sdk::{genesis_config::GenesisConfig, pubkey::Pubkey};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_block_commitment() {
|
fn test_block_commitment() {
|
||||||
|
@ -188,7 +183,6 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_confirmations() {
|
fn test_get_confirmations() {
|
||||||
let bank = Arc::new(Bank::default());
|
|
||||||
// Build BlockCommitmentCache with votes at depths 0 and 1 for 2 slots
|
// Build BlockCommitmentCache with votes at depths 0 and 1 for 2 slots
|
||||||
let mut cache0 = BlockCommitment::default();
|
let mut cache0 = BlockCommitment::default();
|
||||||
cache0.increase_confirmation_stake(1, 5);
|
cache0.increase_confirmation_stake(1, 5);
|
||||||
|
@ -206,7 +200,7 @@ mod tests {
|
||||||
block_commitment.entry(0).or_insert(cache0);
|
block_commitment.entry(0).or_insert(cache0);
|
||||||
block_commitment.entry(1).or_insert(cache1);
|
block_commitment.entry(1).or_insert(cache1);
|
||||||
block_commitment.entry(2).or_insert(cache2);
|
block_commitment.entry(2).or_insert(cache2);
|
||||||
let block_commitment_cache = BlockCommitmentCache::new(block_commitment, 0, 50, bank, 0, 0);
|
let block_commitment_cache = BlockCommitmentCache::new(block_commitment, 0, 50, 0, 0, 0);
|
||||||
|
|
||||||
assert_eq!(block_commitment_cache.get_confirmation_count(0), Some(2));
|
assert_eq!(block_commitment_cache.get_confirmation_count(0), Some(2));
|
||||||
assert_eq!(block_commitment_cache.get_confirmation_count(1), Some(1));
|
assert_eq!(block_commitment_cache.get_confirmation_count(1), Some(1));
|
||||||
|
@ -216,8 +210,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_highest_confirmed_slot() {
|
fn test_highest_confirmed_slot() {
|
||||||
let bank = Arc::new(Bank::new(&GenesisConfig::default()));
|
let bank_slot_5 = 5;
|
||||||
let bank_slot_5 = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 5));
|
|
||||||
let total_stake = 50;
|
let total_stake = 50;
|
||||||
|
|
||||||
// Build cache with confirmation_count 2 given total_stake
|
// Build cache with confirmation_count 2 given total_stake
|
||||||
|
@ -240,7 +233,7 @@ mod tests {
|
||||||
block_commitment.entry(2).or_insert_with(|| cache1.clone()); // Slot 2, conf 1
|
block_commitment.entry(2).or_insert_with(|| cache1.clone()); // Slot 2, conf 1
|
||||||
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
|
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
|
||||||
let block_commitment_cache =
|
let block_commitment_cache =
|
||||||
BlockCommitmentCache::new(block_commitment, 0, total_stake, bank_slot_5.clone(), 0, 0);
|
BlockCommitmentCache::new(block_commitment, 0, total_stake, bank_slot_5, 0, 0);
|
||||||
|
|
||||||
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 2);
|
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 2);
|
||||||
|
|
||||||
|
@ -250,7 +243,7 @@ mod tests {
|
||||||
block_commitment.entry(2).or_insert_with(|| cache1.clone()); // Slot 2, conf 1
|
block_commitment.entry(2).or_insert_with(|| cache1.clone()); // Slot 2, conf 1
|
||||||
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
|
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
|
||||||
let block_commitment_cache =
|
let block_commitment_cache =
|
||||||
BlockCommitmentCache::new(block_commitment, 0, total_stake, bank_slot_5.clone(), 0, 0);
|
BlockCommitmentCache::new(block_commitment, 0, total_stake, bank_slot_5, 0, 0);
|
||||||
|
|
||||||
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 2);
|
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 2);
|
||||||
|
|
||||||
|
@ -260,7 +253,7 @@ mod tests {
|
||||||
block_commitment.entry(3).or_insert(cache1); // Slot 3, conf 1
|
block_commitment.entry(3).or_insert(cache1); // Slot 3, conf 1
|
||||||
block_commitment.entry(5).or_insert_with(|| cache2.clone()); // Slot 5, conf 0
|
block_commitment.entry(5).or_insert_with(|| cache2.clone()); // Slot 5, conf 0
|
||||||
let block_commitment_cache =
|
let block_commitment_cache =
|
||||||
BlockCommitmentCache::new(block_commitment, 0, total_stake, bank_slot_5.clone(), 0, 0);
|
BlockCommitmentCache::new(block_commitment, 0, total_stake, bank_slot_5, 0, 0);
|
||||||
|
|
||||||
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 3);
|
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 3);
|
||||||
|
|
||||||
|
@ -270,7 +263,7 @@ mod tests {
|
||||||
block_commitment.entry(2).or_insert_with(|| cache2.clone()); // Slot 2, conf 0
|
block_commitment.entry(2).or_insert_with(|| cache2.clone()); // Slot 2, conf 0
|
||||||
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
|
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
|
||||||
let block_commitment_cache =
|
let block_commitment_cache =
|
||||||
BlockCommitmentCache::new(block_commitment, 0, total_stake, bank_slot_5.clone(), 0, 0);
|
BlockCommitmentCache::new(block_commitment, 0, total_stake, bank_slot_5, 0, 0);
|
||||||
|
|
||||||
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 1);
|
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue