Struct solana_runtime::accounts::Accounts
source · pub struct Accounts {
pub accounts_db: Arc<AccountsDb>,
pub(crate) account_locks: Mutex<AccountLocks>,
}
Expand description
This structure handles synchronization for db
Fields§
§accounts_db: Arc<AccountsDb>
Single global AccountsDb
account_locks: Mutex<AccountLocks>
set of read-only and writable accounts which are currently being processed by banking/replay threads
Implementations§
source§impl Accounts
impl Accounts
pub fn default_for_tests() -> Self
pub fn new_with_config_for_tests( paths: Vec<PathBuf>, cluster_type: &ClusterType, account_indexes: AccountSecondaryIndexes, shrink_ratio: AccountShrinkThreshold ) -> Self
pub fn new_with_config_for_benches( paths: Vec<PathBuf>, cluster_type: &ClusterType, account_indexes: AccountSecondaryIndexes, shrink_ratio: AccountShrinkThreshold ) -> Self
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
pub(crate) fn new_empty(accounts_db: AccountsDb) -> Self
pub(crate) fn new(accounts_db: Arc<AccountsDb>) -> Self
fn construct_instructions_account( message: &SanitizedMessage, is_owned_by_sysvar: bool ) -> AccountSharedData
sourcefn get_requested_loaded_accounts_data_size_limit(
tx: &SanitizedTransaction,
feature_set: &FeatureSet
) -> Result<Option<NonZeroUsize>>
fn get_requested_loaded_accounts_data_size_limit( tx: &SanitizedTransaction, feature_set: &FeatureSet ) -> Result<Option<NonZeroUsize>>
If feature cap_transaction_accounts_data_size
is active, total accounts data a
transaction can load is limited to
if set_tx_loaded_accounts_data_size
instruction is not activated or not used, then
default value of 64MiB to not break anyone in Mainnet-beta today
else
user requested loaded accounts size.
Note, requesting zero bytes will result transaction error
sourcefn accumulate_and_check_loaded_account_data_size(
accumulated_loaded_accounts_data_size: &mut usize,
account_data_size: usize,
requested_loaded_accounts_data_size_limit: Option<NonZeroUsize>,
error_counters: &mut TransactionErrorMetrics
) -> Result<()>
fn accumulate_and_check_loaded_account_data_size( accumulated_loaded_accounts_data_size: &mut usize, account_data_size: usize, requested_loaded_accounts_data_size_limit: Option<NonZeroUsize>, error_counters: &mut TransactionErrorMetrics ) -> Result<()>
Accumulate loaded account data size into accumulated_accounts_data_size
.
Returns TransactionErr::MaxLoadedAccountsDataSizeExceeded if
requested_loaded_accounts_data_size_limit
is specified and
accumulated_accounts_data_size
exceeds it.
fn load_transaction_accounts( &self, ancestors: &Ancestors, tx: &SanitizedTransaction, fee: u64, error_counters: &mut TransactionErrorMetrics, rent_collector: &RentCollector, feature_set: &FeatureSet, account_overrides: Option<&AccountOverrides>, program_accounts: &HashMap<Pubkey, &Pubkey>, loaded_programs: &HashMap<Pubkey, Arc<LoadedProgram>> ) -> Result<LoadedTransaction>
fn validate_fee_payer( payer_address: &Pubkey, payer_account: &mut AccountSharedData, payer_index: IndexOfAccount, error_counters: &mut TransactionErrorMetrics, rent_collector: &RentCollector, feature_set: &FeatureSet, fee: u64 ) -> Result<()>
sourcepub fn filter_executable_program_accounts<'a>(
&self,
ancestors: &Ancestors,
txs: &[SanitizedTransaction],
lock_results: &mut [TransactionCheckResult],
program_owners: &[&'a Pubkey],
hash_queue: &BlockhashQueue
) -> HashMap<Pubkey, &'a Pubkey>
pub fn filter_executable_program_accounts<'a>( &self, ancestors: &Ancestors, txs: &[SanitizedTransaction], lock_results: &mut [TransactionCheckResult], program_owners: &[&'a Pubkey], hash_queue: &BlockhashQueue ) -> HashMap<Pubkey, &'a Pubkey>
Returns a hash map of executable program accounts (program accounts that are not writable in the given transactions), and their owners, for the transactions with a valid blockhash or nonce.
pub fn load_accounts( &self, ancestors: &Ancestors, txs: &[SanitizedTransaction], lock_results: Vec<TransactionCheckResult>, hash_queue: &BlockhashQueue, error_counters: &mut TransactionErrorMetrics, rent_collector: &RentCollector, feature_set: &FeatureSet, fee_structure: &FeeStructure, account_overrides: Option<&AccountOverrides>, program_accounts: &HashMap<Pubkey, &Pubkey>, loaded_programs: &HashMap<Pubkey, Arc<LoadedProgram>> ) -> Vec<TransactionLoadResult>
pub fn load_lookup_table_addresses( &self, ancestors: &Ancestors, address_table_lookup: &MessageAddressTableLookup, slot_hashes: &SlotHashes ) -> Result<LoadedAddresses, AddressLookupError>
sourcefn load_slow(
&self,
ancestors: &Ancestors,
pubkey: &Pubkey,
load_hint: LoadHint
) -> Option<(AccountSharedData, Slot)>
fn load_slow( &self, ancestors: &Ancestors, pubkey: &Pubkey, load_hint: LoadHint ) -> Option<(AccountSharedData, Slot)>
Slow because lock is held for 1 operation instead of many This always returns None for zero-lamport accounts.
pub fn load_with_fixed_root( &self, ancestors: &Ancestors, pubkey: &Pubkey ) -> Option<(AccountSharedData, Slot)>
pub fn load_without_fixed_root( &self, ancestors: &Ancestors, pubkey: &Pubkey ) -> Option<(AccountSharedData, Slot)>
sourcepub fn scan_slot<F, B>(&self, slot: Slot, func: F) -> Vec<B>where
F: Fn(LoadedAccount<'_>) -> Option<B> + Send + Sync,
B: Sync + Send + Default + Eq,
pub fn scan_slot<F, B>(&self, slot: Slot, func: F) -> Vec<B>where F: Fn(LoadedAccount<'_>) -> Option<B> + Send + Sync, B: Sync + Send + Default + Eq,
scans underlying accounts_db for this delta (slot) with a map function from LoadedAccount to B returns only the latest/current version of B for this slot
pub fn load_by_program_slot( &self, slot: Slot, program_id: Option<&Pubkey> ) -> Vec<TransactionAccount>
pub fn load_largest_accounts( &self, ancestors: &Ancestors, bank_id: BankId, num: usize, filter_by_address: &HashSet<Pubkey>, filter: AccountAddressFilter ) -> ScanResult<Vec<(Pubkey, u64)>>
sourcepub fn verify_accounts_hash_and_lamports(
&self,
slot: Slot,
total_lamports: u64,
base: Option<(Slot, u64)>,
config: VerifyAccountsHashAndLamportsConfig<'_>
) -> bool
pub fn verify_accounts_hash_and_lamports( &self, slot: Slot, total_lamports: u64, base: Option<(Slot, u64)>, config: VerifyAccountsHashAndLamportsConfig<'_> ) -> bool
Only called from startup or test code.
pub fn is_loadable(lamports: u64) -> bool
fn load_while_filtering<F: Fn(&AccountSharedData) -> bool>( collector: &mut Vec<TransactionAccount>, some_account_tuple: Option<(&Pubkey, AccountSharedData, Slot)>, filter: F )
fn load_with_slot( collector: &mut Vec<PubkeyAccountSlot>, some_account_tuple: Option<(&Pubkey, AccountSharedData, Slot)> )
pub fn load_by_program( &self, ancestors: &Ancestors, bank_id: BankId, program_id: &Pubkey, config: &ScanConfig ) -> ScanResult<Vec<TransactionAccount>>
pub fn load_by_program_with_filter<F: Fn(&AccountSharedData) -> bool>( &self, ancestors: &Ancestors, bank_id: BankId, program_id: &Pubkey, filter: F, config: &ScanConfig ) -> ScanResult<Vec<TransactionAccount>>
fn calc_scan_result_size(account: &AccountSharedData) -> usize
sourcefn accumulate_and_check_scan_result_size(
sum: &AtomicUsize,
account: &AccountSharedData,
byte_limit_for_scan: &Option<usize>
) -> bool
fn accumulate_and_check_scan_result_size( sum: &AtomicUsize, account: &AccountSharedData, byte_limit_for_scan: &Option<usize> ) -> bool
Accumulate size of (pubkey + account) into sum. Return true iff sum > ‘byte_limit_for_scan’
fn maybe_abort_scan( result: ScanResult<Vec<TransactionAccount>>, config: &ScanConfig ) -> ScanResult<Vec<TransactionAccount>>
pub fn load_by_index_key_with_filter<F: Fn(&AccountSharedData) -> bool>( &self, ancestors: &Ancestors, bank_id: BankId, index_key: &IndexKey, filter: F, config: &ScanConfig, byte_limit_for_scan: Option<usize> ) -> ScanResult<Vec<TransactionAccount>>
pub fn account_indexes_include_key(&self, key: &Pubkey) -> bool
pub fn load_all( &self, ancestors: &Ancestors, bank_id: BankId ) -> ScanResult<Vec<PubkeyAccountSlot>>
pub fn scan_all<F>( &self, ancestors: &Ancestors, bank_id: BankId, scan_func: F ) -> ScanResult<()>where F: FnMut(Option<(&Pubkey, AccountSharedData, Slot)>),
pub fn hold_range_in_memory<R>( &self, range: &R, start_holding: bool, thread_pool: &ThreadPool )where R: RangeBounds<Pubkey> + Debug + Sync,
pub fn load_to_collect_rent_eagerly<R: RangeBounds<Pubkey> + Debug>( &self, ancestors: &Ancestors, range: R ) -> Vec<PubkeyAccountSlot>
sourcepub fn store_slow_uncached(
&self,
slot: Slot,
pubkey: &Pubkey,
account: &AccountSharedData
)
pub fn store_slow_uncached( &self, slot: Slot, pubkey: &Pubkey, account: &AccountSharedData )
Slow because lock is held for 1 operation instead of many. WARNING: This noncached version is only to be used for tests/benchmarking as bypassing the cache in general is not supported
fn lock_account( &self, account_locks: &mut AccountLocks, writable_keys: Vec<&Pubkey>, readonly_keys: Vec<&Pubkey> ) -> Result<()>
fn unlock_account( &self, account_locks: &mut AccountLocks, writable_keys: Vec<&Pubkey>, readonly_keys: Vec<&Pubkey> )
sourcepub fn lock_accounts<'a>(
&self,
txs: impl Iterator<Item = &'a SanitizedTransaction>,
tx_account_lock_limit: usize
) -> Vec<Result<()>>
pub fn lock_accounts<'a>( &self, txs: impl Iterator<Item = &'a SanitizedTransaction>, tx_account_lock_limit: usize ) -> Vec<Result<()>>
This function will prevent multiple threads from modifying the same account state at the same time
pub fn lock_accounts_with_results<'a>( &self, txs: impl Iterator<Item = &'a SanitizedTransaction>, results: impl Iterator<Item = &'a Result<()>>, tx_account_lock_limit: usize ) -> Vec<Result<()>>
fn lock_accounts_inner( &self, tx_account_locks_results: Vec<Result<TransactionAccountLocks<'_>>> ) -> Vec<Result<()>>
sourcepub fn unlock_accounts<'a>(
&self,
txs: impl Iterator<Item = &'a SanitizedTransaction>,
results: &[Result<()>]
)
pub fn unlock_accounts<'a>( &self, txs: impl Iterator<Item = &'a SanitizedTransaction>, results: &[Result<()>] )
Once accounts are unlocked, new transactions that modify that state can enter the pipeline
sourcepub(crate) fn store_cached(
&self,
slot: Slot,
txs: &[SanitizedTransaction],
res: &[TransactionExecutionResult],
loaded: &mut [TransactionLoadResult],
rent_collector: &RentCollector,
durable_nonce: &DurableNonce,
lamports_per_signature: u64,
include_slot_in_hash: IncludeSlotInHash
)
pub(crate) fn store_cached( &self, slot: Slot, txs: &[SanitizedTransaction], res: &[TransactionExecutionResult], loaded: &mut [TransactionLoadResult], rent_collector: &RentCollector, durable_nonce: &DurableNonce, lamports_per_signature: u64, include_slot_in_hash: IncludeSlotInHash )
Store the accounts into the DB
pub fn store_accounts_cached<'a, T: ReadableAccount + Sync + ZeroLamport + 'a>( &self, accounts: impl StorableAccounts<'a, T> )
sourcepub fn add_root(&self, slot: Slot) -> AccountsAddRootTiming
pub fn add_root(&self, slot: Slot) -> AccountsAddRootTiming
Add a slot to root. Root slots cannot be purged