Send recent votes in Vote Transactions (#3734)
This commit is contained in:
@ -10,6 +10,7 @@ use std::sync::Arc;
|
||||
|
||||
pub const VOTE_THRESHOLD_DEPTH: usize = 8;
|
||||
pub const VOTE_THRESHOLD_SIZE: f64 = 2f64 / 3f64;
|
||||
const MAX_RECENT_VOTES: usize = 16;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct EpochStakes {
|
||||
@ -253,6 +254,13 @@ impl Locktower {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn recent_votes(&self) -> Vec<Vote> {
|
||||
let start = self.lockouts.votes.len().saturating_sub(MAX_RECENT_VOTES);
|
||||
(start..self.lockouts.votes.len())
|
||||
.map(|i| Vote::new(self.lockouts.votes[i].slot))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn root(&self) -> Option<u64> {
|
||||
self.lockouts.root_slot
|
||||
}
|
||||
@ -798,4 +806,29 @@ mod test {
|
||||
locktower.collect_vote_lockouts(vote_to_evaluate, accounts.into_iter(), &ancestors);
|
||||
assert!(!locktower.check_vote_stake_threshold(vote_to_evaluate, &stakes_lockouts));
|
||||
}
|
||||
|
||||
fn vote_and_check_recent(num_votes: usize) {
|
||||
let mut locktower = Locktower::new(EpochStakes::new_for_tests(2), 1, 0.67);
|
||||
let start = num_votes.saturating_sub(MAX_RECENT_VOTES);
|
||||
let expected: Vec<_> = (start..num_votes).map(|i| Vote::new(i as u64)).collect();
|
||||
for i in 0..num_votes {
|
||||
locktower.record_vote(i as u64);
|
||||
}
|
||||
assert_eq!(expected, locktower.recent_votes())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_recent_votes_full() {
|
||||
vote_and_check_recent(MAX_LOCKOUT_HISTORY)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_recent_votes_empty() {
|
||||
vote_and_check_recent(0)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_recent_votes_exact() {
|
||||
vote_and_check_recent(MAX_RECENT_VOTES)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user