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

Commit

Permalink
Moves some accounts-db test-only code into a dev-context-only-utils f…
Browse files Browse the repository at this point in the history
…eature (#32748)
  • Loading branch information
brooksprumo authored Aug 7, 2023
1 parent 0511753 commit 4894eb0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"
42 changes: 26 additions & 16 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>>,

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 4894eb0

Please sign in to comment.