solana_runtime/conformance/
mod.rs1#[cfg(feature = "conformance")]
4pub mod block;
5#[cfg(feature = "conformance")]
6pub mod cost;
7pub mod txn;
8
9#[cfg(feature = "conformance")]
10use {
11 protosol::protos::{
12 AcctState, BlockhashQueueEntry as ProtoBlockhashQueueEntry,
13 FeeRateGovernor as ProtoFeeRateGovernor,
14 },
15 solana_account::AccountSharedData,
16 solana_accounts_db::blockhash_queue::BlockhashQueue,
17 solana_fee_calculator::FeeRateGovernor,
18 solana_hash::Hash,
19 solana_pubkey::Pubkey,
20 solana_svm::conformance::account_state::account_from_proto,
21};
22use {
23 solana_accounts_db::{
24 accounts::Accounts,
25 accounts_db::{ACCOUNTS_DB_CONFIG_FOR_TESTING, AccountsDb, AccountsDbConfig},
26 },
27 std::{num::NonZeroUsize, sync::Arc},
28};
29
30#[cfg(feature = "conformance")]
33pub(crate) fn deserialize_accounts(accounts: &[AcctState]) -> Vec<(Pubkey, AccountSharedData)> {
34 accounts
35 .iter()
36 .filter(|account| account.lamports > 0)
37 .map(|account| {
38 let (pubkey, account) = account_from_proto(account.clone());
39 (pubkey, account.into())
40 })
41 .collect()
42}
43
44#[cfg(feature = "conformance")]
45pub(crate) fn restore_blockhash_queue(entries: &[ProtoBlockhashQueueEntry]) -> BlockhashQueue {
46 let mut blockhash_queue = BlockhashQueue::default();
47 for entry in entries {
48 let blockhash =
49 Hash::new_from_array(<[u8; 32]>::try_from(entry.blockhash.as_slice()).unwrap());
50 blockhash_queue.register_hash(&blockhash, entry.lamports_per_signature);
51 }
52 blockhash_queue
53}
54
55#[cfg(feature = "conformance")]
56pub(crate) fn fee_rate_governor_from_proto(
57 value: &ProtoFeeRateGovernor,
58 lamports_per_signature: u64,
59) -> FeeRateGovernor {
60 FeeRateGovernor {
61 lamports_per_signature,
62 target_lamports_per_signature: value.target_lamports_per_signature,
63 target_signatures_per_slot: value.target_signatures_per_slot,
64 min_lamports_per_signature: value.min_lamports_per_signature,
65 max_lamports_per_signature: value.max_lamports_per_signature,
66 burn_percent: value.burn_percent as u8,
67 }
68}
69
70pub(crate) fn new_accounts_for_tests_single_threaded() -> Accounts {
71 Accounts::new(Arc::new(AccountsDb::new_for_tests_with_config(
72 Vec::new(),
73 new_accounts_db_config_for_tests_single_threaded(),
74 )))
75}
76
77pub(crate) fn new_accounts_db_config_for_tests_single_threaded() -> AccountsDbConfig {
78 let single_thread = NonZeroUsize::new(1).unwrap();
79 AccountsDbConfig {
80 num_background_threads: Some(single_thread),
81 num_foreground_threads: Some(single_thread),
82 read_cache_num_shards: Some(2),
83 skip_initial_hash_calc: true,
84 ..ACCOUNTS_DB_CONFIG_FOR_TESTING
85 }
86}
87
88#[cfg(test)]
89mod tests {
90 use {super::*, solana_accounts_db::accounts_index::IndexLimit};
91
92 #[test]
93 fn test_new_accounts_for_tests_single_threaded() {
94 let accounts = new_accounts_for_tests_single_threaded();
95 let accounts_db = &accounts.accounts_db;
96 assert!(accounts_db.skip_initial_hash_calc);
97 assert_eq!(accounts_db.thread_pool_foreground.current_num_threads(), 1);
98 assert_eq!(accounts_db.thread_pool_background.current_num_threads(), 1);
99 }
100
101 #[test]
102 fn test_new_accounts_db_config_for_tests_single_threaded_config() {
103 let one = NonZeroUsize::new(1).unwrap();
104 let config = new_accounts_db_config_for_tests_single_threaded();
105 let index = config.index.unwrap();
106 assert_eq!(index.bins, Some(2));
107 assert_eq!(index.num_flush_threads, Some(one));
108 assert!(matches!(index.index_limit, IndexLimit::InMemOnly));
109 assert!(config.skip_initial_hash_calc);
110 assert!(!config.exhaustively_verify_refcounts);
111 assert_eq!(config.read_cache_num_shards, Some(2));
112 assert_eq!(config.num_background_threads, Some(one));
113 assert_eq!(config.num_foreground_threads, Some(one));
114 }
115}