Moves some accounts-db test-only code into a dev-context-only-utils feature (#32748)

This commit is contained in:
Brooks 2023-08-07 17:28:15 -04:00 committed by GitHub
parent 0511753276
commit 4894eb0333
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 18 deletions

1
Cargo.lock generated
View File

@ -6769,6 +6769,7 @@ dependencies = [
"solana-perf",
"solana-program-runtime",
"solana-rayon-threadlimit",
"solana-runtime",
"solana-sdk",
"solana-stake-program",
"solana-system-program",

View File

@ -85,6 +85,8 @@ libsecp256k1 = { workspace = true }
memoffset = { workspace = true }
rand_chacha = { workspace = true }
solana-logger = { workspace = true }
# See order-crates-for-publishing.py for using this unusual `path = "."`
solana-runtime = { path = ".", features = ["dev-context-only-utils"] }
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }
static_assertions = { workspace = true }
test-case = { workspace = true }
@ -95,5 +97,8 @@ targets = ["x86_64-unknown-linux-gnu"]
[build-dependencies]
rustc_version = { workspace = true }
[features]
dev-context-only-utils = []
[[bench]]
name = "prioritization_fee_cache"

View File

@ -1421,8 +1421,8 @@ pub struct AccountsDb {
pub thread_pool_clean: ThreadPool,
bank_hash_stats: Mutex<HashMap<Slot, BankHashStats>>,
pub accounts_delta_hashes: Mutex<HashMap<Slot, AccountsDeltaHash>>,
pub accounts_hashes: Mutex<HashMap<Slot, (AccountsHash, /*capitalization*/ u64)>>,
accounts_delta_hashes: Mutex<HashMap<Slot, AccountsDeltaHash>>,
accounts_hashes: Mutex<HashMap<Slot, (AccountsHash, /*capitalization*/ u64)>>,
incremental_accounts_hashes:
Mutex<HashMap<Slot, (IncrementalAccountsHash, /*capitalization*/ u64)>>,
@ -9503,6 +9503,30 @@ impl AccountsDb {
}
}
// These functions/fields are only usable from a dev context (i.e. tests and benches)
#[cfg(feature = "dev-context-only-utils")]
impl AccountsDb {
pub fn accounts_delta_hashes(&self) -> &Mutex<HashMap<Slot, AccountsDeltaHash>> {
&self.accounts_delta_hashes
}
pub fn set_accounts_delta_hash_for_tests(
&self,
slot: Slot,
accounts_delta_hash: AccountsDeltaHash,
) {
self.set_accounts_delta_hash(slot, accounts_delta_hash);
}
pub fn accounts_hashes(&self) -> &Mutex<HashMap<Slot, (AccountsHash, /*capitalization*/ u64)>> {
&self.accounts_hashes
}
pub fn set_accounts_hash_for_tests(&self, slot: Slot, accounts_hash: AccountsHash) {
self.set_accounts_hash(slot, (accounts_hash, u64::default()));
}
}
/// A set of utility functions used for testing and benchmarking
pub mod test_utils {
use {
@ -9649,20 +9673,6 @@ pub mod tests {
fn get_storage_for_slot(&self, slot: Slot) -> Option<Arc<AccountStorageEntry>> {
self.storage.get_slot_storage_entry(slot)
}
// used by serde_snapshot tests
pub fn set_accounts_hash_for_tests(&self, slot: Slot, accounts_hash: AccountsHash) {
self.set_accounts_hash(slot, (accounts_hash, u64::default()));
}
// used by serde_snapshot tests
pub fn set_accounts_delta_hash_for_tests(
&self,
slot: Slot,
accounts_delta_hash: AccountsDeltaHash,
) {
self.set_accounts_delta_hash(slot, accounts_delta_hash);
}
}
/// This impl exists until this feature is activated:

View File

@ -398,8 +398,8 @@ mod serde_snapshot_tests {
// Get the hashes for the latest slot, which should be the only hashes in the
// map on the deserialized AccountsDb
assert_eq!(daccounts.accounts_delta_hashes.lock().unwrap().len(), 1);
assert_eq!(daccounts.accounts_hashes.lock().unwrap().len(), 1);
assert_eq!(daccounts.accounts_delta_hashes().lock().unwrap().len(), 1);
assert_eq!(daccounts.accounts_hashes().lock().unwrap().len(), 1);
assert_eq!(
daccounts.get_accounts_delta_hash(latest_slot).unwrap(),
accounts.get_accounts_delta_hash(latest_slot).unwrap(),