Refactors Accounts constructors (#34466)
This commit is contained in:
parent
36c1bbfe12
commit
e79c09bdc4
|
@ -12,7 +12,7 @@ edition = { workspace = true }
|
|||
clap = { workspace = true }
|
||||
log = { workspace = true }
|
||||
rayon = { workspace = true }
|
||||
solana-accounts-db = { workspace = true }
|
||||
solana-accounts-db = { workspace = true, features = ["dev-context-only-utils"] }
|
||||
solana-logger = { workspace = true }
|
||||
solana-measure = { workspace = true }
|
||||
solana-sdk = { workspace = true }
|
||||
|
@ -20,3 +20,6 @@ solana-version = { workspace = true }
|
|||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[features]
|
||||
dev-context-only-utils = []
|
||||
|
|
|
@ -1,9 +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,
|
||||
ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS, ACCOUNTS_DB_CONFIG_FOR_TESTING,
|
||||
},
|
||||
accounts_index::{
|
||||
AccountSecondaryIndexes, IndexKey, ScanConfig, ScanError, ScanResult, ZeroLamport,
|
||||
|
@ -125,41 +126,7 @@ pub enum AccountAddressFilter {
|
|||
|
||||
impl Accounts {
|
||||
pub fn default_for_tests() -> Self {
|
||||
Self::new_empty(AccountsDb::default_for_tests())
|
||||
}
|
||||
|
||||
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(),
|
||||
)
|
||||
Self::new(Arc::new(AccountsDb::default_for_tests()))
|
||||
}
|
||||
|
||||
pub fn new_with_config(
|
||||
|
@ -171,7 +138,7 @@ impl Accounts {
|
|||
accounts_update_notifier: Option<AccountsUpdateNotifier>,
|
||||
exit: Arc<AtomicBool>,
|
||||
) -> Self {
|
||||
Self::new_empty(AccountsDb::new_with_config(
|
||||
Self::new(Arc::new(AccountsDb::new_with_config(
|
||||
paths,
|
||||
cluster_type,
|
||||
account_indexes,
|
||||
|
@ -179,11 +146,7 @@ impl Accounts {
|
|||
accounts_db_config,
|
||||
accounts_update_notifier,
|
||||
exit,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_empty(accounts_db: AccountsDb) -> Self {
|
||||
Self::new(Arc::new(accounts_db))
|
||||
)))
|
||||
}
|
||||
|
||||
pub fn new(accounts_db: Arc<AccountsDb>) -> Self {
|
||||
|
@ -834,6 +797,44 @@ 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,
|
||||
|
|
|
@ -620,7 +620,7 @@ where
|
|||
bank_fields.incremental_snapshot_persistence.as_ref(),
|
||||
)?;
|
||||
|
||||
let bank_rc = BankRc::new(Accounts::new_empty(accounts_db), bank_fields.slot);
|
||||
let bank_rc = BankRc::new(Accounts::new(Arc::new(accounts_db)), bank_fields.slot);
|
||||
let runtime_config = Arc::new(runtime_config.clone());
|
||||
|
||||
// if limit_load_slot_count_from_snapshot is set, then we need to side-step some correctness checks beneath this call
|
||||
|
|
|
@ -260,7 +260,7 @@ mod serde_snapshot_tests {
|
|||
let buf = writer.into_inner();
|
||||
let mut reader = BufReader::new(&buf[..]);
|
||||
let (_accounts_dir, daccounts_paths) = get_temp_accounts_paths(2).unwrap();
|
||||
let daccounts = Accounts::new_empty(
|
||||
let daccounts = Accounts::new(Arc::new(
|
||||
accountsdb_from_stream(
|
||||
serde_style,
|
||||
&mut reader,
|
||||
|
@ -268,7 +268,7 @@ mod serde_snapshot_tests {
|
|||
storage_and_next_append_vec_id,
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
));
|
||||
check_accounts_local(&daccounts, &pubkeys, 100);
|
||||
let daccounts_delta_hash = daccounts.accounts_db.calculate_accounts_delta_hash(slot);
|
||||
assert_eq!(accounts_delta_hash, daccounts_delta_hash);
|
||||
|
|
|
@ -29,6 +29,7 @@ source ci/rust-version.sh nightly
|
|||
# reason to bend dev-context-only-utils's original intention and that listed
|
||||
# package isn't part of released binaries.
|
||||
declare tainted_packages=(
|
||||
solana-accounts-bench
|
||||
solana-banking-bench
|
||||
solana-ledger-tool
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue