Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 992db24

Browse files
committed
Refactors Accounts::new() fns
1 parent eb6d6e9 commit 992db24

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

runtime/src/accounts.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ pub enum AccountAddressFilter {
142142

143143
impl Accounts {
144144
pub fn default_for_tests() -> Self {
145-
Self {
146-
accounts_db: Arc::new(AccountsDb::default_for_tests()),
147-
account_locks: Mutex::default(),
148-
}
145+
Self::new_empty(AccountsDb::default_for_tests())
149146
}
150147

151148
pub fn new_with_config_for_tests(
@@ -191,32 +188,30 @@ impl Accounts {
191188
accounts_update_notifier: Option<AccountsUpdateNotifier>,
192189
exit: &Arc<AtomicBool>,
193190
) -> Self {
194-
Self {
195-
accounts_db: Arc::new(AccountsDb::new_with_config(
196-
paths,
197-
cluster_type,
198-
account_indexes,
199-
shrink_ratio,
200-
accounts_db_config,
201-
accounts_update_notifier,
202-
exit,
203-
)),
204-
account_locks: Mutex::new(AccountLocks::default()),
205-
}
191+
Self::new_empty(AccountsDb::new_with_config(
192+
paths,
193+
cluster_type,
194+
account_indexes,
195+
shrink_ratio,
196+
accounts_db_config,
197+
accounts_update_notifier,
198+
exit,
199+
))
206200
}
207201

208202
pub fn new_from_parent(parent: &Accounts, slot: Slot, parent_slot: Slot) -> Self {
209203
let accounts_db = parent.accounts_db.clone();
210204
accounts_db.insert_default_bank_hash_stats(slot, parent_slot);
211-
Self {
212-
accounts_db,
213-
account_locks: Mutex::new(AccountLocks::default()),
214-
}
205+
Self::new(accounts_db)
215206
}
216207

217208
pub(crate) fn new_empty(accounts_db: AccountsDb) -> Self {
209+
Self::new(Arc::new(accounts_db))
210+
}
211+
212+
fn new(accounts_db: Arc<AccountsDb>) -> Self {
218213
Self {
219-
accounts_db: Arc::new(accounts_db),
214+
accounts_db,
220215
account_locks: Mutex::new(AccountLocks::default()),
221216
}
222217
}

0 commit comments

Comments
 (0)