Check bank capitalization (#11927)

* Check bank capitalization

* Simplify and unify capitalization calculation

* Improve and add tests

* Avoid overflow and inhibit automatic restart

* Fix test

* Tweak checked sum for cap. and add tests

* Fix broken build after merge conflicts..

* Rename to ClusterType

* Rename confusing method

* Clarify comment

* Verify cap. in rent and inflation tests

Co-authored-by: Stephen Akridge <sakridge@gmail.com>
This commit is contained in:
Ryo Onodera
2020-09-12 01:48:06 +09:00
committed by GitHub
parent f27665662c
commit de4a613610
12 changed files with 360 additions and 98 deletions

View File

@@ -428,9 +428,32 @@ impl Accounts {
accounts_balances
}
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,
)
});
AccountsDB::checked_sum_for_capitalization(balances)
}
#[must_use]
pub fn verify_bank_hash(&self, slot: Slot, ancestors: &Ancestors) -> bool {
if let Err(err) = self.accounts_db.verify_bank_hash(slot, ancestors) {
pub fn verify_bank_hash_and_lamports(
&self,
slot: Slot,
ancestors: &Ancestors,
total_lamports: u64,
) -> bool {
if let Err(err) =
self.accounts_db
.verify_bank_hash_and_lamports(slot, ancestors, total_lamports)
{
warn!("verify_bank_hash failed: {:?}", err);
false
} else {
@@ -460,13 +483,13 @@ impl Accounts {
pub fn load_by_program(
&self,
ancestors: &Ancestors,
program_id: Option<&Pubkey>,
program_id: &Pubkey,
) -> Vec<(Pubkey, Account)> {
self.accounts_db.scan_accounts(
ancestors,
|collector: &mut Vec<(Pubkey, Account)>, some_account_tuple| {
Self::load_while_filtering(collector, some_account_tuple, |account| {
program_id.is_none() || Some(&account.owner) == program_id
account.owner == *program_id
})
},
)