From b97c451200e905a1b2e4f044c16a90e003643e05 Mon Sep 17 00:00:00 2001 From: steviez Date: Wed, 9 Aug 2023 14:13:25 -0500 Subject: [PATCH] ledger-tool: Relax ledger requirements for program subcommand (#32770) Several of the program command subcommands do not require a ledger as they act solely on the program object. So, defer checking the ledger path until we know we need to load. Additionally, remove genesis arg from these commands that do not load a genesis.bin --- ledger-tool/src/main.rs | 5 ++--- ledger-tool/src/program.rs | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 835e4e63bb9ac4..83ee92d6ef82b1 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -2172,6 +2172,8 @@ fn main() { if let ("bigtable", Some(arg_matches)) = matches.subcommand() { bigtable_process_command(&ledger_path, arg_matches) + } else if let ("program", Some(arg_matches)) = matches.subcommand() { + program(&ledger_path, arg_matches) } else { let ledger_path = canonicalize_ledger_path(&ledger_path); @@ -4198,9 +4200,6 @@ fn main() { eprintln!("{err}"); } } - ("program", Some(arg_matches)) => { - program(&ledger_path, arg_matches); - } ("", _) => { eprintln!("{}", matches.usage()); exit(1); diff --git a/ledger-tool/src/program.rs b/ledger-tool/src/program.rs index e8b25e75d89d6c..ed70470b9ee41b 100644 --- a/ledger-tool/src/program.rs +++ b/ledger-tool/src/program.rs @@ -1,5 +1,5 @@ use { - crate::{args::*, ledger_utils::*}, + crate::{args::*, canonicalize_ledger_path, ledger_utils::*}, clap::{value_t, App, AppSettings, Arg, ArgMatches, SubCommand}, log::*, serde::{Deserialize, Serialize}, @@ -162,13 +162,11 @@ impl ProgramSubCommand for App<'_, '_> { .subcommand( SubCommand::with_name("cfg") .about("generates Control Flow Graph of the program.") - .arg(&max_genesis_arg) .arg(&program_arg) ) .subcommand( SubCommand::with_name("disassemble") .about("dumps disassembled code of the program.") - .arg(&max_genesis_arg) .arg(&program_arg) ) .subcommand( @@ -435,7 +433,8 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) { ("run", Some(arg_matches)) => arg_matches, _ => unreachable!(), }; - let bank = load_blockstore(ledger_path, matches); + let ledger_path = canonicalize_ledger_path(ledger_path); + let bank = load_blockstore(&ledger_path, matches); let loader_id = bpf_loader_upgradeable::id(); let mut transaction_accounts = Vec::new(); let mut instruction_accounts = Vec::new();