Skip to content

Commit

Permalink
Adds a direct check of the cached entries around recompilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Feb 28, 2024
1 parent 778e43c commit 4dbf912
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
8 changes: 8 additions & 0 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,14 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
}
}

/// Returns the `slot_versions` of the second level for the given program id.
pub fn get_slot_versions_for_tests(&self, key: &Pubkey) -> &[Arc<LoadedProgram>] {
self.entries
.get(key)
.map(|second_level| second_level.slot_versions.as_ref())
.unwrap_or(&[])
}

/// This function removes the given entry for the given program from the cache.
/// The function expects that the program and entry exists in the cache. Otherwise it'll panic.
fn unload_program_entry(&mut self, program: &Pubkey, remove_entry: &Arc<LoadedProgram>) {
Expand Down
38 changes: 38 additions & 0 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11935,10 +11935,48 @@ fn test_feature_activation_loaded_programs_recompilation_phase() {
// Advance the bank to middle of epoch to start the recompilation phase.
goto_end_of_slot(bank.clone());
let bank = new_bank_from_parent_with_bank_forks(&bank_forks, bank, &Pubkey::default(), 16);
let current_env = bank
.loaded_programs_cache
.read()
.unwrap()
.get_environments_for_epoch(0)
.program_runtime_v1
.clone();
let upcoming_env = bank
.loaded_programs_cache
.read()
.unwrap()
.get_environments_for_epoch(1)
.program_runtime_v1
.clone();

// Advance the bank to recompile the program.
{
let loaded_programs_cache = bank.loaded_programs_cache.read().unwrap();
let slot_versions =
loaded_programs_cache.get_slot_versions_for_tests(&program_keypair.pubkey());
assert_eq!(slot_versions.len(), 1);
assert!(Arc::ptr_eq(
&slot_versions[0].program.get_environment().unwrap(),
&current_env
));
}
goto_end_of_slot(bank.clone());
let bank = new_from_parent_with_fork_next_slot(bank, bank_forks.as_ref());
{
let loaded_programs_cache = bank.loaded_programs_cache.read().unwrap();
let slot_versions =
loaded_programs_cache.get_slot_versions_for_tests(&program_keypair.pubkey());
assert_eq!(slot_versions.len(), 2);
assert!(Arc::ptr_eq(
&slot_versions[0].program.get_environment().unwrap(),
&current_env
));
assert!(Arc::ptr_eq(
&slot_versions[1].program.get_environment().unwrap(),
&upcoming_env
));
}

// Advance the bank to cross the epoch boundary and activate the feature.
goto_end_of_slot(bank.clone());
Expand Down

0 comments on commit 4dbf912

Please sign in to comment.