(cherry picked from commit 68c87469c3)
Co-authored-by: carllin <carl@solana.com>
			
			
This commit is contained in:
		@@ -1439,9 +1439,6 @@ pub mod test {
 | 
			
		||||
 | 
			
		||||
            while let Some(visit) = walk.get() {
 | 
			
		||||
                let slot = visit.node().data;
 | 
			
		||||
                self.progress
 | 
			
		||||
                    .entry(slot)
 | 
			
		||||
                    .or_insert_with(|| ForkProgress::new(Hash::default(), None, None, 0, 0));
 | 
			
		||||
                if self.bank_forks.read().unwrap().get(slot).is_some() {
 | 
			
		||||
                    walk.forward();
 | 
			
		||||
                    continue;
 | 
			
		||||
@@ -1449,6 +1446,9 @@ pub mod test {
 | 
			
		||||
                let parent = walk.get_parent().unwrap().data;
 | 
			
		||||
                let parent_bank = self.bank_forks.read().unwrap().get(parent).unwrap().clone();
 | 
			
		||||
                let new_bank = Bank::new_from_parent(&parent_bank, &Pubkey::default(), slot);
 | 
			
		||||
                self.progress
 | 
			
		||||
                    .entry(slot)
 | 
			
		||||
                    .or_insert_with(|| ForkProgress::new(Hash::default(), None, None, 0, 0));
 | 
			
		||||
                for (pubkey, vote) in cluster_votes.iter() {
 | 
			
		||||
                    if vote.contains(&parent) {
 | 
			
		||||
                        let keypairs = self.validator_keypairs.get(pubkey).unwrap();
 | 
			
		||||
@@ -1701,7 +1701,14 @@ pub mod test {
 | 
			
		||||
        let mut progress = ProgressMap::default();
 | 
			
		||||
        progress.insert(
 | 
			
		||||
            0,
 | 
			
		||||
            ForkProgress::new(bank0.last_blockhash(), None, None, 0, 0),
 | 
			
		||||
            ForkProgress::new_from_bank(
 | 
			
		||||
                &bank0,
 | 
			
		||||
                bank0.collector_id(),
 | 
			
		||||
                &Pubkey::default(),
 | 
			
		||||
                None,
 | 
			
		||||
                0,
 | 
			
		||||
                0,
 | 
			
		||||
            ),
 | 
			
		||||
        );
 | 
			
		||||
        let bank_forks = BankForks::new(bank0);
 | 
			
		||||
        let heaviest_subtree_fork_choice =
 | 
			
		||||
 
 | 
			
		||||
@@ -2496,7 +2496,7 @@ mod tests {
 | 
			
		||||
    use solana_runtime::{
 | 
			
		||||
        accounts_background_service::AbsRequestSender,
 | 
			
		||||
        commitment::BlockCommitment,
 | 
			
		||||
        genesis_utils::{self, GenesisConfigInfo, ValidatorVoteKeypairs},
 | 
			
		||||
        genesis_utils::{GenesisConfigInfo, ValidatorVoteKeypairs},
 | 
			
		||||
    };
 | 
			
		||||
    use solana_sdk::{
 | 
			
		||||
        clock::NUM_CONSECUTIVE_LEADER_SLOTS,
 | 
			
		||||
@@ -2519,11 +2519,11 @@ mod tests {
 | 
			
		||||
        iter,
 | 
			
		||||
        sync::{atomic::AtomicU64, Arc, RwLock},
 | 
			
		||||
    };
 | 
			
		||||
    use trees::tr;
 | 
			
		||||
    use trees::{tr, Tree};
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn test_is_partition_detected() {
 | 
			
		||||
        let VoteSimulator { bank_forks, .. } = setup_forks();
 | 
			
		||||
        let (VoteSimulator { bank_forks, .. }, _) = setup_default_forks(1);
 | 
			
		||||
        let ancestors = bank_forks.read().unwrap().ancestors();
 | 
			
		||||
        // Last vote 1 is an ancestor of the heaviest slot 3, no partition
 | 
			
		||||
        assert!(!ReplayStage::is_partition_detected(&ancestors, 1, 3));
 | 
			
		||||
@@ -2540,8 +2540,8 @@ mod tests {
 | 
			
		||||
    struct ReplayBlockstoreComponents {
 | 
			
		||||
        blockstore: Arc<Blockstore>,
 | 
			
		||||
        validator_node_to_vote_keys: HashMap<Pubkey, Pubkey>,
 | 
			
		||||
        validator_authorized_voter_keypairs: HashMap<Pubkey, ValidatorVoteKeypairs>,
 | 
			
		||||
        my_vote_pubkey: Pubkey,
 | 
			
		||||
        validator_keypairs: HashMap<Pubkey, ValidatorVoteKeypairs>,
 | 
			
		||||
        my_pubkey: Pubkey,
 | 
			
		||||
        progress: ProgressMap,
 | 
			
		||||
        cluster_info: ClusterInfo,
 | 
			
		||||
        leader_schedule_cache: Arc<LeaderScheduleCache>,
 | 
			
		||||
@@ -2551,45 +2551,32 @@ mod tests {
 | 
			
		||||
        rpc_subscriptions: Arc<RpcSubscriptions>,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn replay_blockstore_components() -> ReplayBlockstoreComponents {
 | 
			
		||||
    fn replay_blockstore_components(forks: Option<Tree<Slot>>) -> ReplayBlockstoreComponents {
 | 
			
		||||
        // Setup blockstore
 | 
			
		||||
        let ledger_path = get_tmp_ledger_path!();
 | 
			
		||||
        let blockstore = Arc::new(
 | 
			
		||||
            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();
 | 
			
		||||
        let (vote_simulator, blockstore) =
 | 
			
		||||
            setup_forks_from_tree(forks.unwrap_or_else(|| tr(0)), 20);
 | 
			
		||||
 | 
			
		||||
        let validator_node_to_vote_keys: HashMap<Pubkey, Pubkey> =
 | 
			
		||||
            validator_authorized_voter_keypairs
 | 
			
		||||
                .iter()
 | 
			
		||||
                .map(|v| (v.node_keypair.pubkey(), v.vote_keypair.pubkey()))
 | 
			
		||||
                .collect();
 | 
			
		||||
        let GenesisConfigInfo { genesis_config, .. } =
 | 
			
		||||
            genesis_utils::create_genesis_config_with_vote_accounts(
 | 
			
		||||
                10_000,
 | 
			
		||||
                &validator_authorized_voter_keypairs,
 | 
			
		||||
                vec![100; validator_authorized_voter_keypairs.len()],
 | 
			
		||||
            );
 | 
			
		||||
        let VoteSimulator {
 | 
			
		||||
            validator_keypairs,
 | 
			
		||||
            progress,
 | 
			
		||||
            bank_forks,
 | 
			
		||||
            ..
 | 
			
		||||
        } = vote_simulator;
 | 
			
		||||
 | 
			
		||||
        let bank0 = Bank::new(&genesis_config);
 | 
			
		||||
 | 
			
		||||
        // ProgressMap
 | 
			
		||||
        let mut progress = ProgressMap::default();
 | 
			
		||||
        progress.insert(
 | 
			
		||||
            0,
 | 
			
		||||
            ForkProgress::new_from_bank(
 | 
			
		||||
                &bank0,
 | 
			
		||||
                bank0.collector_id(),
 | 
			
		||||
                &Pubkey::default(),
 | 
			
		||||
                None,
 | 
			
		||||
                0,
 | 
			
		||||
                0,
 | 
			
		||||
            ),
 | 
			
		||||
        );
 | 
			
		||||
        let blockstore = Arc::new(blockstore);
 | 
			
		||||
        let bank_forks = Arc::new(bank_forks);
 | 
			
		||||
        let validator_node_to_vote_keys: HashMap<Pubkey, Pubkey> = validator_keypairs
 | 
			
		||||
            .iter()
 | 
			
		||||
            .map(|(_, keypairs)| {
 | 
			
		||||
                (
 | 
			
		||||
                    keypairs.node_keypair.pubkey(),
 | 
			
		||||
                    keypairs.vote_keypair.pubkey(),
 | 
			
		||||
                )
 | 
			
		||||
            })
 | 
			
		||||
            .collect();
 | 
			
		||||
 | 
			
		||||
        // ClusterInfo
 | 
			
		||||
        let my_keypairs = &validator_authorized_voter_keypairs[0];
 | 
			
		||||
        let my_keypairs = validator_keypairs.values().next().unwrap();
 | 
			
		||||
        let my_pubkey = my_keypairs.node_keypair.pubkey();
 | 
			
		||||
        let cluster_info = ClusterInfo::new(
 | 
			
		||||
            Node::new_localhost_with_pubkey(&my_pubkey).info,
 | 
			
		||||
@@ -2598,16 +2585,18 @@ mod tests {
 | 
			
		||||
        assert_eq!(my_pubkey, cluster_info.id());
 | 
			
		||||
 | 
			
		||||
        // Leader schedule cache
 | 
			
		||||
        let leader_schedule_cache = Arc::new(LeaderScheduleCache::new_from_bank(&bank0));
 | 
			
		||||
        let root_bank = bank_forks.read().unwrap().root_bank();
 | 
			
		||||
        let leader_schedule_cache = Arc::new(LeaderScheduleCache::new_from_bank(&root_bank));
 | 
			
		||||
 | 
			
		||||
        // PohRecorder
 | 
			
		||||
        let working_bank = bank_forks.read().unwrap().working_bank();
 | 
			
		||||
        let poh_recorder = Mutex::new(
 | 
			
		||||
            PohRecorder::new(
 | 
			
		||||
                bank0.tick_height(),
 | 
			
		||||
                bank0.last_blockhash(),
 | 
			
		||||
                bank0.slot(),
 | 
			
		||||
                working_bank.tick_height(),
 | 
			
		||||
                working_bank.last_blockhash(),
 | 
			
		||||
                working_bank.slot(),
 | 
			
		||||
                None,
 | 
			
		||||
                bank0.ticks_per_slot(),
 | 
			
		||||
                working_bank.ticks_per_slot(),
 | 
			
		||||
                &Pubkey::default(),
 | 
			
		||||
                &blockstore,
 | 
			
		||||
                &leader_schedule_cache,
 | 
			
		||||
@@ -2617,14 +2606,11 @@ mod tests {
 | 
			
		||||
            .0,
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        // BankForks
 | 
			
		||||
        let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0)));
 | 
			
		||||
 | 
			
		||||
        // Tower
 | 
			
		||||
        let my_vote_pubkey = my_keypairs.vote_keypair.pubkey();
 | 
			
		||||
        let tower = Tower::new_from_bankforks(
 | 
			
		||||
            &bank_forks.read().unwrap(),
 | 
			
		||||
            &ledger_path,
 | 
			
		||||
            blockstore.ledger_path(),
 | 
			
		||||
            &cluster_info.id(),
 | 
			
		||||
            &my_vote_pubkey,
 | 
			
		||||
        );
 | 
			
		||||
@@ -2640,17 +2626,11 @@ mod tests {
 | 
			
		||||
            optimistically_confirmed_bank,
 | 
			
		||||
        ));
 | 
			
		||||
 | 
			
		||||
        let validator_authorized_voter_keypairs: HashMap<Pubkey, ValidatorVoteKeypairs> =
 | 
			
		||||
            validator_authorized_voter_keypairs
 | 
			
		||||
                .into_iter()
 | 
			
		||||
                .map(|keys| (keys.vote_keypair.pubkey(), keys))
 | 
			
		||||
                .collect();
 | 
			
		||||
 | 
			
		||||
        ReplayBlockstoreComponents {
 | 
			
		||||
            blockstore,
 | 
			
		||||
            validator_node_to_vote_keys,
 | 
			
		||||
            validator_authorized_voter_keypairs,
 | 
			
		||||
            my_vote_pubkey,
 | 
			
		||||
            validator_keypairs,
 | 
			
		||||
            my_pubkey,
 | 
			
		||||
            progress,
 | 
			
		||||
            cluster_info,
 | 
			
		||||
            leader_schedule_cache,
 | 
			
		||||
@@ -2671,7 +2651,7 @@ mod tests {
 | 
			
		||||
            leader_schedule_cache,
 | 
			
		||||
            rpc_subscriptions,
 | 
			
		||||
            ..
 | 
			
		||||
        } = replay_blockstore_components();
 | 
			
		||||
        } = replay_blockstore_components(None);
 | 
			
		||||
 | 
			
		||||
        // Insert a non-root bank so that the propagation logic will update this
 | 
			
		||||
        // bank
 | 
			
		||||
@@ -4267,11 +4247,12 @@ mod tests {
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn test_purge_unconfirmed_duplicate_slot() {
 | 
			
		||||
        let (vote_simulator, _) = setup_default_forks(2);
 | 
			
		||||
        let VoteSimulator {
 | 
			
		||||
            bank_forks,
 | 
			
		||||
            mut progress,
 | 
			
		||||
            ..
 | 
			
		||||
        } = setup_forks();
 | 
			
		||||
        } = vote_simulator;
 | 
			
		||||
        let mut descendants = bank_forks.read().unwrap().descendants().clone();
 | 
			
		||||
        let mut ancestors = bank_forks.read().unwrap().ancestors();
 | 
			
		||||
 | 
			
		||||
@@ -4331,7 +4312,7 @@ mod tests {
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn test_purge_ancestors_descendants() {
 | 
			
		||||
        let VoteSimulator { bank_forks, .. } = setup_forks();
 | 
			
		||||
        let (VoteSimulator { bank_forks, .. }, _) = setup_default_forks(1);
 | 
			
		||||
 | 
			
		||||
        // Purge branch rooted at slot 2
 | 
			
		||||
        let mut descendants = bank_forks.read().unwrap().descendants().clone();
 | 
			
		||||
@@ -4389,7 +4370,7 @@ mod tests {
 | 
			
		||||
            bank_forks,
 | 
			
		||||
            leader_schedule_cache,
 | 
			
		||||
            ..
 | 
			
		||||
        } = replay_blockstore_components();
 | 
			
		||||
        } = replay_blockstore_components(None);
 | 
			
		||||
 | 
			
		||||
        let root_bank = bank_forks.read().unwrap().root_bank();
 | 
			
		||||
        let my_pubkey = leader_schedule_cache
 | 
			
		||||
@@ -4583,13 +4564,16 @@ mod tests {
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn test_gossip_vote_doesnt_affect_fork_choice() {
 | 
			
		||||
        let VoteSimulator {
 | 
			
		||||
            bank_forks,
 | 
			
		||||
            mut heaviest_subtree_fork_choice,
 | 
			
		||||
            mut latest_validator_votes_for_frozen_banks,
 | 
			
		||||
            vote_pubkeys,
 | 
			
		||||
            ..
 | 
			
		||||
        } = setup_forks();
 | 
			
		||||
        let (
 | 
			
		||||
            VoteSimulator {
 | 
			
		||||
                bank_forks,
 | 
			
		||||
                mut heaviest_subtree_fork_choice,
 | 
			
		||||
                mut latest_validator_votes_for_frozen_banks,
 | 
			
		||||
                vote_pubkeys,
 | 
			
		||||
                ..
 | 
			
		||||
            },
 | 
			
		||||
            _,
 | 
			
		||||
        ) = setup_default_forks(1);
 | 
			
		||||
 | 
			
		||||
        let vote_pubkey = vote_pubkeys[0];
 | 
			
		||||
        let mut unfrozen_gossip_verified_vote_hashes = UnfrozenGossipVerifiedVoteHashes::default();
 | 
			
		||||
@@ -4625,14 +4609,14 @@ mod tests {
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn test_replay_stage_refresh_last_vote() {
 | 
			
		||||
        let ReplayBlockstoreComponents {
 | 
			
		||||
            mut validator_authorized_voter_keypairs,
 | 
			
		||||
            mut validator_keypairs,
 | 
			
		||||
            cluster_info,
 | 
			
		||||
            poh_recorder,
 | 
			
		||||
            bank_forks,
 | 
			
		||||
            mut tower,
 | 
			
		||||
            my_vote_pubkey,
 | 
			
		||||
            my_pubkey,
 | 
			
		||||
            ..
 | 
			
		||||
        } = replay_blockstore_components();
 | 
			
		||||
        } = replay_blockstore_components(None);
 | 
			
		||||
 | 
			
		||||
        let mut last_vote_refresh_time = LastVoteRefreshTime {
 | 
			
		||||
            last_refresh_time: Instant::now(),
 | 
			
		||||
@@ -4642,11 +4626,9 @@ mod tests {
 | 
			
		||||
        let mut voted_signatures = vec![];
 | 
			
		||||
 | 
			
		||||
        let my_vote_keypair = vec![Arc::new(
 | 
			
		||||
            validator_authorized_voter_keypairs
 | 
			
		||||
                .remove(&my_vote_pubkey)
 | 
			
		||||
                .unwrap()
 | 
			
		||||
                .vote_keypair,
 | 
			
		||||
            validator_keypairs.remove(&my_pubkey).unwrap().vote_keypair,
 | 
			
		||||
        )];
 | 
			
		||||
        let my_vote_pubkey = my_vote_keypair[0].pubkey();
 | 
			
		||||
        let bank0 = bank_forks.read().unwrap().get(0).unwrap().clone();
 | 
			
		||||
 | 
			
		||||
        fn fill_bank_with_ticks(bank: &Bank) {
 | 
			
		||||
@@ -4902,7 +4884,16 @@ mod tests {
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn setup_forks() -> VoteSimulator {
 | 
			
		||||
    fn setup_forks_from_tree(tree: Tree<Slot>, num_keys: usize) -> (VoteSimulator, Blockstore) {
 | 
			
		||||
        let mut vote_simulator = VoteSimulator::new(num_keys);
 | 
			
		||||
        vote_simulator.fill_bank_forks(tree.clone(), &HashMap::new());
 | 
			
		||||
        let ledger_path = get_tmp_ledger_path!();
 | 
			
		||||
        let blockstore = Blockstore::open(&ledger_path).unwrap();
 | 
			
		||||
        blockstore.add_tree(tree, false, true, 2, Hash::default());
 | 
			
		||||
        (vote_simulator, blockstore)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn setup_default_forks(num_keys: usize) -> (VoteSimulator, Blockstore) {
 | 
			
		||||
        /*
 | 
			
		||||
            Build fork structure:
 | 
			
		||||
 | 
			
		||||
@@ -4917,12 +4908,9 @@ mod tests {
 | 
			
		||||
                      |
 | 
			
		||||
                    slot 6
 | 
			
		||||
        */
 | 
			
		||||
        let forks = tr(0) / (tr(1) / (tr(2) / (tr(4))) / (tr(3) / (tr(5) / (tr(6)))));
 | 
			
		||||
 | 
			
		||||
        let mut vote_simulator = VoteSimulator::new(1);
 | 
			
		||||
        vote_simulator.fill_bank_forks(forks, &HashMap::new());
 | 
			
		||||
 | 
			
		||||
        vote_simulator
 | 
			
		||||
        let tree = tr(0) / (tr(1) / (tr(2) / (tr(4))) / (tr(3) / (tr(5) / (tr(6)))));
 | 
			
		||||
        setup_forks_from_tree(tree, num_keys)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn check_map_eq<K: Eq + std::hash::Hash + std::fmt::Debug, T: PartialEq + std::fmt::Debug>(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user