Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gossip: reduce votes stored per validator from 31 to 2 #2982

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use {
},
crds_value::{
self, CrdsData, CrdsValue, CrdsValueLabel, EpochSlotsIndex, LowestSlot, NodeInstance,
SnapshotHashes, Version, Vote, MAX_WALLCLOCK,
SnapshotHashes, Version, Vote, MAX_VOTES, MAX_WALLCLOCK,
},
duplicate_shred::DuplicateShred,
epoch_slots::EpochSlots,
Expand Down Expand Up @@ -77,7 +77,6 @@ use {
streamer::{PacketBatchReceiver, PacketBatchSender},
},
solana_vote::vote_parser,
solana_vote_program::vote_state::MAX_LOCKOUT_HISTORY,
std::{
borrow::{Borrow, Cow},
collections::{HashMap, HashSet, VecDeque},
Expand Down Expand Up @@ -1054,7 +1053,7 @@ impl ClusterInfo {
}

pub fn push_vote_at_index(&self, vote: Transaction, vote_index: u8) {
assert!((vote_index as usize) < MAX_LOCKOUT_HISTORY);
assert!(vote_index < MAX_VOTES);
let self_pubkey = self.id();
let now = timestamp();
let vote = Vote::new(self_pubkey, vote, now).unwrap();
Expand All @@ -1080,7 +1079,7 @@ impl ClusterInfo {
let vote_index = {
let gossip_crds =
self.time_gossip_read_lock("gossip_read_push_vote", &self.stats.push_vote_read);
(0..MAX_LOCKOUT_HISTORY as u8)
(0..MAX_VOTES)
.filter_map(|ix| {
let vote = CrdsValueLabel::Vote(ix, self_pubkey);
let vote: &CrdsData = gossip_crds.get(&vote)?;
Expand All @@ -1102,7 +1101,7 @@ impl ClusterInfo {
if exists_newer_vote {
return None;
}
if num_crds_votes < MAX_LOCKOUT_HISTORY as u8 {
if num_crds_votes < MAX_VOTES {
// Do not evict if there is space in crds
Some(num_crds_votes)
} else {
Expand All @@ -1127,7 +1126,7 @@ impl ClusterInfo {
tower
);
};
debug_assert!(vote_index < MAX_LOCKOUT_HISTORY as u8);
debug_assert!(vote_index < MAX_VOTES);
self.push_vote_at_index(vote, vote_index);
}

Expand All @@ -1136,7 +1135,7 @@ impl ClusterInfo {
let self_pubkey = self.id();
let gossip_crds =
self.time_gossip_read_lock("gossip_read_push_vote", &self.stats.push_vote_read);
(0..MAX_LOCKOUT_HISTORY as u8).find(|ix| {
(0..MAX_VOTES).find(|ix| {
let vote = CrdsValueLabel::Vote(*ix, self_pubkey);
let Some(vote) = gossip_crds.get::<&CrdsData>(&vote) else {
return false;
Expand Down Expand Up @@ -1168,7 +1167,7 @@ impl ClusterInfo {
);
return;
};
debug_assert!(vote_index < MAX_LOCKOUT_HISTORY as u8);
debug_assert!(vote_index < MAX_VOTES);
self.push_vote_at_index(refresh_vote, vote_index);
}
}
Expand Down Expand Up @@ -3413,10 +3412,14 @@ mod tests {
duplicate_shred::{self, tests::new_rand_shred, MAX_DUPLICATE_SHREDS},
socketaddr,
},
crds_value::MAX_VOTES,
itertools::izip,
solana_ledger::shred::Shredder,
solana_sdk::signature::{Keypair, Signer},
solana_vote_program::{vote_instruction, vote_state::Vote},
solana_vote_program::{
vote_instruction,
vote_state::{Vote, MAX_LOCKOUT_HISTORY},
},
std::{
iter::repeat_with,
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4},
Expand Down Expand Up @@ -3966,7 +3969,7 @@ mod tests {
}

let initial_votes = cluster_info.get_votes(&mut Cursor::default());
assert_eq!(initial_votes.len(), MAX_LOCKOUT_HISTORY);
assert_eq!(initial_votes.len(), MAX_VOTES as usize);

// Trying to refresh a vote less than all votes in gossip should do nothing
let refresh_slot = lowest_vote_slot - 1;
Expand Down Expand Up @@ -4001,7 +4004,7 @@ mod tests {

// This should evict the latest vote since it's for a slot less than refresh_slot
let votes = cluster_info.get_votes(&mut Cursor::default());
assert_eq!(votes.len(), MAX_LOCKOUT_HISTORY);
assert_eq!(votes.len(), MAX_VOTES as usize);
assert!(votes.contains(&refresh_tx));
assert!(!votes.contains(&first_vote.unwrap()));
}
Expand Down
7 changes: 4 additions & 3 deletions gossip/src/crds_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ pub const MAX_WALLCLOCK: u64 = 1_000_000_000_000_000;
pub const MAX_SLOT: u64 = 1_000_000_000_000_000;

pub type VoteIndex = u8;
// TODO: Remove this in favor of vote_state::MAX_LOCKOUT_HISTORY once
// the fleet is updated to the new ClusterInfo::push_vote code.
pub const MAX_VOTES: VoteIndex = 32;
/// Number of votes per validator to store.
/// TODO: update comment after testing
/// Only need latest vote + potential refresh of that vote.
pub const MAX_VOTES: VoteIndex = 2;

pub type EpochSlotsIndex = u8;
pub const MAX_EPOCH_SLOTS: EpochSlotsIndex = 255;
Expand Down
Loading