8
8
solana_measure:: measure:: Measure ,
9
9
solana_program_runtime:: {
10
10
compute_budget:: ComputeBudget ,
11
- executor_cache:: TransactionExecutorCache ,
12
11
ic_logger_msg, ic_msg,
13
12
invoke_context:: { BpfAllocator , InvokeContext , SyscallContext } ,
14
13
loaded_programs:: { LoadProgramMetrics , LoadedProgram , LoadedProgramType } ,
55
54
} ,
56
55
} ,
57
56
std:: {
58
- cell:: { RefCell , RefMut } ,
57
+ cell:: RefCell ,
59
58
mem,
60
59
rc:: Rc ,
61
60
sync:: { atomic:: Ordering , Arc } ,
@@ -146,7 +145,6 @@ pub fn load_program_from_account(
146
145
feature_set : & FeatureSet ,
147
146
compute_budget : & ComputeBudget ,
148
147
log_collector : Option < Rc < RefCell < LogCollector > > > ,
149
- tx_executor_cache : Option < RefMut < TransactionExecutorCache > > ,
150
148
program : & BorrowedAccount ,
151
149
programdata : & BorrowedAccount ,
152
150
debugging_features : bool ,
@@ -159,17 +157,6 @@ pub fn load_program_from_account(
159
157
return Err ( InstructionError :: IncorrectProgramId ) ;
160
158
}
161
159
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
-
173
160
let ( programdata_offset, deployment_slot) =
174
161
get_programdata_offset_and_deployment_offset ( & log_collector, program, programdata) ?;
175
162
@@ -199,15 +186,6 @@ pub fn load_program_from_account(
199
186
false , /* reject_deployment_of_broken_elfs */
200
187
debugging_features,
201
188
) ?) ;
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
- }
211
189
212
190
Ok ( ( loaded_program, Some ( load_program_metrics) ) )
213
191
}
@@ -583,39 +561,23 @@ fn process_instruction_inner(
583
561
return Err ( Box :: new ( InstructionError :: IncorrectProgramId ) ) ;
584
562
}
585
563
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
-
599
564
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
+
609
575
drop ( program_account) ;
610
- drop ( programdata_account) ;
611
576
get_or_create_executor_time. stop ( ) ;
612
577
saturating_add_assign ! (
613
578
invoke_context. timings. get_or_create_executor_us,
614
579
get_or_create_executor_time. as_us( )
615
580
) ;
616
- if let Some ( load_program_metrics) = load_program_metrics {
617
- load_program_metrics. submit_datapoint ( & mut invoke_context. timings ) ;
618
- }
619
581
620
582
executor. usage_counter . fetch_add ( 1 , Ordering :: Relaxed ) ;
621
583
match & executor. program {
@@ -1698,6 +1660,47 @@ fn execute<'a, 'b: 'a>(
1698
1660
execute_or_deserialize_result
1699
1661
}
1700
1662
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
+
1701
1704
#[ cfg( test) ]
1702
1705
mod tests {
1703
1706
use {
@@ -1754,7 +1757,9 @@ mod tests {
1754
1757
instruction_accounts,
1755
1758
expected_result,
1756
1759
super :: process_instruction,
1757
- |_invoke_context| { } ,
1760
+ |invoke_context| {
1761
+ test_utils:: load_all_invoked_programs ( invoke_context) ;
1762
+ } ,
1758
1763
|_invoke_context| { } ,
1759
1764
)
1760
1765
}
@@ -1993,6 +1998,7 @@ mod tests {
1993
1998
super :: process_instruction,
1994
1999
|invoke_context| {
1995
2000
invoke_context. mock_set_remaining ( 0 ) ;
2001
+ test_utils:: load_all_invoked_programs ( invoke_context) ;
1996
2002
} ,
1997
2003
|_invoke_context| { } ,
1998
2004
) ;
0 commit comments