diff --git a/ledger-tool/src/program.rs b/ledger-tool/src/program.rs index b56affd4c905c2..af50d59bca0255 100644 --- a/ledger-tool/src/program.rs +++ b/ledger-tool/src/program.rs @@ -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; diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 29dde36ac20116..ccd3f7c522737f 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -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>, + effective_epoch: Epoch, ) -> Arc { self.transaction_processor - .load_program(self, pubkey, reload, recompile) + .load_program(self, pubkey, reload, effective_epoch) } } diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 5f5d0884ac13ec..00523353142fa6 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -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( diff --git a/svm/src/transaction_processor.rs b/svm/src/transaction_processor.rs index dc3e59389cc295..0c456c918d68ff 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -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 TransactionBatchProcessor { 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 TransactionBatchProcessor { callbacks: &CB, pubkey: &Pubkey, reload: bool, - recompile: Option>, + effective_epoch: Epoch, ) -> Arc { 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 TransactionBatchProcessor { .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) }