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

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 committed May 8, 2023
1 parent 09f5c62 commit 33bbaf5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
16 changes: 14 additions & 2 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ pub struct LoadedPrograms {
pub struct LoadedProgramsForTxBatch {
/// Pubkey is the address of a program.
/// LoadedProgram is the corresponding program entry valid for the slot in which a transaction is being executed.
pub entries: HashMap<Pubkey, Arc<LoadedProgram>>,
entries: HashMap<Pubkey, Arc<LoadedProgram>>,
slot: Slot,
}

Expand Down Expand Up @@ -321,9 +321,15 @@ impl LoadedProgramsForTxBatch {
self.slot
}

pub fn set_slot(&mut self, slot: Slot) {
pub fn set_slot_for_tests(&mut self, slot: Slot) {
self.slot = slot;
}

pub fn merge(&mut self, other: &Self) {
other.entries.iter().for_each(|(key, entry)| {
self.replenish(*key, entry.clone());
})
}
}

pub enum LoadedProgramMatchCriteria {
Expand Down Expand Up @@ -491,6 +497,12 @@ impl LoadedPrograms {
)
}

pub fn merge(&mut self, tx_batch_cache: &LoadedProgramsForTxBatch) {
tx_batch_cache.entries.iter().for_each(|(key, entry)| {
self.replenish(*key, entry.clone());
})
}

/// Unloads programs which were used infrequently
pub fn sort_and_unload(&mut self, shrink_to: PercentageInteger) {
let sorted_candidates: Vec<(Pubkey, Arc<LoadedProgram>)> = self
Expand Down
29 changes: 17 additions & 12 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,17 +1273,22 @@ fn process_loader_upgradeable_instruction(
instruction_context,
&log_collector,
)?;
let clock = invoke_context.get_sysvar_cache().get_clock()?;
invoke_context
.programs_modified_by_tx
.borrow_mut()
.replenish(
program_key,
Arc::new(LoadedProgram::new_tombstone(
clock.slot,
LoadedProgramType::Closed,
)),
);
if invoke_context
.feature_set
.is_active(&delay_visibility_of_program_deployment::id())
{
let clock = invoke_context.get_sysvar_cache().get_clock()?;
invoke_context
.programs_modified_by_tx
.borrow_mut()
.replenish(
program_key,
Arc::new(LoadedProgram::new_tombstone(
clock.slot,
LoadedProgramType::Closed,
)),
);
}
}
_ => {
ic_logger_msg!(log_collector, "Invalid Program account");
Expand Down Expand Up @@ -1706,7 +1711,7 @@ pub mod test_utils {
false,
) {
let mut cache = invoke_context.programs_modified_by_tx.borrow_mut();
cache.set_slot(DELAY_VISIBILITY_SLOT_OFFSET);
cache.set_slot_for_tests(DELAY_VISIBILITY_SLOT_OFFSET);
cache.replenish(*pubkey, Arc::new(loaded_program));
}
}
Expand Down
22 changes: 7 additions & 15 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4706,13 +4706,9 @@ impl Bank {
// Update batch specific cache of the loaded programs with the modifications
// made by the transaction, if it executed successfully.
if details.status.is_ok() {
programs_modified_by_tx.borrow().entries.iter().for_each(
|(key, entry)| {
programs_loaded_for_tx_batch
.borrow_mut()
.replenish(*key, entry.clone());
},
)
programs_loaded_for_tx_batch
.borrow_mut()
.merge(&programs_modified_by_tx.borrow());
}
}
result
Expand Down Expand Up @@ -5204,14 +5200,10 @@ impl Bank {
} = execution_result
{
if details.status.is_ok() {
let mut cache = self.loaded_programs_cache.write().unwrap();
programs_modified_by_tx
.borrow()
.entries
.iter()
.for_each(|(key, entry)| {
cache.replenish(*key, entry.clone());
})
self.loaded_programs_cache
.write()
.unwrap()
.merge(&programs_modified_by_tx.borrow());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7772,7 +7772,7 @@ fn test_bpf_loader_upgradeable_deploy_with_max_len() {
solana_bpf_loader_program::process_instruction,
|invoke_context| {
let mut cache = invoke_context.programs_modified_by_tx.borrow_mut();
cache.set_slot(bank.slot() + DELAY_VISIBILITY_SLOT_OFFSET);
cache.set_slot_for_tests(bank.slot() + DELAY_VISIBILITY_SLOT_OFFSET);
cache.replenish(program_keypair.pubkey(), loaded_program.clone());
},
|_invoke_context| {},
Expand Down

0 comments on commit 33bbaf5

Please sign in to comment.