Refactor - Move recompilation out of program loading (#35297)
Moves recompilation specifics out of load_program().
This commit is contained in:
parent
7da8d82aa1
commit
74758d9fbf
|
@ -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;
|
||||
|
|
|
@ -1363,8 +1363,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);
|
||||
}
|
||||
|
@ -7485,10 +7492,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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7170,7 +7170,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,
|
||||
|
@ -7325,7 +7325,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(
|
||||
|
|
|
@ -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},
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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(),
|
||||
|
@ -754,12 +746,6 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
|
|||
.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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue