Skip to content

Commit

Permalink
Revert "Fix pre-check of blockstore slots during load_bank_forks (sol…
Browse files Browse the repository at this point in the history
…ana-labs#25632)"

This reverts commit 934da5e.
  • Loading branch information
lijunwangs committed Jun 28, 2022
1 parent 31d870f commit 75c9863
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 68 deletions.
21 changes: 15 additions & 6 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ fn load_bank_forks(
snapshot_archive_path.unwrap_or_else(|| blockstore.ledger_path().to_path_buf());
let incremental_snapshot_archives_dir =
incremental_snapshot_archive_path.unwrap_or_else(|| full_snapshot_archives_dir.clone());

if let Some(full_snapshot_slot) =
snapshot_utils::get_highest_full_snapshot_archive_slot(&full_snapshot_archives_dir)
{
Expand All @@ -798,12 +799,20 @@ fn load_bank_forks(
};

if let Some(halt_slot) = process_options.halt_at_slot {
if !blockstore.slots_connected(starting_slot, halt_slot) {
eprintln!(
"Unable to load bank forks at slot {} due to disconnected blocks.",
halt_slot,
);
exit(1);
for slot in starting_slot..=halt_slot {
if let Ok(Some(slot_meta)) = blockstore.meta(slot) {
if !slot_meta.is_full() {
eprintln!("Unable to process from slot {} to {} due to blockstore slot {} not being full",
starting_slot, halt_slot, slot);
exit(1);
}
} else {
eprintln!(
"Unable to process from slot {} to {} due to blockstore missing slot {}",
starting_slot, halt_slot, slot
);
exit(1);
}
}
}

Expand Down
63 changes: 1 addition & 62 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use {
borrow::Cow,
cell::RefCell,
cmp,
collections::{hash_map::Entry as HashMapEntry, BTreeSet, HashMap, HashSet, VecDeque},
collections::{hash_map::Entry as HashMapEntry, BTreeSet, HashMap, HashSet},
convert::TryInto,
fmt::Write,
fs,
Expand Down Expand Up @@ -547,24 +547,6 @@ impl Blockstore {
self.prepare_rooted_slot_iterator(slot, IteratorDirection::Reverse)
}

/// Determines if starting_slot and ending_slot are connected
pub fn slots_connected(&self, starting_slot: Slot, ending_slot: Slot) -> bool {
let mut next_slots: VecDeque<_> = vec![starting_slot].into();
while let Some(slot) = next_slots.pop_front() {
if let Ok(Some(slot_meta)) = self.meta(slot) {
if slot_meta.is_full() {
match slot.cmp(&ending_slot) {
cmp::Ordering::Less => next_slots.extend(slot_meta.next_slots),
cmp::Ordering::Equal => return true,
cmp::Ordering::Greater => {} // slot is greater than the ending slot, so all its children would be as well
}
}
}
}

false
}

fn get_recovery_data_shreds<'a>(
index: &'a Index,
slot: Slot,
Expand Down Expand Up @@ -5477,49 +5459,6 @@ pub mod tests {
}
*/
#[test]
pub fn test_slots_connected_chain() {
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore = Blockstore::open(ledger_path.path()).unwrap();

let num_slots = 3;
for slot in 1..=num_slots {
let (shreds, _) = make_slot_entries(slot, slot.saturating_sub(1), 100);
blockstore.insert_shreds(shreds, None, true).unwrap();

let meta = blockstore.meta(slot).unwrap().unwrap();
assert_eq!(slot, meta.slot);
assert!(meta.is_full());
assert!(meta.next_slots.is_empty());
}

assert!(blockstore.slots_connected(1, 3));
assert!(!blockstore.slots_connected(1, 4)); // slot 4 does not exist
}

#[test]
pub fn test_slots_connected_disconnected() {
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore = Blockstore::open(ledger_path.path()).unwrap();

fn make_and_insert_slot(blockstore: &Blockstore, slot: Slot, parent_slot: Slot) {
let (shreds, _) = make_slot_entries(slot, parent_slot, 100);
blockstore.insert_shreds(shreds, None, true).unwrap();

let meta = blockstore.meta(slot).unwrap().unwrap();
assert_eq!(slot, meta.slot);
assert!(meta.is_full());
assert!(meta.next_slots.is_empty());
}

make_and_insert_slot(&blockstore, 1, 0);
make_and_insert_slot(&blockstore, 2, 1);
make_and_insert_slot(&blockstore, 4, 2);

assert!(!blockstore.slots_connected(1, 3)); // Slot 3 does not exit
assert!(blockstore.slots_connected(1, 4));
}

#[test]
pub fn test_get_slots_since() {
let ledger_path = get_tmp_ledger_path_auto_delete!();
Expand Down

0 comments on commit 75c9863

Please sign in to comment.