Update voting simulation (#8460)
This commit is contained in:
parent
7a2bf7e7eb
commit
d47a47924a
|
@ -513,7 +513,7 @@ pub mod test {
|
||||||
my_keypairs: &ValidatorVoteKeypairs,
|
my_keypairs: &ValidatorVoteKeypairs,
|
||||||
progress: &mut HashMap<u64, ForkProgress>,
|
progress: &mut HashMap<u64, ForkProgress>,
|
||||||
tower: &mut Tower,
|
tower: &mut Tower,
|
||||||
) -> VoteResult {
|
) -> Vec<VoteFailures> {
|
||||||
let node = self
|
let node = self
|
||||||
.find_node_and_update_simulation(vote_slot)
|
.find_node_and_update_simulation(vote_slot)
|
||||||
.expect("Vote to simulate must be for a slot in the tree");
|
.expect("Vote to simulate must be for a slot in the tree");
|
||||||
|
@ -588,6 +588,7 @@ pub mod test {
|
||||||
.values()
|
.values()
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
ReplayStage::compute_bank_stats(
|
ReplayStage::compute_bank_stats(
|
||||||
&my_pubkey,
|
&my_pubkey,
|
||||||
&ancestors,
|
&ancestors,
|
||||||
|
@ -595,7 +596,6 @@ pub mod test {
|
||||||
tower,
|
tower,
|
||||||
progress,
|
progress,
|
||||||
);
|
);
|
||||||
ReplayStage::select_fork(&frozen_banks, tower, progress);
|
|
||||||
|
|
||||||
let bank = bank_forks
|
let bank = bank_forks
|
||||||
.read()
|
.read()
|
||||||
|
@ -609,12 +609,15 @@ pub mod test {
|
||||||
.expect("Slot for vote must exist in progress map");
|
.expect("Slot for vote must exist in progress map");
|
||||||
info!("Checking vote: {}", vote_slot);
|
info!("Checking vote: {}", vote_slot);
|
||||||
info!("lockouts: {:?}", fork_progress.fork_stats.stake_lockouts);
|
info!("lockouts: {:?}", fork_progress.fork_stats.stake_lockouts);
|
||||||
if fork_progress.fork_stats.is_locked_out && !fork_progress.fork_stats.vote_threshold {
|
let mut failures = vec![];
|
||||||
return VoteResult::FailedAllChecks(vote_slot);
|
if fork_progress.fork_stats.is_locked_out {
|
||||||
} else if fork_progress.fork_stats.is_locked_out {
|
failures.push(VoteFailures::LockedOut(vote_slot));
|
||||||
return VoteResult::LockedOut(vote_slot);
|
}
|
||||||
} else if !fork_progress.fork_stats.vote_threshold {
|
if !fork_progress.fork_stats.vote_threshold {
|
||||||
return VoteResult::FailedThreshold(vote_slot);
|
failures.push(VoteFailures::FailedThreshold(vote_slot));
|
||||||
|
}
|
||||||
|
if !failures.is_empty() {
|
||||||
|
return failures;
|
||||||
}
|
}
|
||||||
let vote = tower.new_vote_from_bank(&bank, &my_vote_pubkey).0;
|
let vote = tower.new_vote_from_bank(&bank, &my_vote_pubkey).0;
|
||||||
if let Some(new_root) = tower.record_bank_vote(vote) {
|
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
|
// Mark the vote for this bank under this node's pubkey so it will be
|
||||||
// integrated into any future child banks
|
// integrated into any future child banks
|
||||||
cluster_votes.entry(my_pubkey).or_default().push(vote_slot);
|
cluster_votes.entry(my_pubkey).or_default().push(vote_slot);
|
||||||
VoteResult::Ok
|
vec![]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find a node representing the given slot
|
// Find a node representing the given slot
|
||||||
|
@ -669,11 +672,9 @@ pub mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub(crate) enum VoteResult {
|
pub(crate) enum VoteFailures {
|
||||||
LockedOut(u64),
|
LockedOut(u64),
|
||||||
FailedThreshold(u64),
|
FailedThreshold(u64),
|
||||||
FailedAllChecks(u64),
|
|
||||||
Ok,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup BankForks with bank 0 and all the validator accounts
|
// Setup BankForks with bank 0 and all the validator accounts
|
||||||
|
@ -787,9 +788,8 @@ pub mod test {
|
||||||
|
|
||||||
let mut cluster_votes = HashMap::new();
|
let mut cluster_votes = HashMap::new();
|
||||||
for vote in votes {
|
for vote in votes {
|
||||||
assert_eq!(
|
assert!(voting_simulator
|
||||||
VoteResult::Ok,
|
.simulate_vote(
|
||||||
voting_simulator.simulate_vote(
|
|
||||||
vote,
|
vote,
|
||||||
&bank_forks,
|
&bank_forks,
|
||||||
&mut cluster_votes,
|
&mut cluster_votes,
|
||||||
|
@ -798,7 +798,7 @@ pub mod test {
|
||||||
&mut progress,
|
&mut progress,
|
||||||
&mut tower,
|
&mut tower,
|
||||||
)
|
)
|
||||||
);
|
.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..5 {
|
for i in 0..5 {
|
||||||
|
@ -861,8 +861,8 @@ pub mod test {
|
||||||
let mut tower = Tower::new_with_key(&node_pubkey);
|
let mut tower = Tower::new_with_key(&node_pubkey);
|
||||||
for vote in &votes {
|
for vote in &votes {
|
||||||
// All these votes should be ok
|
// All these votes should be ok
|
||||||
assert_eq!(
|
assert!(voting_simulator
|
||||||
voting_simulator.simulate_vote(
|
.simulate_vote(
|
||||||
*vote,
|
*vote,
|
||||||
&bank_forks,
|
&bank_forks,
|
||||||
&mut cluster_votes,
|
&mut cluster_votes,
|
||||||
|
@ -870,15 +870,14 @@ pub mod test {
|
||||||
keypairs.get(&node_pubkey).unwrap(),
|
keypairs.get(&node_pubkey).unwrap(),
|
||||||
&mut progress,
|
&mut progress,
|
||||||
&mut tower,
|
&mut tower,
|
||||||
),
|
)
|
||||||
VoteResult::Ok
|
.is_empty());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to come back to main fork
|
// Try to come back to main fork
|
||||||
let next_unlocked_slot = 110;
|
let next_unlocked_slot = 110;
|
||||||
assert_eq!(
|
assert!(voting_simulator
|
||||||
voting_simulator.simulate_vote(
|
.simulate_vote(
|
||||||
next_unlocked_slot,
|
next_unlocked_slot,
|
||||||
&bank_forks,
|
&bank_forks,
|
||||||
&mut cluster_votes,
|
&mut cluster_votes,
|
||||||
|
@ -886,9 +885,8 @@ pub mod test {
|
||||||
keypairs.get(&node_pubkey).unwrap(),
|
keypairs.get(&node_pubkey).unwrap(),
|
||||||
&mut progress,
|
&mut progress,
|
||||||
&mut tower,
|
&mut tower,
|
||||||
),
|
)
|
||||||
VoteResult::Ok
|
.is_empty());
|
||||||
);
|
|
||||||
|
|
||||||
info!("local tower: {:#?}", tower.lockouts.votes);
|
info!("local tower: {:#?}", tower.lockouts.votes);
|
||||||
let vote_accounts = bank_forks
|
let vote_accounts = bank_forks
|
||||||
|
|
|
@ -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);
|
Self::report_memory(&allocated, "select_fork", start);
|
||||||
if vote_bank.is_none() {
|
if vote_bank.is_none() {
|
||||||
break;
|
break;
|
||||||
|
@ -842,7 +842,7 @@ impl ReplayStage {
|
||||||
pub(crate) fn select_fork(
|
pub(crate) fn select_fork(
|
||||||
frozen_banks: &[Arc<Bank>],
|
frozen_banks: &[Arc<Bank>],
|
||||||
tower: &Tower,
|
tower: &Tower,
|
||||||
progress: &mut HashMap<u64, ForkProgress>,
|
progress: &HashMap<u64, ForkProgress>,
|
||||||
) -> Option<Arc<Bank>> {
|
) -> Option<Arc<Bank>> {
|
||||||
let tower_start = Instant::now();
|
let tower_start = Instant::now();
|
||||||
let num_frozen_banks = frozen_banks.len();
|
let num_frozen_banks = frozen_banks.len();
|
||||||
|
@ -1068,7 +1068,7 @@ pub(crate) mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
commitment::BlockCommitment,
|
commitment::BlockCommitment,
|
||||||
consensus::test::{initialize_state, VoteResult, VoteSimulator},
|
consensus::test::{initialize_state, VoteSimulator},
|
||||||
consensus::Tower,
|
consensus::Tower,
|
||||||
genesis_utils::{create_genesis_config, create_genesis_config_with_leader},
|
genesis_utils::{create_genesis_config, create_genesis_config_with_leader},
|
||||||
replay_stage::ReplayStage,
|
replay_stage::ReplayStage,
|
||||||
|
@ -1312,7 +1312,7 @@ pub(crate) mod tests {
|
||||||
&mut fork_progresses[i],
|
&mut fork_progresses[i],
|
||||||
);
|
);
|
||||||
let response =
|
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() {
|
if response.is_none() {
|
||||||
None
|
None
|
||||||
|
@ -1952,8 +1952,8 @@ pub(crate) mod tests {
|
||||||
let mut cluster_votes: HashMap<Pubkey, Vec<Slot>> = HashMap::new();
|
let mut cluster_votes: HashMap<Pubkey, Vec<Slot>> = HashMap::new();
|
||||||
let votes: Vec<Slot> = vec![0, 2];
|
let votes: Vec<Slot> = vec![0, 2];
|
||||||
for vote in &votes {
|
for vote in &votes {
|
||||||
assert_eq!(
|
assert!(voting_simulator
|
||||||
voting_simulator.simulate_vote(
|
.simulate_vote(
|
||||||
*vote,
|
*vote,
|
||||||
&bank_forks,
|
&bank_forks,
|
||||||
&mut cluster_votes,
|
&mut cluster_votes,
|
||||||
|
@ -1961,9 +1961,8 @@ pub(crate) mod tests {
|
||||||
keypairs.get(&node_pubkey).unwrap(),
|
keypairs.get(&node_pubkey).unwrap(),
|
||||||
&mut progress,
|
&mut progress,
|
||||||
&mut tower,
|
&mut tower,
|
||||||
),
|
)
|
||||||
VoteResult::Ok
|
.is_empty());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut frozen_banks: Vec<_> = bank_forks
|
let mut frozen_banks: Vec<_> = bank_forks
|
||||||
|
|
Loading…
Reference in New Issue