Skip to content

Commit

Permalink
Add get_incremental_snapshot_hash_for_node() to gossip
Browse files Browse the repository at this point in the history
Fixes #20377
  • Loading branch information
brooksprumo committed Oct 3, 2021
1 parent 490fc04 commit 9e25662
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 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,
SnapshotHash, Version, Vote, MAX_WALLCLOCK,
self, CrdsData, CrdsValue, CrdsValueLabel, EpochSlotsIndex, IncrementalSnapshotHash,
LowestSlot, NodeInstance, SnapshotHash, Version, Vote, MAX_WALLCLOCK,
},
epoch_slots::EpochSlots,
gossip_error::GossipError,
Expand Down Expand Up @@ -1115,6 +1115,18 @@ impl ClusterInfo {
Some(map(hashes))
}

pub fn get_incremental_snapshot_hash_for_node<F, Y>(&self, pubkey: &Pubkey, map: F) -> Option<Y>
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<EpochSlots> {
Expand Down
16 changes: 15 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, SnapshotHash, Version,
CrdsData, CrdsValue, CrdsValueLabel, IncrementalSnapshotHash, LegacyVersion,
LowestSlot, SnapshotHash, Version,
},
},
indexmap::IndexMap,
Expand Down Expand Up @@ -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<Self> {
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 {
Expand Down

0 comments on commit 9e25662

Please sign in to comment.