Update voting simulation (#8460)

This commit is contained in:
carllin 2020-02-26 14:09:07 -08:00 committed by GitHub
parent 7a2bf7e7eb
commit d47a47924a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 35 deletions

View File

@ -513,7 +513,7 @@ pub mod test {
my_keypairs: &ValidatorVoteKeypairs,
progress: &mut HashMap<u64, ForkProgress>,
tower: &mut Tower,
) -> VoteResult {
) -> Vec<VoteFailures> {
let node = self
.find_node_and_update_simulation(vote_slot)
.expect("Vote to simulate must be for a slot in the tree");
@ -588,6 +588,7 @@ pub mod test {
.values()
.cloned()
.collect();
ReplayStage::compute_bank_stats(
&my_pubkey,
&ancestors,
@ -595,7 +596,6 @@ pub mod test {
tower,
progress,
);
ReplayStage::select_fork(&frozen_banks, tower, progress);
let bank = bank_forks
.read()
@ -609,12 +609,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) {
@ -624,7 +627,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
@ -669,11 +672,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
@ -787,9 +788,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,
@ -798,7 +798,7 @@ pub mod test {
&mut progress,
&mut tower,
)
);
.is_empty());
}
for i in 0..5 {
@ -861,8 +861,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,
@ -870,15 +870,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,
@ -886,9 +885,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

View File

@ -277,7 +277,7 @@ impl ReplayStage {
}
}
let vote_bank = Self::select_fork(&frozen_banks, &tower, &mut progress);
let vote_bank = Self::select_fork(&frozen_banks, &tower, &progress);
Self::report_memory(&allocated, "select_fork", start);
if vote_bank.is_none() {
break;
@ -842,7 +842,7 @@ impl ReplayStage {
pub(crate) fn select_fork(
frozen_banks: &[Arc<Bank>],
tower: &Tower,
progress: &mut HashMap<u64, ForkProgress>,
progress: &HashMap<u64, ForkProgress>,
) -> Option<Arc<Bank>> {
let tower_start = Instant::now();
let num_frozen_banks = frozen_banks.len();
@ -1068,7 +1068,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,
@ -1312,7 +1312,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
@ -1952,8 +1952,8 @@ pub(crate) mod tests {
let mut cluster_votes: HashMap<Pubkey, Vec<Slot>> = HashMap::new();
let votes: Vec<Slot> = vec![0, 2];
for vote in &votes {
assert_eq!(
voting_simulator.simulate_vote(
assert!(voting_simulator
.simulate_vote(
*vote,
&bank_forks,
&mut cluster_votes,
@ -1961,9 +1961,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