diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index dac1b444ee..f08586c3df 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -47,7 +47,7 @@ use { bank::Rewrites, cache_hash_data::CacheHashData, contains::Contains, - expected_rent_collection::ExpectedRentCollection, + expected_rent_collection::{ExpectedRentCollection, SlotInfoInEpoch}, pubkey_bins::PubkeyBinCalculator24, read_only_accounts_cache::ReadOnlyAccountsCache, rent_collector::RentCollector, @@ -5544,6 +5544,8 @@ impl AccountsDb { let total_lamports = Mutex::::new(0); let stats = HashStats::default(); + let max_slot_info = SlotInfoInEpoch::new(max_slot, config.epoch_schedule); + let get_hashes = || { keys.par_chunks(chunks) .map(|pubkeys| { @@ -5588,7 +5590,7 @@ impl AccountsDb { config.epoch_schedule, config.rent_collector, &stats, - max_slot, + &max_slot_info, find_unskipped_slot, self.filler_account_suffix.as_ref(), ); @@ -6127,6 +6129,9 @@ impl AccountsDb { let find_unskipped_slot = |slot: Slot| self.find_unskipped_slot(slot, config.ancestors); + let max_slot_info = + SlotInfoInEpoch::new(storage.max_slot_inclusive(), config.epoch_schedule); + let result: Vec = self.scan_account_storage_no_bank( cache_hash_data, config, @@ -6158,7 +6163,7 @@ impl AccountsDb { config.epoch_schedule, config.rent_collector, stats, - storage.max_slot_inclusive(), + &max_slot_info, find_unskipped_slot, filler_account_suffix, ); diff --git a/runtime/src/expected_rent_collection.rs b/runtime/src/expected_rent_collection.rs index 502bf76451..537caf8c81 100644 --- a/runtime/src/expected_rent_collection.rs +++ b/runtime/src/expected_rent_collection.rs @@ -236,7 +236,6 @@ pub struct SlotInfoInEpochInner { impl SlotInfoInEpoch { /// create, populating epoch info - #[allow(dead_code)] pub fn new(slot: Slot, epoch_schedule: &EpochSchedule) -> Self { let mut result = Self::new_small(slot); result.epoch_info = Some(result.get_epoch_info(epoch_schedule)); @@ -392,7 +391,7 @@ impl ExpectedRentCollection { epoch_schedule: &EpochSchedule, rent_collector: &RentCollector, stats: &HashStats, - max_slot_in_storages_inclusive: Slot, + max_slot_in_storages_inclusive: &SlotInfoInEpoch, find_unskipped_slot: impl Fn(Slot) -> Option, filler_account_suffix: Option<&Pubkey>, ) -> Option { @@ -449,26 +448,26 @@ impl ExpectedRentCollection { storage_slot: Slot, epoch_schedule: &EpochSchedule, rent_collector_max_epoch: &RentCollector, - max_slot_in_storages_inclusive: Slot, + max_slot_in_storages_inclusive: &SlotInfoInEpoch, find_unskipped_slot: impl Fn(Slot) -> Option, filler_account_suffix: Option<&Pubkey>, ) -> Option { let mut rent_collector = rent_collector_max_epoch; - let slots_per_epoch_max_epoch = epoch_schedule.get_slots_in_epoch(rent_collector.epoch); - + let SlotInfoInEpochInner { + epoch: epoch_of_max_storage_slot, + partition_index: partition_index_from_max_slot, + slots_in_epoch: slots_per_epoch_max_epoch, + } = max_slot_in_storages_inclusive.get_epoch_info(epoch_schedule); let mut partition_from_pubkey = crate::bank::Bank::partition_from_pubkey(pubkey, slots_per_epoch_max_epoch); - let (epoch_of_max_storage_slot, partition_index_from_max_slot) = - epoch_schedule.get_epoch_and_slot_index(max_slot_in_storages_inclusive); - // now, we have to find the root that is >= the slot where this pubkey's rent would have been collected let first_slot_in_max_epoch = - max_slot_in_storages_inclusive - partition_index_from_max_slot; + max_slot_in_storages_inclusive.slot - partition_index_from_max_slot; let mut expected_rent_collection_slot_max_epoch = first_slot_in_max_epoch + partition_from_pubkey; let calculated_from_index_expected_rent_collection_slot_max_epoch = expected_rent_collection_slot_max_epoch; - if expected_rent_collection_slot_max_epoch <= max_slot_in_storages_inclusive { + if expected_rent_collection_slot_max_epoch <= max_slot_in_storages_inclusive.slot { // may need to find a valid root if let Some(find) = find_unskipped_slot(calculated_from_index_expected_rent_collection_slot_max_epoch) @@ -478,7 +477,7 @@ impl ExpectedRentCollection { } } let mut use_previous_epoch_rent_collector = false; - if expected_rent_collection_slot_max_epoch > max_slot_in_storages_inclusive { + if expected_rent_collection_slot_max_epoch > max_slot_in_storages_inclusive.slot { // max slot has not hit the slot in the max epoch where we would have collected rent yet, so the most recent rent-collected rewrite slot for this pubkey would be in the previous epoch let previous_epoch = epoch_of_max_storage_slot.saturating_sub(1); let slots_per_epoch_previous_epoch = epoch_schedule.get_slots_in_epoch(previous_epoch); @@ -609,7 +608,7 @@ pub mod tests { storage_slot, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, None, ); @@ -637,7 +636,7 @@ pub mod tests { storage_slot, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, None, ); @@ -662,7 +661,7 @@ pub mod tests { expected_rent_collection_slot_max_epoch, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, None, ); @@ -690,7 +689,7 @@ pub mod tests { expected_rent_collection_slot_max_epoch + if greater { 1 } else { 0 }, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, None, ); @@ -716,7 +715,11 @@ pub mod tests { expected_rent_collection_slot_max_epoch, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive + if previous_epoch { slots_per_epoch } else { 0 }, + &SlotInfoInEpoch::new( + max_slot_in_storages_inclusive + + if previous_epoch { slots_per_epoch } else { 0 }, + &epoch_schedule, + ), find_unskipped_slot, None, ); @@ -750,7 +753,7 @@ pub mod tests { expected_rent_collection_slot_max_epoch, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, None, ); @@ -790,7 +793,7 @@ pub mod tests { storage_slot, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, None, ); @@ -840,7 +843,7 @@ pub mod tests { storage_slot, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, None, ); @@ -883,7 +886,7 @@ pub mod tests { storage_slot, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, None, ); @@ -916,7 +919,7 @@ pub mod tests { storage_slot, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, None, ); @@ -1051,7 +1054,7 @@ pub mod tests { storage_slot, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, None, ); @@ -1087,7 +1090,7 @@ pub mod tests { storage_slot, &epoch_schedule, &rent_collector, - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, // treat this pubkey like a filler account so we get a 'LeaveAloneNoRent' result Some(&pubkey), @@ -1119,7 +1122,7 @@ pub mod tests { &epoch_schedule, &rent_collector, &HashStats::default(), - max_slot_in_storages_inclusive, + &SlotInfoInEpoch::new(max_slot_in_storages_inclusive, &epoch_schedule), find_unskipped_slot, None, );