Skip to content

Commit

Permalink
Moves recompilation specifics out of load_program().
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Feb 22, 2024
1 parent 2d370f6 commit 3d4dcb7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
.clone(),
);
for key in cached_account_keys {
loaded_programs.replenish(key, bank.load_program(&key, false, None));
loaded_programs.replenish(key, bank.load_program(&key, false, bank.epoch()));
debug!("Loaded program {}", key);
}
invoke_context.programs_loaded_for_tx_batch = &loaded_programs;
Expand Down
13 changes: 10 additions & 3 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,8 +1360,15 @@ impl Bank {
if let Some((key, program_to_recompile)) =
loaded_programs_cache.programs_to_recompile.pop()
{
let effective_epoch = loaded_programs_cache.latest_root_epoch.saturating_add(1);
drop(loaded_programs_cache);
let recompiled = new.load_program(&key, false, Some(program_to_recompile));
let recompiled = new.load_program(&key, false, effective_epoch);
recompiled
.tx_usage_counter
.fetch_add(program_to_recompile.tx_usage_counter.load(Relaxed), Relaxed);
recompiled
.ix_usage_counter
.fetch_add(program_to_recompile.ix_usage_counter.load(Relaxed), Relaxed);
let mut loaded_programs_cache = new.loaded_programs_cache.write().unwrap();
loaded_programs_cache.assign_program(key, recompiled);
}
Expand Down Expand Up @@ -7480,10 +7487,10 @@ impl Bank {
&self,
pubkey: &Pubkey,
reload: bool,
recompile: Option<Arc<LoadedProgram>>,
effective_epoch: Epoch,
) -> Arc<LoadedProgram> {
self.transaction_processor
.load_program(self, pubkey, reload, recompile)
.load_program(self, pubkey, reload, effective_epoch)
}
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7174,7 +7174,7 @@ fn test_bank_load_program() {
programdata_account.set_rent_epoch(1);
bank.store_account_and_update_capitalization(&key1, &program_account);
bank.store_account_and_update_capitalization(&programdata_key, &programdata_account);
let program = bank.load_program(&key1, false, None);
let program = bank.load_program(&key1, false, bank.epoch());
assert_matches!(program.program, LoadedProgramType::LegacyV1(_));
assert_eq!(
program.account_size,
Expand Down Expand Up @@ -7329,7 +7329,7 @@ fn test_bpf_loader_upgradeable_deploy_with_max_len() {
assert_eq!(*elf.get(i).unwrap(), *byte);
}

let loaded_program = bank.load_program(&program_keypair.pubkey(), false, None);
let loaded_program = bank.load_program(&program_keypair.pubkey(), false, bank.epoch());

// Invoke deployed program
mock_process_instruction(
Expand Down
20 changes: 3 additions & 17 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ use {
collections::{hash_map::Entry, HashMap},
fmt::{Debug, Formatter},
rc::Rc,
sync::{
atomic::{AtomicU64, Ordering},
Arc, RwLock,
},
sync::{atomic::Ordering, Arc, RwLock},
},
};

Expand Down Expand Up @@ -419,7 +416,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {

if let Some((key, count)) = program_to_load {
// Load, verify and compile one program.
let program = self.load_program(callback, &key, false, None);
let program = self.load_program(callback, &key, false, self.epoch);
program.tx_usage_counter.store(count, Ordering::Relaxed);
program_to_store = Some((key, program));
} else if missing_programs.is_empty() {
Expand Down Expand Up @@ -654,14 +651,9 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
callbacks: &CB,
pubkey: &Pubkey,
reload: bool,
recompile: Option<Arc<LoadedProgram>>,
effective_epoch: Epoch,
) -> Arc<LoadedProgram> {
let loaded_programs_cache = self.loaded_programs_cache.read().unwrap();
let effective_epoch = if recompile.is_some() {
loaded_programs_cache.latest_root_epoch.saturating_add(1)
} else {
self.epoch
};
let environments = loaded_programs_cache.get_environments_for_epoch(effective_epoch);
let mut load_program_metrics = LoadProgramMetrics {
program_id: pubkey.to_string(),
Expand Down Expand Up @@ -742,12 +734,6 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
loaded_program.effective_slot = loaded_program
.effective_slot
.max(self.epoch_schedule.get_first_slot_in_epoch(effective_epoch));
if let Some(recompile) = recompile {
loaded_program.tx_usage_counter =
AtomicU64::new(recompile.tx_usage_counter.load(Ordering::Relaxed));
loaded_program.ix_usage_counter =
AtomicU64::new(recompile.ix_usage_counter.load(Ordering::Relaxed));
}
loaded_program.update_access_slot(self.slot);
Arc::new(loaded_program)
}
Expand Down

0 comments on commit 3d4dcb7

Please sign in to comment.