Removes unnecessary Accounts constructors (#34471)

This commit is contained in:
Brooks 2023-12-14 22:50:15 -05:00 committed by GitHub
parent aaccbdd0ae
commit 45eaa4c1a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 117 additions and 131 deletions

View File

@ -9,7 +9,7 @@ use {
accounts::Accounts,
accounts_db::{
test_utils::{create_test_accounts, update_accounts_bench},
AccountShrinkThreshold, CalcAccountsHashDataSource,
AccountShrinkThreshold, AccountsDb, CalcAccountsHashDataSource,
},
accounts_index::AccountSecondaryIndexes,
ancestors::Ancestors,
@ -19,7 +19,7 @@ use {
solana_sdk::{
genesis_config::ClusterType, pubkey::Pubkey, sysvar::epoch_schedule::EpochSchedule,
},
std::{env, fs, path::PathBuf},
std::{env, fs, path::PathBuf, sync::Arc},
};
fn main() {
@ -69,12 +69,13 @@ fn main() {
if fs::remove_dir_all(path.clone()).is_err() {
println!("Warning: Couldn't remove {path:?}");
}
let accounts = Accounts::new_with_config_for_benches(
let accounts_db = AccountsDb::new_with_config_for_benches(
vec![path],
&ClusterType::Testnet,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
println!("Creating {num_accounts} accounts");
let mut create_time = Measure::start("create accounts");
let pubkeys: Vec<_> = (0..num_slots)

View File

@ -1,15 +1,10 @@
#[cfg(feature = "dev-context-only-utils")]
use crate::accounts_db::{ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS, ACCOUNTS_DB_CONFIG_FOR_TESTING};
use {
crate::{
accounts_db::{
AccountShrinkThreshold, AccountsAddRootTiming, AccountsDb, AccountsDbConfig, LoadHint,
LoadedAccount, ScanStorageResult, VerifyAccountsHashAndLamportsConfig,
AccountsAddRootTiming, AccountsDb, LoadHint, LoadedAccount, ScanStorageResult,
VerifyAccountsHashAndLamportsConfig,
},
accounts_index::{
AccountSecondaryIndexes, IndexKey, ScanConfig, ScanError, ScanResult, ZeroLamport,
},
accounts_update_notifier_interface::AccountsUpdateNotifier,
accounts_index::{IndexKey, ScanConfig, ScanError, ScanResult, ZeroLamport},
ancestors::Ancestors,
nonce_info::{NonceFull, NonceInfo},
rent_collector::RentCollector,
@ -24,7 +19,6 @@ use {
account_utils::StateMut,
address_lookup_table::{self, error::AddressLookupError, state::AddressLookupTable},
clock::{BankId, Slot},
genesis_config::ClusterType,
message::v0::{LoadedAddresses, MessageAddressTableLookup},
nonce::{
state::{DurableNonce, Versions as NonceVersions},
@ -42,9 +36,8 @@ use {
BinaryHeap, HashMap, HashSet,
},
ops::RangeBounds,
path::PathBuf,
sync::{
atomic::{AtomicBool, AtomicUsize, Ordering},
atomic::{AtomicUsize, Ordering},
Arc, Mutex,
},
},
@ -125,30 +118,6 @@ pub enum AccountAddressFilter {
}
impl Accounts {
pub fn default_for_tests() -> Self {
Self::new(Arc::new(AccountsDb::default_for_tests()))
}
pub fn new_with_config(
paths: Vec<PathBuf>,
cluster_type: &ClusterType,
account_indexes: AccountSecondaryIndexes,
shrink_ratio: AccountShrinkThreshold,
accounts_db_config: Option<AccountsDbConfig>,
accounts_update_notifier: Option<AccountsUpdateNotifier>,
exit: Arc<AtomicBool>,
) -> Self {
Self::new(Arc::new(AccountsDb::new_with_config(
paths,
cluster_type,
account_indexes,
shrink_ratio,
accounts_db_config,
accounts_update_notifier,
exit,
)))
}
pub fn new(accounts_db: Arc<AccountsDb>) -> Self {
Self {
accounts_db,
@ -797,44 +766,6 @@ impl Accounts {
}
}
// These functions/fields are only usable from a dev context (i.e. tests and benches)
#[cfg(feature = "dev-context-only-utils")]
impl Accounts {
pub fn new_with_config_for_tests(
paths: Vec<PathBuf>,
cluster_type: &ClusterType,
account_indexes: AccountSecondaryIndexes,
shrink_ratio: AccountShrinkThreshold,
) -> Self {
Self::new_with_config(
paths,
cluster_type,
account_indexes,
shrink_ratio,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Arc::default(),
)
}
pub fn new_with_config_for_benches(
paths: Vec<PathBuf>,
cluster_type: &ClusterType,
account_indexes: AccountSecondaryIndexes,
shrink_ratio: AccountShrinkThreshold,
) -> Self {
Self::new_with_config(
paths,
cluster_type,
account_indexes,
shrink_ratio,
Some(ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS),
None,
Arc::default(),
)
}
}
fn prepare_if_nonce_account(
address: &Pubkey,
account: &mut AccountSharedData,
@ -893,6 +824,8 @@ mod tests {
use {
super::*,
crate::{
accounts_db::AccountShrinkThreshold,
accounts_index::AccountSecondaryIndexes,
rent_collector::RentCollector,
transaction_results::{DurableNonceFee, TransactionExecutionDetails},
},
@ -949,7 +882,8 @@ mod tests {
#[test]
fn test_hold_range_in_memory() {
let accts = Accounts::default_for_tests();
let accounts_db = AccountsDb::default_for_tests();
let accts = Accounts::new(Arc::new(accounts_db));
let range = Pubkey::from([0; 32])..=Pubkey::from([0xff; 32]);
accts.hold_range_in_memory(&range, true, &test_thread_pool());
accts.hold_range_in_memory(&range, false, &test_thread_pool());
@ -961,7 +895,8 @@ mod tests {
#[test]
fn test_hold_range_in_memory2() {
let accts = Accounts::default_for_tests();
let accounts_db = AccountsDb::default_for_tests();
let accts = Accounts::new(Arc::new(accounts_db));
let range = Pubkey::from([0; 32])..=Pubkey::from([0xff; 32]);
let idx = &accts.accounts_db.accounts_index;
let bins = idx.account_maps.len();
@ -1004,12 +939,13 @@ mod tests {
#[test]
fn test_load_lookup_table_addresses_account_not_found() {
let ancestors = vec![(0, 0)].into_iter().collect();
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let invalid_table_key = Pubkey::new_unique();
let address_table_lookup = MessageAddressTableLookup {
@ -1031,12 +967,13 @@ mod tests {
#[test]
fn test_load_lookup_table_addresses_invalid_account_owner() {
let ancestors = vec![(0, 0)].into_iter().collect();
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let invalid_table_key = Pubkey::new_unique();
let mut invalid_table_account = AccountSharedData::default();
@ -1062,12 +999,13 @@ mod tests {
#[test]
fn test_load_lookup_table_addresses_invalid_account_data() {
let ancestors = vec![(0, 0)].into_iter().collect();
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let invalid_table_key = Pubkey::new_unique();
let invalid_table_account =
@ -1093,12 +1031,13 @@ mod tests {
#[test]
fn test_load_lookup_table_addresses() {
let ancestors = vec![(1, 1), (0, 0)].into_iter().collect();
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let table_key = Pubkey::new_unique();
let table_addresses = vec![Pubkey::new_unique(), Pubkey::new_unique()];
@ -1138,12 +1077,13 @@ mod tests {
#[test]
fn test_load_by_program_slot() {
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
// Load accounts owned by various programs into AccountsDb
let pubkey0 = solana_sdk::pubkey::new_rand();
@ -1166,24 +1106,26 @@ mod tests {
#[test]
fn test_accounts_empty_bank_hash_stats() {
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
assert!(accounts.accounts_db.get_bank_hash_stats(0).is_some());
assert!(accounts.accounts_db.get_bank_hash_stats(1).is_none());
}
#[test]
fn test_lock_accounts_with_duplicates() {
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let keypair = Keypair::new();
let message = Message {
@ -1202,12 +1144,13 @@ mod tests {
#[test]
fn test_lock_accounts_with_too_many_accounts() {
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let keypair = Keypair::new();
@ -1267,12 +1210,13 @@ mod tests {
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
let account3 = AccountSharedData::new(4, 0, &Pubkey::default());
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
accounts.store_for_tests(0, &keypair0.pubkey(), &account0);
accounts.store_for_tests(0, &keypair1.pubkey(), &account1);
accounts.store_for_tests(0, &keypair2.pubkey(), &account2);
@ -1376,12 +1320,13 @@ mod tests {
let account1 = AccountSharedData::new(2, 0, &Pubkey::default());
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
accounts.store_for_tests(0, &keypair0.pubkey(), &account0);
accounts.store_for_tests(0, &keypair1.pubkey(), &account1);
accounts.store_for_tests(0, &keypair2.pubkey(), &account2);
@ -1457,12 +1402,13 @@ mod tests {
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
let account3 = AccountSharedData::new(4, 0, &Pubkey::default());
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
accounts.store_for_tests(0, &keypair0.pubkey(), &account0);
accounts.store_for_tests(0, &keypair1.pubkey(), &account1);
accounts.store_for_tests(0, &keypair2.pubkey(), &account2);
@ -1533,12 +1479,13 @@ mod tests {
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
let account3 = AccountSharedData::new(4, 0, &Pubkey::default());
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
accounts.store_for_tests(0, &keypair0.pubkey(), &account0);
accounts.store_for_tests(0, &keypair1.pubkey(), &account1);
accounts.store_for_tests(0, &keypair2.pubkey(), &account2);
@ -1692,12 +1639,13 @@ mod tests {
let mut loaded = vec![loaded0, loaded1];
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
{
accounts
.account_locks
@ -1743,12 +1691,13 @@ mod tests {
#[test]
fn huge_clean() {
solana_logger::setup();
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let mut old_pubkey = Pubkey::default();
let zero_account = AccountSharedData::new(0, 0, AccountSharedData::default().owner());
info!("storing..");
@ -2082,12 +2031,13 @@ mod tests {
let mut loaded = vec![loaded];
let durable_nonce = DurableNonce::from_blockhash(&Hash::new_unique());
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let txs = vec![tx];
let execution_results = vec![new_execution_result(
Err(TransactionError::InstructionError(
@ -2195,12 +2145,13 @@ mod tests {
let mut loaded = vec![loaded];
let durable_nonce = DurableNonce::from_blockhash(&Hash::new_unique());
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let txs = vec![tx];
let execution_results = vec![new_execution_result(
Err(TransactionError::InstructionError(
@ -2236,12 +2187,13 @@ mod tests {
#[test]
fn test_load_largest_accounts() {
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
/* This test assumes pubkey0 < pubkey1 < pubkey2.
* But the keys created with new_unique() does not gurantee this

View File

@ -9522,6 +9522,40 @@ pub(crate) enum UpdateIndexThreadSelection {
// 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 new_with_config_for_tests(
paths: Vec<PathBuf>,
cluster_type: &ClusterType,
account_indexes: AccountSecondaryIndexes,
shrink_ratio: AccountShrinkThreshold,
) -> Self {
Self::new_with_config(
paths,
cluster_type,
account_indexes,
shrink_ratio,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Arc::default(),
)
}
pub fn new_with_config_for_benches(
paths: Vec<PathBuf>,
cluster_type: &ClusterType,
account_indexes: AccountSecondaryIndexes,
shrink_ratio: AccountShrinkThreshold,
) -> Self {
Self::new_with_config(
paths,
cluster_type,
account_indexes,
shrink_ratio,
Some(ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS),
None,
Arc::default(),
)
}
pub fn load_without_fixed_root(
&self,
ancestors: &Ancestors,
@ -9821,23 +9855,6 @@ pub mod tests {
}
impl AccountsDb {
pub fn new_with_config_for_tests(
paths: Vec<PathBuf>,
cluster_type: &ClusterType,
account_indexes: AccountSecondaryIndexes,
shrink_ratio: AccountShrinkThreshold,
) -> Self {
Self::new_with_config(
paths,
cluster_type,
account_indexes,
shrink_ratio,
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
None,
Arc::default(),
)
}
pub fn new_sized(paths: Vec<PathBuf>, file_size: u64) -> Self {
AccountsDb {
file_size,

View File

@ -10,7 +10,7 @@ use {
solana_accounts_db::{
accounts::{AccountAddressFilter, Accounts},
accounts_db::{
test_utils::create_test_accounts, AccountShrinkThreshold,
test_utils::create_test_accounts, AccountShrinkThreshold, AccountsDb,
VerifyAccountsHashAndLamportsConfig,
},
accounts_index::{AccountSecondaryIndexes, ScanConfig},
@ -99,12 +99,13 @@ fn test_accounts_squash(bencher: &mut Bencher) {
#[bench]
fn test_accounts_hash_bank_hash(bencher: &mut Bencher) {
let accounts = Accounts::new_with_config_for_benches(
let accounts_db = AccountsDb::new_with_config_for_benches(
vec![PathBuf::from("bench_accounts_hash_internal")],
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let mut pubkeys: Vec<Pubkey> = vec![];
let num_accounts = 60_000;
let slot = 0;
@ -136,12 +137,13 @@ fn test_accounts_hash_bank_hash(bencher: &mut Bencher) {
#[bench]
fn test_update_accounts_hash(bencher: &mut Bencher) {
solana_logger::setup();
let accounts = Accounts::new_with_config_for_benches(
let accounts_db = AccountsDb::new_with_config_for_benches(
vec![PathBuf::from("update_accounts_hash")],
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let mut pubkeys: Vec<Pubkey> = vec![];
create_test_accounts(&accounts, &mut pubkeys, 50_000, 0);
let ancestors = Ancestors::from(vec![0]);
@ -155,12 +157,13 @@ fn test_update_accounts_hash(bencher: &mut Bencher) {
#[bench]
fn test_accounts_delta_hash(bencher: &mut Bencher) {
solana_logger::setup();
let accounts = Accounts::new_with_config_for_benches(
let accounts_db = AccountsDb::new_with_config_for_benches(
vec![PathBuf::from("accounts_delta_hash")],
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let mut pubkeys: Vec<Pubkey> = vec![];
create_test_accounts(&accounts, &mut pubkeys, 100_000, 0);
bencher.iter(|| {
@ -171,12 +174,13 @@ fn test_accounts_delta_hash(bencher: &mut Bencher) {
#[bench]
fn bench_delete_dependencies(bencher: &mut Bencher) {
solana_logger::setup();
let accounts = Accounts::new_with_config_for_benches(
let accounts_db = AccountsDb::new_with_config_for_benches(
vec![PathBuf::from("accounts_delete_deps")],
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let mut old_pubkey = Pubkey::default();
let zero_account = AccountSharedData::new(0, 0, AccountSharedData::default().owner());
for i in 0..1000 {
@ -200,7 +204,7 @@ fn store_accounts_with_possible_contention<F: 'static>(
F: Fn(&Accounts, &[Pubkey]) + Send + Copy,
{
let num_readers = 5;
let accounts = Arc::new(Accounts::new_with_config_for_benches(
let accounts_db = AccountsDb::new_with_config_for_benches(
vec![
PathBuf::from(std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string()))
.join(bench_name),
@ -208,7 +212,8 @@ fn store_accounts_with_possible_contention<F: 'static>(
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
));
);
let accounts = Arc::new(Accounts::new(Arc::new(accounts_db)));
let num_keys = 1000;
let slot = 0;
accounts.add_root(slot);
@ -336,7 +341,7 @@ fn bench_rwlock_hashmap_single_reader_with_n_writers(bencher: &mut Bencher) {
}
fn setup_bench_dashmap_iter() -> (Arc<Accounts>, DashMap<Pubkey, (AccountSharedData, Hash)>) {
let accounts = Arc::new(Accounts::new_with_config_for_benches(
let accounts_db = AccountsDb::new_with_config_for_benches(
vec![
PathBuf::from(std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string()))
.join("bench_dashmap_par_iter"),
@ -344,7 +349,8 @@ fn setup_bench_dashmap_iter() -> (Arc<Accounts>, DashMap<Pubkey, (AccountSharedD
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
));
);
let accounts = Arc::new(Accounts::new(Arc::new(accounts_db)));
let dashmap = DashMap::new();
let num_keys = std::env::var("NUM_BENCH_KEYS")
@ -393,12 +399,13 @@ fn bench_dashmap_iter(bencher: &mut Bencher) {
#[bench]
fn bench_load_largest_accounts(b: &mut Bencher) {
let accounts = Accounts::new_with_config_for_benches(
let accounts_db = AccountsDb::new_with_config_for_benches(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let mut rng = rand::thread_rng();
for _ in 0..10_000 {
let lamports = rng.gen();

View File

@ -561,7 +561,7 @@ mod tests {
transaction::{Result, Transaction, TransactionError},
transaction_context::TransactionAccount,
},
std::convert::TryFrom,
std::{convert::TryFrom, sync::Arc},
};
fn load_accounts_with_fee_and_rent(
@ -575,12 +575,13 @@ mod tests {
) -> Vec<TransactionLoadResult> {
let mut hash_queue = BlockhashQueue::new(100);
hash_queue.register_hash(&tx.message().recent_blockhash, lamports_per_signature);
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
for ka in ka.iter() {
accounts.accounts_db.store_for_tests(0, &[(&ka.0, &ka.1)]);
}
@ -1387,12 +1388,13 @@ mod tests {
#[test]
fn test_instructions() {
solana_logger::setup();
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let instructions_key = solana_sdk::sysvar::instructions::id();
let keypair = Keypair::new();
@ -1413,12 +1415,13 @@ mod tests {
#[test]
fn test_overrides() {
solana_logger::setup();
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
Vec::new(),
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let mut account_overrides = AccountOverrides::default();
let slot_history_id = sysvar::slot_history::id();
let account = AccountSharedData::new(42, 0, &Pubkey::default());

View File

@ -1100,7 +1100,7 @@ impl Bank {
accounts_update_notifier: Option<AccountsUpdateNotifier>,
exit: Arc<AtomicBool>,
) -> Self {
let accounts = Accounts::new_with_config(
let accounts_db = AccountsDb::new_with_config(
paths,
&genesis_config.cluster_type,
account_indexes,
@ -1109,6 +1109,7 @@ impl Bank {
accounts_update_notifier,
exit,
);
let accounts = Accounts::new(Arc::new(accounts_db));
let mut bank = Self::default_with_accounts(accounts);
bank.ancestors = Ancestors::from(vec![bank.slot()]);
bank.transaction_debug_keys = debug_keys;
@ -8173,7 +8174,9 @@ impl Bank {
}
pub fn default_for_tests() -> Self {
Self::default_with_accounts(Accounts::default_for_tests())
let accounts_db = AccountsDb::default_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
Self::default_with_accounts(accounts)
}
pub fn new_with_bank_forks_for_tests(

View File

@ -223,12 +223,13 @@ mod serde_snapshot_tests {
fn test_accounts_serialize_style(serde_style: SerdeStyle) {
solana_logger::setup();
let (_accounts_dir, paths) = get_temp_accounts_paths(4).unwrap();
let accounts = Accounts::new_with_config_for_tests(
let accounts_db = AccountsDb::new_with_config_for_tests(
paths,
&ClusterType::Development,
AccountSecondaryIndexes::default(),
AccountShrinkThreshold::default(),
);
let accounts = Accounts::new(Arc::new(accounts_db));
let slot = 0;
let mut pubkeys: Vec<Pubkey> = vec![];

View File

@ -8,7 +8,7 @@ use {
log::*,
solana_accounts_db::{
accounts::Accounts,
accounts_db::AccountStorageEntry,
accounts_db::{AccountStorageEntry, AccountsDb},
accounts_hash::{AccountsHash, AccountsHashKind},
epoch_accounts_hash::EpochAccountsHash,
rent_collector::RentCollector,
@ -159,6 +159,8 @@ impl AccountsPackage {
/// Create a new Accounts Package where basically every field is defaulted.
/// Only use for tests; many of the fields are invalid!
pub fn default_for_tests() -> Self {
let accounts_db = AccountsDb::default_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
Self {
package_kind: AccountsPackageKind::AccountsHashVerifier,
slot: Slot::default(),
@ -166,7 +168,7 @@ impl AccountsPackage {
snapshot_storages: Vec::default(),
expected_capitalization: u64::default(),
accounts_hash_for_testing: Option::default(),
accounts: Arc::new(Accounts::default_for_tests()),
accounts: Arc::new(accounts),
epoch_schedule: EpochSchedule::default(),
rent_collector: RentCollector::default(),
is_incremental_accounts_hash_feature_enabled: bool::default(),