From 72de632cb51ab1b7bde5b80dbebcd76361027f07 Mon Sep 17 00:00:00 2001 From: Brooks Prumo Date: Mon, 4 Oct 2021 19:59:01 -0500 Subject: [PATCH] Add get_incremental_snapshot_hash_for_node() to gossip Fixes #20377 --- gossip/src/cluster_info.rs | 16 ++++++++++++++-- gossip/src/crds_entry.rs | 11 ++++++++++- gossip/src/crds_value.rs | 8 ++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/gossip/src/cluster_info.rs b/gossip/src/cluster_info.rs index 778f8319a93faf..00f930e8a171d2 100644 --- a/gossip/src/cluster_info.rs +++ b/gossip/src/cluster_info.rs @@ -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, @@ -1115,6 +1115,18 @@ impl ClusterInfo { Some(map(hashes)) } + pub fn get_incremental_snapshot_hash_for_node(&self, pubkey: &Pubkey, map: F) -> Option + where + F: FnOnce((&(Slot, Hash), &Vec<(Slot, Hash)>)) -> Y, + { + let gossip_crds = self.gossip.crds.read().unwrap(); + let incremental_snapshot_hash = gossip_crds.get::<&IncrementalSnapshotHashes>(*pubkey)?; + Some(map(( + &incremental_snapshot_hash.base, + &incremental_snapshot_hash.hashes, + ))) + } + /// 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 { diff --git a/gossip/src/crds_entry.rs b/gossip/src/crds_entry.rs index 38b826b52aeaed..a3541ef3f3ecd5 100644 --- a/gossip/src/crds_entry.rs +++ b/gossip/src/crds_entry.rs @@ -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)) + } _ => (), } } diff --git a/gossip/src/crds_value.rs b/gossip/src/crds_value.rs index d862572bc2bdab..85bae36d240ce1 100644 --- a/gossip/src/crds_value.rs +++ b/gossip/src/crds_value.rs @@ -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 {