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

Commit 4894eb0

Browse files
authored
Moves some accounts-db test-only code into a dev-context-only-utils feature (#32748)
1 parent 0511753 commit 4894eb0

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ libsecp256k1 = { workspace = true }
8585
memoffset = { workspace = true }
8686
rand_chacha = { workspace = true }
8787
solana-logger = { workspace = true }
88+
# See order-crates-for-publishing.py for using this unusual `path = "."`
89+
solana-runtime = { path = ".", features = ["dev-context-only-utils"] }
8890
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }
8991
static_assertions = { workspace = true }
9092
test-case = { workspace = true }
@@ -95,5 +97,8 @@ targets = ["x86_64-unknown-linux-gnu"]
9597
[build-dependencies]
9698
rustc_version = { workspace = true }
9799

100+
[features]
101+
dev-context-only-utils = []
102+
98103
[[bench]]
99104
name = "prioritization_fee_cache"

runtime/src/accounts_db.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,8 +1421,8 @@ pub struct AccountsDb {
14211421
pub thread_pool_clean: ThreadPool,
14221422

14231423
bank_hash_stats: Mutex<HashMap<Slot, BankHashStats>>,
1424-
pub accounts_delta_hashes: Mutex<HashMap<Slot, AccountsDeltaHash>>,
1425-
pub accounts_hashes: Mutex<HashMap<Slot, (AccountsHash, /*capitalization*/ u64)>>,
1424+
accounts_delta_hashes: Mutex<HashMap<Slot, AccountsDeltaHash>>,
1425+
accounts_hashes: Mutex<HashMap<Slot, (AccountsHash, /*capitalization*/ u64)>>,
14261426
incremental_accounts_hashes:
14271427
Mutex<HashMap<Slot, (IncrementalAccountsHash, /*capitalization*/ u64)>>,
14281428

@@ -9503,6 +9503,30 @@ impl AccountsDb {
95039503
}
95049504
}
95059505

9506+
// These functions/fields are only usable from a dev context (i.e. tests and benches)
9507+
#[cfg(feature = "dev-context-only-utils")]
9508+
impl AccountsDb {
9509+
pub fn accounts_delta_hashes(&self) -> &Mutex<HashMap<Slot, AccountsDeltaHash>> {
9510+
&self.accounts_delta_hashes
9511+
}
9512+
9513+
pub fn set_accounts_delta_hash_for_tests(
9514+
&self,
9515+
slot: Slot,
9516+
accounts_delta_hash: AccountsDeltaHash,
9517+
) {
9518+
self.set_accounts_delta_hash(slot, accounts_delta_hash);
9519+
}
9520+
9521+
pub fn accounts_hashes(&self) -> &Mutex<HashMap<Slot, (AccountsHash, /*capitalization*/ u64)>> {
9522+
&self.accounts_hashes
9523+
}
9524+
9525+
pub fn set_accounts_hash_for_tests(&self, slot: Slot, accounts_hash: AccountsHash) {
9526+
self.set_accounts_hash(slot, (accounts_hash, u64::default()));
9527+
}
9528+
}
9529+
95069530
/// A set of utility functions used for testing and benchmarking
95079531
pub mod test_utils {
95089532
use {
@@ -9649,20 +9673,6 @@ pub mod tests {
96499673
fn get_storage_for_slot(&self, slot: Slot) -> Option<Arc<AccountStorageEntry>> {
96509674
self.storage.get_slot_storage_entry(slot)
96519675
}
9652-
9653-
// used by serde_snapshot tests
9654-
pub fn set_accounts_hash_for_tests(&self, slot: Slot, accounts_hash: AccountsHash) {
9655-
self.set_accounts_hash(slot, (accounts_hash, u64::default()));
9656-
}
9657-
9658-
// used by serde_snapshot tests
9659-
pub fn set_accounts_delta_hash_for_tests(
9660-
&self,
9661-
slot: Slot,
9662-
accounts_delta_hash: AccountsDeltaHash,
9663-
) {
9664-
self.set_accounts_delta_hash(slot, accounts_delta_hash);
9665-
}
96669676
}
96679677

96689678
/// This impl exists until this feature is activated:

runtime/src/serde_snapshot/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ mod serde_snapshot_tests {
398398

399399
// Get the hashes for the latest slot, which should be the only hashes in the
400400
// map on the deserialized AccountsDb
401-
assert_eq!(daccounts.accounts_delta_hashes.lock().unwrap().len(), 1);
402-
assert_eq!(daccounts.accounts_hashes.lock().unwrap().len(), 1);
401+
assert_eq!(daccounts.accounts_delta_hashes().lock().unwrap().len(), 1);
402+
assert_eq!(daccounts.accounts_hashes().lock().unwrap().len(), 1);
403403
assert_eq!(
404404
daccounts.get_accounts_delta_hash(latest_slot).unwrap(),
405405
accounts.get_accounts_delta_hash(latest_slot).unwrap(),

0 commit comments

Comments
 (0)