1
1
#[ cfg( RUSTC_WITH_SPECIALIZATION ) ]
2
2
use solana_frozen_abi:: abi_example:: AbiExample ;
3
+ #[ allow( deprecated) ]
4
+ use solana_sdk:: AutoTraitBreakSendSync ;
3
5
use {
4
6
crate :: system_instruction_processor,
5
7
solana_program_runtime:: {
@@ -108,7 +110,7 @@ pub enum BuiltinAction {
108
110
/// State transition enum used for adding and removing builtin programs through
109
111
/// feature activations.
110
112
#[ derive( Debug , Clone , AbiExample ) ]
111
- pub enum BuiltinFeatureTransition {
113
+ enum InnerBuiltinFeatureTransition {
112
114
/// Add a builtin program if a feature is activated.
113
115
Add {
114
116
builtin : Builtin ,
@@ -123,6 +125,13 @@ pub enum BuiltinFeatureTransition {
123
125
} ,
124
126
}
125
127
128
+ #[ allow( deprecated) ]
129
+ #[ cfg( debug_assertions) ]
130
+ impl AutoTraitBreakSendSync for InnerBuiltinFeatureTransition { }
131
+
132
+ #[ derive( AbiExample , Clone , Debug ) ]
133
+ pub struct BuiltinFeatureTransition ( InnerBuiltinFeatureTransition ) ;
134
+
126
135
// https://github.com/solana-labs/solana/pull/23233 added `BuiltinFeatureTransition`
127
136
// to `Bank` which triggers https://github.com/rust-lang/rust/issues/92987 while
128
137
// attempting to resolve `Sync` on `BankRc` in `AccountsBackgroundService::new` ala,
@@ -142,25 +151,49 @@ unsafe impl Send for BuiltinFeatureTransition {}
142
151
unsafe impl Sync for BuiltinFeatureTransition { }
143
152
144
153
impl 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
+ }
145
178
pub fn to_action (
146
179
& self ,
147
180
should_apply_action_for_feature : & impl Fn ( & Pubkey ) -> bool ,
148
181
) -> Option < BuiltinAction > {
149
- match self {
150
- Self :: Add {
182
+ match & self . 0 {
183
+ InnerBuiltinFeatureTransition :: Add {
151
184
builtin,
152
- feature_id,
185
+ ref feature_id,
153
186
} => {
154
187
if should_apply_action_for_feature ( feature_id) {
155
188
Some ( BuiltinAction :: Add ( builtin. clone ( ) ) )
156
189
} else {
157
190
None
158
191
}
159
192
}
160
- Self :: RemoveOrRetain {
193
+ InnerBuiltinFeatureTransition :: RemoveOrRetain {
161
194
previously_added_builtin,
162
- addition_feature_id,
163
- removal_feature_id,
195
+ ref addition_feature_id,
196
+ ref removal_feature_id,
164
197
} => {
165
198
if should_apply_action_for_feature ( removal_feature_id) {
166
199
Some ( BuiltinAction :: Remove ( previously_added_builtin. id ) )
@@ -213,48 +246,38 @@ fn dummy_process_instruction(
213
246
/// Dynamic feature transitions for builtin programs
214
247
fn builtin_feature_transitions ( ) -> Vec < BuiltinFeatureTransition > {
215
248
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
+ ) ,
258
281
]
259
282
}
260
283
0 commit comments