Co-authored-by: Carl <carl@solana.com>
(cherry picked from commit c0dc21620b
)
Co-authored-by: carllin <wumu727@gmail.com>
This commit is contained in:
@ -1948,18 +1948,23 @@ pub(crate) mod tests {
|
|||||||
assert!(ReplayStage::is_partition_detected(&ancestors, 4, 3));
|
assert!(ReplayStage::is_partition_detected(&ancestors, 4, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
struct ReplayBlockstoreComponents {
|
||||||
fn test_child_slots_of_same_parent() {
|
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!();
|
let ledger_path = get_tmp_ledger_path!();
|
||||||
{
|
|
||||||
// Setup
|
|
||||||
let blockstore = Arc::new(
|
let blockstore = Arc::new(
|
||||||
Blockstore::open(&ledger_path)
|
Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"),
|
||||||
.expect("Expected to be able to open database ledger"),
|
|
||||||
);
|
);
|
||||||
let validator_authorized_voter_keypairs: Vec<_> = (0..20)
|
let validator_authorized_voter_keypairs: Vec<_> =
|
||||||
.map(|_| ValidatorVoteKeypairs::new(Keypair::new(), Keypair::new(), Keypair::new()))
|
(0..20).map(|_| ValidatorVoteKeypairs::new_rand()).collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
let validator_voting_keys: HashMap<_, _> = validator_authorized_voter_keypairs
|
let validator_voting_keys: HashMap<_, _> = validator_authorized_voter_keypairs
|
||||||
.iter()
|
.iter()
|
||||||
@ -1971,7 +1976,10 @@ pub(crate) mod tests {
|
|||||||
&validator_authorized_voter_keypairs,
|
&validator_authorized_voter_keypairs,
|
||||||
100,
|
100,
|
||||||
);
|
);
|
||||||
|
|
||||||
let bank0 = Bank::new(&genesis_config);
|
let bank0 = Bank::new(&genesis_config);
|
||||||
|
|
||||||
|
// ProgressMap
|
||||||
let mut progress = ProgressMap::default();
|
let mut progress = ProgressMap::default();
|
||||||
progress.insert(
|
progress.insert(
|
||||||
0,
|
0,
|
||||||
@ -1984,14 +1992,48 @@ pub(crate) mod tests {
|
|||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Leader schedule cache
|
||||||
let leader_schedule_cache = Arc::new(LeaderScheduleCache::new_from_bank(&bank0));
|
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 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_with_blockstore(
|
||||||
|
blockstore.clone(),
|
||||||
|
))),
|
||||||
|
));
|
||||||
|
|
||||||
|
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
|
// Insert a non-root bank so that the propagation logic will update this
|
||||||
// bank
|
// bank
|
||||||
let bank1 = Bank::new_from_parent(
|
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(),
|
&leader_schedule_cache.slot_leader_at(1, None).unwrap(),
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
@ -2000,7 +2042,7 @@ pub(crate) mod tests {
|
|||||||
ForkProgress::new_from_bank(
|
ForkProgress::new_from_bank(
|
||||||
&bank1,
|
&bank1,
|
||||||
bank1.collector_id(),
|
bank1.collector_id(),
|
||||||
&validator_voting_keys.get(&bank1.collector_id()).unwrap(),
|
validator_voting_keys.get(&bank1.collector_id()).unwrap(),
|
||||||
Some(0),
|
Some(0),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@ -2008,15 +2050,7 @@ pub(crate) mod tests {
|
|||||||
);
|
);
|
||||||
assert!(progress.get_propagated_stats(1).unwrap().is_leader_slot);
|
assert!(progress.get_propagated_stats(1).unwrap().is_leader_slot);
|
||||||
bank1.freeze();
|
bank1.freeze();
|
||||||
bank_forks.insert(bank1);
|
bank_forks.write().unwrap().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_with_blockstore(
|
|
||||||
blockstore.clone(),
|
|
||||||
))),
|
|
||||||
));
|
|
||||||
|
|
||||||
// Insert shreds for slot NUM_CONSECUTIVE_LEADER_SLOTS,
|
// Insert shreds for slot NUM_CONSECUTIVE_LEADER_SLOTS,
|
||||||
// chaining to slot 1
|
// chaining to slot 1
|
||||||
@ -2031,7 +2065,7 @@ pub(crate) mod tests {
|
|||||||
&blockstore,
|
&blockstore,
|
||||||
&bank_forks,
|
&bank_forks,
|
||||||
&leader_schedule_cache,
|
&leader_schedule_cache,
|
||||||
&subscriptions,
|
&rpc_subscriptions,
|
||||||
None,
|
None,
|
||||||
&mut progress,
|
&mut progress,
|
||||||
&mut PubkeyReferences::default(),
|
&mut PubkeyReferences::default(),
|
||||||
@ -2055,7 +2089,7 @@ pub(crate) mod tests {
|
|||||||
&blockstore,
|
&blockstore,
|
||||||
&bank_forks,
|
&bank_forks,
|
||||||
&leader_schedule_cache,
|
&leader_schedule_cache,
|
||||||
&subscriptions,
|
&rpc_subscriptions,
|
||||||
None,
|
None,
|
||||||
&mut progress,
|
&mut progress,
|
||||||
&mut PubkeyReferences::default(),
|
&mut PubkeyReferences::default(),
|
||||||
@ -2071,7 +2105,7 @@ pub(crate) mod tests {
|
|||||||
.get(2 * NUM_CONSECUTIVE_LEADER_SLOTS)
|
.get(2 * NUM_CONSECUTIVE_LEADER_SLOTS)
|
||||||
.is_some());
|
.is_some());
|
||||||
|
|
||||||
// // There are 20 equally staked acccounts, of which 3 have built
|
// // There are 20 equally staked accounts, of which 3 have built
|
||||||
// banks above or at bank 1. Because 3/20 < SUPERMINORITY_THRESHOLD,
|
// banks above or at bank 1. Because 3/20 < SUPERMINORITY_THRESHOLD,
|
||||||
// we should see 3 validators in bank 1's propagated_validator set.
|
// we should see 3 validators in bank 1's propagated_validator set.
|
||||||
let expected_leader_slots = vec![
|
let expected_leader_slots = vec![
|
||||||
@ -2089,7 +2123,6 @@ pub(crate) mod tests {
|
|||||||
.contains(vote_key));
|
.contains(vote_key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_handle_new_root() {
|
fn test_handle_new_root() {
|
||||||
@ -2811,10 +2844,7 @@ pub(crate) mod tests {
|
|||||||
&replay_votes_sender,
|
&replay_votes_sender,
|
||||||
);
|
);
|
||||||
// No new stats should have been computed
|
// No new stats should have been computed
|
||||||
assert!(replay_votes_receiver
|
assert!(replay_votes_receiver.try_iter().next().is_none());
|
||||||
.try_iter()
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.is_empty());
|
|
||||||
assert!(newly_computed.is_empty());
|
assert!(newly_computed.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user