2023-04-21 09:08:32 -07:00
|
|
|
use {
|
2023-04-24 10:01:40 -07:00
|
|
|
solana_program_runtime::builtin_program::BuiltinProgram,
|
2023-04-25 10:04:11 -07:00
|
|
|
solana_sdk::{feature_set, pubkey::Pubkey},
|
2021-12-03 09:00:31 -08:00
|
|
|
};
|
2020-11-12 12:44:37 -08:00
|
|
|
|
2021-09-02 21:29:11 -07:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct Builtins {
|
|
|
|
/// Builtin programs that are always available
|
2023-04-24 10:01:40 -07:00
|
|
|
pub genesis_builtins: Vec<BuiltinProgram>,
|
2021-09-02 21:29:11 -07:00
|
|
|
|
2022-02-18 18:36:59 -08:00
|
|
|
/// Dynamic feature transitions for builtin programs
|
|
|
|
pub feature_transitions: Vec<BuiltinFeatureTransition>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Actions taken by a bank when managing the list of active builtin programs.
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub enum BuiltinAction {
|
2023-04-24 10:01:40 -07:00
|
|
|
Add(BuiltinProgram),
|
2022-02-18 18:36:59 -08:00
|
|
|
Remove(Pubkey),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// State transition enum used for adding and removing builtin programs through
|
|
|
|
/// feature activations.
|
|
|
|
#[derive(Debug, Clone, AbiExample)]
|
2022-06-23 05:22:30 -07:00
|
|
|
pub enum BuiltinFeatureTransition {
|
2022-02-18 18:36:59 -08:00
|
|
|
/// Add a builtin program if a feature is activated.
|
|
|
|
Add {
|
2023-04-24 10:01:40 -07:00
|
|
|
builtin: BuiltinProgram,
|
2022-02-18 18:36:59 -08:00
|
|
|
feature_id: Pubkey,
|
|
|
|
},
|
|
|
|
/// Remove a builtin program if a feature is activated or
|
|
|
|
/// retain a previously added builtin.
|
|
|
|
RemoveOrRetain {
|
2023-04-24 10:01:40 -07:00
|
|
|
previously_added_builtin: BuiltinProgram,
|
2022-02-22 04:54:08 -08:00
|
|
|
addition_feature_id: Pubkey,
|
2022-02-18 18:36:59 -08:00
|
|
|
removal_feature_id: Pubkey,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BuiltinFeatureTransition {
|
|
|
|
pub fn to_action(
|
|
|
|
&self,
|
|
|
|
should_apply_action_for_feature: &impl Fn(&Pubkey) -> bool,
|
|
|
|
) -> Option<BuiltinAction> {
|
2022-06-23 05:22:30 -07:00
|
|
|
match self {
|
|
|
|
Self::Add {
|
2022-02-18 18:36:59 -08:00
|
|
|
builtin,
|
2022-06-23 05:22:30 -07:00
|
|
|
feature_id,
|
2022-02-18 18:36:59 -08:00
|
|
|
} => {
|
|
|
|
if should_apply_action_for_feature(feature_id) {
|
|
|
|
Some(BuiltinAction::Add(builtin.clone()))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2022-06-23 05:22:30 -07:00
|
|
|
Self::RemoveOrRetain {
|
2022-02-22 04:54:08 -08:00
|
|
|
previously_added_builtin,
|
2022-06-23 05:22:30 -07:00
|
|
|
addition_feature_id,
|
|
|
|
removal_feature_id,
|
2022-02-18 18:36:59 -08:00
|
|
|
} => {
|
|
|
|
if should_apply_action_for_feature(removal_feature_id) {
|
2023-04-24 10:01:40 -07:00
|
|
|
Some(BuiltinAction::Remove(previously_added_builtin.program_id))
|
2022-02-22 04:54:08 -08:00
|
|
|
} else if should_apply_action_for_feature(addition_feature_id) {
|
2022-02-18 18:36:59 -08:00
|
|
|
// Retaining is no different from adding a new builtin.
|
2022-02-22 04:54:08 -08:00
|
|
|
Some(BuiltinAction::Add(previously_added_builtin.clone()))
|
|
|
|
} else {
|
|
|
|
None
|
2022-02-18 18:36:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-02 21:29:11 -07:00
|
|
|
}
|
|
|
|
|
2023-04-24 10:01:40 -07:00
|
|
|
/// Built-in programs that are always available
|
|
|
|
fn genesis_builtins() -> Vec<BuiltinProgram> {
|
2020-09-24 12:23:09 -07:00
|
|
|
vec![
|
2023-04-24 10:01:40 -07:00
|
|
|
BuiltinProgram {
|
|
|
|
name: "system_program".to_string(),
|
|
|
|
program_id: solana_system_program::id(),
|
|
|
|
process_instruction: solana_system_program::system_processor::process_instruction,
|
|
|
|
},
|
|
|
|
BuiltinProgram {
|
|
|
|
name: "vote_program".to_string(),
|
|
|
|
program_id: solana_vote_program::id(),
|
|
|
|
process_instruction: solana_vote_program::vote_processor::process_instruction,
|
|
|
|
},
|
|
|
|
BuiltinProgram {
|
|
|
|
name: "stake_program".to_string(),
|
2023-04-25 10:04:11 -07:00
|
|
|
program_id: solana_stake_program::id(),
|
2023-04-24 10:01:40 -07:00
|
|
|
process_instruction: solana_stake_program::stake_instruction::process_instruction,
|
|
|
|
},
|
|
|
|
BuiltinProgram {
|
|
|
|
name: "config_program".to_string(),
|
|
|
|
program_id: solana_config_program::id(),
|
|
|
|
process_instruction: solana_config_program::config_processor::process_instruction,
|
|
|
|
},
|
2020-09-24 12:23:09 -07:00
|
|
|
]
|
2020-08-14 12:32:45 -07:00
|
|
|
}
|
|
|
|
|
2022-02-18 18:36:59 -08:00
|
|
|
/// Dynamic feature transitions for builtin programs
|
|
|
|
fn builtin_feature_transitions() -> Vec<BuiltinFeatureTransition> {
|
2021-09-03 14:35:38 -07:00
|
|
|
vec![
|
2022-06-23 05:22:30 -07:00
|
|
|
BuiltinFeatureTransition::Add {
|
2023-04-24 10:01:40 -07:00
|
|
|
builtin: BuiltinProgram {
|
|
|
|
name: "compute_budget_program".to_string(),
|
|
|
|
program_id: solana_sdk::compute_budget::id(),
|
|
|
|
process_instruction: solana_compute_budget_program::process_instruction,
|
|
|
|
},
|
2022-02-18 18:36:59 -08:00
|
|
|
feature_id: feature_set::add_compute_budget_program::id(),
|
2022-06-23 05:22:30 -07:00
|
|
|
},
|
|
|
|
BuiltinFeatureTransition::Add {
|
2023-04-24 10:01:40 -07:00
|
|
|
builtin: BuiltinProgram {
|
|
|
|
name: "address_lookup_table_program".to_string(),
|
|
|
|
program_id: solana_address_lookup_table_program::id(),
|
|
|
|
process_instruction:
|
|
|
|
solana_address_lookup_table_program::processor::process_instruction,
|
|
|
|
},
|
2022-02-18 18:36:59 -08:00
|
|
|
feature_id: feature_set::versioned_tx_message_enabled::id(),
|
2022-06-23 05:22:30 -07:00
|
|
|
},
|
|
|
|
BuiltinFeatureTransition::Add {
|
2023-04-24 10:01:40 -07:00
|
|
|
builtin: BuiltinProgram {
|
|
|
|
name: "zk_token_proof_program".to_string(),
|
|
|
|
program_id: solana_zk_token_sdk::zk_token_proof_program::id(),
|
|
|
|
process_instruction: solana_zk_token_proof_program::process_instruction,
|
|
|
|
},
|
2022-02-18 18:36:59 -08:00
|
|
|
feature_id: feature_set::zk_token_sdk_enabled::id(),
|
2022-06-23 05:22:30 -07:00
|
|
|
},
|
2021-09-03 14:35:38 -07:00
|
|
|
]
|
2020-09-21 22:36:23 -07:00
|
|
|
}
|
|
|
|
|
2020-09-24 12:23:09 -07:00
|
|
|
pub(crate) fn get() -> Builtins {
|
|
|
|
Builtins {
|
|
|
|
genesis_builtins: genesis_builtins(),
|
2022-02-18 18:36:59 -08:00
|
|
|
feature_transitions: builtin_feature_transitions(),
|
2020-08-25 09:49:15 -07:00
|
|
|
}
|
2020-08-14 12:32:45 -07:00
|
|
|
}
|
2022-06-22 10:17:43 -07:00
|
|
|
|
|
|
|
/// Returns the addresses of all builtin programs.
|
|
|
|
pub fn get_pubkeys() -> Vec<Pubkey> {
|
|
|
|
let builtins = get();
|
|
|
|
|
|
|
|
let mut pubkeys = Vec::new();
|
2023-04-24 10:01:40 -07:00
|
|
|
pubkeys.extend(builtins.genesis_builtins.iter().map(|b| b.program_id));
|
2022-06-23 09:56:09 -07:00
|
|
|
pubkeys.extend(builtins.feature_transitions.iter().filter_map(|f| match f {
|
2023-04-24 10:01:40 -07:00
|
|
|
BuiltinFeatureTransition::Add { builtin, .. } => Some(builtin.program_id),
|
2022-06-23 09:56:09 -07:00
|
|
|
BuiltinFeatureTransition::RemoveOrRetain { .. } => None,
|
|
|
|
}));
|
2022-06-22 10:17:43 -07:00
|
|
|
pubkeys
|
|
|
|
}
|