Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slots_connected: check if the range is connected (>= ending_slot) #27152

Merged
merged 1 commit into from
Aug 19, 2022
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
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 @@ -5501,7 +5500,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 @@ -5510,41 +5509,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