diff --git a/Cargo.lock b/Cargo.lock index 16a90d562..f43ba8e1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6769,6 +6769,7 @@ dependencies = [ "solana-perf", "solana-program-runtime", "solana-rayon-threadlimit", + "solana-runtime", "solana-sdk", "solana-stake-program", "solana-system-program", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index e7ca12265..f2da3dce0 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -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" diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index f813050d5..c8d827d49 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -1421,8 +1421,8 @@ pub struct AccountsDb { pub thread_pool_clean: ThreadPool, bank_hash_stats: Mutex>, - pub accounts_delta_hashes: Mutex>, - pub accounts_hashes: Mutex>, + accounts_delta_hashes: Mutex>, + accounts_hashes: Mutex>, incremental_accounts_hashes: Mutex>, @@ -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> { + &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> { + &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> { 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: diff --git a/runtime/src/serde_snapshot/tests.rs b/runtime/src/serde_snapshot/tests.rs index a2212269f..f5ee7969c 100644 --- a/runtime/src/serde_snapshot/tests.rs +++ b/runtime/src/serde_snapshot/tests.rs @@ -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(),