implements generic lookups into gossip crds table (#18765)

This commit adds CrdsEntry trait which allows generic lookups into crds
table. For example to get ContactInfo or LowestSlot associated with a
Pubkey, the lookup code would be respectively:
   crds.get::<&ContactInfo>(pubkey)
   crds.get::<&LowestSlot>(pubkey)
This commit is contained in:
behzad nouri
2021-07-21 12:16:26 +00:00
committed by GitHub
parent 65152373de
commit bbd22f06f4
11 changed files with 204 additions and 108 deletions

View File

@ -179,7 +179,7 @@ impl ClusterSlotsService {
mod test {
use {
super::*,
solana_gossip::{cluster_info::Node, crds_value::CrdsValueLabel},
solana_gossip::{cluster_info::Node, crds_value::LowestSlot},
solana_sdk::pubkey::Pubkey,
};
@ -191,10 +191,8 @@ mod test {
ClusterSlotsService::update_lowest_slot(5, &cluster_info);
cluster_info.flush_push_queue();
let lowest = {
let label = CrdsValueLabel::LowestSlot(pubkey);
let gossip_crds = cluster_info.gossip.crds.read().unwrap();
let entry = gossip_crds.get(&label).unwrap();
entry.value.lowest_slot().unwrap().clone()
gossip_crds.get::<&LowestSlot>(pubkey).unwrap().clone()
};
assert_eq!(lowest.lowest, 5);
}