Moves some accounts-db test-only code into a dev-context-only-utils feature (#32748)
This commit is contained in:
parent
0511753276
commit
4894eb0333
|
@ -6769,6 +6769,7 @@ dependencies = [
|
||||||
"solana-perf",
|
"solana-perf",
|
||||||
"solana-program-runtime",
|
"solana-program-runtime",
|
||||||
"solana-rayon-threadlimit",
|
"solana-rayon-threadlimit",
|
||||||
|
"solana-runtime",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
"solana-stake-program",
|
"solana-stake-program",
|
||||||
"solana-system-program",
|
"solana-system-program",
|
||||||
|
|
|
@ -85,6 +85,8 @@ libsecp256k1 = { workspace = true }
|
||||||
memoffset = { workspace = true }
|
memoffset = { workspace = true }
|
||||||
rand_chacha = { workspace = true }
|
rand_chacha = { workspace = true }
|
||||||
solana-logger = { 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"] }
|
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }
|
||||||
static_assertions = { workspace = true }
|
static_assertions = { workspace = true }
|
||||||
test-case = { workspace = true }
|
test-case = { workspace = true }
|
||||||
|
@ -95,5 +97,8 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
rustc_version = { workspace = true }
|
rustc_version = { workspace = true }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
dev-context-only-utils = []
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "prioritization_fee_cache"
|
name = "prioritization_fee_cache"
|
||||||
|
|
|
@ -1421,8 +1421,8 @@ pub struct AccountsDb {
|
||||||
pub thread_pool_clean: ThreadPool,
|
pub thread_pool_clean: ThreadPool,
|
||||||
|
|
||||||
bank_hash_stats: Mutex<HashMap<Slot, BankHashStats>>,
|
bank_hash_stats: Mutex<HashMap<Slot, BankHashStats>>,
|
||||||
pub accounts_delta_hashes: Mutex<HashMap<Slot, AccountsDeltaHash>>,
|
accounts_delta_hashes: Mutex<HashMap<Slot, AccountsDeltaHash>>,
|
||||||
pub accounts_hashes: Mutex<HashMap<Slot, (AccountsHash, /*capitalization*/ u64)>>,
|
accounts_hashes: Mutex<HashMap<Slot, (AccountsHash, /*capitalization*/ u64)>>,
|
||||||
incremental_accounts_hashes:
|
incremental_accounts_hashes:
|
||||||
Mutex<HashMap<Slot, (IncrementalAccountsHash, /*capitalization*/ u64)>>,
|
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
|
/// A set of utility functions used for testing and benchmarking
|
||||||
pub mod test_utils {
|
pub mod test_utils {
|
||||||
use {
|
use {
|
||||||
|
@ -9649,20 +9673,6 @@ pub mod tests {
|
||||||
fn get_storage_for_slot(&self, slot: Slot) -> Option<Arc<AccountStorageEntry>> {
|
fn get_storage_for_slot(&self, slot: Slot) -> Option<Arc<AccountStorageEntry>> {
|
||||||
self.storage.get_slot_storage_entry(slot)
|
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:
|
/// This impl exists until this feature is activated:
|
||||||
|
|
|
@ -398,8 +398,8 @@ mod serde_snapshot_tests {
|
||||||
|
|
||||||
// Get the hashes for the latest slot, which should be the only hashes in the
|
// Get the hashes for the latest slot, which should be the only hashes in the
|
||||||
// map on the deserialized AccountsDb
|
// map on the deserialized AccountsDb
|
||||||
assert_eq!(daccounts.accounts_delta_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.accounts_hashes().lock().unwrap().len(), 1);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
daccounts.get_accounts_delta_hash(latest_slot).unwrap(),
|
daccounts.get_accounts_delta_hash(latest_slot).unwrap(),
|
||||||
accounts.get_accounts_delta_hash(latest_slot).unwrap(),
|
accounts.get_accounts_delta_hash(latest_slot).unwrap(),
|
||||||
|
|
Loading…
Reference in New Issue