forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runtime: Refactor builtins module (solana-labs#304)
* runtime: builtins: move to new bank submodule * runtime: builtins: change `feature_id` to `enable_feature_id` * runtime: builtins: add stateless builtins
- Loading branch information
1 parent
54575fe
commit f194f70
Showing
7 changed files
with
80 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 19 additions & 51 deletions
70
runtime/src/builtins.rs → runtime/src/bank/builtins/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,78 @@ | ||
use { | ||
solana_program_runtime::invoke_context::BuiltinFunctionWithContext, | ||
solana_sdk::{ | ||
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, feature_set, pubkey::Pubkey, | ||
}, | ||
}; | ||
|
||
/// Transitions of built-in programs at epoch bondaries when features are activated. | ||
pub struct BuiltinPrototype { | ||
pub feature_id: Option<Pubkey>, | ||
pub program_id: Pubkey, | ||
pub name: &'static str, | ||
pub entrypoint: BuiltinFunctionWithContext, | ||
} | ||
pub mod prototypes; | ||
|
||
impl std::fmt::Debug for BuiltinPrototype { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
let mut builder = f.debug_struct("BuiltinPrototype"); | ||
builder.field("program_id", &self.program_id); | ||
builder.field("name", &self.name); | ||
builder.field("feature_id", &self.feature_id); | ||
builder.finish() | ||
} | ||
} | ||
|
||
#[cfg(RUSTC_WITH_SPECIALIZATION)] | ||
impl solana_frozen_abi::abi_example::AbiExample for BuiltinPrototype { | ||
fn example() -> Self { | ||
// BuiltinPrototype isn't serializable by definition. | ||
solana_program_runtime::declare_process_instruction!(MockBuiltin, 0, |_invoke_context| { | ||
// Do nothing | ||
Ok(()) | ||
}); | ||
Self { | ||
feature_id: None, | ||
program_id: Pubkey::default(), | ||
name: "", | ||
entrypoint: MockBuiltin::vm, | ||
} | ||
} | ||
} | ||
pub use prototypes::{BuiltinPrototype, StatelessBuiltinPrototype}; | ||
use solana_sdk::{bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, feature_set}; | ||
|
||
pub static BUILTINS: &[BuiltinPrototype] = &[ | ||
BuiltinPrototype { | ||
feature_id: None, | ||
enable_feature_id: None, | ||
program_id: solana_system_program::id(), | ||
name: "system_program", | ||
entrypoint: solana_system_program::system_processor::Entrypoint::vm, | ||
}, | ||
BuiltinPrototype { | ||
feature_id: None, | ||
enable_feature_id: None, | ||
program_id: solana_vote_program::id(), | ||
name: "vote_program", | ||
entrypoint: solana_vote_program::vote_processor::Entrypoint::vm, | ||
}, | ||
BuiltinPrototype { | ||
feature_id: None, | ||
enable_feature_id: None, | ||
program_id: solana_stake_program::id(), | ||
name: "stake_program", | ||
entrypoint: solana_stake_program::stake_instruction::Entrypoint::vm, | ||
}, | ||
BuiltinPrototype { | ||
feature_id: None, | ||
enable_feature_id: None, | ||
program_id: solana_config_program::id(), | ||
name: "config_program", | ||
entrypoint: solana_config_program::config_processor::Entrypoint::vm, | ||
}, | ||
BuiltinPrototype { | ||
feature_id: None, | ||
enable_feature_id: None, | ||
program_id: bpf_loader_deprecated::id(), | ||
name: "solana_bpf_loader_deprecated_program", | ||
entrypoint: solana_bpf_loader_program::Entrypoint::vm, | ||
}, | ||
BuiltinPrototype { | ||
feature_id: None, | ||
enable_feature_id: None, | ||
program_id: bpf_loader::id(), | ||
name: "solana_bpf_loader_program", | ||
entrypoint: solana_bpf_loader_program::Entrypoint::vm, | ||
}, | ||
BuiltinPrototype { | ||
feature_id: None, | ||
enable_feature_id: None, | ||
program_id: bpf_loader_upgradeable::id(), | ||
name: "solana_bpf_loader_upgradeable_program", | ||
entrypoint: solana_bpf_loader_program::Entrypoint::vm, | ||
}, | ||
BuiltinPrototype { | ||
feature_id: None, | ||
enable_feature_id: None, | ||
program_id: solana_sdk::compute_budget::id(), | ||
name: "compute_budget_program", | ||
entrypoint: solana_compute_budget_program::Entrypoint::vm, | ||
}, | ||
BuiltinPrototype { | ||
feature_id: None, | ||
enable_feature_id: None, | ||
program_id: solana_sdk::address_lookup_table::program::id(), | ||
name: "address_lookup_table_program", | ||
entrypoint: solana_address_lookup_table_program::processor::Entrypoint::vm, | ||
}, | ||
BuiltinPrototype { | ||
feature_id: Some(feature_set::zk_token_sdk_enabled::id()), | ||
enable_feature_id: Some(feature_set::zk_token_sdk_enabled::id()), | ||
program_id: solana_zk_token_sdk::zk_token_proof_program::id(), | ||
name: "zk_token_proof_program", | ||
entrypoint: solana_zk_token_proof_program::Entrypoint::vm, | ||
}, | ||
BuiltinPrototype { | ||
feature_id: Some(feature_set::enable_program_runtime_v2_and_loader_v4::id()), | ||
enable_feature_id: Some(feature_set::enable_program_runtime_v2_and_loader_v4::id()), | ||
program_id: solana_sdk::loader_v4::id(), | ||
name: "loader_v4", | ||
entrypoint: solana_loader_v4_program::Entrypoint::vm, | ||
}, | ||
]; | ||
|
||
pub static STATELESS_BUILTINS: &[StatelessBuiltinPrototype] = &[StatelessBuiltinPrototype { | ||
program_id: solana_sdk::feature::id(), | ||
name: "feature_gate_program", | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use { | ||
solana_program_runtime::invoke_context::BuiltinFunctionWithContext, solana_sdk::pubkey::Pubkey, | ||
}; | ||
|
||
/// Transitions of built-in programs at epoch boundaries when features are activated. | ||
pub struct BuiltinPrototype { | ||
pub enable_feature_id: Option<Pubkey>, | ||
pub program_id: Pubkey, | ||
pub name: &'static str, | ||
pub entrypoint: BuiltinFunctionWithContext, | ||
} | ||
|
||
impl std::fmt::Debug for BuiltinPrototype { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
let mut builder = f.debug_struct("BuiltinPrototype"); | ||
builder.field("program_id", &self.program_id); | ||
builder.field("name", &self.name); | ||
builder.field("enable_feature_id", &self.enable_feature_id); | ||
builder.finish() | ||
} | ||
} | ||
|
||
#[cfg(RUSTC_WITH_SPECIALIZATION)] | ||
impl solana_frozen_abi::abi_example::AbiExample for BuiltinPrototype { | ||
fn example() -> Self { | ||
// BuiltinPrototype isn't serializable by definition. | ||
solana_program_runtime::declare_process_instruction!(MockBuiltin, 0, |_invoke_context| { | ||
// Do nothing | ||
Ok(()) | ||
}); | ||
Self { | ||
enable_feature_id: None, | ||
program_id: Pubkey::default(), | ||
name: "", | ||
entrypoint: MockBuiltin::vm, | ||
} | ||
} | ||
} | ||
|
||
/// Transitions of stateless built-in programs at epoch boundaries when | ||
/// features are activated. | ||
/// These are built-in programs that don't actually exist, but their address | ||
/// is reserved. | ||
#[derive(Debug)] | ||
pub struct StatelessBuiltinPrototype { | ||
pub program_id: Pubkey, | ||
pub name: &'static str, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters