From e713f0e5fb279d0bb2fc7bf3fd13ccf58e5843b2 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2020 20:00:20 -0800 Subject: [PATCH] Update voting simulation (#8489) --- core/src/consensus.rs | 50 +++++++++++++++++++--------------------- core/src/replay_stage.rs | 17 +++++++------- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 6cbe1e8997..b34173bb43 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -510,7 +510,7 @@ pub mod test { my_keypairs: &ValidatorVoteKeypairs, progress: &mut HashMap, tower: &mut Tower, - ) -> VoteResult { + ) -> Vec { let node = self .find_node_and_update_simulation(vote_slot) .expect("Vote to simulate must be for a slot in the tree"); @@ -585,6 +585,7 @@ pub mod test { .values() .cloned() .collect(); + ReplayStage::compute_bank_stats( &my_pubkey, &ancestors, @@ -592,7 +593,6 @@ pub mod test { tower, progress, ); - ReplayStage::select_fork(&frozen_banks, tower, progress); let bank = bank_forks .read() @@ -606,12 +606,15 @@ pub mod test { .expect("Slot for vote must exist in progress map"); info!("Checking vote: {}", vote_slot); info!("lockouts: {:?}", fork_progress.fork_stats.stake_lockouts); - if fork_progress.fork_stats.is_locked_out && !fork_progress.fork_stats.vote_threshold { - return VoteResult::FailedAllChecks(vote_slot); - } else if fork_progress.fork_stats.is_locked_out { - return VoteResult::LockedOut(vote_slot); - } else if !fork_progress.fork_stats.vote_threshold { - return VoteResult::FailedThreshold(vote_slot); + let mut failures = vec![]; + if fork_progress.fork_stats.is_locked_out { + failures.push(VoteFailures::LockedOut(vote_slot)); + } + if !fork_progress.fork_stats.vote_threshold { + failures.push(VoteFailures::FailedThreshold(vote_slot)); + } + if !failures.is_empty() { + return failures; } let vote = tower.new_vote_from_bank(&bank, &my_vote_pubkey).0; if let Some(new_root) = tower.record_bank_vote(vote) { @@ -621,7 +624,7 @@ pub mod test { // Mark the vote for this bank under this node's pubkey so it will be // integrated into any future child banks cluster_votes.entry(my_pubkey).or_default().push(vote_slot); - VoteResult::Ok + vec![] } // Find a node representing the given slot @@ -666,11 +669,9 @@ pub mod test { } #[derive(PartialEq, Debug)] - pub(crate) enum VoteResult { + pub(crate) enum VoteFailures { LockedOut(u64), FailedThreshold(u64), - FailedAllChecks(u64), - Ok, } // Setup BankForks with bank 0 and all the validator accounts @@ -782,9 +783,8 @@ pub mod test { let mut cluster_votes = HashMap::new(); for vote in votes { - assert_eq!( - VoteResult::Ok, - voting_simulator.simulate_vote( + assert!(voting_simulator + .simulate_vote( vote, &bank_forks, &mut cluster_votes, @@ -793,7 +793,7 @@ pub mod test { &mut progress, &mut tower, ) - ); + .is_empty()); } for i in 0..5 { @@ -856,8 +856,8 @@ pub mod test { let mut tower = Tower::new_with_key(&node_pubkey); for vote in &votes { // All these votes should be ok - assert_eq!( - voting_simulator.simulate_vote( + assert!(voting_simulator + .simulate_vote( *vote, &bank_forks, &mut cluster_votes, @@ -865,15 +865,14 @@ pub mod test { keypairs.get(&node_pubkey).unwrap(), &mut progress, &mut tower, - ), - VoteResult::Ok - ); + ) + .is_empty()); } // Try to come back to main fork let next_unlocked_slot = 110; - assert_eq!( - voting_simulator.simulate_vote( + assert!(voting_simulator + .simulate_vote( next_unlocked_slot, &bank_forks, &mut cluster_votes, @@ -881,9 +880,8 @@ pub mod test { keypairs.get(&node_pubkey).unwrap(), &mut progress, &mut tower, - ), - VoteResult::Ok - ); + ) + .is_empty()); info!("local tower: {:#?}", tower.lockouts.votes); let vote_accounts = bank_forks diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index d757d6c01f..5bc91d856b 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -287,7 +287,7 @@ impl ReplayStage { } } - let vote_bank = Self::select_fork(&frozen_banks, &tower, &mut progress); + let vote_bank = Self::select_fork(&frozen_banks, &tower, &progress); datapoint_debug!( "replay_stage-memory", ("select_fork", (allocated.get() - start) as i64, i64), @@ -849,7 +849,7 @@ impl ReplayStage { pub(crate) fn select_fork( frozen_banks: &[Arc], tower: &Tower, - progress: &mut HashMap, + progress: &HashMap, ) -> Option> { let tower_start = Instant::now(); let num_frozen_banks = frozen_banks.len(); @@ -1056,7 +1056,7 @@ pub(crate) mod tests { use super::*; use crate::{ commitment::BlockCommitment, - consensus::test::{initialize_state, VoteResult, VoteSimulator}, + consensus::test::{initialize_state, VoteSimulator}, consensus::Tower, genesis_utils::{create_genesis_config, create_genesis_config_with_leader}, replay_stage::ReplayStage, @@ -1299,7 +1299,7 @@ pub(crate) mod tests { &mut fork_progresses[i], ); let response = - ReplayStage::select_fork(&frozen_banks, &towers[i], &mut fork_progresses[i]); + ReplayStage::select_fork(&frozen_banks, &towers[i], &fork_progresses[i]); if response.is_none() { None @@ -1938,8 +1938,8 @@ pub(crate) mod tests { let mut cluster_votes: HashMap> = HashMap::new(); let votes: Vec = vec![0, 2]; for vote in &votes { - assert_eq!( - voting_simulator.simulate_vote( + assert!(voting_simulator + .simulate_vote( *vote, &bank_forks, &mut cluster_votes, @@ -1947,9 +1947,8 @@ pub(crate) mod tests { keypairs.get(&node_pubkey).unwrap(), &mut progress, &mut tower, - ), - VoteResult::Ok - ); + ) + .is_empty()); } let mut frozen_banks: Vec<_> = bank_forks