Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
calculate_capitalization uses hash calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed May 28, 2021
1 parent 4e5657b commit 05eef8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 9 additions & 3 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,12 @@ impl Accounts {
.collect()
}

pub fn calculate_capitalization(&self, ancestors: &Ancestors) -> u64 {
self.accounts_db.unchecked_scan_accounts(
pub fn calculate_capitalization(&self, ancestors: &Ancestors, slot: Slot) -> u64 {
let cap = self
.accounts_db
.update_accounts_hash_with_index_option(false, false, slot, ancestors, None)
.1;
let cap2 = self.accounts_db.unchecked_scan_accounts(
"calculate_capitalization_scan_elapsed",
ancestors,
|total_capitalization: &mut u64, (_pubkey, loaded_account, _slot)| {
Expand All @@ -632,7 +636,9 @@ impl Accounts {
);
}
},
)
);
assert_eq!(cap, cap2);
cap2
}

#[must_use]
Expand Down
4 changes: 3 additions & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4560,7 +4560,9 @@ impl Bank {
}

pub fn calculate_capitalization(&self) -> u64 {
self.rc.accounts.calculate_capitalization(&self.ancestors)
self.rc
.accounts
.calculate_capitalization(&self.ancestors, self.slot())
}

pub fn calculate_and_verify_capitalization(&self) -> bool {
Expand Down

0 comments on commit 05eef8f

Please sign in to comment.