From dd22ae047b55ac66a0056205ab811606cd586d96 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Mon, 24 May 2021 17:01:02 -0500 Subject: [PATCH] ancestors is set instead of map (#17363) --- runtime/src/ancestors.rs | 14 +++++++------- runtime/src/bank.rs | 4 ++-- runtime/src/status_cache.rs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/runtime/src/ancestors.rs b/runtime/src/ancestors.rs index 71b4927e69..bfef0925ce 100644 --- a/runtime/src/ancestors.rs +++ b/runtime/src/ancestors.rs @@ -83,7 +83,7 @@ impl From<&Ancestors> for HashMap { fn from(source: &Ancestors) -> HashMap { let mut result = HashMap::with_capacity(source.len()); source.keys().iter().for_each(|slot| { - result.insert(*slot, *source.get(slot).unwrap()); + result.insert(*slot, 0); }); result } @@ -102,15 +102,15 @@ impl Ancestors { } } - pub fn get(&self, slot: &Slot) -> Option<&usize> { + pub fn get(&self, slot: &Slot) -> bool { if self.large_range_slots.is_empty() { if slot < &self.min || slot >= &self.max { - return None; + return false; } let slot = self.slot_index(slot); - self.slots[slot].as_ref() + self.slots[slot].is_some() } else { - self.large_range_slots.get(slot) + self.large_range_slots.get(slot).is_some() } } @@ -272,10 +272,10 @@ pub mod tests { let key = item.0; min = std::cmp::min(min, *key); max = std::cmp::max(max, *key); - assert_eq!(ancestors.get(&key).unwrap(), item.1); + assert!(ancestors.get(&key)); } for slot in min - 1..max + 2 { - assert_eq!(ancestors.get(&slot), hashset.get(&slot)); + assert_eq!(ancestors.get(&slot), hashset.contains(&slot)); } } diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 49ee0bcda5..9cc9af225c 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -1185,8 +1185,8 @@ impl Bank { let mut ancestors = Vec::with_capacity(1 + new.parents().len()); ancestors.push((new.slot(), 0)); - new.parents().iter().enumerate().for_each(|(i, p)| { - ancestors.push((p.slot(), i + 1)); + new.parents().iter().for_each(|p| { + ancestors.push((p.slot(), 0)); }); new.ancestors = Ancestors::from(ancestors); diff --git a/runtime/src/status_cache.rs b/runtime/src/status_cache.rs index e66537ae66..96fb54cd8a 100644 --- a/runtime/src/status_cache.rs +++ b/runtime/src/status_cache.rs @@ -143,7 +143,7 @@ impl StatusCache { if let Some(stored_forks) = keymap.get(key_slice) { let res = stored_forks .iter() - .find(|(f, _)| ancestors.get(f).is_some() || self.roots.get(f).is_some()) + .find(|(f, _)| ancestors.get(f) || self.roots.get(f).is_some()) .cloned(); if res.is_some() { return res;