11#[ cfg( RUSTC_WITH_SPECIALIZATION ) ]
22use solana_frozen_abi:: abi_example:: AbiExample ;
3+ #[ allow( deprecated) ]
4+ use solana_sdk:: AutoTraitBreakSendSync ;
35use {
46 crate :: system_instruction_processor,
57 solana_program_runtime:: {
@@ -108,7 +110,7 @@ pub enum BuiltinAction {
108110/// State transition enum used for adding and removing builtin programs through
109111/// feature activations.
110112#[ derive( Debug , Clone , AbiExample ) ]
111- pub enum BuiltinFeatureTransition {
113+ enum InnerBuiltinFeatureTransition {
112114 /// Add a builtin program if a feature is activated.
113115 Add {
114116 builtin : Builtin ,
@@ -123,6 +125,13 @@ pub enum BuiltinFeatureTransition {
123125 } ,
124126}
125127
128+ #[ allow( deprecated) ]
129+ #[ cfg( debug_assertions) ]
130+ impl AutoTraitBreakSendSync for InnerBuiltinFeatureTransition { }
131+
132+ #[ derive( Clone , Debug ) ]
133+ pub struct BuiltinFeatureTransition ( InnerBuiltinFeatureTransition ) ;
134+
126135// https://github.com/solana-labs/solana/pull/23233 added `BuiltinFeatureTransition`
127136// to `Bank` which triggers https://github.com/rust-lang/rust/issues/92987 while
128137// attempting to resolve `Sync` on `BankRc` in `AccountsBackgroundService::new` ala,
@@ -142,25 +151,49 @@ unsafe impl Send for BuiltinFeatureTransition {}
142151unsafe impl Sync for BuiltinFeatureTransition { }
143152
144153impl BuiltinFeatureTransition {
154+ pub fn new_add (
155+ name : & str ,
156+ id : Pubkey ,
157+ process_instruction_with_context : ProcessInstructionWithContext ,
158+ feature_id : Pubkey ,
159+ ) -> Self {
160+ Self ( InnerBuiltinFeatureTransition :: Add {
161+ builtin : Builtin :: new ( name, id, process_instruction_with_context) ,
162+ feature_id,
163+ } )
164+ }
165+ pub fn new_remove_or_retain (
166+ name : & str ,
167+ id : Pubkey ,
168+ process_instruction_with_context : ProcessInstructionWithContext ,
169+ addition_feature_id : Pubkey ,
170+ removal_feature_id : Pubkey ,
171+ ) -> Self {
172+ Self ( InnerBuiltinFeatureTransition :: RemoveOrRetain {
173+ previously_added_builtin : Builtin :: new ( name, id, process_instruction_with_context) ,
174+ addition_feature_id,
175+ removal_feature_id,
176+ } )
177+ }
145178 pub fn to_action (
146179 & self ,
147180 should_apply_action_for_feature : & impl Fn ( & Pubkey ) -> bool ,
148181 ) -> Option < BuiltinAction > {
149- match self {
150- Self :: Add {
182+ match & self . 0 {
183+ InnerBuiltinFeatureTransition :: Add {
151184 builtin,
152- feature_id,
185+ ref feature_id,
153186 } => {
154187 if should_apply_action_for_feature ( feature_id) {
155188 Some ( BuiltinAction :: Add ( builtin. clone ( ) ) )
156189 } else {
157190 None
158191 }
159192 }
160- Self :: RemoveOrRetain {
193+ InnerBuiltinFeatureTransition :: RemoveOrRetain {
161194 previously_added_builtin,
162- addition_feature_id,
163- removal_feature_id,
195+ ref addition_feature_id,
196+ ref removal_feature_id,
164197 } => {
165198 if should_apply_action_for_feature ( removal_feature_id) {
166199 Some ( BuiltinAction :: Remove ( previously_added_builtin. id ) )
@@ -213,48 +246,38 @@ fn dummy_process_instruction(
213246/// Dynamic feature transitions for builtin programs
214247fn builtin_feature_transitions ( ) -> Vec < BuiltinFeatureTransition > {
215248 vec ! [
216- BuiltinFeatureTransition :: Add {
217- builtin: Builtin :: new(
218- "compute_budget_program" ,
219- solana_sdk:: compute_budget:: id( ) ,
220- solana_compute_budget_program:: process_instruction,
221- ) ,
222- feature_id: feature_set:: add_compute_budget_program:: id( ) ,
223- } ,
224- BuiltinFeatureTransition :: RemoveOrRetain {
225- previously_added_builtin: Builtin :: new(
226- "secp256k1_program" ,
227- solana_sdk:: secp256k1_program:: id( ) ,
228- dummy_process_instruction,
229- ) ,
230- addition_feature_id: feature_set:: secp256k1_program_enabled:: id( ) ,
231- removal_feature_id: feature_set:: prevent_calling_precompiles_as_programs:: id( ) ,
232- } ,
233- BuiltinFeatureTransition :: RemoveOrRetain {
234- previously_added_builtin: Builtin :: new(
235- "ed25519_program" ,
236- solana_sdk:: ed25519_program:: id( ) ,
237- dummy_process_instruction,
238- ) ,
239- addition_feature_id: feature_set:: ed25519_program_enabled:: id( ) ,
240- removal_feature_id: feature_set:: prevent_calling_precompiles_as_programs:: id( ) ,
241- } ,
242- BuiltinFeatureTransition :: Add {
243- builtin: Builtin :: new(
244- "address_lookup_table_program" ,
245- solana_address_lookup_table_program:: id( ) ,
246- solana_address_lookup_table_program:: processor:: process_instruction,
247- ) ,
248- feature_id: feature_set:: versioned_tx_message_enabled:: id( ) ,
249- } ,
250- BuiltinFeatureTransition :: Add {
251- builtin: Builtin :: new(
252- "zk_token_proof_program" ,
253- solana_zk_token_sdk:: zk_token_proof_program:: id( ) ,
254- with_program_logging!( solana_zk_token_proof_program:: process_instruction) ,
255- ) ,
256- feature_id: feature_set:: zk_token_sdk_enabled:: id( ) ,
257- } ,
249+ BuiltinFeatureTransition :: new_add(
250+ "compute_budget_program" ,
251+ solana_sdk:: compute_budget:: id( ) ,
252+ solana_compute_budget_program:: process_instruction,
253+ feature_set:: add_compute_budget_program:: id( ) ,
254+ ) ,
255+ BuiltinFeatureTransition :: new_remove_or_retain(
256+ "secp256k1_program" ,
257+ solana_sdk:: secp256k1_program:: id( ) ,
258+ dummy_process_instruction,
259+ feature_set:: secp256k1_program_enabled:: id( ) ,
260+ feature_set:: prevent_calling_precompiles_as_programs:: id( ) ,
261+ ) ,
262+ BuiltinFeatureTransition :: new_remove_or_retain(
263+ "ed25519_program" ,
264+ solana_sdk:: ed25519_program:: id( ) ,
265+ dummy_process_instruction,
266+ feature_set:: ed25519_program_enabled:: id( ) ,
267+ feature_set:: prevent_calling_precompiles_as_programs:: id( ) ,
268+ ) ,
269+ BuiltinFeatureTransition :: new_add(
270+ "address_lookup_table_program" ,
271+ solana_address_lookup_table_program:: id( ) ,
272+ solana_address_lookup_table_program:: processor:: process_instruction,
273+ feature_set:: versioned_tx_message_enabled:: id( ) ,
274+ ) ,
275+ BuiltinFeatureTransition :: new_add(
276+ "zk_token_proof_program" ,
277+ solana_zk_token_sdk:: zk_token_proof_program:: id( ) ,
278+ with_program_logging!( solana_zk_token_proof_program:: process_instruction) ,
279+ feature_set:: zk_token_sdk_enabled:: id( ) ,
280+ ) ,
258281 ]
259282}
260283
0 commit comments