Remove associated functions on AccountsDb, replace with methods (#13953)

Co-authored-by: Carl Lin <carl@solana.com>
This commit is contained in:
carllin 2020-12-03 17:53:42 -08:00 committed by GitHub
parent f2b31c3a89
commit 5dceddd21d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 57 deletions

View File

@ -1,8 +1,6 @@
use crate::{ use crate::{
accounts_db::{ accounts_db::{AccountsDB, AppendVecId, BankHashInfo, ErrorCounters},
AccountInfo, AccountStorage, AccountsDB, AppendVecId, BankHashInfo, ErrorCounters, accounts_index::Ancestors,
},
accounts_index::{AccountsIndex, Ancestors},
append_vec::StoredAccount, append_vec::StoredAccount,
bank::{ bank::{
NonceRollbackFull, NonceRollbackInfo, TransactionCheckResult, TransactionExecutionResult, NonceRollbackFull, NonceRollbackInfo, TransactionCheckResult, TransactionExecutionResult,
@ -130,9 +128,7 @@ impl Accounts {
fn load_tx_accounts( fn load_tx_accounts(
&self, &self,
storage: &AccountStorage,
ancestors: &Ancestors, ancestors: &Ancestors,
accounts_index: &AccountsIndex<AccountInfo>,
tx: &Transaction, tx: &Transaction,
fee: u64, fee: u64,
error_counters: &mut ErrorCounters, error_counters: &mut ErrorCounters,
@ -165,22 +161,22 @@ impl Accounts {
} }
Self::construct_instructions_account(message) Self::construct_instructions_account(message)
} else { } else {
let (account, rent) = let (account, rent) = self
AccountsDB::load(storage, ancestors, accounts_index, key) .accounts_db
.map(|(mut account, _)| { .load(ancestors, key)
if message.is_writable(i) { .map(|(mut account, _)| {
let rent_due = rent_collector if message.is_writable(i) {
.collect_from_existing_account( let rent_due = rent_collector.collect_from_existing_account(
&key, &key,
&mut account, &mut account,
rent_fix_enabled, rent_fix_enabled,
); );
(account, rent_due) (account, rent_due)
} else { } else {
(account, 0) (account, 0)
} }
}) })
.unwrap_or_default(); .unwrap_or_default();
tx_rent += rent; tx_rent += rent;
account account
@ -228,9 +224,8 @@ impl Accounts {
} }
fn load_executable_accounts( fn load_executable_accounts(
storage: &AccountStorage, &self,
ancestors: &Ancestors, ancestors: &Ancestors,
accounts_index: &AccountsIndex<AccountInfo>,
program_id: &Pubkey, program_id: &Pubkey,
error_counters: &mut ErrorCounters, error_counters: &mut ErrorCounters,
) -> Result<Vec<(Pubkey, Account)>> { ) -> Result<Vec<(Pubkey, Account)>> {
@ -249,7 +244,9 @@ impl Accounts {
} }
depth += 1; depth += 1;
let program = match AccountsDB::load(storage, ancestors, accounts_index, &program_id) let program = match self
.accounts_db
.load(ancestors, &program_id)
.map(|(account, _)| account) .map(|(account, _)| account)
{ {
Some(program) => program, Some(program) => program,
@ -273,9 +270,8 @@ impl Accounts {
/// For each program_id in the transaction, load its loaders. /// For each program_id in the transaction, load its loaders.
fn load_loaders( fn load_loaders(
storage: &AccountStorage, &self,
ancestors: &Ancestors, ancestors: &Ancestors,
accounts_index: &AccountsIndex<AccountInfo>,
tx: &Transaction, tx: &Transaction,
error_counters: &mut ErrorCounters, error_counters: &mut ErrorCounters,
) -> Result<TransactionLoaders> { ) -> Result<TransactionLoaders> {
@ -289,13 +285,7 @@ impl Accounts {
return Err(TransactionError::AccountNotFound); return Err(TransactionError::AccountNotFound);
} }
let program_id = message.account_keys[ix.program_id_index as usize]; let program_id = message.account_keys[ix.program_id_index as usize];
Self::load_executable_accounts( self.load_executable_accounts(ancestors, &program_id, error_counters)
storage,
ancestors,
accounts_index,
&program_id,
error_counters,
)
}) })
.collect() .collect()
} }
@ -311,8 +301,6 @@ impl Accounts {
rent_collector: &RentCollector, rent_collector: &RentCollector,
feature_set: &FeatureSet, feature_set: &FeatureSet,
) -> Vec<TransactionLoadResult> { ) -> Vec<TransactionLoadResult> {
let accounts_index = &self.accounts_db.accounts_index;
let fee_config = FeeConfig { let fee_config = FeeConfig {
secp256k1_program_enabled: feature_set secp256k1_program_enabled: feature_set
.is_active(&feature_set::secp256k1_program_enabled::id()), .is_active(&feature_set::secp256k1_program_enabled::id()),
@ -336,9 +324,7 @@ impl Accounts {
}; };
let load_res = self.load_tx_accounts( let load_res = self.load_tx_accounts(
&self.accounts_db.storage,
ancestors, ancestors,
accounts_index,
tx, tx,
fee, fee,
error_counters, error_counters,
@ -350,13 +336,7 @@ impl Accounts {
Err(e) => return (Err(e), None), Err(e) => return (Err(e), None),
}; };
let load_res = Self::load_loaders( let load_res = self.load_loaders(ancestors, tx, error_counters);
&self.accounts_db.storage,
ancestors,
accounts_index,
tx,
error_counters,
);
let loaders = match load_res { let loaders = match load_res {
Ok(loaders) => loaders, Ok(loaders) => loaders,
Err(e) => return (Err(e), None), Err(e) => return (Err(e), None),
@ -1549,10 +1529,8 @@ mod tests {
let ancestors = vec![(0, 0)].into_iter().collect(); let ancestors = vec![(0, 0)].into_iter().collect();
assert_eq!( assert_eq!(
Accounts::load_executable_accounts( accounts.load_executable_accounts(
&accounts.accounts_db.storage,
&ancestors, &ancestors,
&accounts.accounts_db.accounts_index,
&solana_sdk::pubkey::new_rand(), &solana_sdk::pubkey::new_rand(),
&mut error_counters &mut error_counters
), ),

View File

@ -1386,14 +1386,9 @@ impl AccountsDB {
bank_hashes.insert(slot, new_hash_info); bank_hashes.insert(slot, new_hash_info);
} }
pub fn load( pub fn load(&self, ancestors: &Ancestors, pubkey: &Pubkey) -> Option<(Account, Slot)> {
storage: &AccountStorage,
ancestors: &Ancestors,
accounts_index: &AccountsIndex<AccountInfo>,
pubkey: &Pubkey,
) -> Option<(Account, Slot)> {
let (slot, store_id, offset) = { let (slot, store_id, offset) = {
let (lock, index) = accounts_index.get(pubkey, Some(ancestors), None)?; let (lock, index) = self.accounts_index.get(pubkey, Some(ancestors), None)?;
let slot_list = lock.slot_list(); let slot_list = lock.slot_list();
let ( let (
slot, slot,
@ -1406,7 +1401,7 @@ impl AccountsDB {
}; };
//TODO: thread this as a ref //TODO: thread this as a ref
storage self.storage
.get_account_storage_entry(slot, store_id) .get_account_storage_entry(slot, store_id)
.and_then(|store| { .and_then(|store| {
store store
@ -1443,7 +1438,7 @@ impl AccountsDB {
} }
pub fn load_slow(&self, ancestors: &Ancestors, pubkey: &Pubkey) -> Option<(Account, Slot)> { pub fn load_slow(&self, ancestors: &Ancestors, pubkey: &Pubkey) -> Option<(Account, Slot)> {
Self::load(&self.storage, ancestors, &self.accounts_index, pubkey) self.load(ancestors, pubkey)
} }
fn get_account_from_storage(&self, slot: Slot, account_info: &AccountInfo) -> Option<Account> { fn get_account_from_storage(&self, slot: Slot, account_info: &AccountInfo) -> Option<Account> {