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

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Comment on lines +9513 to +9519
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryoqun Do you have any suggestions/thoughts on how to name dcou functions that exist to re-export private functions for tests?

Rust won't let me call the dcou-version set_accounts_delta_hash(), since there's already one. And the _for_tests() is not needed anymore, since it's now within a dcou block. But I can't think of a better name... Have you already pondered on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you already pondered on this?

yep. seems this is common use case for dcou, i encountered this problem already...

not the rename, but i hope you like the taste of #32822


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