parent
6578ad7d08
commit
c0dc21620b
|
@ -1946,14 +1946,20 @@ pub(crate) mod tests {
|
|||
assert!(ReplayStage::is_partition_detected(&ancestors, 4, 3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_child_slots_of_same_parent() {
|
||||
struct ReplayBlockstoreComponents {
|
||||
blockstore: Arc<Blockstore>,
|
||||
validator_voting_keys: HashMap<Pubkey, Pubkey>,
|
||||
progress: ProgressMap,
|
||||
bank_forks: Arc<RwLock<BankForks>>,
|
||||
leader_schedule_cache: Arc<LeaderScheduleCache>,
|
||||
rpc_subscriptions: Arc<RpcSubscriptions>,
|
||||
}
|
||||
|
||||
fn replay_blockstore_components() -> ReplayBlockstoreComponents {
|
||||
// Setup blockstore
|
||||
let ledger_path = get_tmp_ledger_path!();
|
||||
{
|
||||
// Setup
|
||||
let blockstore = Arc::new(
|
||||
Blockstore::open(&ledger_path)
|
||||
.expect("Expected to be able to open database ledger"),
|
||||
Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"),
|
||||
);
|
||||
let validator_authorized_voter_keypairs: Vec<_> =
|
||||
(0..20).map(|_| ValidatorVoteKeypairs::new_rand()).collect();
|
||||
|
@ -1968,7 +1974,10 @@ pub(crate) mod tests {
|
|||
&validator_authorized_voter_keypairs,
|
||||
vec![100; validator_authorized_voter_keypairs.len()],
|
||||
);
|
||||
|
||||
let bank0 = Bank::new(&genesis_config);
|
||||
|
||||
// ProgressMap
|
||||
let mut progress = ProgressMap::default();
|
||||
progress.insert(
|
||||
0,
|
||||
|
@ -1981,14 +1990,46 @@ pub(crate) mod tests {
|
|||
0,
|
||||
),
|
||||
);
|
||||
|
||||
// Leader schedule cache
|
||||
let leader_schedule_cache = Arc::new(LeaderScheduleCache::new_from_bank(&bank0));
|
||||
|
||||
// BankForks
|
||||
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0)));
|
||||
|
||||
// RpcSubscriptions
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
let mut bank_forks = BankForks::new(bank0);
|
||||
let rpc_subscriptions = Arc::new(RpcSubscriptions::new(
|
||||
&exit,
|
||||
bank_forks.clone(),
|
||||
Arc::new(RwLock::new(BlockCommitmentCache::default())),
|
||||
));
|
||||
|
||||
ReplayBlockstoreComponents {
|
||||
blockstore,
|
||||
validator_voting_keys,
|
||||
progress,
|
||||
bank_forks,
|
||||
leader_schedule_cache,
|
||||
rpc_subscriptions,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_child_slots_of_same_parent() {
|
||||
let ReplayBlockstoreComponents {
|
||||
blockstore,
|
||||
validator_voting_keys,
|
||||
mut progress,
|
||||
bank_forks,
|
||||
leader_schedule_cache,
|
||||
rpc_subscriptions,
|
||||
} = replay_blockstore_components();
|
||||
|
||||
// Insert a non-root bank so that the propagation logic will update this
|
||||
// bank
|
||||
let bank1 = Bank::new_from_parent(
|
||||
bank_forks.get(0).unwrap(),
|
||||
bank_forks.read().unwrap().get(0).unwrap(),
|
||||
&leader_schedule_cache.slot_leader_at(1, None).unwrap(),
|
||||
1,
|
||||
);
|
||||
|
@ -1997,7 +2038,7 @@ pub(crate) mod tests {
|
|||
ForkProgress::new_from_bank(
|
||||
&bank1,
|
||||
bank1.collector_id(),
|
||||
&validator_voting_keys.get(&bank1.collector_id()).unwrap(),
|
||||
validator_voting_keys.get(&bank1.collector_id()).unwrap(),
|
||||
Some(0),
|
||||
0,
|
||||
0,
|
||||
|
@ -2005,13 +2046,7 @@ pub(crate) mod tests {
|
|||
);
|
||||
assert!(progress.get_propagated_stats(1).unwrap().is_leader_slot);
|
||||
bank1.freeze();
|
||||
bank_forks.insert(bank1);
|
||||
let bank_forks = Arc::new(RwLock::new(bank_forks));
|
||||
let subscriptions = Arc::new(RpcSubscriptions::new(
|
||||
&exit,
|
||||
bank_forks.clone(),
|
||||
Arc::new(RwLock::new(BlockCommitmentCache::default())),
|
||||
));
|
||||
bank_forks.write().unwrap().insert(bank1);
|
||||
|
||||
// Insert shreds for slot NUM_CONSECUTIVE_LEADER_SLOTS,
|
||||
// chaining to slot 1
|
||||
|
@ -2026,7 +2061,7 @@ pub(crate) mod tests {
|
|||
&blockstore,
|
||||
&bank_forks,
|
||||
&leader_schedule_cache,
|
||||
&subscriptions,
|
||||
&rpc_subscriptions,
|
||||
None,
|
||||
&mut progress,
|
||||
&mut PubkeyReferences::default(),
|
||||
|
@ -2050,7 +2085,7 @@ pub(crate) mod tests {
|
|||
&blockstore,
|
||||
&bank_forks,
|
||||
&leader_schedule_cache,
|
||||
&subscriptions,
|
||||
&rpc_subscriptions,
|
||||
None,
|
||||
&mut progress,
|
||||
&mut PubkeyReferences::default(),
|
||||
|
@ -2084,7 +2119,6 @@ pub(crate) mod tests {
|
|||
.contains(vote_key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_handle_new_root() {
|
||||
|
|
Loading…
Reference in New Issue