add epoch_schedule and rent_collector to hash calc (#23857)

This commit is contained in:
Jeff Washington (jwash) 2022-03-24 09:39:22 -05:00 committed by GitHub
parent db5d68f01f
commit f1a411c897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 11 deletions

View File

@ -125,6 +125,7 @@ fn main() {
None,
false,
None,
None,
false,
);
time_store.stop();

View File

@ -114,7 +114,9 @@ fn test_accounts_hash_bank_hash(bencher: &mut Bencher) {
0,
&ancestors,
total_lamports,
test_hash_calculation
test_hash_calculation,
None,
None,
))
});
}

View File

@ -42,7 +42,7 @@ use {
pubkey::Pubkey,
slot_hashes::SlotHashes,
system_program,
sysvar::{self, instructions::construct_instructions_data},
sysvar::{self, epoch_schedule::EpochSchedule, instructions::construct_instructions_data},
transaction::{Result, SanitizedTransaction, TransactionAccountLocks, TransactionError},
transaction_context::TransactionAccount,
},
@ -747,6 +747,8 @@ impl Accounts {
slot: Slot,
can_cached_slot_be_unflushed: bool,
debug_verify: bool,
epoch_schedule: Option<&EpochSchedule>,
rent_collector: Option<&RentCollector>,
) -> u64 {
let use_index = false;
let is_startup = false; // there may be conditions where this is called at startup.
@ -758,7 +760,8 @@ impl Accounts {
ancestors,
None,
can_cached_slot_be_unflushed,
None,
epoch_schedule,
rent_collector,
is_startup,
)
.1
@ -772,12 +775,16 @@ impl Accounts {
ancestors: &Ancestors,
total_lamports: u64,
test_hash_calculation: bool,
epoch_schedule: Option<&EpochSchedule>,
rent_collector: Option<&RentCollector>,
) -> bool {
if let Err(err) = self.accounts_db.verify_bank_hash_and_lamports(
if let Err(err) = self.accounts_db.verify_bank_hash_and_lamports_new(
slot,
ancestors,
total_lamports,
test_hash_calculation,
epoch_schedule,
rent_collector,
) {
warn!("verify_bank_hash failed: {:?}", err);
false

View File

@ -5233,13 +5233,13 @@ impl AccountsDb {
pub fn update_accounts_hash(&self, slot: Slot, ancestors: &Ancestors) -> (Hash, u64) {
self.update_accounts_hash_with_index_option(
true, false, slot, ancestors, None, false, None, false,
true, false, slot, ancestors, None, false, None, None, false,
)
}
pub fn update_accounts_hash_test(&self, slot: Slot, ancestors: &Ancestors) -> (Hash, u64) {
self.update_accounts_hash_with_index_option(
true, true, slot, ancestors, None, false, None, false,
true, true, slot, ancestors, None, false, None, None, false,
)
}
@ -5575,6 +5575,7 @@ impl AccountsDb {
Ok((hash, total_lamports))
}
#[allow(clippy::too_many_arguments)]
pub fn update_accounts_hash_with_index_option(
&self,
use_index: bool,
@ -5583,10 +5584,12 @@ impl AccountsDb {
ancestors: &Ancestors,
expected_capitalization: Option<u64>,
can_cached_slot_be_unflushed: bool,
slots_per_epoch: Option<Slot>,
epoch_schedule: Option<&EpochSchedule>,
_rent_collector: Option<&RentCollector>,
is_startup: bool,
) -> (Hash, u64) {
let check_hash = false;
let slots_per_epoch = epoch_schedule.map(|epoch_schedule| epoch_schedule.slots_per_epoch);
let (hash, total_lamports) = self
.calculate_accounts_hash_helper_with_verify(
use_index,
@ -5782,6 +5785,26 @@ impl AccountsDb {
ancestors: &Ancestors,
total_lamports: u64,
test_hash_calculation: bool,
) -> Result<(), BankHashVerificationError> {
self.verify_bank_hash_and_lamports_new(
slot,
ancestors,
total_lamports,
test_hash_calculation,
None,
None,
)
}
/// Only called from startup or test code.
pub fn verify_bank_hash_and_lamports_new(
&self,
slot: Slot,
ancestors: &Ancestors,
total_lamports: u64,
test_hash_calculation: bool,
_epoch_schedule: Option<&EpochSchedule>,
_rent_collector: Option<&RentCollector>,
) -> Result<(), BankHashVerificationError> {
use BankHashVerificationError::*;
@ -5798,7 +5821,7 @@ impl AccountsDb {
None,
can_cached_slot_be_unflushed,
check_hash,
None,
None, // could use epoch_schedule.slots_per_epoch here
is_startup,
)?;

View File

@ -5857,6 +5857,8 @@ impl Bank {
&self.ancestors,
self.capitalization(),
test_hash_calculation,
Some(self.epoch_schedule()),
Some(&self.rent_collector),
)
}
@ -5924,6 +5926,8 @@ impl Bank {
self.slot(),
can_cached_slot_be_unflushed,
debug_verify,
Some(self.epoch_schedule()),
Some(&self.rent_collector),
)
}
@ -5965,7 +5969,6 @@ impl Bank {
mut debug_verify: bool,
is_startup: bool,
) -> Hash {
let slots_per_epoch = Some(self.epoch_schedule().get_slots_in_epoch(self.epoch));
let (hash, total_lamports) = self
.rc
.accounts
@ -5977,7 +5980,8 @@ impl Bank {
&self.ancestors,
Some(self.capitalization()),
false,
slots_per_epoch,
Some(self.epoch_schedule()),
Some(&self.rent_collector),
is_startup,
);
if total_lamports != self.capitalization() {
@ -6002,7 +6006,8 @@ impl Bank {
&self.ancestors,
Some(self.capitalization()),
false,
slots_per_epoch,
Some(self.epoch_schedule()),
Some(&self.rent_collector),
is_startup,
);
}