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: Subfunction for snapshot args #1773

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ledger-tool/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,38 @@ pub fn accounts_db_args<'a, 'b>() -> Box<[Arg<'a, 'b>]> {
.into_boxed_slice()
}

/// Returns the arguments that configure snapshot loading
steviez marked this conversation as resolved.
Show resolved Hide resolved
pub fn snapshot_args<'a, 'b>() -> Box<[Arg<'a, 'b>]> {
vec![
Arg::with_name("no_snapshot")
.long("no-snapshot")
.takes_value(false)
.help("Do not start from a local snapshot if present"),
Arg::with_name("snapshots")
.long("snapshots")
.alias("snapshot-archive-path")
.alias("full-snapshot-archive-path")
.value_name("DIR")
.takes_value(true)
.global(true)
.help("Use DIR for snapshot location [default: --ledger value]"),
Arg::with_name("incremental_snapshot_archive_path")
.long("incremental-snapshot-archive-path")
.value_name("DIR")
.takes_value(true)
.global(true)
.help("Use DIR for separate incremental snapshot location"),
Arg::with_name(use_snapshot_archives_at_startup::cli::NAME)
.long(use_snapshot_archives_at_startup::cli::LONG_ARG)
.takes_value(true)
.possible_values(use_snapshot_archives_at_startup::cli::POSSIBLE_VALUES)
.default_value(use_snapshot_archives_at_startup::cli::default_value_for_ledger_tool())
.help(use_snapshot_archives_at_startup::cli::HELP)
.long_help(use_snapshot_archives_at_startup::cli::LONG_HELP),
]
.into_boxed_slice()
}

/// Parse a `ProcessOptions` from subcommand arguments. This function attempts
/// to parse all flags related to `ProcessOptions`; however, subcommands that
/// use this function may not support all flags.
Expand Down
17 changes: 8 additions & 9 deletions ledger-tool/src/ledger_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,13 @@ pub fn load_and_process_ledger_or_exit(
genesis_config: &GenesisConfig,
blockstore: Arc<Blockstore>,
process_options: ProcessOptions,
snapshot_archive_path: Option<PathBuf>,
incremental_snapshot_archive_path: Option<PathBuf>,
transaction_status_sender: Option<TransactionStatusSender>,
) -> (Arc<RwLock<BankForks>>, Option<StartingSnapshotHashes>) {
load_and_process_ledger(
arg_matches,
genesis_config,
blockstore,
process_options,
snapshot_archive_path,
incremental_snapshot_archive_path,
transaction_status_sender,
)
.unwrap_or_else(|err| {
Expand All @@ -122,8 +118,6 @@ pub fn load_and_process_ledger(
genesis_config: &GenesisConfig,
blockstore: Arc<Blockstore>,
process_options: ProcessOptions,
snapshot_archive_path: Option<PathBuf>,
incremental_snapshot_archive_path: Option<PathBuf>,
transaction_status_sender: Option<TransactionStatusSender>,
) -> Result<(Arc<RwLock<BankForks>>, Option<StartingSnapshotHashes>), LoadAndProcessLedgerError> {
let bank_snapshots_dir = if blockstore.is_primary_access() {
Expand All @@ -139,10 +133,15 @@ pub fn load_and_process_ledger(
let snapshot_config = if arg_matches.is_present("no_snapshot") {
None
} else {
let full_snapshot_archives_dir =
snapshot_archive_path.unwrap_or_else(|| blockstore.ledger_path().to_path_buf());
let full_snapshot_archives_dir = value_t!(arg_matches, "snapshots", String)
.ok()
.map(PathBuf::from)
.unwrap_or_else(|| blockstore.ledger_path().to_path_buf());
let incremental_snapshot_archives_dir =
incremental_snapshot_archive_path.unwrap_or_else(|| full_snapshot_archives_dir.clone());
value_t!(arg_matches, "incremental_snapshot_archive_path", String)
.ok()
.map(PathBuf::from)
.unwrap_or_else(|| full_snapshot_archives_dir.clone());
if let Some(full_snapshot_slot) =
snapshot_utils::get_highest_full_snapshot_archive_slot(&full_snapshot_archives_dir)
{
Expand Down
78 changes: 15 additions & 63 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ use {
blockstore_processor::{
ProcessSlotCallback, TransactionStatusMessage, TransactionStatusSender,
},
use_snapshot_archives_at_startup,
},
solana_measure::{measure, measure::Measure},
solana_runtime::{
Expand Down Expand Up @@ -563,11 +562,8 @@ fn main() {
solana_logger::setup_with_default_filter();

let accounts_db_config_args = accounts_db_args();
let snapshot_config_args = snapshot_args();

let no_snapshot_arg = Arg::with_name("no_snapshot")
.long("no-snapshot")
.takes_value(false)
.help("Do not start from a local snapshot if present");
let accounts_db_test_hash_calculation_arg = Arg::with_name("accounts_db_test_hash_calculation")
.long("accounts-db-test-hash-calculation")
.help("Enable hash calculation test");
Expand Down Expand Up @@ -641,14 +637,6 @@ fn main() {
.multiple(true)
.takes_value(true)
.help("Log when transactions are processed that reference the given key(s).");
let use_snapshot_archives_at_startup =
Arg::with_name(use_snapshot_archives_at_startup::cli::NAME)
.long(use_snapshot_archives_at_startup::cli::LONG_ARG)
.takes_value(true)
.possible_values(use_snapshot_archives_at_startup::cli::POSSIBLE_VALUES)
.default_value(use_snapshot_archives_at_startup::cli::default_value_for_ledger_tool())
.help(use_snapshot_archives_at_startup::cli::HELP)
.long_help(use_snapshot_archives_at_startup::cli::LONG_HELP);

let geyser_plugin_args = Arg::with_name("geyser_plugin_config")
.long("geyser-plugin-config")
Expand Down Expand Up @@ -733,24 +721,6 @@ fn main() {
run fine with a reduced file descriptor limit while others will not",
),
)
.arg(
Arg::with_name("snapshots")
.long("snapshots")
.alias("snapshot-archive-path")
.alias("full-snapshot-archive-path")
.value_name("DIR")
.takes_value(true)
.global(true)
.help("Use DIR for snapshot location [default: --ledger value]"),
)
.arg(
Arg::with_name("incremental_snapshot_archive_path")
.long("incremental-snapshot-archive-path")
.value_name("DIR")
.takes_value(true)
.global(true)
.help("Use DIR for separate incremental snapshot location"),
)
.arg(
Arg::with_name("block_verification_method")
.long("block-verification-method")
Expand Down Expand Up @@ -846,23 +816,23 @@ fn main() {
SubCommand::with_name("shred-version")
.about("Prints the ledger's shred hash")
.args(&accounts_db_config_args)
.args(&snapshot_config_args)
.arg(&hard_forks_arg)
.arg(&max_genesis_archive_unpacked_size_arg)
.arg(&use_snapshot_archives_at_startup),
)
.subcommand(
SubCommand::with_name("bank-hash")
.about("Prints the hash of the working bank after reading the ledger")
.args(&accounts_db_config_args)
.args(&snapshot_config_args)
.arg(&max_genesis_archive_unpacked_size_arg)
.arg(&halt_at_slot_arg)
.arg(&use_snapshot_archives_at_startup),
)
.subcommand(
SubCommand::with_name("verify")
.about("Verify the ledger")
.args(&accounts_db_config_args)
.arg(&no_snapshot_arg)
.args(&snapshot_config_args)
.arg(&halt_at_slot_arg)
.arg(&limit_load_slot_count_from_snapshot_arg)
.arg(&verify_index_arg)
Expand All @@ -875,7 +845,6 @@ fn main() {
.arg(&debug_key_arg)
.arg(&geyser_plugin_args)
.arg(&log_messages_bytes_limit_arg)
.arg(&use_snapshot_archives_at_startup)
.arg(
Arg::with_name("skip_poh_verify")
.long("skip-poh-verify")
Expand Down Expand Up @@ -999,11 +968,10 @@ fn main() {
SubCommand::with_name("graph")
.about("Create a Graphviz rendering of the ledger")
.args(&accounts_db_config_args)
.arg(&no_snapshot_arg)
.args(&snapshot_config_args)
.arg(&halt_at_slot_arg)
.arg(&hard_forks_arg)
.arg(&max_genesis_archive_unpacked_size_arg)
.arg(&use_snapshot_archives_at_startup)
.arg(
Arg::with_name("include_all_votes")
.long("include-all-votes")
Expand Down Expand Up @@ -1033,13 +1001,12 @@ fn main() {
SubCommand::with_name("create-snapshot")
.about("Create a new ledger snapshot")
.args(&accounts_db_config_args)
.arg(&no_snapshot_arg)
.args(&snapshot_config_args)
.arg(&hard_forks_arg)
.arg(&max_genesis_archive_unpacked_size_arg)
.arg(&snapshot_version_arg)
.arg(&geyser_plugin_args)
.arg(&log_messages_bytes_limit_arg)
.arg(&use_snapshot_archives_at_startup)
.arg(
Arg::with_name("snapshot_slot")
.index(1)
Expand Down Expand Up @@ -1240,13 +1207,12 @@ fn main() {
SubCommand::with_name("accounts")
.about("Print account stats and contents after processing the ledger")
.args(&accounts_db_config_args)
.arg(&no_snapshot_arg)
.args(&snapshot_config_args)
.arg(&halt_at_slot_arg)
.arg(&hard_forks_arg)
.arg(&geyser_plugin_args)
.arg(&log_messages_bytes_limit_arg)
.arg(&accounts_data_encoding_arg)
.arg(&use_snapshot_archives_at_startup)
.arg(&max_genesis_archive_unpacked_size_arg)
.arg(
Arg::with_name("include_sysvars")
Expand Down Expand Up @@ -1295,13 +1261,12 @@ fn main() {
SubCommand::with_name("capitalization")
.about("Print capitalization (aka, total supply) while checksumming it")
.args(&accounts_db_config_args)
.arg(&no_snapshot_arg)
.args(&snapshot_config_args)
.arg(&halt_at_slot_arg)
.arg(&hard_forks_arg)
.arg(&max_genesis_archive_unpacked_size_arg)
.arg(&geyser_plugin_args)
.arg(&log_messages_bytes_limit_arg)
.arg(&use_snapshot_archives_at_startup)
.arg(
Arg::with_name("warp_epoch")
.required(false)
Expand Down Expand Up @@ -1372,14 +1337,6 @@ fn main() {
info!("{} {}", crate_name!(), solana_version::version!());

let ledger_path = PathBuf::from(value_t_or_exit!(matches, "ledger_path", String));
let snapshot_archive_path = value_t!(matches, "snapshots", String)
.ok()
.map(PathBuf::from);
let incremental_snapshot_archive_path =
value_t!(matches, "incremental_snapshot_archive_path", String)
.ok()
.map(PathBuf::from);

let verbose_level = matches.occurrences_of("verbose");

// Name the rayon global thread pool
Expand Down Expand Up @@ -1487,8 +1444,6 @@ fn main() {
&genesis_config,
Arc::new(blockstore),
process_options,
snapshot_archive_path,
incremental_snapshot_archive_path,
None,
);

Expand Down Expand Up @@ -1679,8 +1634,6 @@ fn main() {
&genesis_config,
Arc::new(blockstore),
process_options,
snapshot_archive_path,
incremental_snapshot_archive_path,
transaction_status_sender,
);

Expand Down Expand Up @@ -1747,8 +1700,6 @@ fn main() {
&genesis_config,
Arc::new(blockstore),
process_options,
snapshot_archive_path,
incremental_snapshot_archive_path,
None,
);

Expand All @@ -1773,6 +1724,13 @@ fn main() {
let is_minimized = arg_matches.is_present("minimized");
let output_directory = value_t!(arg_matches, "output_directory", PathBuf)
.unwrap_or_else(|_| {
let snapshot_archive_path = value_t!(matches, "snapshots", String)
.ok()
.map(PathBuf::from);
let incremental_snapshot_archive_path =
value_t!(matches, "incremental_snapshot_archive_path", String)
.ok()
.map(PathBuf::from);
steviez marked this conversation as resolved.
Show resolved Hide resolved
match (
is_incremental,
&snapshot_archive_path,
Expand Down Expand Up @@ -1911,8 +1869,6 @@ fn main() {
&genesis_config,
blockstore.clone(),
process_options,
snapshot_archive_path,
incremental_snapshot_archive_path,
None,
);
let mut bank = bank_forks
Expand Down Expand Up @@ -2301,8 +2257,6 @@ fn main() {
&genesis_config,
Arc::new(blockstore),
process_options,
snapshot_archive_path,
incremental_snapshot_archive_path,
None,
);
let bank = bank_forks.read().unwrap().working_bank();
Expand Down Expand Up @@ -2354,8 +2308,6 @@ fn main() {
&genesis_config,
Arc::new(blockstore),
process_options,
snapshot_archive_path,
incremental_snapshot_archive_path,
None,
);
let bank_forks = bank_forks.read().unwrap();
Expand Down
28 changes: 5 additions & 23 deletions ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::{args::*, canonicalize_ledger_path, ledger_utils::*},
clap::{value_t, App, AppSettings, Arg, ArgMatches, SubCommand},
clap::{App, AppSettings, Arg, ArgMatches, SubCommand},
log::*,
serde_derive::{Deserialize, Serialize},
serde_json::Result,
Expand All @@ -9,7 +9,7 @@ use {
syscalls::create_program_runtime_environment_v1,
},
solana_cli_output::{OutputFormat, QuietDisplay, VerboseDisplay},
solana_ledger::{blockstore_options::AccessType, use_snapshot_archives_at_startup},
solana_ledger::blockstore_options::AccessType,
solana_program_runtime::{
invoke_context::InvokeContext,
loaded_programs::{
Expand All @@ -36,7 +36,7 @@ use {
fmt::{self, Debug, Formatter},
fs::File,
io::{Read, Seek, Write},
path::{Path, PathBuf},
path::Path,
process::exit,
sync::Arc,
time::{Duration, Instant},
Expand Down Expand Up @@ -75,13 +75,6 @@ fn load_accounts(path: &Path) -> Result<Input> {

fn load_blockstore(ledger_path: &Path, arg_matches: &ArgMatches<'_>) -> Arc<Bank> {
let process_options = parse_process_options(ledger_path, arg_matches);
let snapshot_archive_path = value_t!(arg_matches, "snapshots", String)
.ok()
.map(PathBuf::from);
let incremental_snapshot_archive_path =
value_t!(arg_matches, "incremental_snapshot_archive_path", String)
.ok()
.map(PathBuf::from);

let genesis_config = open_genesis_config_by(ledger_path, arg_matches);
info!("genesis hash: {}", genesis_config.hash());
Expand All @@ -91,8 +84,6 @@ fn load_blockstore(ledger_path: &Path, arg_matches: &ArgMatches<'_>) -> Arc<Bank
&genesis_config,
Arc::new(blockstore),
process_options,
snapshot_archive_path,
incremental_snapshot_archive_path,
None,
);
let bank = bank_forks.read().unwrap().working_bank();
Expand All @@ -118,16 +109,7 @@ impl ProgramSubCommand for App<'_, '_> {
.takes_value(true)
.default_value("10485760")
.help("maximum total uncompressed size of unpacked genesis archive");
let use_snapshot_archives_at_startup =
Arg::with_name(use_snapshot_archives_at_startup::cli::NAME)
.long(use_snapshot_archives_at_startup::cli::LONG_ARG)
.takes_value(true)
.possible_values(use_snapshot_archives_at_startup::cli::POSSIBLE_VALUES)
.default_value(
use_snapshot_archives_at_startup::cli::default_value_for_ledger_tool(),
)
.help(use_snapshot_archives_at_startup::cli::HELP)
.long_help(use_snapshot_archives_at_startup::cli::LONG_HELP);
let snapshot_config_args = snapshot_args();

self.subcommand(
SubCommand::with_name("program")
Expand Down Expand Up @@ -179,8 +161,8 @@ and the following fields are required
.takes_value(true)
.default_value("0"),
)
.args(&snapshot_config_args)
.arg(&max_genesis_arg)
.arg(&use_snapshot_archives_at_startup)
.arg(
Arg::with_name("memory")
.help("Heap memory for the program to run on")
Expand Down