Skip to content

Commit

Permalink
slots_connected: check if the range is connected (>= ending_slot) (so…
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge authored Aug 19, 2022
1 parent dba2fd5 commit 40b9f2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,9 +955,9 @@ fn load_bank_forks(
};

if let Some(halt_slot) = process_options.halt_at_slot {
// Check if we have the slot data necessary to replay from starting_slot to halt_slot.
// Check if we have the slot data necessary to replay from starting_slot to >= halt_slot.
// - This will not catch the case when loading from genesis without a full slot 0.
if !blockstore.slots_connected(starting_slot, halt_slot) {
if !blockstore.slot_range_connected(starting_slot, halt_slot) {
eprintln!(
"Unable to load bank forks at slot {} due to disconnected blocks.",
halt_slot,
Expand Down
27 changes: 13 additions & 14 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,9 @@ impl Blockstore {
self.prepare_rooted_slot_iterator(slot, IteratorDirection::Reverse)
}

/// Determines if `starting_slot` and `ending_slot` are connected by full slots
/// Determines if we can iterate from `starting_slot` to >= `ending_slot` by full slots
/// `starting_slot` is excluded from the `is_full()` check
pub fn slots_connected(&self, starting_slot: Slot, ending_slot: Slot) -> bool {
pub fn slot_range_connected(&self, starting_slot: Slot, ending_slot: Slot) -> bool {
if starting_slot == ending_slot {
return true;
}
Expand All @@ -562,8 +562,7 @@ impl Blockstore {
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
_ => return true,
}
}
}
Expand Down Expand Up @@ -5502,7 +5501,7 @@ pub mod tests {
}
*/
#[test]
fn test_slots_connected_chain() {
fn test_slot_range_connected_chain() {
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore = Blockstore::open(ledger_path.path()).unwrap();

Expand All @@ -5511,41 +5510,41 @@ pub mod tests {
make_and_insert_slot(&blockstore, slot, slot.saturating_sub(1));
}

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

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

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));
assert!(blockstore.slot_range_connected(1, 3)); // Slot 3 does not exist, but we can still replay this range to slot 4
assert!(blockstore.slot_range_connected(1, 4));
}

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

assert!(blockstore.slots_connected(54, 54));
assert!(blockstore.slot_range_connected(54, 54));
}

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

make_and_insert_slot(&blockstore, 5, 4);
make_and_insert_slot(&blockstore, 6, 5);

assert!(!blockstore.meta(4).unwrap().unwrap().is_full());
assert!(blockstore.slots_connected(4, 6));
assert!(blockstore.slot_range_connected(4, 6));
}

#[test]
Expand Down

0 comments on commit 40b9f2f

Please sign in to comment.