Fix root scan in ledger tool (#15532)

This commit is contained in:
carllin
2021-02-25 15:52:16 -08:00
committed by GitHub
parent 28a9926ba1
commit a6b9327cd0

View File

@ -1285,7 +1285,7 @@ fn main() {
) )
.subcommand( .subcommand(
SubCommand::with_name("list-roots") SubCommand::with_name("list-roots")
.about("Output upto last <num-roots> root hashes and their heights starting at the given block height") .about("Output up to last <num-roots> root hashes and their heights starting at the given block height")
.arg( .arg(
Arg::with_name("max_height") Arg::with_name("max_height")
.long("max-height") .long("max-height")
@ -1293,6 +1293,13 @@ fn main() {
.takes_value(true) .takes_value(true)
.help("Maximum block height") .help("Maximum block height")
) )
.arg(
Arg::with_name("start_root")
.long("start-root")
.value_name("NUM")
.takes_value(true)
.help("First root to start searching from")
)
.arg( .arg(
Arg::with_name("slot_list") Arg::with_name("slot_list")
.long("slot-list") .long("slot-list")
@ -2698,6 +2705,11 @@ fn main() {
} else { } else {
usize::MAX usize::MAX
}; };
let start_root = if let Some(height) = arg_matches.value_of("start_root") {
Slot::from_str(height).expect("Starting root must be a number")
} else {
0
};
let num_roots = if let Some(roots) = arg_matches.value_of("num_roots") { let num_roots = if let Some(roots) = arg_matches.value_of("num_roots") {
usize::from_str(roots).expect("Number of roots must be a number") usize::from_str(roots).expect("Number of roots must be a number")
} else { } else {
@ -2705,7 +2717,7 @@ fn main() {
}; };
let iter = blockstore let iter = blockstore
.rooted_slot_iterator(0) .rooted_slot_iterator(start_root)
.expect("Failed to get rooted slot"); .expect("Failed to get rooted slot");
let mut slot_hash = Vec::new(); let mut slot_hash = Vec::new();