Remove StatusCacheRc type and use StatusCache directly (#26184)
This commit is contained in:
parent
4a729effff
commit
877fedadac
|
@ -281,12 +281,7 @@ mod tests {
|
||||||
let last_bank_snapshot_info =
|
let last_bank_snapshot_info =
|
||||||
snapshot_utils::get_highest_bank_snapshot_pre(bank_snapshots_dir)
|
snapshot_utils::get_highest_bank_snapshot_pre(bank_snapshots_dir)
|
||||||
.expect("no bank snapshots found in path");
|
.expect("no bank snapshots found in path");
|
||||||
let slot_deltas = last_bank
|
let slot_deltas = last_bank.status_cache.read().unwrap().root_slot_deltas();
|
||||||
.src
|
|
||||||
.status_cache
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.root_slot_deltas();
|
|
||||||
let accounts_package = AccountsPackage::new(
|
let accounts_package = AccountsPackage::new(
|
||||||
&last_bank,
|
&last_bank,
|
||||||
&last_bank_snapshot_info,
|
&last_bank_snapshot_info,
|
||||||
|
@ -631,7 +626,6 @@ mod tests {
|
||||||
.bank_forks
|
.bank_forks
|
||||||
.get(snapshot_test_config.bank_forks.root())
|
.get(snapshot_test_config.bank_forks.root())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.src
|
|
||||||
.status_cache
|
.status_cache
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -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 type TransactionCheckResult = (Result<()>, Option<NoncePartial>);
|
||||||
|
|
||||||
pub struct TransactionResults {
|
pub struct TransactionResults {
|
||||||
|
@ -1020,7 +1013,7 @@ impl PartialEq for Bank {
|
||||||
}
|
}
|
||||||
let Self {
|
let Self {
|
||||||
rc: _,
|
rc: _,
|
||||||
src: _,
|
status_cache: _,
|
||||||
blockhash_queue,
|
blockhash_queue,
|
||||||
ancestors,
|
ancestors,
|
||||||
hash,
|
hash,
|
||||||
|
@ -1190,7 +1183,8 @@ pub struct Bank {
|
||||||
/// References to accounts, parent and signature status
|
/// References to accounts, parent and signature status
|
||||||
pub rc: BankRc,
|
pub rc: BankRc,
|
||||||
|
|
||||||
pub src: StatusCacheRc,
|
/// A cache of signature statuses
|
||||||
|
pub status_cache: Arc<RwLock<BankStatusCache>>,
|
||||||
|
|
||||||
/// FIFO queue of `recent_blockhash` items
|
/// FIFO queue of `recent_blockhash` items
|
||||||
blockhash_queue: RwLock<BlockhashQueue>,
|
blockhash_queue: RwLock<BlockhashQueue>,
|
||||||
|
@ -1489,7 +1483,7 @@ impl Bank {
|
||||||
let mut bank = Self {
|
let mut bank = Self {
|
||||||
rewrites_skipped_this_slot: Rewrites::default(),
|
rewrites_skipped_this_slot: Rewrites::default(),
|
||||||
rc: BankRc::new(accounts, Slot::default()),
|
rc: BankRc::new(accounts, Slot::default()),
|
||||||
src: StatusCacheRc::default(),
|
status_cache: Arc::<RwLock<BankStatusCache>>::default(),
|
||||||
blockhash_queue: RwLock::<BlockhashQueue>::default(),
|
blockhash_queue: RwLock::<BlockhashQueue>::default(),
|
||||||
ancestors: Ancestors::default(),
|
ancestors: Ancestors::default(),
|
||||||
hash: RwLock::<Hash>::default(),
|
hash: RwLock::<Hash>::default(),
|
||||||
|
@ -1724,12 +1718,8 @@ impl Bank {
|
||||||
"bank_rc_creation",
|
"bank_rc_creation",
|
||||||
);
|
);
|
||||||
|
|
||||||
let (src, status_cache_rc_time) = measure!(
|
let (status_cache, status_cache_time) =
|
||||||
StatusCacheRc {
|
measure!(Arc::clone(&parent.status_cache), "status_cache_creation",);
|
||||||
status_cache: parent.src.status_cache.clone(),
|
|
||||||
},
|
|
||||||
"status_cache_rc_creation",
|
|
||||||
);
|
|
||||||
|
|
||||||
let ((fee_rate_governor, fee_calculator), fee_components_time) = measure!(
|
let ((fee_rate_governor, fee_calculator), fee_components_time) = measure!(
|
||||||
{
|
{
|
||||||
|
@ -1799,7 +1789,7 @@ impl Bank {
|
||||||
let mut new = Bank {
|
let mut new = Bank {
|
||||||
rewrites_skipped_this_slot: Rewrites::default(),
|
rewrites_skipped_this_slot: Rewrites::default(),
|
||||||
rc,
|
rc,
|
||||||
src,
|
status_cache,
|
||||||
slot,
|
slot,
|
||||||
bank_id,
|
bank_id,
|
||||||
epoch,
|
epoch,
|
||||||
|
@ -2027,7 +2017,7 @@ impl Bank {
|
||||||
("parent_slot", parent.slot(), i64),
|
("parent_slot", parent.slot(), i64),
|
||||||
("bank_rc_creation_us", bank_rc_time.as_us(), i64),
|
("bank_rc_creation_us", bank_rc_time.as_us(), i64),
|
||||||
("total_elapsed_us", 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),
|
("fee_components_us", fee_components_time.as_us(), i64),
|
||||||
("blockhash_queue_us", blockhash_queue_time.as_us(), i64),
|
("blockhash_queue_us", blockhash_queue_time.as_us(), i64),
|
||||||
("stakes_cache_us", stakes_cache_time.as_us(), i64),
|
("stakes_cache_us", stakes_cache_time.as_us(), i64),
|
||||||
|
@ -2155,7 +2145,7 @@ impl Bank {
|
||||||
let mut bank = Self {
|
let mut bank = Self {
|
||||||
rewrites_skipped_this_slot: Rewrites::default(),
|
rewrites_skipped_this_slot: Rewrites::default(),
|
||||||
rc: bank_rc,
|
rc: bank_rc,
|
||||||
src: new(),
|
status_cache: new(),
|
||||||
blockhash_queue: RwLock::new(fields.blockhash_queue),
|
blockhash_queue: RwLock::new(fields.blockhash_queue),
|
||||||
ancestors,
|
ancestors,
|
||||||
hash: RwLock::new(fields.hash),
|
hash: RwLock::new(fields.hash),
|
||||||
|
@ -2356,7 +2346,7 @@ impl Bank {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn status_cache_ancestors(&self) -> Vec<u64> {
|
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);
|
let min = roots.iter().min().cloned().unwrap_or(0);
|
||||||
for ancestor in self.ancestors.keys() {
|
for ancestor in self.ancestors.keys() {
|
||||||
if ancestor >= min {
|
if ancestor >= min {
|
||||||
|
@ -3450,7 +3440,7 @@ impl Bank {
|
||||||
let mut squash_cache_time = Measure::start("squash_cache_time");
|
let mut squash_cache_time = Measure::start("squash_cache_time");
|
||||||
roots
|
roots
|
||||||
.iter()
|
.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();
|
squash_cache_time.stop();
|
||||||
|
|
||||||
SquashTiming {
|
SquashTiming {
|
||||||
|
@ -3757,15 +3747,11 @@ impl Bank {
|
||||||
|
|
||||||
/// Forget all signatures. Useful for benchmarking.
|
/// Forget all signatures. Useful for benchmarking.
|
||||||
pub fn clear_signatures(&self) {
|
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) {
|
pub fn clear_slot_signatures(&self, slot: Slot) {
|
||||||
self.src
|
self.status_cache.write().unwrap().clear_slot_entries(slot);
|
||||||
.status_cache
|
|
||||||
.write()
|
|
||||||
.unwrap()
|
|
||||||
.clear_slot_entries(slot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_transaction_statuses(
|
fn update_transaction_statuses(
|
||||||
|
@ -3773,7 +3759,7 @@ impl Bank {
|
||||||
sanitized_txs: &[SanitizedTransaction],
|
sanitized_txs: &[SanitizedTransaction],
|
||||||
execution_results: &[TransactionExecutionResult],
|
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());
|
assert_eq!(sanitized_txs.len(), execution_results.len());
|
||||||
for (tx, execution_result) in sanitized_txs.iter().zip(execution_results) {
|
for (tx, execution_result) in sanitized_txs.iter().zip(execution_results) {
|
||||||
if let Some(details) = execution_result.details() {
|
if let Some(details) = execution_result.details() {
|
||||||
|
@ -4113,7 +4099,7 @@ impl Bank {
|
||||||
lock_results: Vec<TransactionCheckResult>,
|
lock_results: Vec<TransactionCheckResult>,
|
||||||
error_counters: &mut TransactionErrorMetrics,
|
error_counters: &mut TransactionErrorMetrics,
|
||||||
) -> Vec<TransactionCheckResult> {
|
) -> Vec<TransactionCheckResult> {
|
||||||
let rcache = self.src.status_cache.read().unwrap();
|
let rcache = self.status_cache.read().unwrap();
|
||||||
sanitized_txs
|
sanitized_txs
|
||||||
.iter()
|
.iter()
|
||||||
.zip(lock_results)
|
.zip(lock_results)
|
||||||
|
@ -6648,14 +6634,14 @@ impl Bank {
|
||||||
signature: &Signature,
|
signature: &Signature,
|
||||||
blockhash: &Hash,
|
blockhash: &Hash,
|
||||||
) -> Option<Result<()>> {
|
) -> Option<Result<()>> {
|
||||||
let rcache = self.src.status_cache.read().unwrap();
|
let rcache = self.status_cache.read().unwrap();
|
||||||
rcache
|
rcache
|
||||||
.get_status(signature, blockhash, &self.ancestors)
|
.get_status(signature, blockhash, &self.ancestors)
|
||||||
.map(|v| v.1)
|
.map(|v| v.1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_signature_status_slot(&self, signature: &Signature) -> Option<(Slot, Result<()>)> {
|
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)
|
rcache.get_status_any_blockhash(signature, &self.ancestors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -281,7 +281,6 @@ impl BankForks {
|
||||||
// Save off the status cache because these may get pruned if another
|
// Save off the status cache because these may get pruned if another
|
||||||
// `set_root()` is called before the snapshots package can be generated
|
// `set_root()` is called before the snapshots package can be generated
|
||||||
let status_cache_slot_deltas = snapshot_root_bank
|
let status_cache_slot_deltas = snapshot_root_bank
|
||||||
.src
|
|
||||||
.status_cache
|
.status_cache
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -4,10 +4,11 @@ use {
|
||||||
crate::{
|
crate::{
|
||||||
accounts::{test_utils::create_test_accounts, Accounts},
|
accounts::{test_utils::create_test_accounts, Accounts},
|
||||||
accounts_db::{get_temp_accounts_paths, AccountShrinkThreshold},
|
accounts_db::{get_temp_accounts_paths, AccountShrinkThreshold},
|
||||||
bank::{Bank, Rewrites, StatusCacheRc},
|
bank::{Bank, Rewrites},
|
||||||
genesis_utils::{activate_all_features, activate_feature},
|
genesis_utils::{activate_all_features, activate_feature},
|
||||||
hardened_unpack::UnpackedAppendVecMap,
|
hardened_unpack::UnpackedAppendVecMap,
|
||||||
snapshot_utils::ArchiveFormat,
|
snapshot_utils::ArchiveFormat,
|
||||||
|
status_cache::StatusCache,
|
||||||
},
|
},
|
||||||
bincode::serialize_into,
|
bincode::serialize_into,
|
||||||
rand::{thread_rng, Rng},
|
rand::{thread_rng, Rng},
|
||||||
|
@ -22,6 +23,7 @@ use {
|
||||||
std::{
|
std::{
|
||||||
io::{BufReader, Cursor},
|
io::{BufReader, Cursor},
|
||||||
path::Path,
|
path::Path,
|
||||||
|
sync::{Arc, RwLock},
|
||||||
},
|
},
|
||||||
tempfile::TempDir,
|
tempfile::TempDir,
|
||||||
};
|
};
|
||||||
|
@ -276,8 +278,8 @@ fn test_bank_serialize_style(
|
||||||
|
|
||||||
// Create a new set of directories for this bank's accounts
|
// Create a new set of directories for this bank's accounts
|
||||||
let (_accounts_dir, dbank_paths) = get_temp_accounts_paths(4).unwrap();
|
let (_accounts_dir, dbank_paths) = get_temp_accounts_paths(4).unwrap();
|
||||||
let ref_sc = StatusCacheRc::default();
|
let mut status_cache = StatusCache::default();
|
||||||
ref_sc.status_cache.write().unwrap().add_root(2);
|
status_cache.add_root(2);
|
||||||
// Create a directory to simulate AppendVecs unpackaged from a snapshot tar
|
// Create a directory to simulate AppendVecs unpackaged from a snapshot tar
|
||||||
let copied_accounts = TempDir::new().unwrap();
|
let copied_accounts = TempDir::new().unwrap();
|
||||||
let unpacked_append_vec_map =
|
let unpacked_append_vec_map =
|
||||||
|
@ -304,7 +306,7 @@ fn test_bank_serialize_style(
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.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(&key1.pubkey()), 0);
|
||||||
assert_eq!(dbank.get_balance(&key2.pubkey()), 10);
|
assert_eq!(dbank.get_balance(&key2.pubkey()), 10);
|
||||||
assert_eq!(dbank.get_balance(&key3.pubkey()), 0);
|
assert_eq!(dbank.get_balance(&key3.pubkey()), 0);
|
||||||
|
|
|
@ -1663,7 +1663,7 @@ fn rebuild_bank_from_snapshots(
|
||||||
Ok(slot_deltas)
|
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();
|
bank.prepare_rewrites_for_hash();
|
||||||
|
|
||||||
|
@ -1949,7 +1949,7 @@ pub fn package_and_archive_full_snapshot(
|
||||||
maximum_full_snapshot_archives_to_retain: usize,
|
maximum_full_snapshot_archives_to_retain: usize,
|
||||||
maximum_incremental_snapshot_archives_to_retain: usize,
|
maximum_incremental_snapshot_archives_to_retain: usize,
|
||||||
) -> Result<FullSnapshotArchiveInfo> {
|
) -> 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(
|
let accounts_package = AccountsPackage::new(
|
||||||
bank,
|
bank,
|
||||||
bank_snapshot_info,
|
bank_snapshot_info,
|
||||||
|
@ -1999,7 +1999,7 @@ pub fn package_and_archive_incremental_snapshot(
|
||||||
maximum_full_snapshot_archives_to_retain: usize,
|
maximum_full_snapshot_archives_to_retain: usize,
|
||||||
maximum_incremental_snapshot_archives_to_retain: usize,
|
maximum_incremental_snapshot_archives_to_retain: usize,
|
||||||
) -> Result<IncrementalSnapshotArchiveInfo> {
|
) -> 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(
|
let accounts_package = AccountsPackage::new(
|
||||||
bank,
|
bank,
|
||||||
bank_snapshot_info,
|
bank_snapshot_info,
|
||||||
|
|
Loading…
Reference in New Issue