From e9ab2142371a98b207819007e5bdc0663c5a164e Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Thu, 28 Oct 2021 10:26:30 -0500 Subject: [PATCH] filler accts: only add filler accts to slots in the current epoch (#21024) --- runtime/src/accounts_db.rs | 21 +++++++++++++++++++-- runtime/src/bank.rs | 6 ++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 82dffb269f..8f27563f37 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -52,7 +52,7 @@ use solana_measure::measure::Measure; use solana_rayon_threadlimit::get_thread_count; use solana_sdk::{ account::{AccountSharedData, ReadableAccount}, - clock::{BankId, Epoch, Slot}, + clock::{BankId, Epoch, Slot, SlotCount}, epoch_schedule::EpochSchedule, genesis_config::ClusterType, hash::{Hash, Hasher}, @@ -6761,6 +6761,14 @@ impl AccountsDb { Self::is_filler_account_helper(pubkey, self.filler_account_suffix.as_ref()) } + /// retain slots in 'roots' that are > (max(roots) - slots_per_epoch) + fn retain_roots_within_one_epoch_range(roots: &mut Vec, slots_per_epoch: SlotCount) { + if let Some(max) = roots.iter().max() { + let min = max - slots_per_epoch; + roots.retain(|slot| slot > &min); + } + } + /// filler accounts are space-holding accounts which are ignored by hash calculations and rent. /// They are designed to allow a validator to run against a network successfully while simulating having many more accounts present. /// All filler accounts share a common pubkey suffix. The suffix is randomly generated per validator on startup. @@ -6775,7 +6783,8 @@ impl AccountsDb { info!("adding {} filler accounts", self.filler_account_count); // break this up to force the accounts out of memory after each pass let passes = 100; - let roots = self.storage.all_slots(); + let mut roots = self.storage.all_slots(); + Self::retain_roots_within_one_epoch_range(&mut roots, epoch_schedule.slots_per_epoch); let root_count = roots.len(); let per_pass = std::cmp::max(1, root_count / passes); let overall_index = AtomicUsize::new(0); @@ -7374,6 +7383,14 @@ pub mod tests { } } + #[test] + fn test_retain_roots_within_one_epoch_range() { + let mut roots = vec![0, 1, 2]; + let slots_per_epoch = 2; + AccountsDb::retain_roots_within_one_epoch_range(&mut roots, slots_per_epoch); + assert_eq!(&vec![1, 2], &roots); + } + #[test] #[should_panic( expected = "bin_range.start < bins && bin_range.end <= bins &&\\n bin_range.start < bin_range.end" diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 928da98ebc..883ee689f1 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -4546,6 +4546,8 @@ impl Bank { Self::get_partitions(self.slot(), self.parent_slot(), slot_count_in_two_day) } + /// used only by filler accounts in debug path + /// previous means slot - 1, not parent pub fn variable_cycle_partition_from_previous_slot( epoch_schedule: &EpochSchedule, slot: Slot, @@ -4630,7 +4632,7 @@ impl Bank { ) } - pub fn get_partition_from_slot_indexes( + fn get_partition_from_slot_indexes( cycle_params: RentCollectionCycleParams, start_slot_index: SlotIndex, end_slot_index: SlotIndex, @@ -4705,7 +4707,7 @@ impl Bank { self.do_partition_from_slot_indexes(start_slot_index, end_slot_index, epoch, true) } - pub fn rent_single_epoch_collection_cycle_params( + fn rent_single_epoch_collection_cycle_params( epoch: Epoch, slot_count_per_epoch: SlotCount, ) -> RentCollectionCycleParams {