From 3fd3e6d4e15271f3952d60f95436c880f66fb198 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 9 May 2023 11:28:56 -0700 Subject: [PATCH] Use current root slot to disambiguate pruning of old programs (#31548) * Use current root slot to unambiguate pruning of old programs * simplify the change * address comment --- program-runtime/src/loaded_programs.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/program-runtime/src/loaded_programs.rs b/program-runtime/src/loaded_programs.rs index 10790bef34c84e..6fee2b3849005a 100644 --- a/program-runtime/src/loaded_programs.rs +++ b/program-runtime/src/loaded_programs.rs @@ -374,6 +374,7 @@ impl LoadedPrograms { /// Before rerooting the blockstore this removes all programs of orphan forks pub fn prune(&mut self, fork_graph: &F, new_root: Slot) { + let previous_root = self.latest_root; self.entries.retain(|_key, second_level| { let mut first_ancestor_found = false; *second_level = second_level @@ -383,7 +384,10 @@ impl LoadedPrograms { let relation = fork_graph.relationship(entry.deployment_slot, new_root); if entry.deployment_slot >= new_root { matches!(relation, BlockRelation::Equal | BlockRelation::Descendant) - } else if !first_ancestor_found && matches!(relation, BlockRelation::Ancestor) { + } else if !first_ancestor_found + && (matches!(relation, BlockRelation::Ancestor) + || entry.deployment_slot < previous_root) + { first_ancestor_found = true; first_ancestor_found } else {