ledger-tool: Add --all option to bounds, to display all non-empty slots (#7592) (#7598)

automerge
This commit is contained in:
mergify[bot]
2019-12-20 21:30:47 -08:00
committed by Grimes
parent f120449aae
commit 0398f6b87a
2 changed files with 33 additions and 22 deletions

View File

@ -446,7 +446,7 @@ pub fn process_show_block_production(
first_slot_in_epoch first_slot_in_epoch
}; };
let start_slot_index = (start_slot - first_slot_in_epoch) as usize; let start_slot_index = (start_slot - first_slot_in_epoch) as usize;
let end_slot_index = (end_slot - start_slot) as usize; let end_slot_index = (end_slot - first_slot_in_epoch) as usize;
let progress_bar = new_spinner_progress_bar(); let progress_bar = new_spinner_progress_bar();
progress_bar.set_message(&format!( progress_bar.set_message(&format!(

View File

@ -560,7 +560,14 @@ fn main() {
) )
.subcommand( .subcommand(
SubCommand::with_name("bounds") SubCommand::with_name("bounds")
.about("Print lowest and highest non-empty slots. Note: This ignores gaps in slots") .about("Print lowest and highest non-empty slots. Note that there may be empty slots within the bounds")
.arg(
Arg::with_name("all")
.long("all")
.takes_value(false)
.required(false)
.help("Additionally print all the non-empty slots within the bounds"),
)
) )
.subcommand( .subcommand(
SubCommand::with_name("json") SubCommand::with_name("json")
@ -845,8 +852,11 @@ fn main() {
} }
}); });
} }
("bounds", _) => match open_blocktree(&ledger_path).slot_meta_iterator(0) { ("bounds", Some(args_matches)) => {
match open_blocktree(&ledger_path).slot_meta_iterator(0) {
Ok(metas) => { Ok(metas) => {
let all = args_matches.is_present("all");
println!("Collecting Ledger information..."); println!("Collecting Ledger information...");
let slots: Vec<_> = metas.map(|(slot, _)| slot).collect(); let slots: Vec<_> = metas.map(|(slot, _)| slot).collect();
if slots.is_empty() { if slots.is_empty() {
@ -855,10 +865,10 @@ fn main() {
let first = slots.first().unwrap(); let first = slots.first().unwrap();
let last = slots.last().unwrap_or_else(|| first); let last = slots.last().unwrap_or_else(|| first);
if first != last { if first != last {
println!( println!("Ledger contains data from slots {:?} to {:?}", first, last);
"Ledger contains some data for slots {:?} to {:?}", if all {
first, last println!("Non-empty slots: {:?}", slots);
); }
} else { } else {
println!("Ledger only contains some data for slot {:?}", first); println!("Ledger only contains some data for slot {:?}", first);
} }
@ -868,7 +878,8 @@ fn main() {
eprintln!("Unable to read the Ledger: {:?}", err); eprintln!("Unable to read the Ledger: {:?}", err);
exit(1); exit(1);
} }
}, }
}
("analyze-storage", _) => match analyze_storage(&open_database(&ledger_path)) { ("analyze-storage", _) => match analyze_storage(&open_database(&ledger_path)) {
Ok(()) => { Ok(()) => {
println!("Ok."); println!("Ok.");