diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 817508f8f6..eb3902859a 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -5529,8 +5529,8 @@ impl AccountsDb { let result = self.calculate_accounts_hash_without_index(config, &storages, timings); - // now that calculate_accounts_hash_without_index is complete, we can remove old roots - self.remove_old_roots(slot); + // now that calculate_accounts_hash_without_index is complete, we can remove old historical roots + self.remove_old_historical_roots(slot, &HashSet::default()); result } else { @@ -5771,15 +5771,15 @@ impl AccountsDb { } } - /// get rid of old original_roots - fn remove_old_roots(&self, slot: Slot) { + /// get rid of old historical roots + /// except keep those in 'keep' + fn remove_old_historical_roots(&self, current_max_root_inclusive: Slot, keep: &HashSet) { // epoch_schedule::DEFAULT_SLOTS_PER_EPOCH is a sufficient approximation for now let width = solana_sdk::epoch_schedule::DEFAULT_SLOTS_PER_EPOCH * 11 / 10; // a buffer - if slot > width { - let min_root = slot - width; - let valid_slots = HashSet::default(); + if current_max_root_inclusive > width { + let min_root = current_max_root_inclusive - width; self.accounts_index - .remove_old_original_roots(min_root, &valid_slots); + .remove_old_historical_roots(min_root, keep); } } diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index af96cb1514..979c4b8a9a 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -1751,7 +1751,7 @@ impl AccountsIndex { /// roots are removed form 'roots' as all entries in the append vec become outdated. /// This function exists to clean older entries from 'roots_original'. /// all roots < 'oldest_slot_to_keep' are removed from 'roots_original'. - pub fn remove_old_original_roots(&self, oldest_slot_to_keep: Slot, keep: &HashSet) { + pub fn remove_old_historical_roots(&self, oldest_slot_to_keep: Slot, keep: &HashSet) { let w_roots_tracker = self.roots_tracker.read().unwrap(); let mut roots = w_roots_tracker .roots_original @@ -2081,7 +2081,7 @@ pub mod tests { } #[test] - fn test_remove_old_original_roots() { + fn test_remove_old_historical_roots() { let index = AccountsIndex::::default_for_tests(); index.add_root(1, true); index.add_root(2, true); @@ -2090,12 +2090,12 @@ pub mod tests { vec![1, 2] ); let empty_hash_set = HashSet::default(); - index.remove_old_original_roots(2, &empty_hash_set); + index.remove_old_historical_roots(2, &empty_hash_set); assert_eq!( index.roots_tracker.read().unwrap().roots_original.get_all(), vec![2] ); - index.remove_old_original_roots(3, &empty_hash_set); + index.remove_old_historical_roots(3, &empty_hash_set); assert!( index .roots_tracker @@ -2116,12 +2116,12 @@ pub mod tests { index.roots_tracker.read().unwrap().roots_original.get_all(), vec![1, 2] ); - index.remove_old_original_roots(2, &hash_set_1); + index.remove_old_historical_roots(2, &hash_set_1); assert_eq!( index.roots_tracker.read().unwrap().roots_original.get_all(), vec![1, 2] ); - index.remove_old_original_roots(3, &hash_set_1); + index.remove_old_historical_roots(3, &hash_set_1); assert_eq!( index.roots_tracker.read().unwrap().roots_original.get_all(), vec![1]