Remove `fn slot_deltas()` from StatusCache (#26931)
This commit is contained in:
parent
3a9bc4bf37
commit
bc0d01110c
|
@ -28,26 +28,12 @@ fn bench_status_cache_serialize(bencher: &mut Bencher) {
|
||||||
status_cache.insert(&blockhash, &sig, 0, Ok(()));
|
status_cache.insert(&blockhash, &sig, 0, Ok(()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assert!(status_cache.roots().contains(&0));
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
let _ = serialize(&status_cache.slot_deltas(&[0])).unwrap();
|
let _ = serialize(&status_cache.root_slot_deltas()).unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
|
||||||
fn bench_status_cache_slot_deltas(bencher: &mut Bencher) {
|
|
||||||
let mut status_cache = BankStatusCache::default();
|
|
||||||
|
|
||||||
// fill the status cache
|
|
||||||
let slots: Vec<_> = (42..).take(MAX_CACHE_ENTRIES).collect();
|
|
||||||
for slot in &slots {
|
|
||||||
for _ in 0..5 {
|
|
||||||
status_cache.insert(&Hash::new_unique(), Hash::new_unique(), *slot, Ok(()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bencher.iter(|| test::black_box(status_cache.slot_deltas(&slots)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_status_cache_root_slot_deltas(bencher: &mut Bencher) {
|
fn bench_status_cache_root_slot_deltas(bencher: &mut Bencher) {
|
||||||
let mut status_cache = BankStatusCache::default();
|
let mut status_cache = BankStatusCache::default();
|
||||||
|
|
|
@ -221,30 +221,15 @@ impl<T: Serialize + Clone> StatusCache<T> {
|
||||||
.for_each(|(_, status)| status.lock().unwrap().clear());
|
.for_each(|(_, status)| status.lock().unwrap().clear());
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the statuses for each slot in the slots provided
|
|
||||||
pub fn slot_deltas(&self, slots: &[Slot]) -> Vec<SlotDelta<T>> {
|
|
||||||
let empty = Arc::new(Mutex::new(HashMap::new()));
|
|
||||||
slots
|
|
||||||
.iter()
|
|
||||||
.map(|slot| {
|
|
||||||
(
|
|
||||||
*slot,
|
|
||||||
self.roots.contains(slot),
|
|
||||||
Arc::clone(self.slot_deltas.get(slot).unwrap_or(&empty)),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the statuses for all the root slots
|
/// Get the statuses for all the root slots
|
||||||
pub fn root_slot_deltas(&self) -> Vec<SlotDelta<T>> {
|
pub fn root_slot_deltas(&self) -> Vec<SlotDelta<T>> {
|
||||||
self.roots
|
self.roots()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|slot| {
|
.map(|root| {
|
||||||
(
|
(
|
||||||
*slot,
|
*root,
|
||||||
true,
|
true, // <-- is_root
|
||||||
self.slot_deltas.get(slot).cloned().unwrap_or_default(),
|
self.slot_deltas.get(root).cloned().unwrap_or_default(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -444,10 +429,11 @@ mod tests {
|
||||||
let blockhash = hash(Hash::default().as_ref());
|
let blockhash = hash(Hash::default().as_ref());
|
||||||
status_cache.clear();
|
status_cache.clear();
|
||||||
status_cache.insert(&blockhash, &sig, 0, ());
|
status_cache.insert(&blockhash, &sig, 0, ());
|
||||||
let slot_deltas = status_cache.slot_deltas(&[0]);
|
assert!(status_cache.roots().contains(&0));
|
||||||
|
let slot_deltas = status_cache.root_slot_deltas();
|
||||||
let cache = StatusCache::from_slot_deltas(&slot_deltas);
|
let cache = StatusCache::from_slot_deltas(&slot_deltas);
|
||||||
assert_eq!(cache, status_cache);
|
assert_eq!(cache, status_cache);
|
||||||
let slot_deltas = cache.slot_deltas(&[0]);
|
let slot_deltas = cache.root_slot_deltas();
|
||||||
let cache = StatusCache::from_slot_deltas(&slot_deltas);
|
let cache = StatusCache::from_slot_deltas(&slot_deltas);
|
||||||
assert_eq!(cache, status_cache);
|
assert_eq!(cache, status_cache);
|
||||||
}
|
}
|
||||||
|
@ -464,10 +450,9 @@ mod tests {
|
||||||
for i in 0..(MAX_CACHE_ENTRIES + 1) {
|
for i in 0..(MAX_CACHE_ENTRIES + 1) {
|
||||||
status_cache.add_root(i as u64);
|
status_cache.add_root(i as u64);
|
||||||
}
|
}
|
||||||
let slots: Vec<_> = (0..MAX_CACHE_ENTRIES as u64 + 1).collect();
|
|
||||||
assert_eq!(status_cache.slot_deltas.len(), 1);
|
assert_eq!(status_cache.slot_deltas.len(), 1);
|
||||||
assert!(status_cache.slot_deltas.get(&1).is_some());
|
assert!(status_cache.slot_deltas.get(&1).is_some());
|
||||||
let slot_deltas = status_cache.slot_deltas(&slots);
|
let slot_deltas = status_cache.root_slot_deltas();
|
||||||
let cache = StatusCache::from_slot_deltas(&slot_deltas);
|
let cache = StatusCache::from_slot_deltas(&slot_deltas);
|
||||||
assert_eq!(cache, status_cache);
|
assert_eq!(cache, status_cache);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue