Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ledger-tool: Make verify --print-bank-hash support json #1745

Merged
merged 8 commits into from
Jun 20, 2024
14 changes: 9 additions & 5 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use {
ledger_utils::*,
output::{
output_account, AccountsOutputConfig, AccountsOutputMode, AccountsOutputStreamer,
SlotBankHash,
},
program::*,
},
Expand Down Expand Up @@ -1791,9 +1792,12 @@ fn main() {

process_options.slot_callback = slot_callback;

let output_format =
OutputFormat::from_matches(arg_matches, "output_format", false);
let print_accounts_stats = arg_matches.is_present("print_accounts_stats");
let print_bank_hash = arg_matches.is_present("print_bank_hash");
let write_bank_file = arg_matches.is_present("write_bank_file");

let genesis_config = open_genesis_config_by(&ledger_path, arg_matches);
info!("genesis hash: {}", genesis_config.hash());

Expand All @@ -1817,11 +1821,11 @@ fn main() {
working_bank.print_accounts_stats();
steviez marked this conversation as resolved.
Show resolved Hide resolved
}
if print_bank_hash {
println!(
"Bank hash for slot {}: {}",
working_bank.slot(),
working_bank.hash()
);
let slot_bank_hash = SlotBankHash {
slot: working_bank.slot(),
hash: working_bank.hash().to_string(),
};
println!("{}", output_format.formatted_string(&slot_bank_hash));
Comment on lines +1824 to +1828

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you given any thought to how to handle once shred_version is also optionally printed? If a single, flat map, can be handled in later PR. If a nested map (eg. {"bankHash": {"slot": .. }, "shredVersion": .. }), might be best to set that up here.

Imo, flat map would be better, if it makes sense.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you given any thought to how to handle once shred_version is also optionally printed?

I gave a little thought, but couldn't think of a solution I loved. Conceptually, I think the types for shred-version and bank-hash could/should be separate. But you're absolutely right that if I implement shred-version in an identical manner, we'd print this non-ideal output:

{
  "bankHash": ...
}
{
  "shredVersion": ...
}

I probably prefer the flat-map as well, will have to take a sec to think about how to most cleanly do that

}
if write_bank_file {
bank_hash_details::write_bank_hash_details_file(&working_bank)
Expand Down
16 changes: 16 additions & 0 deletions ledger-tool/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ impl Display for SlotBounds<'_> {
}
}

#[derive(Serialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct SlotBankHash {
pub slot: Slot,
pub hash: String,
}

impl VerboseDisplay for SlotBankHash {}
impl QuietDisplay for SlotBankHash {}

impl Display for SlotBankHash {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
writeln!(f, "Bank hash for slot {}: {}", self.slot, self.hash)
}
}

fn writeln_entry(f: &mut dyn fmt::Write, i: usize, entry: &CliEntry, prefix: &str) -> fmt::Result {
writeln!(
f,
Expand Down
1 change: 1 addition & 0 deletions net/gce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ $(
install-certbot.sh \
install-earlyoom.sh \
install-iftop.sh \
install-jq.sh \
install-libssl-compatability.sh \
install-rsync.sh \
install-perf.sh \
Expand Down
2 changes: 1 addition & 1 deletion net/remote/remote-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ EOF
agave-ledger-tool -l config/bootstrap-validator shred-version --max-genesis-archive-unpacked-size 1073741824 | tee config/shred-version

if [[ -n "$maybeWaitForSupermajority" ]]; then
bankHash=$(agave-ledger-tool -l config/bootstrap-validator bank-hash --halt-at-slot 0)
bankHash=$(agave-ledger-tool -l config/bootstrap-validator verify --halt-at-slot 0 --print-bank-hash --output json | jq -r ".hash")
shredVersion="$(cat "$SOLANA_CONFIG_DIR"/shred-version)"
extraNodeArgs="$extraNodeArgs --expected-bank-hash $bankHash --expected-shred-version $shredVersion"
echo "$bankHash" > config/bank-hash
Expand Down
10 changes: 10 additions & 0 deletions net/scripts/install-jq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
#
# jq setup
#
set -ex

[[ $(uname) = Linux ]] || exit 1
[[ $USER = root ]] || exit 1

apt-get --assume-yes install jq