This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add output in JSON for
solana-ledger-tool bounds
subcommand (#28410)
Introduce a struct to store all of the relevant slot/root information, and then output all in one go at the end as either human-readable or json. There are some slight changes to the human-readable format for the case of an empty ledger
- Loading branch information
Showing
2 changed files
with
129 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use { | ||
serde::Serialize, | ||
solana_cli_output::{QuietDisplay, VerboseDisplay}, | ||
std::fmt::{Display, Formatter, Result}, | ||
}; | ||
|
||
#[derive(Serialize, Debug, Default)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct SlotInfo { | ||
pub total: usize, | ||
pub first: Option<u64>, | ||
pub last: Option<u64>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub num_after_last_root: Option<usize>, | ||
} | ||
|
||
#[derive(Serialize, Debug, Default)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct SlotBounds<'a> { | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub all_slots: Option<&'a Vec<u64>>, | ||
pub slots: SlotInfo, | ||
pub roots: SlotInfo, | ||
} | ||
|
||
impl VerboseDisplay for SlotBounds<'_> {} | ||
impl QuietDisplay for SlotBounds<'_> {} | ||
|
||
impl Display for SlotBounds<'_> { | ||
fn fmt(&self, f: &mut Formatter) -> Result { | ||
if self.slots.total > 0 { | ||
let first = self.slots.first.unwrap(); | ||
let last = self.slots.last.unwrap(); | ||
|
||
if first != last { | ||
writeln!( | ||
f, | ||
"Ledger has data for {:?} slots {:?} to {:?}", | ||
self.slots.total, first, last | ||
)?; | ||
|
||
if let Some(all_slots) = self.all_slots { | ||
writeln!(f, "Non-empty slots: {:?}", all_slots)?; | ||
} | ||
} else { | ||
writeln!(f, "Ledger has data for slot {:?}", first)?; | ||
} | ||
|
||
if self.roots.total > 0 { | ||
let first_rooted = self.roots.first.unwrap_or_default(); | ||
let last_rooted = self.roots.last.unwrap_or_default(); | ||
let num_after_last_root = self.roots.num_after_last_root.unwrap_or_default(); | ||
writeln!( | ||
f, | ||
" with {:?} rooted slots from {:?} to {:?}", | ||
self.roots.total, first_rooted, last_rooted | ||
)?; | ||
|
||
writeln!( | ||
f, | ||
" and {:?} slots past the last root", | ||
num_after_last_root | ||
)?; | ||
} else { | ||
writeln!(f, " with no rooted slots")?; | ||
} | ||
} else { | ||
writeln!(f, "Ledger is empty")?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |