From 66d833f957bc0db5d60cbf5b68ee73f5f37e27c7 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Wed, 18 May 2022 10:11:58 -0500 Subject: [PATCH 1/4] Add a check during ledger-tool create-snapshot startup to see if the snapshot slot is available --- ledger-tool/src/main.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index fcc6714bbaecca..11bcd9cda8025f 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -2332,6 +2332,11 @@ fn main() { value_t_or_exit!(arg_matches, "snapshot_slot", Slot) }; + if blockstore.meta(snapshot_slot).unwrap().is_none() { + eprintln!("snapshot slot {} is not available in the blockstore. Cannot create a snapshot at this slot", snapshot_slot); + exit(1); + } + info!( "Creating {}snapshot of slot {} in {}", if is_incremental { "incremental " } else { "" }, From dc2aa8290808fede2923b39f53f268d1b0e7a2ad Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Thu, 19 May 2022 09:45:51 -0500 Subject: [PATCH 2/4] check all slots from the start to snapshot_slot during load_bank_forks --- ledger-tool/src/main.rs | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 11bcd9cda8025f..6773227d4f306b 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -741,6 +741,8 @@ fn load_bank_forks( } else { "snapshot.ledger-tool" }); + + let mut starting_slot = 0; // default start check with genesis let snapshot_config = if arg_matches.is_present("no_snapshot") { None } else { @@ -748,6 +750,21 @@ 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) + { + let incremental_snapshot_slot = + snapshot_utils::get_highest_incremental_snapshot_archive_slot( + &incremental_snapshot_archives_dir, + full_snapshot_slot, + ); + starting_slot = std::cmp::max( + full_snapshot_slot, + incremental_snapshot_slot.unwrap_or_default(), + ); + } + Some(SnapshotConfig { full_snapshot_archive_interval_slots: Slot::MAX, incremental_snapshot_archive_interval_slots: Slot::MAX, @@ -757,6 +774,22 @@ fn load_bank_forks( ..SnapshotConfig::default() }) }; + + if let Some(halt_slot) = process_options.halt_at_slot { + for slot in starting_slot..=halt_slot { + if let Ok(Some(slot_meta)) = blockstore.meta(slot) { + if !slot_meta.is_full() { + eprintln!("blockstore slot {} is not full which is required for replaying slots {}..={}", + slot, starting_slot, halt_slot); + exit(1); + } + } else { + eprintln!("blockstore missing data for slot {} which is required for replaying slots {}..={}", slot, starting_slot, halt_slot); + exit(1); + } + } + } + let account_paths = if let Some(account_paths) = arg_matches.value_of("account_paths") { if !blockstore.is_primary_access() { // Be defensive, when default account dir is explicitly specified, it's still possible @@ -2332,11 +2365,6 @@ fn main() { value_t_or_exit!(arg_matches, "snapshot_slot", Slot) }; - if blockstore.meta(snapshot_slot).unwrap().is_none() { - eprintln!("snapshot slot {} is not available in the blockstore. Cannot create a snapshot at this slot", snapshot_slot); - exit(1); - } - info!( "Creating {}snapshot of slot {} in {}", if is_incremental { "incremental " } else { "" }, From 024710a362946ed01edfa0f59fcdd24f6fff4da6 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Thu, 19 May 2022 12:53:22 -0500 Subject: [PATCH 3/4] unwrap_or_default incremental snapshot slot before comparison --- ledger-tool/src/main.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 6773227d4f306b..8da78460ea74bb 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -758,11 +758,9 @@ fn load_bank_forks( snapshot_utils::get_highest_incremental_snapshot_archive_slot( &incremental_snapshot_archives_dir, full_snapshot_slot, - ); - starting_slot = std::cmp::max( - full_snapshot_slot, - incremental_snapshot_slot.unwrap_or_default(), - ); + ) + .unwrap_or_default(); + starting_slot = std::cmp::max(full_snapshot_slot, incremental_snapshot_slot); } Some(SnapshotConfig { From bd00d86b3c1aa18a84f02f935ca67352486b89b0 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Thu, 19 May 2022 14:55:33 -0500 Subject: [PATCH 4/4] Improve error messages on missing or not full slots --- ledger-tool/src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 8da78460ea74bb..0a20ea658d4c49 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -777,12 +777,15 @@ fn load_bank_forks( for slot in starting_slot..=halt_slot { if let Ok(Some(slot_meta)) = blockstore.meta(slot) { if !slot_meta.is_full() { - eprintln!("blockstore slot {} is not full which is required for replaying slots {}..={}", - slot, starting_slot, halt_slot); + eprintln!("Unable to process from slot {} to {} due to blockstore slot {} not being full", + starting_slot, halt_slot, slot); exit(1); } } else { - eprintln!("blockstore missing data for slot {} which is required for replaying slots {}..={}", slot, starting_slot, halt_slot); + eprintln!( + "Unable to process from slot {} to {} due to blockstore missing slot {}", + starting_slot, halt_slot, slot + ); exit(1); } }