Add --allow-dead-slots argument to `slot`/`print`/`json` commands (#9408)
automerge
This commit is contained in:
parent
900933bbcc
commit
d5a9ee97f2
|
@ -642,8 +642,8 @@ pub mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
let blockstore = broadcast_service.blockstore;
|
let blockstore = broadcast_service.blockstore;
|
||||||
let (entries, _, _) = blockstore
|
let entries = blockstore
|
||||||
.get_slot_entries_with_shred_info(slot, 0)
|
.get_slot_entries(slot, 0)
|
||||||
.expect("Expect entries to be present");
|
.expect("Expect entries to be present");
|
||||||
assert_eq!(entries.len(), max_tick_height as usize);
|
assert_eq!(entries.len(), max_tick_height as usize);
|
||||||
|
|
||||||
|
|
|
@ -67,13 +67,28 @@ fn output_slot_rewards(
|
||||||
fn output_slot(
|
fn output_slot(
|
||||||
blockstore: &Blockstore,
|
blockstore: &Blockstore,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
|
allow_dead_slots: bool,
|
||||||
method: &LedgerOutputMethod,
|
method: &LedgerOutputMethod,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
println!("Slot Meta {:?}", blockstore.meta(slot));
|
if blockstore.is_dead(slot) {
|
||||||
let entries = blockstore
|
if allow_dead_slots {
|
||||||
.get_slot_entries(slot, 0)
|
if *method == LedgerOutputMethod::Print {
|
||||||
|
println!("Slot is dead");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Err("Dead slot".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let (entries, num_shreds, _is_full) = blockstore
|
||||||
|
.get_slot_entries_with_shred_info(slot, 0, allow_dead_slots)
|
||||||
.map_err(|err| format!("Failed to load entries for slot {}: {}", slot, err))?;
|
.map_err(|err| format!("Failed to load entries for slot {}: {}", slot, err))?;
|
||||||
|
|
||||||
|
if *method == LedgerOutputMethod::Print {
|
||||||
|
println!("Slot Meta {:?}", blockstore.meta(slot));
|
||||||
|
println!("Number of shreds: {}", num_shreds);
|
||||||
|
}
|
||||||
|
|
||||||
for (entry_index, entry) in entries.iter().enumerate() {
|
for (entry_index, entry) in entries.iter().enumerate() {
|
||||||
match method {
|
match method {
|
||||||
LedgerOutputMethod::Print => {
|
LedgerOutputMethod::Print => {
|
||||||
|
@ -204,7 +219,12 @@ fn output_slot(
|
||||||
output_slot_rewards(blockstore, slot, method)
|
output_slot_rewards(blockstore, slot, method)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn output_ledger(blockstore: Blockstore, starting_slot: Slot, method: LedgerOutputMethod) {
|
fn output_ledger(
|
||||||
|
blockstore: Blockstore,
|
||||||
|
starting_slot: Slot,
|
||||||
|
allow_dead_slots: bool,
|
||||||
|
method: LedgerOutputMethod,
|
||||||
|
) {
|
||||||
let rooted_slot_iterator =
|
let rooted_slot_iterator =
|
||||||
RootedSlotIterator::new(starting_slot, &blockstore).unwrap_or_else(|err| {
|
RootedSlotIterator::new(starting_slot, &blockstore).unwrap_or_else(|err| {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
|
@ -227,7 +247,7 @@ fn output_ledger(blockstore: Blockstore, starting_slot: Slot, method: LedgerOutp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = output_slot(&blockstore, slot, &method) {
|
if let Err(err) = output_slot(&blockstore, slot, allow_dead_slots, &method) {
|
||||||
eprintln!("{}", err);
|
eprintln!("{}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -667,6 +687,10 @@ fn main() {
|
||||||
.multiple(true)
|
.multiple(true)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.help("Add a hard fork at this slot");
|
.help("Add a hard fork at this slot");
|
||||||
|
let allow_dead_slots_arg = Arg::with_name("allow_dead_slots")
|
||||||
|
.long("allow-dead-slots")
|
||||||
|
.takes_value(false)
|
||||||
|
.help("Output dead slots as well");
|
||||||
|
|
||||||
let matches = App::new(crate_name!())
|
let matches = App::new(crate_name!())
|
||||||
.about(crate_description!())
|
.about(crate_description!())
|
||||||
|
@ -684,6 +708,7 @@ fn main() {
|
||||||
SubCommand::with_name("print")
|
SubCommand::with_name("print")
|
||||||
.about("Print the ledger")
|
.about("Print the ledger")
|
||||||
.arg(&starting_slot_arg)
|
.arg(&starting_slot_arg)
|
||||||
|
.arg(&allow_dead_slots_arg)
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("slot")
|
SubCommand::with_name("slot")
|
||||||
|
@ -698,6 +723,7 @@ fn main() {
|
||||||
.required(true)
|
.required(true)
|
||||||
.help("Slots to print"),
|
.help("Slots to print"),
|
||||||
)
|
)
|
||||||
|
.arg(&allow_dead_slots_arg)
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("set-dead-slot")
|
SubCommand::with_name("set-dead-slot")
|
||||||
|
@ -740,6 +766,7 @@ fn main() {
|
||||||
SubCommand::with_name("json")
|
SubCommand::with_name("json")
|
||||||
.about("Print the ledger in JSON format")
|
.about("Print the ledger in JSON format")
|
||||||
.arg(&starting_slot_arg)
|
.arg(&starting_slot_arg)
|
||||||
|
.arg(&allow_dead_slots_arg)
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("verify")
|
SubCommand::with_name("verify")
|
||||||
|
@ -891,9 +918,11 @@ fn main() {
|
||||||
match matches.subcommand() {
|
match matches.subcommand() {
|
||||||
("print", Some(arg_matches)) => {
|
("print", Some(arg_matches)) => {
|
||||||
let starting_slot = value_t_or_exit!(arg_matches, "starting_slot", Slot);
|
let starting_slot = value_t_or_exit!(arg_matches, "starting_slot", Slot);
|
||||||
|
let allow_dead_slots = arg_matches.is_present("allow_dead_slots");
|
||||||
output_ledger(
|
output_ledger(
|
||||||
open_blockstore(&ledger_path),
|
open_blockstore(&ledger_path),
|
||||||
starting_slot,
|
starting_slot,
|
||||||
|
allow_dead_slots,
|
||||||
LedgerOutputMethod::Print,
|
LedgerOutputMethod::Print,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -932,19 +961,27 @@ fn main() {
|
||||||
}
|
}
|
||||||
("slot", Some(arg_matches)) => {
|
("slot", Some(arg_matches)) => {
|
||||||
let slots = values_t_or_exit!(arg_matches, "slots", Slot);
|
let slots = values_t_or_exit!(arg_matches, "slots", Slot);
|
||||||
|
let allow_dead_slots = arg_matches.is_present("allow_dead_slots");
|
||||||
let blockstore = open_blockstore(&ledger_path);
|
let blockstore = open_blockstore(&ledger_path);
|
||||||
for slot in slots {
|
for slot in slots {
|
||||||
println!("Slot {}", slot);
|
println!("Slot {}", slot);
|
||||||
if let Err(err) = output_slot(&blockstore, slot, &LedgerOutputMethod::Print) {
|
if let Err(err) = output_slot(
|
||||||
|
&blockstore,
|
||||||
|
slot,
|
||||||
|
allow_dead_slots,
|
||||||
|
&LedgerOutputMethod::Print,
|
||||||
|
) {
|
||||||
eprintln!("{}", err);
|
eprintln!("{}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
("json", Some(arg_matches)) => {
|
("json", Some(arg_matches)) => {
|
||||||
let starting_slot = value_t_or_exit!(arg_matches, "starting_slot", Slot);
|
let starting_slot = value_t_or_exit!(arg_matches, "starting_slot", Slot);
|
||||||
|
let allow_dead_slots = arg_matches.is_present("allow_dead_slots");
|
||||||
output_ledger(
|
output_ledger(
|
||||||
open_blockstore(&ledger_path),
|
open_blockstore(&ledger_path),
|
||||||
starting_slot,
|
starting_slot,
|
||||||
|
allow_dead_slots,
|
||||||
LedgerOutputMethod::Json,
|
LedgerOutputMethod::Json,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ fn bad_arguments() {
|
||||||
fn nominal() {
|
fn nominal() {
|
||||||
let genesis_config = create_genesis_config(100).genesis_config;
|
let genesis_config = create_genesis_config(100).genesis_config;
|
||||||
let ticks_per_slot = genesis_config.ticks_per_slot;
|
let ticks_per_slot = genesis_config.ticks_per_slot;
|
||||||
let meta_lines = 1;
|
let meta_lines = 2;
|
||||||
|
|
||||||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
|
||||||
let ticks = ticks_per_slot as usize;
|
let ticks = ticks_per_slot as usize;
|
||||||
|
|
|
@ -1797,7 +1797,7 @@ impl Blockstore {
|
||||||
|
|
||||||
/// Returns the entry vector for the slot starting with `shred_start_index`
|
/// Returns the entry vector for the slot starting with `shred_start_index`
|
||||||
pub fn get_slot_entries(&self, slot: Slot, shred_start_index: u64) -> Result<Vec<Entry>> {
|
pub fn get_slot_entries(&self, slot: Slot, shred_start_index: u64) -> Result<Vec<Entry>> {
|
||||||
self.get_slot_entries_with_shred_info(slot, shred_start_index)
|
self.get_slot_entries_with_shred_info(slot, shred_start_index, false)
|
||||||
.map(|x| x.0)
|
.map(|x| x.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1807,8 +1807,9 @@ impl Blockstore {
|
||||||
&self,
|
&self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
start_index: u64,
|
start_index: u64,
|
||||||
|
allow_dead_slots: bool,
|
||||||
) -> Result<(Vec<Entry>, u64, bool)> {
|
) -> Result<(Vec<Entry>, u64, bool)> {
|
||||||
if self.is_dead(slot) {
|
if self.is_dead(slot) && !allow_dead_slots {
|
||||||
return Err(BlockstoreError::DeadSlot);
|
return Err(BlockstoreError::DeadSlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -538,7 +538,7 @@ pub fn confirm_slot(
|
||||||
let (entries, num_shreds, slot_full) = {
|
let (entries, num_shreds, slot_full) = {
|
||||||
let mut load_elapsed = Measure::start("load_elapsed");
|
let mut load_elapsed = Measure::start("load_elapsed");
|
||||||
let load_result = blockstore
|
let load_result = blockstore
|
||||||
.get_slot_entries_with_shred_info(slot, progress.num_shreds)
|
.get_slot_entries_with_shred_info(slot, progress.num_shreds, false)
|
||||||
.map_err(BlockstoreProcessorError::FailedToLoadEntries);
|
.map_err(BlockstoreProcessorError::FailedToLoadEntries);
|
||||||
load_elapsed.stop();
|
load_elapsed.stop();
|
||||||
if load_result.is_err() {
|
if load_result.is_err() {
|
||||||
|
|
Loading…
Reference in New Issue