Prevent scans from seeing root updates/clean (#13464) (#13686)

Co-authored-by: Carl Lin <carl@solana.com>
(cherry picked from commit 6276360468)

Co-authored-by: carllin <wumu727@gmail.com>
This commit is contained in:
mergify[bot]
2020-11-19 07:11:59 +00:00
committed by GitHub
parent 15f6b6ccd6
commit 60beb509f7
4 changed files with 301 additions and 42 deletions

View File

@@ -462,16 +462,16 @@ impl Accounts {
}
pub fn calculate_capitalization(&self, ancestors: &Ancestors) -> u64 {
let balances = self
.load_all(ancestors)
.into_iter()
.map(|(_pubkey, account, _slot)| {
AccountsDB::account_balance_for_capitalization(
account.lamports,
&account.owner,
account.executable,
)
});
let balances =
self.load_all_unchecked(ancestors)
.into_iter()
.map(|(_pubkey, account, _slot)| {
AccountsDB::account_balance_for_capitalization(
account.lamports,
&account.owner,
account.executable,
)
});
AccountsDB::checked_sum_for_capitalization(balances)
}
@@ -541,6 +541,19 @@ impl Accounts {
)
}
fn load_all_unchecked(&self, ancestors: &Ancestors) -> Vec<(Pubkey, Account, Slot)> {
self.accounts_db.unchecked_scan_accounts(
ancestors,
|collector: &mut Vec<(Pubkey, Account, Slot)>, some_account_tuple| {
if let Some((pubkey, account, slot)) =
some_account_tuple.filter(|(_, account, _)| Self::is_loadable(account))
{
collector.push((*pubkey, account, slot))
}
},
)
}
pub fn load_to_collect_rent_eagerly<R: RangeBounds<Pubkey>>(
&self,
ancestors: &Ancestors,