Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove StatusCacheRc and use StatusCache directly #26184

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -631,7 +626,6 @@ mod tests {
.bank_forks
.get(snapshot_test_config.bank_forks.root())
.unwrap()
.src
.status_cache
.read()
.unwrap()
Expand Down
48 changes: 17 additions & 31 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RwLock<BankStatusCache>>,
}

pub type TransactionCheckResult = (Result<()>, Option<NoncePartial>);

pub struct TransactionResults {
Expand Down Expand Up @@ -1020,7 +1013,7 @@ impl PartialEq for Bank {
}
let Self {
rc: _,
src: _,
status_cache: _,
blockhash_queue,
ancestors,
hash,
Expand Down Expand Up @@ -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<RwLock<BankStatusCache>>,

/// FIFO queue of `recent_blockhash` items
blockhash_queue: RwLock<BlockhashQueue>,
Expand Down Expand Up @@ -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::<RwLock<BankStatusCache>>::default(),
blockhash_queue: RwLock::<BlockhashQueue>::default(),
ancestors: Ancestors::default(),
hash: RwLock::<Hash>::default(),
Expand Down Expand Up @@ -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!(
{
Expand Down Expand Up @@ -1799,7 +1789,7 @@ impl Bank {
let mut new = Bank {
rewrites_skipped_this_slot: Rewrites::default(),
rc,
src,
status_cache,
slot,
bank_id,
epoch,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -2356,7 +2346,7 @@ impl Bank {
}

pub fn status_cache_ancestors(&self) -> Vec<u64> {
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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -3757,23 +3747,19 @@ 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(
&self,
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() {
Expand Down Expand Up @@ -4113,7 +4099,7 @@ impl Bank {
lock_results: Vec<TransactionCheckResult>,
error_counters: &mut TransactionErrorMetrics,
) -> Vec<TransactionCheckResult> {
let rcache = self.src.status_cache.read().unwrap();
let rcache = self.status_cache.read().unwrap();
sanitized_txs
.iter()
.zip(lock_results)
Expand Down Expand Up @@ -6647,14 +6633,14 @@ impl Bank {
signature: &Signature,
blockhash: &Hash,
) -> Option<Result<()>> {
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)
}

Expand Down
1 change: 0 additions & 1 deletion runtime/src/bank_forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 6 additions & 4 deletions runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -22,6 +23,7 @@ use {
std::{
io::{BufReader, Cursor},
path::Path,
sync::{Arc, RwLock},
},
tempfile::TempDir,
};
Expand Down Expand Up @@ -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 =
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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<FullSnapshotArchiveInfo> {
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,
Expand Down Expand Up @@ -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<IncrementalSnapshotArchiveInfo> {
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,
Expand Down