Skip to content

Commit

Permalink
Add get_incremental_snapshot_hash_for_node() to gossip (#20394)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Oct 8, 2021
1 parent 069586c commit 57592e4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
16 changes: 14 additions & 2 deletions gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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> {
Expand Down
11 changes: 10 additions & 1 deletion gossip/src/crds_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
}
_ => (),
}
}
Expand Down
8 changes: 4 additions & 4 deletions gossip/src/crds_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 57592e4

Please sign in to comment.