From f1a411c8975c65a089895d5dc15382a27d360a71 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Thu, 24 Mar 2022 09:39:22 -0500 Subject: [PATCH] add epoch_schedule and rent_collector to hash calc (#23857) --- accounts-bench/src/main.rs | 1 + runtime/benches/accounts.rs | 4 +++- runtime/src/accounts.rs | 13 ++++++++++--- runtime/src/accounts_db.rs | 31 +++++++++++++++++++++++++++---- runtime/src/bank.rs | 11 ++++++++--- 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/accounts-bench/src/main.rs b/accounts-bench/src/main.rs index 6e0a92a2f..c2f5bbf50 100644 --- a/accounts-bench/src/main.rs +++ b/accounts-bench/src/main.rs @@ -125,6 +125,7 @@ fn main() { None, false, None, + None, false, ); time_store.stop(); diff --git a/runtime/benches/accounts.rs b/runtime/benches/accounts.rs index 2d63763c7..bd95d831f 100644 --- a/runtime/benches/accounts.rs +++ b/runtime/benches/accounts.rs @@ -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, )) }); } diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 24dabe3ff..80d2e5778 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -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 diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index dc96e056f..e66f7ac3d 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -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, can_cached_slot_be_unflushed: bool, - slots_per_epoch: Option, + 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, )?; diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index b08291603..88da129f9 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -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, ); }