Refactors Accounts::new() fns (#30343)

This commit is contained in:
Brooks 2023-02-15 18:34:52 -05:00 committed by GitHub
parent ba43883cce
commit 5680c76c86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 21 deletions

View File

@ -142,10 +142,7 @@ pub enum AccountAddressFilter {
impl Accounts { impl Accounts {
pub fn default_for_tests() -> Self { pub fn default_for_tests() -> Self {
Self { Self::new_empty(AccountsDb::default_for_tests())
accounts_db: Arc::new(AccountsDb::default_for_tests()),
account_locks: Mutex::default(),
}
} }
pub fn new_with_config_for_tests( pub fn new_with_config_for_tests(
@ -191,8 +188,7 @@ impl Accounts {
accounts_update_notifier: Option<AccountsUpdateNotifier>, accounts_update_notifier: Option<AccountsUpdateNotifier>,
exit: &Arc<AtomicBool>, exit: &Arc<AtomicBool>,
) -> Self { ) -> Self {
Self { Self::new_empty(AccountsDb::new_with_config(
accounts_db: Arc::new(AccountsDb::new_with_config(
paths, paths,
cluster_type, cluster_type,
account_indexes, account_indexes,
@ -200,23 +196,22 @@ impl Accounts {
accounts_db_config, accounts_db_config,
accounts_update_notifier, accounts_update_notifier,
exit, exit,
)), ))
account_locks: Mutex::new(AccountLocks::default()),
}
} }
pub fn new_from_parent(parent: &Accounts, slot: Slot, parent_slot: Slot) -> Self { pub fn new_from_parent(parent: &Accounts, slot: Slot, parent_slot: Slot) -> Self {
let accounts_db = parent.accounts_db.clone(); let accounts_db = parent.accounts_db.clone();
accounts_db.insert_default_bank_hash_stats(slot, parent_slot); accounts_db.insert_default_bank_hash_stats(slot, parent_slot);
Self { Self::new(accounts_db)
accounts_db,
account_locks: Mutex::new(AccountLocks::default()),
}
} }
pub(crate) fn new_empty(accounts_db: AccountsDb) -> Self { pub(crate) fn new_empty(accounts_db: AccountsDb) -> Self {
Self::new(Arc::new(accounts_db))
}
fn new(accounts_db: Arc<AccountsDb>) -> Self {
Self { Self {
accounts_db: Arc::new(accounts_db), accounts_db,
account_locks: Mutex::new(AccountLocks::default()), account_locks: Mutex::new(AccountLocks::default()),
} }
} }