From 9e25662deec2917dfae7e863fbc306935c05936c Mon Sep 17 00:00:00 2001 From: Brooks Prumo Date: Sun, 3 Oct 2021 10:35:32 -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 | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/gossip/src/cluster_info.rs b/gossip/src/cluster_info.rs index 77aaf524bbf5fc..ac1ed7e52465f6 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, - SnapshotHash, Version, Vote, MAX_WALLCLOCK, + self, CrdsData, CrdsValue, CrdsValueLabel, EpochSlotsIndex, IncrementalSnapshotHash, + LowestSlot, NodeInstance, SnapshotHash, 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, &Vec<(Slot, Hash)>)) -> Y, + { + let gossip_crds = self.gossip.crds.read().unwrap(); + let incremental_snapshot_hash = gossip_crds.get::<&IncrementalSnapshotHash>(*pubkey)?; + Some(map(( + incremental_snapshot_hash.base_slot, + &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 3492af2966d1f4..051e59c9db04d5 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, SnapshotHash, Version, + CrdsData, CrdsValue, CrdsValueLabel, IncrementalSnapshotHash, LegacyVersion, + LowestSlot, SnapshotHash, Version, }, }, indexmap::IndexMap, @@ -68,6 +69,19 @@ impl<'a, 'b> CrdsEntry<'a, 'b> for &'a SnapshotHash { } } +impl<'a, 'b> CrdsEntry<'a, 'b> for &'a IncrementalSnapshotHash { + type Key = Pubkey; + fn get_entry(table: &'a CrdsTable, key: Self::Key) -> Option { + let key = CrdsValueLabel::IncrementalSnapshotHashes(key); + match &table.get(&key)?.value.data { + CrdsData::IncrementalSnapshotHashes(incremental_snapshot_hash) => { + Some(incremental_snapshot_hash) + } + _ => None, + } + } +} + #[cfg(test)] mod tests { use {