Rename SnapshotHashes to LegacySnapshotHashes (#31086)

This commit is contained in:
Brooks 2023-04-10 17:52:20 -04:00 committed by GitHub
parent e12c250cf5
commit f3083ad2e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 54 deletions

View File

@ -1,7 +1,7 @@
use {
crossbeam_channel::{Receiver, Sender},
solana_gossip::cluster_info::{
ClusterInfo, MAX_INCREMENTAL_SNAPSHOT_HASHES, MAX_SNAPSHOT_HASHES,
ClusterInfo, MAX_INCREMENTAL_SNAPSHOT_HASHES, MAX_LEGACY_SNAPSHOT_HASHES,
},
solana_measure::measure_us,
solana_perf::thread::renice_this_thread,
@ -46,7 +46,7 @@ impl SnapshotPackagerService {
let exit = exit.clone();
let cluster_info = cluster_info.clone();
let max_full_snapshot_hashes = std::cmp::min(
MAX_SNAPSHOT_HASHES,
MAX_LEGACY_SNAPSHOT_HASHES,
snapshot_config
.maximum_full_snapshot_archives_to_retain
.get(),
@ -279,7 +279,7 @@ impl SnapshotGossipManager {
);
self.cluster_info
.push_snapshot_hashes(Self::clone_hashes_for_crds(
.push_legacy_snapshot_hashes(Self::clone_hashes_for_crds(
&self.full_snapshot_hashes.hashes,
));
}

View File

@ -33,8 +33,8 @@ use {
},
crds_value::{
self, AccountsHashes, CrdsData, CrdsValue, CrdsValueLabel, EpochSlotsIndex,
IncrementalSnapshotHashes, LowestSlot, NodeInstance, SnapshotHashes, Version, Vote,
MAX_WALLCLOCK,
IncrementalSnapshotHashes, LegacySnapshotHashes, LowestSlot, NodeInstance, Version,
Vote, MAX_WALLCLOCK,
},
duplicate_shred::DuplicateShred,
epoch_slots::EpochSlots,
@ -119,10 +119,10 @@ pub(crate) const DUPLICATE_SHRED_MAX_PAYLOAD_SIZE: usize = PACKET_DATA_SIZE - 11
/// such that the serialized size of the push/pull message stays below
/// PACKET_DATA_SIZE.
pub const MAX_ACCOUNTS_HASHES: usize = 16;
/// Maximum number of hashes in SnapshotHashes a node publishes
/// Maximum number of hashes in LegacySnapshotHashes a node publishes
/// such that the serialized size of the push/pull message stays below
/// PACKET_DATA_SIZE.
pub const MAX_SNAPSHOT_HASHES: usize = 16;
pub const MAX_LEGACY_SNAPSHOT_HASHES: usize = 16;
/// Maximum number of hashes in IncrementalSnapshotHashes a node publishes
/// such that the serialized size of the push/pull message stays below
/// PACKET_DATA_SIZE.
@ -273,7 +273,7 @@ pub fn make_accounts_hashes_message(
pub(crate) type Ping = ping_pong::Ping<[u8; GOSSIP_PING_TOKEN_SIZE]>;
// TODO These messages should go through the gpu pipeline for spam filtering
#[frozen_abi(digest = "5rGt5M3ujgfduA2dtN3rYg1CmvrGpZdRBq7KW4U58C8H")]
#[frozen_abi(digest = "9pQAWSpV411icPZjDnBcTJKjLyzYPVFWgYxx3bqWQbtg")]
#[derive(Serialize, Deserialize, Debug, AbiEnumVisitor, AbiExample)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum Protocol {
@ -390,7 +390,7 @@ fn retain_staked(values: &mut Vec<CrdsValue>, stakes: &HashMap<Pubkey, u64>) {
// Unstaked nodes can still help repair.
CrdsData::EpochSlots(_, _) => true,
// Unstaked nodes can still serve snapshots.
CrdsData::SnapshotHashes(_) | CrdsData::IncrementalSnapshotHashes(_) => true,
CrdsData::LegacySnapshotHashes(_) | CrdsData::IncrementalSnapshotHashes(_) => true,
// Otherwise unstaked voting nodes will show up with no version in
// the various dashboards.
CrdsData::Version(_) => true,
@ -982,8 +982,8 @@ impl ClusterInfo {
self.push_message(CrdsValue::new_signed(message, &self.keypair()));
}
pub fn push_snapshot_hashes(&self, snapshot_hashes: Vec<(Slot, Hash)>) {
if snapshot_hashes.len() > MAX_SNAPSHOT_HASHES {
pub fn push_legacy_snapshot_hashes(&self, snapshot_hashes: Vec<(Slot, Hash)>) {
if snapshot_hashes.len() > MAX_LEGACY_SNAPSHOT_HASHES {
warn!(
"snapshot hashes too large, ignored: {}",
snapshot_hashes.len(),
@ -991,7 +991,8 @@ impl ClusterInfo {
return;
}
let message = CrdsData::SnapshotHashes(SnapshotHashes::new(self.id(), snapshot_hashes));
let message =
CrdsData::LegacySnapshotHashes(LegacySnapshotHashes::new(self.id(), snapshot_hashes));
self.push_message(CrdsValue::new_signed(message, &self.keypair()));
}
@ -1194,12 +1195,12 @@ impl ClusterInfo {
.map(map)
}
pub fn get_snapshot_hash_for_node<F, Y>(&self, pubkey: &Pubkey, map: F) -> Option<Y>
pub fn get_legacy_snapshot_hash_for_node<F, Y>(&self, pubkey: &Pubkey, map: F) -> Option<Y>
where
F: FnOnce(&Vec<(Slot, Hash)>) -> Y,
{
let gossip_crds = self.gossip.crds.read().unwrap();
let hashes = &gossip_crds.get::<&SnapshotHashes>(*pubkey)?.hashes;
let hashes = &gossip_crds.get::<&LegacySnapshotHashes>(*pubkey)?.hashes;
Some(map(hashes))
}
@ -3497,12 +3498,14 @@ RPC Enabled Nodes: 1"#;
}
#[test]
fn test_max_snapshot_hashes_with_push_messages() {
fn test_max_legecy_snapshot_hashes_with_push_messages() {
let mut rng = rand::thread_rng();
for _ in 0..256 {
let snapshot_hash = SnapshotHashes::new_rand(&mut rng, None);
let crds_value =
CrdsValue::new_signed(CrdsData::SnapshotHashes(snapshot_hash), &Keypair::new());
let snapshot_hash = LegacySnapshotHashes::new_rand(&mut rng, None);
let crds_value = CrdsValue::new_signed(
CrdsData::LegacySnapshotHashes(snapshot_hash),
&Keypair::new(),
);
let message = Protocol::PushMessage(Pubkey::new_unique(), vec![crds_value]);
let socket = new_rand_socket_addr(&mut rng);
assert!(Packet::from_data(Some(&socket), message).is_ok());
@ -3510,12 +3513,14 @@ RPC Enabled Nodes: 1"#;
}
#[test]
fn test_max_snapshot_hashes_with_pull_responses() {
fn test_max_legacy_snapshot_hashes_with_pull_responses() {
let mut rng = rand::thread_rng();
for _ in 0..256 {
let snapshot_hash = SnapshotHashes::new_rand(&mut rng, None);
let crds_value =
CrdsValue::new_signed(CrdsData::SnapshotHashes(snapshot_hash), &Keypair::new());
let snapshot_hash = LegacySnapshotHashes::new_rand(&mut rng, None);
let crds_value = CrdsValue::new_signed(
CrdsData::LegacySnapshotHashes(snapshot_hash),
&Keypair::new(),
);
let response = Protocol::PullResponse(Pubkey::new_unique(), vec![crds_value]);
let socket = new_rand_socket_addr(&mut rng);
assert!(Packet::from_data(Some(&socket), response).is_ok());
@ -4194,15 +4199,16 @@ RPC Enabled Nodes: 1"#;
fn test_split_messages_packet_size() {
// Test that if a value is smaller than payload size but too large to be wrapped in a vec
// that it is still dropped
let mut value = CrdsValue::new_unsigned(CrdsData::SnapshotHashes(SnapshotHashes {
from: Pubkey::default(),
hashes: vec![],
wallclock: 0,
}));
let mut value =
CrdsValue::new_unsigned(CrdsData::LegacySnapshotHashes(LegacySnapshotHashes {
from: Pubkey::default(),
hashes: vec![],
wallclock: 0,
}));
let mut i = 0;
while value.size() < PUSH_MESSAGE_MAX_PAYLOAD_SIZE as u64 {
value.data = CrdsData::SnapshotHashes(SnapshotHashes {
value.data = CrdsData::LegacySnapshotHashes(LegacySnapshotHashes {
from: Pubkey::default(),
hashes: vec![(0, Hash::default()); i],
wallclock: 0,

View File

@ -681,7 +681,7 @@ impl CrdsDataStats {
CrdsData::LegacyContactInfo(_) => 0,
CrdsData::Vote(_, _) => 1,
CrdsData::LowestSlot(_, _) => 2,
CrdsData::SnapshotHashes(_) => 3,
CrdsData::LegacySnapshotHashes(_) => 3,
CrdsData::AccountsHashes(_) => 4,
CrdsData::EpochSlots(_, _) => 5,
CrdsData::LegacyVersion(_) => 6,
@ -720,7 +720,7 @@ mod tests {
use {
super::*,
crate::{
crds_value::{new_rand_timestamp, NodeInstance, SnapshotHashes},
crds_value::{new_rand_timestamp, LegacySnapshotHashes, NodeInstance},
socketaddr,
},
rand::{thread_rng, Rng, SeedableRng},
@ -1319,8 +1319,8 @@ mod tests {
);
assert_eq!(crds.get_shred_version(&pubkey), Some(8));
// Add other crds values with the same pubkey.
let val = SnapshotHashes::new_rand(&mut rng, Some(pubkey));
let val = CrdsData::SnapshotHashes(val);
let val = LegacySnapshotHashes::new_rand(&mut rng, Some(pubkey));
let val = CrdsData::LegacySnapshotHashes(val);
let val = CrdsValue::new_unsigned(val);
assert_eq!(
crds.insert(val, timestamp(), GossipRoute::LocalMessage),
@ -1333,7 +1333,7 @@ mod tests {
assert_eq!(crds.get::<&ContactInfo>(pubkey), None);
assert_eq!(crds.get_shred_version(&pubkey), Some(8));
// Remove the remaining entry with the same pubkey.
crds.remove(&CrdsValueLabel::SnapshotHashes(pubkey), timestamp());
crds.remove(&CrdsValueLabel::LegacySnapshotHashes(pubkey), timestamp());
assert_eq!(crds.get_records(&pubkey).count(), 0);
assert_eq!(crds.get_shred_version(&pubkey), None);
}

View File

@ -2,8 +2,8 @@ use {
crate::{
crds::VersionedCrdsValue,
crds_value::{
CrdsData, CrdsValue, CrdsValueLabel, IncrementalSnapshotHashes, LegacyVersion,
LowestSlot, SnapshotHashes, Version,
CrdsData, CrdsValue, CrdsValueLabel, IncrementalSnapshotHashes, LegacySnapshotHashes,
LegacyVersion, LowestSlot, Version,
},
legacy_contact_info::LegacyContactInfo,
},
@ -58,8 +58,8 @@ impl_crds_entry!(LegacyVersion, CrdsData::LegacyVersion(version), version);
impl_crds_entry!(LowestSlot, CrdsData::LowestSlot(_, slot), slot);
impl_crds_entry!(Version, CrdsData::Version(version), version);
impl_crds_entry!(
SnapshotHashes,
CrdsData::SnapshotHashes(snapshot_hashes),
LegacySnapshotHashes,
CrdsData::LegacySnapshotHashes(snapshot_hashes),
snapshot_hashes
);
impl_crds_entry!(
@ -118,8 +118,8 @@ mod tests {
CrdsData::LegacyVersion(version) => {
assert_eq!(crds.get::<&LegacyVersion>(key), Some(version))
}
CrdsData::SnapshotHashes(hash) => {
assert_eq!(crds.get::<&SnapshotHashes>(key), Some(hash))
CrdsData::LegacySnapshotHashes(hash) => {
assert_eq!(crds.get::<&LegacySnapshotHashes>(key), Some(hash))
}
CrdsData::IncrementalSnapshotHashes(hash) => {
assert_eq!(crds.get::<&IncrementalSnapshotHashes>(key), Some(hash))

View File

@ -1,6 +1,6 @@
use {
crate::{
cluster_info::MAX_SNAPSHOT_HASHES,
cluster_info::MAX_LEGACY_SNAPSHOT_HASHES,
contact_info::ContactInfo,
deprecated,
duplicate_shred::{DuplicateShred, DuplicateShredIndex, MAX_DUPLICATE_SHREDS},
@ -85,7 +85,7 @@ pub enum CrdsData {
LegacyContactInfo(LegacyContactInfo),
Vote(VoteIndex, Vote),
LowestSlot(/*DEPRECATED:*/ u8, LowestSlot),
SnapshotHashes(SnapshotHashes),
LegacySnapshotHashes(LegacySnapshotHashes),
AccountsHashes(AccountsHashes),
EpochSlots(EpochSlotsIndex, EpochSlots),
LegacyVersion(LegacyVersion),
@ -112,7 +112,7 @@ impl Sanitize for CrdsData {
}
val.sanitize()
}
CrdsData::SnapshotHashes(val) => val.sanitize(),
CrdsData::LegacySnapshotHashes(val) => val.sanitize(),
CrdsData::AccountsHashes(val) => val.sanitize(),
CrdsData::EpochSlots(ix, val) => {
if *ix as usize >= MAX_EPOCH_SLOTS as usize {
@ -153,7 +153,7 @@ impl CrdsData {
0 => CrdsData::LegacyContactInfo(LegacyContactInfo::new_rand(rng, pubkey)),
// Index for LowestSlot is deprecated and should be zero.
1 => CrdsData::LowestSlot(0, LowestSlot::new_rand(rng, pubkey)),
2 => CrdsData::SnapshotHashes(SnapshotHashes::new_rand(rng, pubkey)),
2 => CrdsData::LegacySnapshotHashes(LegacySnapshotHashes::new_rand(rng, pubkey)),
3 => CrdsData::AccountsHashes(AccountsHashes::new_rand(rng, pubkey)),
4 => CrdsData::Version(Version::new_rand(rng, pubkey)),
5 => CrdsData::Vote(rng.gen_range(0, MAX_VOTES), Vote::new_rand(rng, pubkey)),
@ -195,7 +195,7 @@ impl AccountsHashes {
/// New random AccountsHashes for tests and benchmarks.
pub(crate) fn new_rand<R: Rng>(rng: &mut R, pubkey: Option<Pubkey>) -> Self {
let num_hashes = rng.gen_range(0, MAX_SNAPSHOT_HASHES) + 1;
let num_hashes = rng.gen_range(0, MAX_LEGACY_SNAPSHOT_HASHES) + 1;
let hashes = std::iter::repeat_with(|| {
let slot = 47825632 + rng.gen_range(0, 512);
let hash = solana_sdk::hash::new_rand(rng);
@ -211,7 +211,7 @@ impl AccountsHashes {
}
}
pub type SnapshotHashes = AccountsHashes;
pub type LegacySnapshotHashes = AccountsHashes;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample)]
pub struct IncrementalSnapshotHashes {
@ -493,7 +493,7 @@ pub enum CrdsValueLabel {
LegacyContactInfo(Pubkey),
Vote(VoteIndex, Pubkey),
LowestSlot(Pubkey),
SnapshotHashes(Pubkey),
LegacySnapshotHashes(Pubkey),
EpochSlots(EpochSlotsIndex, Pubkey),
AccountsHashes(Pubkey),
LegacyVersion(Pubkey),
@ -512,7 +512,9 @@ impl fmt::Display for CrdsValueLabel {
}
CrdsValueLabel::Vote(ix, _) => write!(f, "Vote({}, {})", ix, self.pubkey()),
CrdsValueLabel::LowestSlot(_) => write!(f, "LowestSlot({})", self.pubkey()),
CrdsValueLabel::SnapshotHashes(_) => write!(f, "SnapshotHashes({})", self.pubkey()),
CrdsValueLabel::LegacySnapshotHashes(_) => {
write!(f, "LegacySnapshotHashes({})", self.pubkey())
}
CrdsValueLabel::EpochSlots(ix, _) => write!(f, "EpochSlots({}, {})", ix, self.pubkey()),
CrdsValueLabel::AccountsHashes(_) => write!(f, "AccountsHashes({})", self.pubkey()),
CrdsValueLabel::LegacyVersion(_) => write!(f, "LegacyVersion({})", self.pubkey()),
@ -533,7 +535,7 @@ impl CrdsValueLabel {
CrdsValueLabel::LegacyContactInfo(p) => *p,
CrdsValueLabel::Vote(_, p) => *p,
CrdsValueLabel::LowestSlot(p) => *p,
CrdsValueLabel::SnapshotHashes(p) => *p,
CrdsValueLabel::LegacySnapshotHashes(p) => *p,
CrdsValueLabel::EpochSlots(_, p) => *p,
CrdsValueLabel::AccountsHashes(p) => *p,
CrdsValueLabel::LegacyVersion(p) => *p,
@ -583,7 +585,7 @@ impl CrdsValue {
CrdsData::LegacyContactInfo(contact_info) => contact_info.wallclock,
CrdsData::Vote(_, vote) => vote.wallclock,
CrdsData::LowestSlot(_, obj) => obj.wallclock,
CrdsData::SnapshotHashes(hash) => hash.wallclock,
CrdsData::LegacySnapshotHashes(hash) => hash.wallclock,
CrdsData::AccountsHashes(hash) => hash.wallclock,
CrdsData::EpochSlots(_, p) => p.wallclock,
CrdsData::LegacyVersion(version) => version.wallclock,
@ -599,7 +601,7 @@ impl CrdsValue {
CrdsData::LegacyContactInfo(contact_info) => contact_info.id,
CrdsData::Vote(_, vote) => vote.from,
CrdsData::LowestSlot(_, slots) => slots.from,
CrdsData::SnapshotHashes(hash) => hash.from,
CrdsData::LegacySnapshotHashes(hash) => hash.from,
CrdsData::AccountsHashes(hash) => hash.from,
CrdsData::EpochSlots(_, p) => p.from,
CrdsData::LegacyVersion(version) => version.from,
@ -615,7 +617,9 @@ impl CrdsValue {
CrdsData::LegacyContactInfo(_) => CrdsValueLabel::LegacyContactInfo(self.pubkey()),
CrdsData::Vote(ix, _) => CrdsValueLabel::Vote(*ix, self.pubkey()),
CrdsData::LowestSlot(_, _) => CrdsValueLabel::LowestSlot(self.pubkey()),
CrdsData::SnapshotHashes(_) => CrdsValueLabel::SnapshotHashes(self.pubkey()),
CrdsData::LegacySnapshotHashes(_) => {
CrdsValueLabel::LegacySnapshotHashes(self.pubkey())
}
CrdsData::AccountsHashes(_) => CrdsValueLabel::AccountsHashes(self.pubkey()),
CrdsData::EpochSlots(ix, _) => CrdsValueLabel::EpochSlots(*ix, self.pubkey()),
CrdsData::LegacyVersion(_) => CrdsValueLabel::LegacyVersion(self.pubkey()),
@ -905,7 +909,7 @@ mod test {
}
assert_eq!(count, currents.len());
// Currently CrdsData::new_rand is implemented for:
// AccountsHashes, ContactInfo, LowestSlot, SnapshotHashes, Version
// AccountsHashes, ContactInfo, LowestSlot, LegacySnapshotHashes, Version
// EpochSlots x MAX_EPOCH_SLOTS
// Vote x MAX_VOTES
let num_kinds = 5 + MAX_VOTES as usize + MAX_EPOCH_SLOTS as usize;

View File

@ -855,7 +855,7 @@ fn get_snapshot_hashes_from_known_validators(
// Get the full snapshot hashes for a node from CRDS
let get_full_snapshot_hashes_for_node = |node| {
let mut full_snapshot_hashes = Vec::new();
cluster_info.get_snapshot_hash_for_node(node, |snapshot_hashes| {
cluster_info.get_legacy_snapshot_hash_for_node(node, |snapshot_hashes| {
full_snapshot_hashes = snapshot_hashes.clone();
});
full_snapshot_hashes
@ -1429,7 +1429,7 @@ fn get_highest_full_snapshot_hash_for_peer(
peer: &Pubkey,
) -> Option<SnapshotHash> {
let mut full_snapshot_hashes = Vec::new();
cluster_info.get_snapshot_hash_for_node(peer, |snapshot_hashes| {
cluster_info.get_legacy_snapshot_hash_for_node(peer, |snapshot_hashes| {
full_snapshot_hashes = snapshot_hashes.clone()
});
full_snapshot_hashes