Skip to content

Commit 491baf0

Browse files
authored
gossip: reduce votes stored per validator from 32 to 12 (anza-xyz#3315)
1 parent eff7b9f commit 491baf0

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

gossip/src/cluster_info.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use {
1818
cluster_info_metrics::{Counter, GossipStats, ScopedTimer, TimedGuard},
1919
contact_info::{self, ContactInfo, ContactInfoQuery, Error as ContactInfoError},
2020
crds::{Crds, Cursor, GossipRoute},
21-
crds_data::{self, CrdsData, EpochSlotsIndex, LowestSlot, SnapshotHashes, Vote},
21+
crds_data::{self, CrdsData, EpochSlotsIndex, LowestSlot, SnapshotHashes, Vote, MAX_VOTES},
2222
crds_gossip::CrdsGossip,
2323
crds_gossip_error::CrdsGossipError,
2424
crds_gossip_pull::{
@@ -76,7 +76,6 @@ use {
7676
solana_time_utils::timestamp,
7777
solana_transaction::Transaction,
7878
solana_vote::vote_parser,
79-
solana_vote_program::vote_state::MAX_LOCKOUT_HISTORY,
8079
std::{
8180
borrow::Borrow,
8281
collections::{HashMap, HashSet, VecDeque},
@@ -786,7 +785,7 @@ impl ClusterInfo {
786785
}
787786

788787
pub fn push_vote_at_index(&self, vote: Transaction, vote_index: u8) {
789-
assert!((vote_index as usize) < MAX_LOCKOUT_HISTORY);
788+
assert!(vote_index < MAX_VOTES);
790789
let self_pubkey = self.id();
791790
let now = timestamp();
792791
let vote = Vote::new(self_pubkey, vote, now).unwrap();
@@ -812,7 +811,7 @@ impl ClusterInfo {
812811
let vote_index = {
813812
let gossip_crds =
814813
self.time_gossip_read_lock("gossip_read_push_vote", &self.stats.push_vote_read);
815-
(0..MAX_LOCKOUT_HISTORY as u8)
814+
(0..MAX_VOTES)
816815
.filter_map(|ix| {
817816
let vote = CrdsValueLabel::Vote(ix, self_pubkey);
818817
let vote: &CrdsData = gossip_crds.get(&vote)?;
@@ -834,7 +833,7 @@ impl ClusterInfo {
834833
if exists_newer_vote {
835834
return None;
836835
}
837-
if num_crds_votes < MAX_LOCKOUT_HISTORY as u8 {
836+
if num_crds_votes < MAX_VOTES {
838837
// Do not evict if there is space in crds
839838
Some(num_crds_votes)
840839
} else {
@@ -859,7 +858,7 @@ impl ClusterInfo {
859858
tower
860859
);
861860
};
862-
debug_assert!(vote_index < MAX_LOCKOUT_HISTORY as u8);
861+
debug_assert!(vote_index < MAX_VOTES);
863862
self.push_vote_at_index(vote, vote_index);
864863
}
865864

@@ -868,7 +867,7 @@ impl ClusterInfo {
868867
let self_pubkey = self.id();
869868
let gossip_crds =
870869
self.time_gossip_read_lock("gossip_read_push_vote", &self.stats.push_vote_read);
871-
(0..MAX_LOCKOUT_HISTORY as u8).find(|ix| {
870+
(0..MAX_VOTES).find(|ix| {
872871
let vote = CrdsValueLabel::Vote(*ix, self_pubkey);
873872
let Some(vote) = gossip_crds.get::<&CrdsData>(&vote) else {
874873
return false;
@@ -900,7 +899,7 @@ impl ClusterInfo {
900899
);
901900
return;
902901
};
903-
debug_assert!(vote_index < MAX_LOCKOUT_HISTORY as u8);
902+
debug_assert!(vote_index < MAX_VOTES);
904903
self.push_vote_at_index(refresh_vote, vote_index);
905904
}
906905
}
@@ -3072,7 +3071,10 @@ mod tests {
30723071
solana_ledger::shred::Shredder,
30733072
solana_net_utils::bind_to,
30743073
solana_signer::Signer,
3075-
solana_vote_program::{vote_instruction, vote_state::Vote},
3074+
solana_vote_program::{
3075+
vote_instruction,
3076+
vote_state::{Vote, MAX_LOCKOUT_HISTORY},
3077+
},
30763078
std::{
30773079
iter::repeat_with,
30783080
net::{IpAddr, Ipv4Addr},
@@ -3483,7 +3485,7 @@ mod tests {
34833485
}
34843486

34853487
let initial_votes = cluster_info.get_votes(&mut Cursor::default());
3486-
assert_eq!(initial_votes.len(), MAX_LOCKOUT_HISTORY);
3488+
assert_eq!(initial_votes.len(), MAX_VOTES as usize);
34873489

34883490
// Trying to refresh a vote less than all votes in gossip should do nothing
34893491
let refresh_slot = lowest_vote_slot - 1;
@@ -3518,7 +3520,7 @@ mod tests {
35183520

35193521
// This should evict the latest vote since it's for a slot less than refresh_slot
35203522
let votes = cluster_info.get_votes(&mut Cursor::default());
3521-
assert_eq!(votes.len(), MAX_LOCKOUT_HISTORY);
3523+
assert_eq!(votes.len(), MAX_VOTES as usize);
35223524
assert!(votes.contains(&refresh_tx));
35233525
assert!(!votes.contains(&first_vote.unwrap()));
35243526
}
@@ -3688,7 +3690,7 @@ mod tests {
36883690
cluster_info.push_vote(&tower, vote);
36893691

36903692
let vote_slots = get_vote_slots(&cluster_info);
3691-
let min_vote = k.saturating_sub(MAX_LOCKOUT_HISTORY - 1) as u64;
3693+
let min_vote = k.saturating_sub(MAX_VOTES as usize - 1) as u64;
36923694
assert!(vote_slots.into_iter().eq(min_vote..=(k as u64)));
36933695
sleep(Duration::from_millis(1));
36943696
}

gossip/src/crds_data.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ pub(crate) const MAX_SLOT: u64 = 1_000_000_000_000_000;
2727
const MAX_ACCOUNTS_HASHES: usize = 16;
2828

2929
pub(crate) type VoteIndex = u8;
30-
// TODO: Remove this in favor of vote_state::MAX_LOCKOUT_HISTORY once
31-
// the fleet is updated to the new ClusterInfo::push_vote code.
32-
const MAX_VOTES: VoteIndex = 32;
30+
// Until the cluster upgrades we allow votes from higher indices
31+
const OLD_MAX_VOTES: VoteIndex = 32;
32+
/// Number of votes per validator to store.
33+
pub const MAX_VOTES: VoteIndex = 12;
3334

3435
pub(crate) type EpochSlotsIndex = u8;
3536
pub(crate) const MAX_EPOCH_SLOTS: EpochSlotsIndex = 255;
@@ -68,7 +69,7 @@ impl Sanitize for CrdsData {
6869
match self {
6970
CrdsData::LegacyContactInfo(val) => val.sanitize(),
7071
CrdsData::Vote(ix, val) => {
71-
if *ix >= MAX_VOTES {
72+
if *ix >= OLD_MAX_VOTES {
7273
return Err(SanitizeError::ValueOutOfBounds);
7374
}
7475
val.sanitize()
@@ -539,7 +540,7 @@ mod test {
539540
let mut rng = rand::thread_rng();
540541
let keypair = Keypair::new();
541542
let vote = Vote::new(keypair.pubkey(), new_test_vote_tx(&mut rng), timestamp()).unwrap();
542-
let vote = CrdsValue::new(CrdsData::Vote(MAX_VOTES, vote), &keypair);
543+
let vote = CrdsValue::new(CrdsData::Vote(OLD_MAX_VOTES, vote), &keypair);
543544
assert!(vote.sanitize().is_err());
544545
}
545546

local-cluster/tests/local_cluster.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use {
2020
},
2121
solana_download_utils::download_snapshot_archive,
2222
solana_entry::entry::create_ticks,
23-
solana_gossip::gossip_service::discover_cluster,
23+
solana_gossip::{crds_data::MAX_VOTES, gossip_service::discover_cluster},
2424
solana_ledger::{
2525
ancestor_iterator::AncestorIterator,
2626
bank_forks_utils,
@@ -4072,8 +4072,8 @@ fn run_duplicate_shreds_broadcast_leader(vote_on_duplicate: bool) {
40724072
None,
40734073
);
40744074
gossip_vote_index += 1;
4075-
gossip_vote_index %= MAX_LOCKOUT_HISTORY;
4076-
cluster_info.push_vote_at_index(vote_tx, gossip_vote_index as u8)
4075+
gossip_vote_index %= MAX_VOTES;
4076+
cluster_info.push_vote_at_index(vote_tx, gossip_vote_index);
40774077
}
40784078
}
40794079
},

0 commit comments

Comments
 (0)