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

Commit 877feda

Browse files
authored
Remove StatusCacheRc type and use StatusCache directly (#26184)
1 parent 4a729ef commit 877feda

File tree

5 files changed

+27
-46
lines changed

5 files changed

+27
-46
lines changed

core/tests/snapshots.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,7 @@ mod tests {
281281
let last_bank_snapshot_info =
282282
snapshot_utils::get_highest_bank_snapshot_pre(bank_snapshots_dir)
283283
.expect("no bank snapshots found in path");
284-
let slot_deltas = last_bank
285-
.src
286-
.status_cache
287-
.read()
288-
.unwrap()
289-
.root_slot_deltas();
284+
let slot_deltas = last_bank.status_cache.read().unwrap().root_slot_deltas();
290285
let accounts_package = AccountsPackage::new(
291286
&last_bank,
292287
&last_bank_snapshot_info,
@@ -631,7 +626,6 @@ mod tests {
631626
.bank_forks
632627
.get(snapshot_test_config.bank_forks.root())
633628
.unwrap()
634-
.src
635629
.status_cache
636630
.read()
637631
.unwrap()

runtime/src/bank.rs

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,6 @@ impl BankRc {
591591
}
592592
}
593593

594-
#[derive(Default, Debug, AbiExample)]
595-
pub struct StatusCacheRc {
596-
/// where all the Accounts are stored
597-
/// A cache of signature statuses
598-
pub status_cache: Arc<RwLock<BankStatusCache>>,
599-
}
600-
601594
pub type TransactionCheckResult = (Result<()>, Option<NoncePartial>);
602595

603596
pub struct TransactionResults {
@@ -1020,7 +1013,7 @@ impl PartialEq for Bank {
10201013
}
10211014
let Self {
10221015
rc: _,
1023-
src: _,
1016+
status_cache: _,
10241017
blockhash_queue,
10251018
ancestors,
10261019
hash,
@@ -1190,7 +1183,8 @@ pub struct Bank {
11901183
/// References to accounts, parent and signature status
11911184
pub rc: BankRc,
11921185

1193-
pub src: StatusCacheRc,
1186+
/// A cache of signature statuses
1187+
pub status_cache: Arc<RwLock<BankStatusCache>>,
11941188

11951189
/// FIFO queue of `recent_blockhash` items
11961190
blockhash_queue: RwLock<BlockhashQueue>,
@@ -1489,7 +1483,7 @@ impl Bank {
14891483
let mut bank = Self {
14901484
rewrites_skipped_this_slot: Rewrites::default(),
14911485
rc: BankRc::new(accounts, Slot::default()),
1492-
src: StatusCacheRc::default(),
1486+
status_cache: Arc::<RwLock<BankStatusCache>>::default(),
14931487
blockhash_queue: RwLock::<BlockhashQueue>::default(),
14941488
ancestors: Ancestors::default(),
14951489
hash: RwLock::<Hash>::default(),
@@ -1724,12 +1718,8 @@ impl Bank {
17241718
"bank_rc_creation",
17251719
);
17261720

1727-
let (src, status_cache_rc_time) = measure!(
1728-
StatusCacheRc {
1729-
status_cache: parent.src.status_cache.clone(),
1730-
},
1731-
"status_cache_rc_creation",
1732-
);
1721+
let (status_cache, status_cache_time) =
1722+
measure!(Arc::clone(&parent.status_cache), "status_cache_creation",);
17331723

17341724
let ((fee_rate_governor, fee_calculator), fee_components_time) = measure!(
17351725
{
@@ -1799,7 +1789,7 @@ impl Bank {
17991789
let mut new = Bank {
18001790
rewrites_skipped_this_slot: Rewrites::default(),
18011791
rc,
1802-
src,
1792+
status_cache,
18031793
slot,
18041794
bank_id,
18051795
epoch,
@@ -2027,7 +2017,7 @@ impl Bank {
20272017
("parent_slot", parent.slot(), i64),
20282018
("bank_rc_creation_us", bank_rc_time.as_us(), i64),
20292019
("total_elapsed_us", time.as_us(), i64),
2030-
("status_cache_rc_us", status_cache_rc_time.as_us(), i64),
2020+
("status_cache_us", status_cache_time.as_us(), i64),
20312021
("fee_components_us", fee_components_time.as_us(), i64),
20322022
("blockhash_queue_us", blockhash_queue_time.as_us(), i64),
20332023
("stakes_cache_us", stakes_cache_time.as_us(), i64),
@@ -2155,7 +2145,7 @@ impl Bank {
21552145
let mut bank = Self {
21562146
rewrites_skipped_this_slot: Rewrites::default(),
21572147
rc: bank_rc,
2158-
src: new(),
2148+
status_cache: new(),
21592149
blockhash_queue: RwLock::new(fields.blockhash_queue),
21602150
ancestors,
21612151
hash: RwLock::new(fields.hash),
@@ -2356,7 +2346,7 @@ impl Bank {
23562346
}
23572347

23582348
pub fn status_cache_ancestors(&self) -> Vec<u64> {
2359-
let mut roots = self.src.status_cache.read().unwrap().roots().clone();
2349+
let mut roots = self.status_cache.read().unwrap().roots().clone();
23602350
let min = roots.iter().min().cloned().unwrap_or(0);
23612351
for ancestor in self.ancestors.keys() {
23622352
if ancestor >= min {
@@ -3450,7 +3440,7 @@ impl Bank {
34503440
let mut squash_cache_time = Measure::start("squash_cache_time");
34513441
roots
34523442
.iter()
3453-
.for_each(|slot| self.src.status_cache.write().unwrap().add_root(*slot));
3443+
.for_each(|slot| self.status_cache.write().unwrap().add_root(*slot));
34543444
squash_cache_time.stop();
34553445

34563446
SquashTiming {
@@ -3757,23 +3747,19 @@ impl Bank {
37573747

37583748
/// Forget all signatures. Useful for benchmarking.
37593749
pub fn clear_signatures(&self) {
3760-
self.src.status_cache.write().unwrap().clear();
3750+
self.status_cache.write().unwrap().clear();
37613751
}
37623752

37633753
pub fn clear_slot_signatures(&self, slot: Slot) {
3764-
self.src
3765-
.status_cache
3766-
.write()
3767-
.unwrap()
3768-
.clear_slot_entries(slot);
3754+
self.status_cache.write().unwrap().clear_slot_entries(slot);
37693755
}
37703756

37713757
fn update_transaction_statuses(
37723758
&self,
37733759
sanitized_txs: &[SanitizedTransaction],
37743760
execution_results: &[TransactionExecutionResult],
37753761
) {
3776-
let mut status_cache = self.src.status_cache.write().unwrap();
3762+
let mut status_cache = self.status_cache.write().unwrap();
37773763
assert_eq!(sanitized_txs.len(), execution_results.len());
37783764
for (tx, execution_result) in sanitized_txs.iter().zip(execution_results) {
37793765
if let Some(details) = execution_result.details() {
@@ -4113,7 +4099,7 @@ impl Bank {
41134099
lock_results: Vec<TransactionCheckResult>,
41144100
error_counters: &mut TransactionErrorMetrics,
41154101
) -> Vec<TransactionCheckResult> {
4116-
let rcache = self.src.status_cache.read().unwrap();
4102+
let rcache = self.status_cache.read().unwrap();
41174103
sanitized_txs
41184104
.iter()
41194105
.zip(lock_results)
@@ -6648,14 +6634,14 @@ impl Bank {
66486634
signature: &Signature,
66496635
blockhash: &Hash,
66506636
) -> Option<Result<()>> {
6651-
let rcache = self.src.status_cache.read().unwrap();
6637+
let rcache = self.status_cache.read().unwrap();
66526638
rcache
66536639
.get_status(signature, blockhash, &self.ancestors)
66546640
.map(|v| v.1)
66556641
}
66566642

66576643
pub fn get_signature_status_slot(&self, signature: &Signature) -> Option<(Slot, Result<()>)> {
6658-
let rcache = self.src.status_cache.read().unwrap();
6644+
let rcache = self.status_cache.read().unwrap();
66596645
rcache.get_status_any_blockhash(signature, &self.ancestors)
66606646
}
66616647

runtime/src/bank_forks.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ impl BankForks {
281281
// Save off the status cache because these may get pruned if another
282282
// `set_root()` is called before the snapshots package can be generated
283283
let status_cache_slot_deltas = snapshot_root_bank
284-
.src
285284
.status_cache
286285
.read()
287286
.unwrap()

runtime/src/serde_snapshot/tests.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use {
44
crate::{
55
accounts::{test_utils::create_test_accounts, Accounts},
66
accounts_db::{get_temp_accounts_paths, AccountShrinkThreshold},
7-
bank::{Bank, Rewrites, StatusCacheRc},
7+
bank::{Bank, Rewrites},
88
genesis_utils::{activate_all_features, activate_feature},
99
hardened_unpack::UnpackedAppendVecMap,
1010
snapshot_utils::ArchiveFormat,
11+
status_cache::StatusCache,
1112
},
1213
bincode::serialize_into,
1314
rand::{thread_rng, Rng},
@@ -22,6 +23,7 @@ use {
2223
std::{
2324
io::{BufReader, Cursor},
2425
path::Path,
26+
sync::{Arc, RwLock},
2527
},
2628
tempfile::TempDir,
2729
};
@@ -276,8 +278,8 @@ fn test_bank_serialize_style(
276278

277279
// Create a new set of directories for this bank's accounts
278280
let (_accounts_dir, dbank_paths) = get_temp_accounts_paths(4).unwrap();
279-
let ref_sc = StatusCacheRc::default();
280-
ref_sc.status_cache.write().unwrap().add_root(2);
281+
let mut status_cache = StatusCache::default();
282+
status_cache.add_root(2);
281283
// Create a directory to simulate AppendVecs unpackaged from a snapshot tar
282284
let copied_accounts = TempDir::new().unwrap();
283285
let unpacked_append_vec_map =
@@ -304,7 +306,7 @@ fn test_bank_serialize_style(
304306
false,
305307
)
306308
.unwrap();
307-
dbank.src = ref_sc;
309+
dbank.status_cache = Arc::new(RwLock::new(status_cache));
308310
assert_eq!(dbank.get_balance(&key1.pubkey()), 0);
309311
assert_eq!(dbank.get_balance(&key2.pubkey()), 10);
310312
assert_eq!(dbank.get_balance(&key3.pubkey()), 0);

runtime/src/snapshot_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ fn rebuild_bank_from_snapshots(
16631663
Ok(slot_deltas)
16641664
})?;
16651665

1666-
bank.src.status_cache.write().unwrap().append(&slot_deltas);
1666+
bank.status_cache.write().unwrap().append(&slot_deltas);
16671667

16681668
bank.prepare_rewrites_for_hash();
16691669

@@ -1949,7 +1949,7 @@ pub fn package_and_archive_full_snapshot(
19491949
maximum_full_snapshot_archives_to_retain: usize,
19501950
maximum_incremental_snapshot_archives_to_retain: usize,
19511951
) -> Result<FullSnapshotArchiveInfo> {
1952-
let slot_deltas = bank.src.status_cache.read().unwrap().root_slot_deltas();
1952+
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
19531953
let accounts_package = AccountsPackage::new(
19541954
bank,
19551955
bank_snapshot_info,
@@ -1999,7 +1999,7 @@ pub fn package_and_archive_incremental_snapshot(
19991999
maximum_full_snapshot_archives_to_retain: usize,
20002000
maximum_incremental_snapshot_archives_to_retain: usize,
20012001
) -> Result<IncrementalSnapshotArchiveInfo> {
2002-
let slot_deltas = bank.src.status_cache.read().unwrap().root_slot_deltas();
2002+
let slot_deltas = bank.status_cache.read().unwrap().root_slot_deltas();
20032003
let accounts_package = AccountsPackage::new(
20042004
bank,
20052005
bank_snapshot_info,

0 commit comments

Comments
 (0)