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 07b470b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 32 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
21 changes: 7 additions & 14 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use {
compute_budget::ComputeBudget,
ic_logger_msg, ic_msg,
invoke_context::{BpfAllocator, InvokeContext, SyscallContext},
loaded_programs::{
LoadProgramMetrics, LoadedProgram, LoadedProgramType, DELAY_VISIBILITY_SLOT_OFFSET,
},
loaded_programs::{LoadProgramMetrics, LoadedProgram, LoadedProgramType},
log_collector::LogCollector,
stable_log,
sysvar_cache::get_sysvar_with_account_check,
Expand All @@ -34,11 +32,10 @@ use {
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
feature_set::{
bpf_account_data_direct_mapping, cap_accounts_data_allocations_per_transaction,
cap_bpf_program_instruction_accounts, delay_visibility_of_program_deployment,
disable_deploy_of_alloc_free_syscall, enable_bpf_loader_extend_program_ix,
enable_bpf_loader_set_authority_checked_ix, enable_program_redeployment_cooldown,
limit_max_instruction_trace_length, native_programs_consume_cu,
remove_bpf_loader_incorrect_program_id, FeatureSet,
cap_bpf_program_instruction_accounts, disable_deploy_of_alloc_free_syscall,
enable_bpf_loader_extend_program_ix, enable_bpf_loader_set_authority_checked_ix,
enable_program_redeployment_cooldown, limit_max_instruction_trace_length,
native_programs_consume_cu, remove_bpf_loader_incorrect_program_id, FeatureSet,
},
instruction::{AccountMeta, InstructionError},
loader_instruction::LoaderInstruction,
Expand Down Expand Up @@ -92,11 +89,7 @@ pub fn load_program_from_bytes(
})?;
register_syscalls_time.stop();
load_program_metrics.register_syscalls_us = register_syscalls_time.as_us();
let effective_slot = if feature_set.is_active(&delay_visibility_of_program_deployment::id()) {
deployment_slot.saturating_add(DELAY_VISIBILITY_SLOT_OFFSET)
} else {
deployment_slot
};
let effective_slot = deployment_slot;
let loaded_program = LoadedProgram::new(
loader_key,
loader,
Expand Down Expand Up @@ -1706,7 +1699,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 07b470b

Please sign in to comment.