Add get_incremental_snapshot_hash_for_node() to gossip (#20394)

This commit is contained in:
Brooks Prumo 2021-10-07 19:47:14 -05:00 committed by GitHub
parent 069586c171
commit 57592e463e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 7 deletions

View File

@ -23,8 +23,8 @@ use {
crds_gossip_error::CrdsGossipError,
crds_gossip_pull::{CrdsFilter, ProcessPullStats, CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS},
crds_value::{
self, CrdsData, CrdsValue, CrdsValueLabel, EpochSlotsIndex, LowestSlot, NodeInstance,
SnapshotHashes, Version, Vote, MAX_WALLCLOCK,
self, CrdsData, CrdsValue, CrdsValueLabel, EpochSlotsIndex, IncrementalSnapshotHashes,
LowestSlot, NodeInstance, SnapshotHashes, Version, Vote, MAX_WALLCLOCK,
},
epoch_slots::EpochSlots,
gossip_error::GossipError,
@ -1116,6 +1116,18 @@ impl ClusterInfo {
Some(map(hashes))
}
pub fn get_incremental_snapshot_hashes_for_node(
&self,
pubkey: &Pubkey,
) -> Option<IncrementalSnapshotHashes> {
self.gossip
.crds
.read()
.unwrap()
.get::<&IncrementalSnapshotHashes>(*pubkey)
.cloned()
}
/// Returns epoch-slots inserted since the given cursor.
/// Excludes entries from nodes with unkown or different shred version.
pub fn get_epoch_slots(&self, cursor: &mut Cursor) -> Vec<EpochSlots> {

View File

@ -3,7 +3,8 @@ use {
contact_info::ContactInfo,
crds::VersionedCrdsValue,
crds_value::{
CrdsData, CrdsValue, CrdsValueLabel, LegacyVersion, LowestSlot, SnapshotHashes, Version,
CrdsData, CrdsValue, CrdsValueLabel, IncrementalSnapshotHashes, LegacyVersion,
LowestSlot, SnapshotHashes, Version,
},
},
indexmap::IndexMap,
@ -56,6 +57,11 @@ impl_crds_entry!(ContactInfo, CrdsData::ContactInfo(node), node);
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!(
IncrementalSnapshotHashes,
CrdsData::IncrementalSnapshotHashes(incremental_snapshot_hashes),
incremental_snapshot_hashes
);
impl<'a, 'b> CrdsEntry<'a, 'b> for &'a SnapshotHashes {
type Key = Pubkey;
@ -114,6 +120,9 @@ mod tests {
CrdsData::SnapshotHashes(hash) => {
assert_eq!(crds.get::<&SnapshotHashes>(key), Some(hash))
}
CrdsData::IncrementalSnapshotHashes(hash) => {
assert_eq!(crds.get::<&IncrementalSnapshotHashes>(key), Some(hash))
}
_ => (),
}
}

View File

@ -209,10 +209,10 @@ impl SnapshotHashes {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, AbiExample)]
pub struct IncrementalSnapshotHashes {
from: Pubkey,
base: (Slot, Hash),
hashes: Vec<(Slot, Hash)>,
wallclock: u64,
pub(crate) from: Pubkey,
pub(crate) base: (Slot, Hash),
pub(crate) hashes: Vec<(Slot, Hash)>,
pub(crate) wallclock: u64,
}
impl Sanitize for IncrementalSnapshotHashes {