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

Commit ba6f7e8

Browse files
authored
Remove obsolete code for lazily loading programs (#31395)
1 parent ae75c7c commit ba6f7e8

File tree

4 files changed

+71
-52
lines changed

4 files changed

+71
-52
lines changed

programs/bpf_loader/src/lib.rs

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use {
88
solana_measure::measure::Measure,
99
solana_program_runtime::{
1010
compute_budget::ComputeBudget,
11-
executor_cache::TransactionExecutorCache,
1211
ic_logger_msg, ic_msg,
1312
invoke_context::{BpfAllocator, InvokeContext, SyscallContext},
1413
loaded_programs::{LoadProgramMetrics, LoadedProgram, LoadedProgramType},
@@ -55,7 +54,7 @@ use {
5554
},
5655
},
5756
std::{
58-
cell::{RefCell, RefMut},
57+
cell::RefCell,
5958
mem,
6059
rc::Rc,
6160
sync::{atomic::Ordering, Arc},
@@ -146,7 +145,6 @@ pub fn load_program_from_account(
146145
feature_set: &FeatureSet,
147146
compute_budget: &ComputeBudget,
148147
log_collector: Option<Rc<RefCell<LogCollector>>>,
149-
tx_executor_cache: Option<RefMut<TransactionExecutorCache>>,
150148
program: &BorrowedAccount,
151149
programdata: &BorrowedAccount,
152150
debugging_features: bool,
@@ -159,17 +157,6 @@ pub fn load_program_from_account(
159157
return Err(InstructionError::IncorrectProgramId);
160158
}
161159

162-
if let Some(ref tx_executor_cache) = tx_executor_cache {
163-
if let Some(loaded_program) = tx_executor_cache.get(program.get_key()) {
164-
if loaded_program.is_tombstone() {
165-
// We cached that the Executor does not exist, abort
166-
return Err(InstructionError::InvalidAccountData);
167-
}
168-
// Executor exists and is cached, use it
169-
return Ok((loaded_program, None));
170-
}
171-
}
172-
173160
let (programdata_offset, deployment_slot) =
174161
get_programdata_offset_and_deployment_offset(&log_collector, program, programdata)?;
175162

@@ -199,15 +186,6 @@ pub fn load_program_from_account(
199186
false, /* reject_deployment_of_broken_elfs */
200187
debugging_features,
201188
)?);
202-
if let Some(mut tx_executor_cache) = tx_executor_cache {
203-
tx_executor_cache.set(
204-
*program.get_key(),
205-
loaded_program.clone(),
206-
false,
207-
feature_set.is_active(&delay_visibility_of_program_deployment::id()),
208-
deployment_slot,
209-
);
210-
}
211189

212190
Ok((loaded_program, Some(load_program_metrics)))
213191
}
@@ -583,39 +561,23 @@ fn process_instruction_inner(
583561
return Err(Box::new(InstructionError::IncorrectProgramId));
584562
}
585563

586-
let programdata_account = if bpf_loader_upgradeable::check_id(program_account.get_owner()) {
587-
instruction_context
588-
.try_borrow_program_account(
589-
transaction_context,
590-
instruction_context
591-
.get_number_of_program_accounts()
592-
.saturating_sub(2),
593-
)
594-
.ok()
595-
} else {
596-
None
597-
};
598-
599564
let mut get_or_create_executor_time = Measure::start("get_or_create_executor_time");
600-
let (executor, load_program_metrics) = load_program_from_account(
601-
&invoke_context.feature_set,
602-
invoke_context.get_compute_budget(),
603-
log_collector,
604-
Some(invoke_context.tx_executor_cache.borrow_mut()),
605-
&program_account,
606-
programdata_account.as_ref().unwrap_or(&program_account),
607-
false, /* debugging_features */
608-
)?;
565+
let executor = invoke_context
566+
.tx_executor_cache
567+
.borrow()
568+
.get(program_account.get_key())
569+
.ok_or(InstructionError::InvalidAccountData)?;
570+
571+
if executor.is_tombstone() {
572+
return Err(Box::new(InstructionError::InvalidAccountData));
573+
}
574+
609575
drop(program_account);
610-
drop(programdata_account);
611576
get_or_create_executor_time.stop();
612577
saturating_add_assign!(
613578
invoke_context.timings.get_or_create_executor_us,
614579
get_or_create_executor_time.as_us()
615580
);
616-
if let Some(load_program_metrics) = load_program_metrics {
617-
load_program_metrics.submit_datapoint(&mut invoke_context.timings);
618-
}
619581

620582
executor.usage_counter.fetch_add(1, Ordering::Relaxed);
621583
match &executor.program {
@@ -1698,6 +1660,47 @@ fn execute<'a, 'b: 'a>(
16981660
execute_or_deserialize_result
16991661
}
17001662

1663+
pub mod test_utils {
1664+
use {super::*, solana_sdk::account::ReadableAccount};
1665+
1666+
pub fn load_all_invoked_programs(invoke_context: &mut InvokeContext) {
1667+
let num_accounts = invoke_context.transaction_context.get_number_of_accounts();
1668+
for index in 0..num_accounts {
1669+
let account = invoke_context
1670+
.transaction_context
1671+
.get_account_at_index(index)
1672+
.expect("Failed to get the account")
1673+
.borrow();
1674+
1675+
let owner = account.owner();
1676+
if check_loader_id(owner) {
1677+
let pubkey = invoke_context
1678+
.transaction_context
1679+
.get_key_of_account_at_index(index)
1680+
.expect("Failed to get account key");
1681+
1682+
let mut load_program_metrics = LoadProgramMetrics::default();
1683+
1684+
if let Ok(loaded_program) = load_program_from_bytes(
1685+
&FeatureSet::all_enabled(),
1686+
&ComputeBudget::default(),
1687+
None,
1688+
&mut load_program_metrics,
1689+
account.data(),
1690+
owner,
1691+
account.data().len(),
1692+
0,
1693+
true,
1694+
false,
1695+
) {
1696+
let mut cache = invoke_context.tx_executor_cache.borrow_mut();
1697+
cache.set(*pubkey, Arc::new(loaded_program), true, false, 0)
1698+
}
1699+
}
1700+
}
1701+
}
1702+
}
1703+
17011704
#[cfg(test)]
17021705
mod tests {
17031706
use {
@@ -1754,7 +1757,9 @@ mod tests {
17541757
instruction_accounts,
17551758
expected_result,
17561759
super::process_instruction,
1757-
|_invoke_context| {},
1760+
|invoke_context| {
1761+
test_utils::load_all_invoked_programs(invoke_context);
1762+
},
17581763
|_invoke_context| {},
17591764
)
17601765
}
@@ -1993,6 +1998,7 @@ mod tests {
19931998
super::process_instruction,
19941999
|invoke_context| {
19952000
invoke_context.mock_set_remaining(0);
2001+
test_utils::load_all_invoked_programs(invoke_context);
19962002
},
19972003
|_invoke_context| {},
19982004
);

programs/sbf/tests/programs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,7 @@ fn assert_instruction_count() {
14011401
solana_bpf_loader_program::process_instruction,
14021402
|invoke_context| {
14031403
*prev_compute_meter.borrow_mut() = invoke_context.get_remaining();
1404+
solana_bpf_loader_program::test_utils::load_all_invoked_programs(invoke_context);
14041405
},
14051406
|invoke_context| {
14061407
let consumption = prev_compute_meter

runtime/src/bank.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4234,7 +4234,6 @@ impl Bank {
42344234
&self.feature_set,
42354235
&self.runtime_config.compute_budget.unwrap_or_default(),
42364236
None, // log_collector
4237-
None,
42384237
&program,
42394238
programdata.as_ref().unwrap_or(&program),
42404239
debugging_features,

runtime/src/bank/tests.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7754,6 +7754,10 @@ fn test_bpf_loader_upgradeable_deploy_with_max_len() {
77547754
assert_eq!(*elf.get(i).unwrap(), *byte);
77557755
}
77567756

7757+
let loaded_program = bank
7758+
.load_program(&program_keypair.pubkey(), false)
7759+
.expect("Failed to load the program");
7760+
77577761
// Invoke deployed program
77587762
mock_process_instruction(
77597763
&bpf_loader_upgradeable::id(),
@@ -7766,7 +7770,16 @@ fn test_bpf_loader_upgradeable_deploy_with_max_len() {
77667770
Vec::new(),
77677771
Ok(()),
77687772
solana_bpf_loader_program::process_instruction,
7769-
|_invoke_context| {},
7773+
|invoke_context| {
7774+
let mut cache = invoke_context.tx_executor_cache.borrow_mut();
7775+
cache.set(
7776+
program_keypair.pubkey(),
7777+
loaded_program.clone(),
7778+
true,
7779+
false,
7780+
0,
7781+
);
7782+
},
77707783
|_invoke_context| {},
77717784
);
77727785

0 commit comments

Comments
 (0)