diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 156e29999acd71..5b1dc475b9cf04 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -1803,7 +1803,7 @@ impl Blockstore { }; // Parent for slot meta should have been set by this point - assert!(!is_orphan(slot_meta)); + assert!(!slot_meta.is_orphan()); let new_consumed = if slot_meta.consumed == index { let mut current_index = index + 1; @@ -3822,7 +3822,8 @@ impl Blockstore { let meta_backup = &slot_meta_entry.old_slot_meta; { let mut meta_mut = meta.borrow_mut(); - let was_orphan_slot = meta_backup.is_some() && is_orphan(meta_backup.as_ref().unwrap()); + let was_orphan_slot = + meta_backup.is_some() && meta_backup.as_ref().unwrap().is_orphan(); // If: // 1) This is a new slot @@ -3848,7 +3849,7 @@ impl Blockstore { // If the parent of `slot` is a newly inserted orphan, insert it into the orphans // column family - if is_orphan(&RefCell::borrow(&*prev_slot_meta)) { + if RefCell::borrow(&*prev_slot_meta).is_orphan() { write_batch.put::(prev_slot, &true)?; } } @@ -3956,7 +3957,7 @@ impl Blockstore { // during the chaining process, see the function find_slot_meta_in_cached_state() // for details. Slots that are orphans are missing a parent_slot, so we should // fill in the parent now that we know it. - if is_orphan(&meta) { + if meta.is_orphan() { meta.parent_slot = Some(parent_slot); } @@ -4216,12 +4217,6 @@ fn find_slot_meta_in_cached_state<'a>( } } -fn is_orphan(meta: &SlotMeta) -> bool { - // If we have no parent, then this is the head of a detached chain of - // slots - meta.parent_slot.is_none() -} - // 1) Chain current_slot to the previous slot defined by prev_slot_meta fn chain_new_slot_to_prev_slot( prev_slot_meta: &mut SlotMeta, @@ -6324,7 +6319,7 @@ pub mod tests { .meta(1) .expect("Expect database get to succeed") .unwrap(); - assert!(is_orphan(&meta)); + assert!(meta.is_orphan()); assert_eq!( blockstore.orphans_iterator(0).unwrap().collect::>(), vec![1] @@ -6340,12 +6335,12 @@ pub mod tests { .meta(1) .expect("Expect database get to succeed") .unwrap(); - assert!(!is_orphan(&meta)); + assert!(!meta.is_orphan()); let meta = blockstore .meta(0) .expect("Expect database get to succeed") .unwrap(); - assert!(is_orphan(&meta)); + assert!(meta.is_orphan()); assert_eq!( blockstore.orphans_iterator(0).unwrap().collect::>(), vec![0] @@ -6369,7 +6364,7 @@ pub mod tests { .meta(i) .expect("Expect database get to succeed") .unwrap(); - assert!(!is_orphan(&meta)); + assert!(!meta.is_orphan()); } // Orphans cf is empty assert!(blockstore.orphans_cf.is_empty().unwrap()); diff --git a/ledger/src/blockstore_meta.rs b/ledger/src/blockstore_meta.rs index 60f8a223c8a3b6..c8b5f6cb4fee99 100644 --- a/ledger/src/blockstore_meta.rs +++ b/ledger/src/blockstore_meta.rs @@ -263,6 +263,13 @@ impl SlotMeta { Some(self.consumed) == self.last_index.map(|ix| ix + 1) } + /// Returns a boolean indicating whether this meta's parent slot is known. + /// This value being true indicates that this meta's slot is the head of a + /// detached chain of slots. + pub(crate) fn is_orphan(&self) -> bool { + self.parent_slot.is_none() + } + /// Returns a boolean indicating whether the meta is connected. pub fn is_connected(&self) -> bool { self.connected_flags.contains(ConnectedFlags::CONNECTED)