From 877fedadac6c868acbd2a4500253ab116ff78cb5 Mon Sep 17 00:00:00 2001 From: Brooks Prumo Date: Fri, 24 Jun 2022 08:38:56 -0500 Subject: [PATCH] Remove StatusCacheRc type and use StatusCache directly (#26184) --- core/tests/snapshots.rs | 8 +---- runtime/src/bank.rs | 48 ++++++++++------------------- runtime/src/bank_forks.rs | 1 - runtime/src/serde_snapshot/tests.rs | 10 +++--- runtime/src/snapshot_utils.rs | 6 ++-- 5 files changed, 27 insertions(+), 46 deletions(-) diff --git a/core/tests/snapshots.rs b/core/tests/snapshots.rs index 174ee22ed6..d6b65214c5 100644 --- a/core/tests/snapshots.rs +++ b/core/tests/snapshots.rs @@ -281,12 +281,7 @@ mod tests { let last_bank_snapshot_info = snapshot_utils::get_highest_bank_snapshot_pre(bank_snapshots_dir) .expect("no bank snapshots found in path"); - let slot_deltas = last_bank - .src - .status_cache - .read() - .unwrap() - .root_slot_deltas(); + let slot_deltas = last_bank.status_cache.read().unwrap().root_slot_deltas(); let accounts_package = AccountsPackage::new( &last_bank, &last_bank_snapshot_info, @@ -631,7 +626,6 @@ mod tests { .bank_forks .get(snapshot_test_config.bank_forks.root()) .unwrap() - .src .status_cache .read() .unwrap() diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 767ed45fdc..9a5f0c79da 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -591,13 +591,6 @@ impl BankRc { } } -#[derive(Default, Debug, AbiExample)] -pub struct StatusCacheRc { - /// where all the Accounts are stored - /// A cache of signature statuses - pub status_cache: Arc>, -} - pub type TransactionCheckResult = (Result<()>, Option); pub struct TransactionResults { @@ -1020,7 +1013,7 @@ impl PartialEq for Bank { } let Self { rc: _, - src: _, + status_cache: _, blockhash_queue, ancestors, hash, @@ -1190,7 +1183,8 @@ pub struct Bank { /// References to accounts, parent and signature status pub rc: BankRc, - pub src: StatusCacheRc, + /// A cache of signature statuses + pub status_cache: Arc>, /// FIFO queue of `recent_blockhash` items blockhash_queue: RwLock, @@ -1489,7 +1483,7 @@ impl Bank { let mut bank = Self { rewrites_skipped_this_slot: Rewrites::default(), rc: BankRc::new(accounts, Slot::default()), - src: StatusCacheRc::default(), + status_cache: Arc::>::default(), blockhash_queue: RwLock::::default(), ancestors: Ancestors::default(), hash: RwLock::::default(), @@ -1724,12 +1718,8 @@ impl Bank { "bank_rc_creation", ); - let (src, status_cache_rc_time) = measure!( - StatusCacheRc { - status_cache: parent.src.status_cache.clone(), - }, - "status_cache_rc_creation", - ); + let (status_cache, status_cache_time) = + measure!(Arc::clone(&parent.status_cache), "status_cache_creation",); let ((fee_rate_governor, fee_calculator), fee_components_time) = measure!( { @@ -1799,7 +1789,7 @@ impl Bank { let mut new = Bank { rewrites_skipped_this_slot: Rewrites::default(), rc, - src, + status_cache, slot, bank_id, epoch, @@ -2027,7 +2017,7 @@ impl Bank { ("parent_slot", parent.slot(), i64), ("bank_rc_creation_us", bank_rc_time.as_us(), i64), ("total_elapsed_us", time.as_us(), i64), - ("status_cache_rc_us", status_cache_rc_time.as_us(), i64), + ("status_cache_us", status_cache_time.as_us(), i64), ("fee_components_us", fee_components_time.as_us(), i64), ("blockhash_queue_us", blockhash_queue_time.as_us(), i64), ("stakes_cache_us", stakes_cache_time.as_us(), i64), @@ -2155,7 +2145,7 @@ impl Bank { let mut bank = Self { rewrites_skipped_this_slot: Rewrites::default(), rc: bank_rc, - src: new(), + status_cache: new(), blockhash_queue: RwLock::new(fields.blockhash_queue), ancestors, hash: RwLock::new(fields.hash), @@ -2356,7 +2346,7 @@ impl Bank { } pub fn status_cache_ancestors(&self) -> Vec { - let mut roots = self.src.status_cache.read().unwrap().roots().clone(); + let mut roots = self.status_cache.read().unwrap().roots().clone(); let min = roots.iter().min().cloned().unwrap_or(0); for ancestor in self.ancestors.keys() { if ancestor >= min { @@ -3450,7 +3440,7 @@ impl Bank { let mut squash_cache_time = Measure::start("squash_cache_time"); roots .iter() - .for_each(|slot| self.src.status_cache.write().unwrap().add_root(*slot)); + .for_each(|slot| self.status_cache.write().unwrap().add_root(*slot)); squash_cache_time.stop(); SquashTiming { @@ -3757,15 +3747,11 @@ impl Bank { /// Forget all signatures. Useful for benchmarking. pub fn clear_signatures(&self) { - self.src.status_cache.write().unwrap().clear(); + self.status_cache.write().unwrap().clear(); } pub fn clear_slot_signatures(&self, slot: Slot) { - self.src - .status_cache - .write() - .unwrap() - .clear_slot_entries(slot); + self.status_cache.write().unwrap().clear_slot_entries(slot); } fn update_transaction_statuses( @@ -3773,7 +3759,7 @@ impl Bank { sanitized_txs: &[SanitizedTransaction], execution_results: &[TransactionExecutionResult], ) { - let mut status_cache = self.src.status_cache.write().unwrap(); + let mut status_cache = self.status_cache.write().unwrap(); assert_eq!(sanitized_txs.len(), execution_results.len()); for (tx, execution_result) in sanitized_txs.iter().zip(execution_results) { if let Some(details) = execution_result.details() { @@ -4113,7 +4099,7 @@ impl Bank { lock_results: Vec, error_counters: &mut TransactionErrorMetrics, ) -> Vec { - let rcache = self.src.status_cache.read().unwrap(); + let rcache = self.status_cache.read().unwrap(); sanitized_txs .iter() .zip(lock_results) @@ -6648,14 +6634,14 @@ impl Bank { signature: &Signature, blockhash: &Hash, ) -> Option> { - let rcache = self.src.status_cache.read().unwrap(); + let rcache = self.status_cache.read().unwrap(); rcache .get_status(signature, blockhash, &self.ancestors) .map(|v| v.1) } pub fn get_signature_status_slot(&self, signature: &Signature) -> Option<(Slot, Result<()>)> { - let rcache = self.src.status_cache.read().unwrap(); + let rcache = self.status_cache.read().unwrap(); rcache.get_status_any_blockhash(signature, &self.ancestors) } diff --git a/runtime/src/bank_forks.rs b/runtime/src/bank_forks.rs index b9640336e5..5f62bd385b 100644 --- a/runtime/src/bank_forks.rs +++ b/runtime/src/bank_forks.rs @@ -281,7 +281,6 @@ impl BankForks { // Save off the status cache because these may get pruned if another // `set_root()` is called before the snapshots package can be generated let status_cache_slot_deltas = snapshot_root_bank - .src .status_cache .read() .unwrap() diff --git a/runtime/src/serde_snapshot/tests.rs b/runtime/src/serde_snapshot/tests.rs index d638185fc1..ab80c166c3 100644 --- a/runtime/src/serde_snapshot/tests.rs +++ b/runtime/src/serde_snapshot/tests.rs @@ -4,10 +4,11 @@ use { crate::{ accounts::{test_utils::create_test_accounts, Accounts}, accounts_db::{get_temp_accounts_paths, AccountShrinkThreshold}, - bank::{Bank, Rewrites, StatusCacheRc}, + bank::{Bank, Rewrites}, genesis_utils::{activate_all_features, activate_feature}, hardened_unpack::UnpackedAppendVecMap, snapshot_utils::ArchiveFormat, + status_cache::StatusCache, }, bincode::serialize_into, rand::{thread_rng, Rng}, @@ -22,6 +23,7 @@ use { std::{ io::{BufReader, Cursor}, path::Path, + sync::{Arc, RwLock}, }, tempfile::TempDir, }; @@ -276,8 +278,8 @@ fn test_bank_serialize_style( // Create a new set of directories for this bank's accounts let (_accounts_dir, dbank_paths) = get_temp_accounts_paths(4).unwrap(); - let ref_sc = StatusCacheRc::default(); - ref_sc.status_cache.write().unwrap().add_root(2); + let mut status_cache = StatusCache::default(); + status_cache.add_root(2); // Create a directory to simulate AppendVecs unpackaged from a snapshot tar let copied_accounts = TempDir::new().unwrap(); let unpacked_append_vec_map = @@ -304,7 +306,7 @@ fn test_bank_serialize_style( false, ) .unwrap(); - dbank.src = ref_sc; + dbank.status_cache = Arc::new(RwLock::new(status_cache)); assert_eq!(dbank.get_balance(&key1.pubkey()), 0); assert_eq!(dbank.get_balance(&key2.pubkey()), 10); assert_eq!(dbank.get_balance(&key3.pubkey()), 0); diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index a0be8c334f..c0b1ce54bf 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -1663,7 +1663,7 @@ fn rebuild_bank_from_snapshots( Ok(slot_deltas) })?; - bank.src.status_cache.write().unwrap().append(&slot_deltas); + bank.status_cache.write().unwrap().append(&slot_deltas); bank.prepare_rewrites_for_hash(); @@ -1949,7 +1949,7 @@ pub fn package_and_archive_full_snapshot( maximum_full_snapshot_archives_to_retain: usize, maximum_incremental_snapshot_archives_to_retain: usize, ) -> Result { - let slot_deltas = bank.src.status_cache.read().unwrap().root_slot_deltas(); + let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas(); let accounts_package = AccountsPackage::new( bank, bank_snapshot_info, @@ -1999,7 +1999,7 @@ pub fn package_and_archive_incremental_snapshot( maximum_full_snapshot_archives_to_retain: usize, maximum_incremental_snapshot_archives_to_retain: usize, ) -> Result { - let slot_deltas = bank.src.status_cache.read().unwrap().root_slot_deltas(); + let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas(); let accounts_package = AccountsPackage::new( bank, bank_snapshot_info,