From 5ed30beb2a771820879e3eb5ffec93361a1ed8b4 Mon Sep 17 00:00:00 2001 From: steviez Date: Wed, 13 Mar 2024 11:29:05 -0500 Subject: [PATCH] ledger-tool: Allow compute-slot-cost to operate on dead slots (#213) Make this command accept the --allow-dead-slots arg as well --- ledger-tool/src/main.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 8445782f8..94298623e 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -445,14 +445,14 @@ fn graph_forks(bank_forks: &BankForks, config: &GraphConfig) -> String { dot.join("\n") } -fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String> { - if blockstore.is_dead(slot) { - return Err("Dead slot".to_string()); - } - +fn compute_slot_cost( + blockstore: &Blockstore, + slot: Slot, + allow_dead_slots: bool, +) -> Result<(), String> { let (entries, _num_shreds, _is_full) = blockstore - .get_slot_entries_with_shred_info(slot, 0, false) - .map_err(|err| format!(" Slot: {slot}, Failed to load entries, err {err:?}"))?; + .get_slot_entries_with_shred_info(slot, 0, allow_dead_slots) + .map_err(|err| format!("Slot: {slot}, Failed to load entries, err {err:?}"))?; let num_entries = entries.len(); let mut num_transactions = 0; @@ -1482,7 +1482,8 @@ fn main() { "Slots that their blocks are computed for cost, default to all slots \ in ledger", ), - ), + ) + .arg(&allow_dead_slots_arg), ) .program_subcommand() .get_matches(); @@ -2947,9 +2948,10 @@ fn main() { } else { slots = values_t_or_exit!(arg_matches, "slots", Slot); } + let allow_dead_slots = arg_matches.is_present("allow_dead_slots"); for slot in slots { - if let Err(err) = compute_slot_cost(&blockstore, slot) { + if let Err(err) = compute_slot_cost(&blockstore, slot, allow_dead_slots) { eprintln!("{err}"); } }