diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 9369e5ec1b..4653510ff6 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -161,6 +161,14 @@ pub enum CreateAncientStorage { Pack, } +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +enum StoreTo { + /// write to cache + Cache, + /// write to storage + Storage, +} + #[derive(Default)] /// hold alive accounts and bytes used by those accounts /// alive means in the accounts index @@ -6575,7 +6583,7 @@ impl AccountsDb { hashes: Option>>, storage_finder: F, mut write_version_producer: P, - is_cached_store: bool, + store_to: StoreTo, txn_signatures: Option<&[Option<&'a Signature>]>, ) -> Vec { let mut calc_stored_meta_time = Measure::start("calc_stored_meta"); @@ -6589,7 +6597,7 @@ impl AccountsDb { .calc_stored_meta .fetch_add(calc_stored_meta_time.as_us(), Ordering::Relaxed); - if is_cached_store { + if store_to == StoreTo::Cache { let signature_iter: Box>> = match txn_signatures { Some(txn_signatures) => { @@ -8163,7 +8171,12 @@ impl AccountsDb { accounts: impl StorableAccounts<'a, T>, txn_signatures: Option<&'a [Option<&'a Signature>]>, ) { - self.store(accounts, true, txn_signatures, StoreReclaims::Default); + self.store( + accounts, + StoreTo::Cache, + txn_signatures, + StoreReclaims::Default, + ); } /// Store the account update. @@ -8171,7 +8184,7 @@ impl AccountsDb { pub fn store_uncached(&self, slot: Slot, accounts: &[(&Pubkey, &AccountSharedData)]) { self.store( (slot, accounts, INCLUDE_SLOT_IN_HASH_TESTS), - false, + StoreTo::Storage, None, StoreReclaims::Default, ); @@ -8180,7 +8193,7 @@ impl AccountsDb { fn store<'a, T: ReadableAccount + Sync + ZeroLamport + 'a>( &self, accounts: impl StorableAccounts<'a, T>, - is_cached_store: bool, + store_to: StoreTo, txn_signatures: Option<&'a [Option<&'a Signature>]>, reclaim: StoreReclaims, ) { @@ -8216,7 +8229,7 @@ impl AccountsDb { self.store_accounts_unfrozen( accounts, None::>, - is_cached_store, + store_to, txn_signatures, reclaim, ); @@ -8350,7 +8363,7 @@ impl AccountsDb { &self, accounts: impl StorableAccounts<'a, T>, hashes: Option>>, - is_cached_store: bool, + store_to: StoreTo, txn_signatures: Option<&'a [Option<&'a Signature>]>, reclaim: StoreReclaims, ) { @@ -8367,7 +8380,7 @@ impl AccountsDb { hashes, None, None::>>, - is_cached_store, + store_to, reset_accounts, txn_signatures, reclaim, @@ -8386,13 +8399,12 @@ impl AccountsDb { // the append vec so that hashing could happen on the store // and accounts in the append_vec can be unrefed correctly let reset_accounts = false; - let is_cached_store = false; self.store_accounts_custom( accounts, hashes, storage, write_version_producer, - is_cached_store, + StoreTo::Storage, reset_accounts, None, reclaim, @@ -8405,7 +8417,7 @@ impl AccountsDb { hashes: Option>>, storage: Option<&Arc>, write_version_producer: Option>>, - is_cached_store: bool, + store_to: StoreTo, reset_accounts: bool, txn_signatures: Option<&[Option<&Signature>]>, reclaim: StoreReclaims, @@ -8435,7 +8447,7 @@ impl AccountsDb { hashes, storage_finder, write_version_producer, - is_cached_store, + store_to, txn_signatures, ); store_accounts_time.stop(); @@ -8446,7 +8458,7 @@ impl AccountsDb { let reclaim = if matches!(reclaim, StoreReclaims::Ignore) { UpsertReclaim::IgnoreReclaims - } else if is_cached_store { + } else if store_to == StoreTo::Cache { UpsertReclaim::PreviousSlotEntryWasCached } else { UpsertReclaim::PopulateReclaims @@ -8469,7 +8481,7 @@ impl AccountsDb { // entries reclaims.retain(|(_, r)| !r.is_cached()); - if is_cached_store { + if store_to == StoreTo::Cache { assert!(reclaims.is_empty()); } @@ -12377,7 +12389,7 @@ pub mod tests { db.store_accounts_unfrozen( (some_slot, &[(&key, &account)][..]), Some(vec![&Hash::default()]), - false, + StoreTo::Storage, None, StoreReclaims::Default, ); @@ -12645,7 +12657,7 @@ pub mod tests { db.store_accounts_unfrozen( (some_slot, accounts), Some(vec![&some_hash]), - false, + StoreTo::Storage, None, StoreReclaims::Default, ); @@ -16066,7 +16078,7 @@ pub mod tests { pub fn store_for_tests(&self, slot: Slot, accounts: &[(&Pubkey, &AccountSharedData)]) { self.store( (slot, accounts, INCLUDE_SLOT_IN_HASH_TESTS), - true, + StoreTo::Cache, None, StoreReclaims::Default, );