88 solana_loader_v3_interface:: state:: UpgradeableLoaderState ,
99 solana_loader_v4_interface:: state:: { LoaderV4State , LoaderV4Status } ,
1010 solana_program_runtime:: {
11- invoke_context:: { BuiltinFunctionWithContext , InvokeContext } ,
11+ invoke_context:: BuiltinFunctionWithContext ,
1212 loaded_programs:: { LoadProgramMetrics , ProgramCacheEntry , ProgramCacheForTxBatch } ,
13- solana_sbpf:: {
14- elf:: ElfError ,
15- program:: { BuiltinFunction , BuiltinProgram } ,
16- } ,
1713 } ,
1814 solana_pubkey:: Pubkey ,
1915 solana_rent:: Rent ,
@@ -61,23 +57,13 @@ pub struct ProgramCache {
6157 //
6258 // K: program ID, V: loader key
6359 entries_cache : Rc < RefCell < HashMap < Pubkey , Pubkey > > > ,
64- // The function registry (syscalls) to use for verifying and loading
65- // program ELFs.
66- program_runtime_environment : BuiltinProgram < InvokeContext < ' static > > ,
6760}
6861
69- impl ProgramCache {
70- pub fn new ( feature_set : & FeatureSet , compute_budget : & ComputeBudget ) -> Self {
62+ impl Default for ProgramCache {
63+ fn default ( ) -> Self {
7164 let me = Self {
7265 cache : Rc :: new ( RefCell :: new ( ProgramCacheForTxBatch :: default ( ) ) ) ,
7366 entries_cache : Rc :: new ( RefCell :: new ( HashMap :: new ( ) ) ) ,
74- program_runtime_environment : create_program_runtime_environment_v1 (
75- feature_set,
76- compute_budget,
77- /* reject_deployment_of_broken_elfs */ false ,
78- /* debugging_features */ false ,
79- )
80- . unwrap ( ) ,
8167 } ;
8268 BUILTINS . iter ( ) . for_each ( |builtin| {
8369 let program_id = builtin. program_id ;
@@ -86,7 +72,9 @@ impl ProgramCache {
8672 } ) ;
8773 me
8874 }
75+ }
8976
77+ impl ProgramCache {
9078 pub ( crate ) fn cache ( & self ) -> RefMut < ProgramCacheForTxBatch > {
9179 self . cache . borrow_mut ( )
9280 }
@@ -106,24 +94,18 @@ impl ProgramCache {
10694 }
10795
10896 /// Add a program to the cache.
109- pub fn add_program ( & mut self , program_id : & Pubkey , loader_key : & Pubkey , elf : & [ u8 ] ) {
110- // This might look rough, but it's actually functionally the same as
111- // calling `create_program_runtime_environment_v1` on every addition.
112- let environment = {
113- let config = self . program_runtime_environment . get_config ( ) . clone ( ) ;
114- let mut loader = BuiltinProgram :: new_loader ( config) ;
115-
116- for ( _key, ( name, value) ) in self
117- . program_runtime_environment
118- . get_function_registry ( )
119- . iter ( )
120- {
121- let name = std:: str:: from_utf8 ( name) . unwrap ( ) ;
122- loader. register_function ( name, value) . unwrap ( ) ;
123- }
124-
125- Arc :: new ( loader)
126- } ;
97+ pub fn add_program (
98+ & mut self ,
99+ program_id : & Pubkey ,
100+ loader_key : & Pubkey ,
101+ elf : & [ u8 ] ,
102+ compute_budget : & ComputeBudget ,
103+ feature_set : & FeatureSet ,
104+ ) {
105+ let environment = Arc :: new (
106+ create_program_runtime_environment_v1 ( feature_set, compute_budget, false , false )
107+ . unwrap ( ) ,
108+ ) ;
127109 self . replenish (
128110 * program_id,
129111 Arc :: new (
@@ -167,19 +149,6 @@ impl ProgramCache {
167149 } )
168150 . collect ( )
169151 }
170-
171- /// Register a new function (syscall) with the program runtime environment.
172- ///
173- /// **Important**: You should register all custom syscalls BEFORE adding any
174- /// programs to the store that will use them.
175- pub fn register_function (
176- & mut self ,
177- name : & str ,
178- value : BuiltinFunction < InvokeContext < ' static > > ,
179- ) -> Result < ( ) , ElfError > {
180- self . program_runtime_environment
181- . register_function ( name, value)
182- }
183152}
184153
185154pub struct Builtin {
0 commit comments