ledger-tool: Minor cleanup on accountsdb config argument parsing (#34671)

- Avoid repeated parsing + use of values_t_or_exit!()
- Move associated items closer to show grouping
This commit is contained in:
steviez 2024-01-09 16:42:15 -06:00 committed by GitHub
parent 642a7e0acb
commit 48391152ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 16 deletions

View File

@ -1,6 +1,6 @@
use {
crate::LEDGER_TOOL_DIRECTORY,
clap::{value_t, values_t_or_exit, ArgMatches},
clap::{value_t, values_t, values_t_or_exit, ArgMatches},
solana_accounts_db::{
accounts_db::{AccountsDb, AccountsDbConfig},
accounts_index::{AccountsIndexConfig, IndexLimitMb},
@ -20,6 +20,7 @@ pub fn get_accounts_db_config(
arg_matches: &ArgMatches<'_>,
) -> AccountsDbConfig {
let ledger_tool_ledger_path = ledger_path.join(LEDGER_TOOL_DIRECTORY);
let accounts_index_bins = value_t!(arg_matches, "accounts_index_bins", usize).ok();
let accounts_index_index_limit_mb =
if let Ok(limit) = value_t!(arg_matches, "accounts_index_memory_limit_mb", usize) {
@ -29,6 +30,17 @@ pub fn get_accounts_db_config(
} else {
IndexLimitMb::Unspecified
};
let accounts_index_drives = values_t!(arg_matches, "accounts_index_path", String)
.ok()
.map(|drives| drives.into_iter().map(PathBuf::from).collect())
.unwrap_or_else(|| vec![ledger_tool_ledger_path.join("accounts_index")]);
let accounts_index_config = AccountsIndexConfig {
bins: accounts_index_bins,
index_limit_mb: accounts_index_index_limit_mb,
drives: Some(accounts_index_drives),
..AccountsIndexConfig::default()
};
let test_partitioned_epoch_rewards =
if arg_matches.is_present("partitioned_epoch_rewards_compare_calculation") {
TestPartitionedEpochRewards::CompareResults
@ -38,21 +50,6 @@ pub fn get_accounts_db_config(
TestPartitionedEpochRewards::None
};
let accounts_index_drives: Vec<PathBuf> = if arg_matches.is_present("accounts_index_path") {
values_t_or_exit!(arg_matches, "accounts_index_path", String)
.into_iter()
.map(PathBuf::from)
.collect()
} else {
vec![ledger_tool_ledger_path.join("accounts_index")]
};
let accounts_index_config = AccountsIndexConfig {
bins: accounts_index_bins,
index_limit_mb: accounts_index_index_limit_mb,
drives: Some(accounts_index_drives),
..AccountsIndexConfig::default()
};
let accounts_hash_cache_path = arg_matches
.value_of("accounts_hash_cache_path")
.map(Into::into)