Skip to content

Commit

Permalink
ledger-tool: Make verify --print-bank-hash support json (anza-xyz#1745)
Browse files Browse the repository at this point in the history
The bank-hash command in ledger-tool was recently deprecated. However,
the command is used by some of the scripts that coordinate starting up
a fresh cluster. So, the deprecation of bank-hash broke those scripts.

This change fixes the scripts by doing the following:
- Makes --print-bank-hash support --output json
- Updates scripts to install jq on provisioned nodes
- Update remote-node.sh to parse the bank hash from json using jq
  • Loading branch information
steviez authored and samkim-crypto committed Jul 31, 2024
1 parent a78c562 commit cf0ec38
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
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 @@ -1610,9 +1611,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 @@ -1635,11 +1639,11 @@ fn main() {
working_bank.print_accounts_stats();
}
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));
}
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

0 comments on commit cf0ec38

Please sign in to comment.