test_utils::create_test_accounts pre-allocates an append vec first (#29336)
* test_utils::create_test_accounts pre-allocates an append vec first * remove comment
This commit is contained in:
parent
0244b0144a
commit
4a64f6d421
|
@ -6,11 +6,11 @@ use {
|
|||
rayon::prelude::*,
|
||||
solana_measure::measure::Measure,
|
||||
solana_runtime::{
|
||||
accounts::{
|
||||
accounts::Accounts,
|
||||
accounts_db::{
|
||||
test_utils::{create_test_accounts, update_accounts_bench},
|
||||
Accounts,
|
||||
AccountShrinkThreshold, CalcAccountsHashDataSource,
|
||||
},
|
||||
accounts_db::{AccountShrinkThreshold, CalcAccountsHashDataSource},
|
||||
accounts_index::AccountSecondaryIndexes,
|
||||
ancestors::Ancestors,
|
||||
rent_collector::RentCollector,
|
||||
|
|
|
@ -8,8 +8,8 @@ use {
|
|||
rand::Rng,
|
||||
rayon::iter::{IntoParallelRefIterator, ParallelIterator},
|
||||
solana_runtime::{
|
||||
accounts::{test_utils::create_test_accounts, AccountAddressFilter, Accounts},
|
||||
accounts_db::AccountShrinkThreshold,
|
||||
accounts::{AccountAddressFilter, Accounts},
|
||||
accounts_db::{test_utils::create_test_accounts, AccountShrinkThreshold},
|
||||
accounts_index::{AccountSecondaryIndexes, ScanConfig},
|
||||
ancestors::Ancestors,
|
||||
bank::*,
|
||||
|
|
|
@ -27,7 +27,6 @@ use {
|
|||
DashMap,
|
||||
},
|
||||
log::*,
|
||||
rand::{thread_rng, Rng},
|
||||
solana_address_lookup_table_program::{error::AddressLookupError, state::AddressLookupTable},
|
||||
solana_program_runtime::compute_budget::ComputeBudget,
|
||||
solana_sdk::{
|
||||
|
@ -1462,36 +1461,6 @@ fn prepare_if_nonce_account(
|
|||
}
|
||||
}
|
||||
|
||||
/// A set of utility functions used for testing and benchmarking
|
||||
pub mod test_utils {
|
||||
use super::*;
|
||||
|
||||
pub fn create_test_accounts(
|
||||
accounts: &Accounts,
|
||||
pubkeys: &mut Vec<Pubkey>,
|
||||
num: usize,
|
||||
slot: Slot,
|
||||
) {
|
||||
for t in 0..num {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let account =
|
||||
AccountSharedData::new((t + 1) as u64, 0, AccountSharedData::default().owner());
|
||||
accounts.store_slow_uncached(slot, &pubkey, &account);
|
||||
pubkeys.push(pubkey);
|
||||
}
|
||||
}
|
||||
|
||||
// Only used by bench, not safe to call otherwise accounts can conflict with the
|
||||
// accounts cache!
|
||||
pub fn update_accounts_bench(accounts: &Accounts, pubkeys: &[Pubkey], slot: u64) {
|
||||
for pubkey in pubkeys {
|
||||
let amount = thread_rng().gen_range(0, 10);
|
||||
let account = AccountSharedData::new(amount, 0, AccountSharedData::default().owner());
|
||||
accounts.store_slow_uncached(slot, pubkey, &account);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use {
|
||||
|
|
|
@ -9427,6 +9427,53 @@ impl AccountsDb {
|
|||
}
|
||||
}
|
||||
|
||||
/// A set of utility functions used for testing and benchmarking
|
||||
pub mod test_utils {
|
||||
use {
|
||||
super::*,
|
||||
crate::{accounts::Accounts, append_vec::aligned_stored_size},
|
||||
};
|
||||
|
||||
pub fn create_test_accounts(
|
||||
accounts: &Accounts,
|
||||
pubkeys: &mut Vec<Pubkey>,
|
||||
num: usize,
|
||||
slot: Slot,
|
||||
) {
|
||||
let data_size = 0;
|
||||
if accounts.accounts_db.storage.get_slot_stores(slot).is_none() {
|
||||
let bytes_required = num * aligned_stored_size(data_size);
|
||||
// allocate an append vec for this slot that can hold all the test accounts. This prevents us from creating more than 1 append vec for this slot.
|
||||
_ = accounts.accounts_db.create_and_insert_store(
|
||||
slot,
|
||||
bytes_required as u64,
|
||||
"create_test_accounts",
|
||||
);
|
||||
}
|
||||
|
||||
for t in 0..num {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let account = AccountSharedData::new(
|
||||
(t + 1) as u64,
|
||||
data_size,
|
||||
AccountSharedData::default().owner(),
|
||||
);
|
||||
accounts.store_slow_uncached(slot, &pubkey, &account);
|
||||
pubkeys.push(pubkey);
|
||||
}
|
||||
}
|
||||
|
||||
// Only used by bench, not safe to call otherwise accounts can conflict with the
|
||||
// accounts cache!
|
||||
pub fn update_accounts_bench(accounts: &Accounts, pubkeys: &[Pubkey], slot: u64) {
|
||||
for pubkey in pubkeys {
|
||||
let amount = thread_rng().gen_range(0, 10);
|
||||
let account = AccountSharedData::new(amount, 0, AccountSharedData::default().owner());
|
||||
accounts.store_slow_uncached(slot, pubkey, &account);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use {
|
||||
|
|
|
@ -4,8 +4,10 @@ use {
|
|||
super::*,
|
||||
crate::{
|
||||
account_storage::AccountStorageMap,
|
||||
accounts::{test_utils::create_test_accounts, Accounts},
|
||||
accounts_db::{get_temp_accounts_paths, AccountShrinkThreshold},
|
||||
accounts::Accounts,
|
||||
accounts_db::{
|
||||
get_temp_accounts_paths, test_utils::create_test_accounts, AccountShrinkThreshold,
|
||||
},
|
||||
accounts_hash::AccountsHash,
|
||||
append_vec::AppendVec,
|
||||
bank::{Bank, BankTestConfig},
|
||||
|
|
Loading…
Reference in New Issue