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

Commit 63d1c3e

Browse files
committed
consistent owner across builtins and precompiles + nits
1 parent fcc54fa commit 63d1c3e

File tree

2 files changed

+63
-71
lines changed

2 files changed

+63
-71
lines changed

runtime/src/bank.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,7 +3220,7 @@ impl Bank {
32203220
let (lamports, rent_epoch) = self.inherit_specially_retained_account_fields(&None);
32213221
let account = AccountSharedData::from(Account {
32223222
lamports,
3223-
owner: solana_sdk::system_program::id(),
3223+
owner: native_loader::id(),
32243224
data: vec![],
32253225
executable: true,
32263226
rent_epoch,
@@ -6432,9 +6432,9 @@ impl Bank {
64326432
}
64336433

64346434
if !debug_do_not_add_builtins {
6435-
let apply_transitions_for_old_features = init_finish_or_warp;
6435+
let apply_transitions_for_new_features = !init_finish_or_warp;
64366436
self.apply_builtin_program_feature_transitions(
6437-
apply_transitions_for_old_features,
6437+
apply_transitions_for_new_features,
64386438
&new_feature_activations,
64396439
);
64406440
self.reconfigure_token2_native_mint();
@@ -6495,15 +6495,15 @@ impl Bank {
64956495

64966496
fn apply_builtin_program_feature_transitions(
64976497
&mut self,
6498-
apply_transitions_for_old_features: bool,
6498+
apply_transitions_for_new_features: bool,
64996499
new_feature_activations: &HashSet<Pubkey>,
65006500
) {
65016501
let feature_set = self.feature_set.clone();
65026502
let should_apply_action_for_feature = |feature_id: &Pubkey| -> bool {
6503-
if apply_transitions_for_old_features {
6504-
feature_set.is_active(feature_id)
6505-
} else {
6503+
if apply_transitions_for_new_features {
65066504
new_feature_activations.contains(feature_id)
6505+
} else {
6506+
feature_set.is_active(feature_id)
65076507
}
65086508
};
65096509

@@ -6516,7 +6516,7 @@ impl Bank {
65166516
&builtin.id,
65176517
builtin.process_instruction_with_context,
65186518
),
6519-
BuiltinAction::Remove { program_id } => self.remove_builtin(&program_id),
6519+
BuiltinAction::Remove(program_id) => self.remove_builtin(&program_id),
65206520
}
65216521
}
65226522
}

runtime/src/builtins.rs

Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -51,63 +51,6 @@ macro_rules! with_program_logging {
5151
};
5252
}
5353

54-
/// State transition enum used for adding and removing builtin programs through
55-
/// feature activations.
56-
#[derive(Debug, Clone)]
57-
pub enum BuiltinFeatureTransition {
58-
/// Add a builtin program if a feature is activated.
59-
Add {
60-
builtin: Builtin,
61-
feature_id: Pubkey,
62-
},
63-
/// Remove a builtin program if a feature is activated or
64-
/// retain a previously added builtin.
65-
RemoveOrRetain {
66-
previous_builtin: Builtin,
67-
removal_feature_id: Pubkey,
68-
},
69-
}
70-
71-
/// Actions taken by a bank when managing the list of active builtin programs.
72-
#[derive(Debug, Clone)]
73-
pub enum BuiltinAction {
74-
Add(Builtin),
75-
Remove { program_id: Pubkey },
76-
}
77-
78-
impl BuiltinFeatureTransition {
79-
pub fn to_action(
80-
&self,
81-
should_apply_action_for_feature: &impl Fn(&Pubkey) -> bool,
82-
) -> Option<BuiltinAction> {
83-
match self {
84-
Self::Add {
85-
builtin,
86-
feature_id,
87-
} => {
88-
if should_apply_action_for_feature(feature_id) {
89-
Some(BuiltinAction::Add(builtin.clone()))
90-
} else {
91-
None
92-
}
93-
}
94-
Self::RemoveOrRetain {
95-
previous_builtin,
96-
removal_feature_id,
97-
} => {
98-
if should_apply_action_for_feature(removal_feature_id) {
99-
Some(BuiltinAction::Remove {
100-
program_id: previous_builtin.id,
101-
})
102-
} else {
103-
// Retaining is no different from adding a new builtin.
104-
Some(BuiltinAction::Add(previous_builtin.clone()))
105-
}
106-
}
107-
}
108-
}
109-
}
110-
11154
#[derive(Clone)]
11255
pub struct Builtin {
11356
pub name: String,
@@ -155,6 +98,61 @@ pub struct Builtins {
15598
pub feature_transitions: Vec<BuiltinFeatureTransition>,
15699
}
157100

101+
/// Actions taken by a bank when managing the list of active builtin programs.
102+
#[derive(Debug, Clone)]
103+
pub enum BuiltinAction {
104+
Add(Builtin),
105+
Remove(Pubkey),
106+
}
107+
108+
/// State transition enum used for adding and removing builtin programs through
109+
/// feature activations.
110+
#[derive(Debug, Clone)]
111+
pub enum BuiltinFeatureTransition {
112+
/// Add a builtin program if a feature is activated.
113+
Add {
114+
builtin: Builtin,
115+
feature_id: Pubkey,
116+
},
117+
/// Remove a builtin program if a feature is activated or
118+
/// retain a previously added builtin.
119+
RemoveOrRetain {
120+
previous_builtin: Builtin,
121+
removal_feature_id: Pubkey,
122+
},
123+
}
124+
125+
impl BuiltinFeatureTransition {
126+
pub fn to_action(
127+
&self,
128+
should_apply_action_for_feature: &impl Fn(&Pubkey) -> bool,
129+
) -> Option<BuiltinAction> {
130+
match self {
131+
Self::Add {
132+
builtin,
133+
feature_id,
134+
} => {
135+
if should_apply_action_for_feature(feature_id) {
136+
Some(BuiltinAction::Add(builtin.clone()))
137+
} else {
138+
None
139+
}
140+
}
141+
Self::RemoveOrRetain {
142+
previous_builtin,
143+
removal_feature_id,
144+
} => {
145+
if should_apply_action_for_feature(removal_feature_id) {
146+
Some(BuiltinAction::Remove(previous_builtin.id))
147+
} else {
148+
// Retaining is no different from adding a new builtin.
149+
Some(BuiltinAction::Add(previous_builtin.clone()))
150+
}
151+
}
152+
}
153+
}
154+
}
155+
158156
/// Builtin programs that are always available
159157
fn genesis_builtins() -> Vec<Builtin> {
160158
vec![
@@ -201,9 +199,6 @@ fn builtin_feature_transitions() -> Vec<BuiltinFeatureTransition> {
201199
),
202200
feature_id: feature_set::add_compute_budget_program::id(),
203201
},
204-
// TODO when feature `prevent_calling_precompiles_as_programs` is
205-
// cleaned up also remove "secp256k1_program" from the main builtins
206-
// list
207202
BuiltinFeatureTransition::RemoveOrRetain {
208203
previous_builtin: Builtin::new(
209204
"secp256k1_program",
@@ -212,9 +207,6 @@ fn builtin_feature_transitions() -> Vec<BuiltinFeatureTransition> {
212207
),
213208
removal_feature_id: feature_set::prevent_calling_precompiles_as_programs::id(),
214209
},
215-
// TODO when feature `prevent_calling_precompiles_as_programs` is
216-
// cleaned up also remove "ed25519_program" from the main builtins
217-
// list
218210
BuiltinFeatureTransition::RemoveOrRetain {
219211
previous_builtin: Builtin::new(
220212
"ed25519_program",

0 commit comments

Comments
 (0)