Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

blockstore: Make is_orphan() a method of SlotMeta #34889

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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::<cf::Orphans>(prev_slot, &true)?;
}
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<_>>(),
vec![1]
Expand All @@ -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<_>>(),
vec![0]
Expand All @@ -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());
Expand Down
7 changes: 7 additions & 0 deletions ledger/src/blockstore_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down