Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Adds LoadedPrograms::prune_feature_set_transition().
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Jun 5, 2023
1 parent 10cb343 commit e55a582
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,36 @@ impl LoadedPrograms {
entry
}

/// On the epoch boundary this removes all programs of the outdated feature set
pub fn prune_feature_set_transition(&mut self) {
for second_level in self.entries.values_mut() {
second_level.retain(|entry| {
let retain = match &entry.program {
LoadedProgramType::Builtin(_) | LoadedProgramType::Closed => true,
LoadedProgramType::LegacyV0(program) | LoadedProgramType::LegacyV1(program)
if Arc::ptr_eq(
program.get_loader(),
&self.program_runtime_environment_v1,
) =>
{
true
}
LoadedProgramType::Unloaded(environment)
if Arc::ptr_eq(environment, &self.program_runtime_environment_v1) =>
{
true
}
_ => false,
};
if !retain {
self.stats.prunes.fetch_add(1, Ordering::Relaxed);
}
retain
});
}
self.remove_programs_with_no_entries();
}

/// Before rerooting the blockstore this removes all programs of orphan forks
pub fn prune<F: ForkGraph>(&mut self, fork_graph: &F, new_root: Slot) {
let previous_root = self.latest_root;
Expand Down
1 change: 1 addition & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7591,6 +7591,7 @@ impl Bank {
loaded_programs_cache.program_runtime_environment_v1 =
Arc::new(program_runtime_environment_v1);
}
loaded_programs_cache.prune_feature_set_transition();
}
for builtin in BUILTINS.iter() {
if let Some(feature_id) = builtin.feature_id {
Expand Down

0 comments on commit e55a582

Please sign in to comment.