From 5f72b3c7347b8c8c9c783573ab3fb58eb97841e1 Mon Sep 17 00:00:00 2001 From: Ashwin Sekar Date: Wed, 25 Sep 2024 13:37:27 +0000 Subject: [PATCH] gossip: reduce votes stored per validator from 32 to 12 --- gossip/src/cluster_info.rs | 25 ++++++++++++++----------- gossip/src/crds_value.rs | 5 ++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/gossip/src/cluster_info.rs b/gossip/src/cluster_info.rs index 67a587825d5843..dc2c18b1fbeee4 100644 --- a/gossip/src/cluster_info.rs +++ b/gossip/src/cluster_info.rs @@ -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, @@ -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}, @@ -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(); @@ -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)?; @@ -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 { @@ -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); } @@ -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; @@ -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); } } @@ -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}, @@ -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; @@ -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())); } diff --git a/gossip/src/crds_value.rs b/gossip/src/crds_value.rs index 50061fe4df2c9c..19becaebff7575 100644 --- a/gossip/src/crds_value.rs +++ b/gossip/src/crds_value.rs @@ -33,9 +33,8 @@ 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. +pub const MAX_VOTES: VoteIndex = 12; pub type EpochSlotsIndex = u8; pub const MAX_EPOCH_SLOTS: EpochSlotsIndex = 255;