Skip to content

Commit

Permalink
Consolidate AccountsDb parameters (#3324)
Browse files Browse the repository at this point in the history
Move shrink_ratio and account_indexes into AccountsDbConfig struct
  • Loading branch information
steviez authored Oct 28, 2024
1 parent d8225b5 commit 5de9be0
Show file tree
Hide file tree
Showing 23 changed files with 120 additions and 252 deletions.
6 changes: 1 addition & 5 deletions accounts-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use {
accounts::Accounts,
accounts_db::{
test_utils::{create_test_accounts, update_accounts_bench},
AccountShrinkThreshold, AccountsDb, CalcAccountsHashDataSource,
ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS,
AccountsDb, CalcAccountsHashDataSource, ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS,
},
accounts_index::AccountSecondaryIndexes,
ancestors::Ancestors,
},
solana_measure::measure::Measure,
Expand Down Expand Up @@ -71,8 +69,6 @@ fn main() {
}
let accounts_db = AccountsDb::new_with_config(
vec![path],
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
Some(ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS),
None,
Arc::default(),
Expand Down
29 changes: 24 additions & 5 deletions accounts-cluster-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,10 @@ fn main() {
pub mod test {
use {
super::*,
solana_accounts_db::accounts_index::{AccountIndex, AccountSecondaryIndexes},
solana_accounts_db::{
accounts_db::ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS,
accounts_index::{AccountIndex, AccountSecondaryIndexes},
},
solana_core::validator::ValidatorConfig,
solana_faucet::faucet::run_local_faucet,
solana_local_cluster::{
Expand All @@ -1072,6 +1075,24 @@ pub mod test {
},
};

fn initialize_and_add_secondary_indexes(validator_config: &mut ValidatorConfig) {
if validator_config.accounts_db_config.is_none() {
validator_config.accounts_db_config = Some(ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS);
}

let account_indexes = &mut validator_config
.accounts_db_config
.as_mut()
.unwrap()
.account_indexes;
if account_indexes.is_none() {
*account_indexes = Some(AccountSecondaryIndexes::default());
}
add_secondary_indexes(account_indexes.as_mut().unwrap());

add_secondary_indexes(&mut validator_config.rpc_config.account_indexes);
}

fn add_secondary_indexes(indexes: &mut AccountSecondaryIndexes) {
indexes.indexes.insert(AccountIndex::SplTokenOwner);
indexes.indexes.insert(AccountIndex::SplTokenMint);
Expand All @@ -1082,9 +1103,8 @@ pub mod test {
fn test_accounts_cluster_bench() {
solana_logger::setup();
let mut validator_config = ValidatorConfig::default_for_test();
initialize_and_add_secondary_indexes(&mut validator_config);
let num_nodes = 1;
add_secondary_indexes(&mut validator_config.account_indexes);
add_secondary_indexes(&mut validator_config.rpc_config.account_indexes);
let mut config = ClusterConfig {
cluster_lamports: 10_000_000,
poh_config: PohConfig::new_sleep(Duration::from_millis(50)),
Expand Down Expand Up @@ -1133,9 +1153,8 @@ pub mod test {
fn test_halt_accounts_creation_at_max() {
solana_logger::setup();
let mut validator_config = ValidatorConfig::default_for_test();
initialize_and_add_secondary_indexes(&mut validator_config);
let num_nodes = 1;
add_secondary_indexes(&mut validator_config.account_indexes);
add_secondary_indexes(&mut validator_config.rpc_config.account_indexes);
let mut config = ClusterConfig {
cluster_lamports: 10_000_000,
poh_config: PohConfig::new_sleep(Duration::from_millis(50)),
Expand Down
8 changes: 3 additions & 5 deletions accounts-db/benches/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use {
account_info::{AccountInfo, StorageLocation},
accounts::{AccountAddressFilter, Accounts},
accounts_db::{
test_utils::create_test_accounts, AccountFromStorage, AccountShrinkThreshold,
AccountsDb, VerifyAccountsHashAndLamportsConfig, ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS,
test_utils::create_test_accounts, AccountFromStorage, AccountsDb,
VerifyAccountsHashAndLamportsConfig, ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS,
},
accounts_index::{AccountSecondaryIndexes, ScanConfig},
accounts_index::ScanConfig,
ancestors::Ancestors,
},
solana_sdk::{
Expand All @@ -36,8 +36,6 @@ use {
fn new_accounts_db(account_paths: Vec<PathBuf>) -> AccountsDb {
AccountsDb::new_with_config(
account_paths,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
Some(ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS),
None,
Arc::default(),
Expand Down
20 changes: 8 additions & 12 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,11 @@ pub(crate) struct ShrinkCollect<'a, T: ShrinkCollectRefs<'a>> {

pub const ACCOUNTS_DB_CONFIG_FOR_TESTING: AccountsDbConfig = AccountsDbConfig {
index: Some(ACCOUNTS_INDEX_CONFIG_FOR_TESTING),
account_indexes: None,
base_working_path: None,
accounts_hash_cache_path: None,
shrink_paths: None,
shrink_ratio: DEFAULT_ACCOUNTS_SHRINK_THRESHOLD_OPTION,
read_cache_limit_bytes: None,
write_cache_limit_bytes: None,
ancient_append_vec_offset: None,
Expand All @@ -516,9 +518,11 @@ pub const ACCOUNTS_DB_CONFIG_FOR_TESTING: AccountsDbConfig = AccountsDbConfig {
};
pub const ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS: AccountsDbConfig = AccountsDbConfig {
index: Some(ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS),
account_indexes: None,
base_working_path: None,
accounts_hash_cache_path: None,
shrink_paths: None,
shrink_ratio: DEFAULT_ACCOUNTS_SHRINK_THRESHOLD_OPTION,
read_cache_limit_bytes: None,
write_cache_limit_bytes: None,
ancient_append_vec_offset: None,
Expand Down Expand Up @@ -624,10 +628,12 @@ const ANCIENT_APPEND_VEC_DEFAULT_OFFSET: Option<i64> = Some(100_000);
#[derive(Debug, Default, Clone)]
pub struct AccountsDbConfig {
pub index: Option<AccountsIndexConfig>,
pub account_indexes: Option<AccountSecondaryIndexes>,
/// Base directory for various necessary files
pub base_working_path: Option<PathBuf>,
pub accounts_hash_cache_path: Option<PathBuf>,
pub shrink_paths: Option<Vec<PathBuf>>,
pub shrink_ratio: AccountShrinkThreshold,
/// The low and high watermark sizes for the read cache, in bytes.
/// If None, defaults will be used.
pub read_cache_limit_bytes: Option<(usize, usize)>,
Expand Down Expand Up @@ -1839,8 +1845,6 @@ impl AccountsDb {
) -> Self {
let mut db = AccountsDb::new_with_config(
paths,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Arc::default(),
Expand All @@ -1851,8 +1855,6 @@ impl AccountsDb {

pub fn new_with_config(
paths: Vec<PathBuf>,
account_indexes: AccountSecondaryIndexes,
shrink_ratio: AccountShrinkThreshold,
accounts_db_config: Option<AccountsDbConfig>,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
exit: Arc<AtomicBool>,
Expand Down Expand Up @@ -1943,8 +1945,8 @@ impl AccountsDb {
ancient_append_vec_offset: accounts_db_config
.ancient_append_vec_offset
.or(ANCIENT_APPEND_VEC_DEFAULT_OFFSET),
account_indexes,
shrink_ratio,
account_indexes: accounts_db_config.account_indexes.unwrap_or_default(),
shrink_ratio: accounts_db_config.shrink_ratio,
accounts_update_notifier,
create_ancient_storage: accounts_db_config.create_ancient_storage,
read_only_accounts_cache: ReadOnlyAccountsCache::new(
Expand Down Expand Up @@ -15741,8 +15743,6 @@ pub mod tests {
] {
let db = AccountsDb::new_with_config(
Vec::new(),
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
Some(AccountsDbConfig {
ancient_append_vec_offset: Some(ancient_append_vec_offset as i64),
..ACCOUNTS_DB_CONFIG_FOR_TESTING
Expand Down Expand Up @@ -15774,8 +15774,6 @@ pub mod tests {
let ancient_append_vec_offset = 50_000;
let db = AccountsDb::new_with_config(
Vec::new(),
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
Some(AccountsDbConfig {
ancient_append_vec_offset: Some(ancient_append_vec_offset),
..ACCOUNTS_DB_CONFIG_FOR_TESTING
Expand Down Expand Up @@ -15828,8 +15826,6 @@ pub mod tests {
for starting_slot_offset in [0, avoid_saturation] {
let db = AccountsDb::new_with_config(
Vec::new(),
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
Some(AccountsDbConfig {
ancient_append_vec_offset: Some(ancient_append_vec_offset),
..ACCOUNTS_DB_CONFIG_FOR_TESTING
Expand Down
10 changes: 2 additions & 8 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ use {
lazy_static::lazy_static,
quinn::Endpoint,
solana_accounts_db::{
accounts_db::{AccountShrinkThreshold, AccountsDbConfig},
accounts_index::AccountSecondaryIndexes,
accounts_db::{AccountsDbConfig, ACCOUNTS_DB_CONFIG_FOR_TESTING},
accounts_update_notifier_interface::AccountsUpdateNotifier,
hardened_unpack::{
open_genesis_config, OpenGenesisConfigError, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
Expand Down Expand Up @@ -261,7 +260,6 @@ pub struct ValidatorConfig {
pub poh_pinned_cpu_core: usize,
pub poh_hashes_per_batch: u64,
pub process_ledger_before_services: bool,
pub account_indexes: AccountSecondaryIndexes,
pub accounts_db_config: Option<AccountsDbConfig>,
pub warp_slot: Option<Slot>,
pub accounts_db_test_hash_calculation: bool,
Expand All @@ -271,7 +269,6 @@ pub struct ValidatorConfig {
pub staked_nodes_overrides: Arc<RwLock<HashMap<Pubkey, u64>>>,
pub validator_exit: Arc<RwLock<Exit>>,
pub no_wait_for_vote_to_start_leader: bool,
pub accounts_shrink_ratio: AccountShrinkThreshold,
pub wait_to_vote_slot: Option<Slot>,
pub ledger_column_options: LedgerColumnOptions,
pub runtime_config: RuntimeConfig,
Expand Down Expand Up @@ -335,7 +332,6 @@ impl Default for ValidatorConfig {
poh_pinned_cpu_core: poh_service::DEFAULT_PINNED_CPU_CORE,
poh_hashes_per_batch: poh_service::DEFAULT_HASHES_PER_BATCH,
process_ledger_before_services: false,
account_indexes: AccountSecondaryIndexes::default(),
warp_slot: None,
accounts_db_test_hash_calculation: false,
accounts_db_skip_shrink: false,
Expand All @@ -344,7 +340,6 @@ impl Default for ValidatorConfig {
staked_nodes_overrides: Arc::new(RwLock::new(HashMap::new())),
validator_exit: Arc::new(RwLock::new(Exit::default())),
no_wait_for_vote_to_start_leader: true,
accounts_shrink_ratio: AccountShrinkThreshold::default(),
accounts_db_config: None,
wait_to_vote_slot: None,
ledger_column_options: LedgerColumnOptions::default(),
Expand All @@ -371,6 +366,7 @@ impl ValidatorConfig {
pub fn default_for_test() -> Self {
Self {
enforce_ulimit_nofile: false,
accounts_db_config: Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
rpc_config: JsonRpcConfig::default_for_test(),
block_production_method: BlockProductionMethod::default(),
enable_block_production_forwarding: true, // enable forwarding by default for tests
Expand Down Expand Up @@ -1943,9 +1939,7 @@ fn load_blockstore(
halt_at_slot,
new_hard_forks: config.new_hard_forks.clone(),
debug_keys: config.debug_keys.clone(),
account_indexes: config.account_indexes.clone(),
accounts_db_config: config.accounts_db_config.clone(),
shrink_ratio: config.accounts_shrink_ratio,
accounts_db_test_hash_calculation: config.accounts_db_test_hash_calculation,
accounts_db_skip_shrink: config.accounts_db_skip_shrink,
accounts_db_force_initial_clean: config.accounts_db_force_initial_clean,
Expand Down
6 changes: 1 addition & 5 deletions core/tests/epoch_accounts_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use {
crate::snapshot_utils::create_tmp_accounts_dir_for_tests,
log::*,
solana_accounts_db::{
accounts_db::{AccountShrinkThreshold, CalcAccountsHashDataSource},
accounts_hash::CalcAccountsHashConfig,
accounts_index::AccountSecondaryIndexes,
accounts_db::CalcAccountsHashDataSource, accounts_hash::CalcAccountsHashConfig,
epoch_accounts_hash::EpochAccountsHash,
},
solana_core::{
Expand Down Expand Up @@ -456,9 +454,7 @@ fn test_snapshots_have_expected_epoch_accounts_hash() {
&RuntimeConfig::default(),
None,
None,
AccountSecondaryIndexes::default(),
None,
AccountShrinkThreshold::default(),
true,
true,
false,
Expand Down
14 changes: 3 additions & 11 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use {
itertools::Itertools,
log::{info, trace},
solana_accounts_db::{
accounts_db::{self, AccountsDbConfig, ACCOUNTS_DB_CONFIG_FOR_TESTING},
accounts_index::AccountSecondaryIndexes,
accounts_db::{AccountsDbConfig, ACCOUNTS_DB_CONFIG_FOR_TESTING},
epoch_accounts_hash::EpochAccountsHash,
},
solana_core::{
Expand All @@ -20,7 +19,7 @@ use {
AbsRequestHandlers, AbsRequestSender, AccountsBackgroundService,
PrunedBanksRequestHandler, SendDroppedBankCallback, SnapshotRequestHandler,
},
bank::Bank,
bank::{Bank, BankTestConfig},
bank_forks::BankForks,
genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo},
runtime_config::RuntimeConfig,
Expand Down Expand Up @@ -96,9 +95,8 @@ impl SnapshotTestConfig {
let bank0 = Bank::new_with_paths_for_tests(
&genesis_config_info.genesis_config,
Arc::<RuntimeConfig>::default(),
BankTestConfig::default(),
vec![accounts_dir.clone()],
AccountSecondaryIndexes::default(),
accounts_db::AccountShrinkThreshold::default(),
);
bank0.freeze();
bank0.set_startup_verification_complete();
Expand Down Expand Up @@ -160,9 +158,7 @@ fn restore_from_snapshot(
&RuntimeConfig::default(),
None,
None,
AccountSecondaryIndexes::default(),
None,
accounts_db::AccountShrinkThreshold::default(),
check_hash_calculation,
false,
false,
Expand Down Expand Up @@ -611,9 +607,7 @@ fn restore_from_snapshots_and_check_banks_are_equal(
&RuntimeConfig::default(),
None,
None,
AccountSecondaryIndexes::default(),
None,
accounts_db::AccountShrinkThreshold::default(),
false,
false,
false,
Expand Down Expand Up @@ -846,9 +840,7 @@ fn test_snapshots_with_background_services(
&RuntimeConfig::default(),
None,
None,
AccountSecondaryIndexes::default(),
None,
accounts_db::AccountShrinkThreshold::default(),
false,
false,
false,
Expand Down
4 changes: 0 additions & 4 deletions ledger/src/bank_forks_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,7 @@ fn bank_forks_from_snapshot(
&process_options.runtime_config,
process_options.debug_keys.clone(),
None,
process_options.account_indexes.clone(),
process_options.limit_load_slot_count_from_snapshot,
process_options.shrink_ratio,
process_options.verify_index,
process_options.accounts_db_config.clone(),
accounts_update_notifier,
Expand All @@ -314,9 +312,7 @@ fn bank_forks_from_snapshot(
&process_options.runtime_config,
process_options.debug_keys.clone(),
None,
process_options.account_indexes.clone(),
process_options.limit_load_slot_count_from_snapshot,
process_options.shrink_ratio,
process_options.accounts_db_test_hash_calculation,
process_options.accounts_db_skip_shrink,
process_options.accounts_db_force_initial_clean,
Expand Down
Loading

0 comments on commit 5de9be0

Please sign in to comment.