diff --git a/builtins/src/cost_modeling.rs b/builtins/src/cost_modeling.rs new file mode 100644 index 00000000000000..9b783830faae32 --- /dev/null +++ b/builtins/src/cost_modeling.rs @@ -0,0 +1,23 @@ +//! Configurations for handling cost modeling of builtin programs. + +use solana_pubkey::Pubkey; + +/// Configuration for cost modeling of a builtin program. +#[derive(Debug)] +pub struct CostModelingConfig { + /// The default cost of the builtin program. + /// If None, this builtin program is not cost modeled. + pub default_cost: Option, + /// Configuration for updating the cost of the builtin program. + /// If None, the cost is never updated. + pub new_cost_config: Option, +} + +/// Configuration for updating the cost of a builtin program. +#[derive(Debug)] +pub struct NewCostModelingConfig { + /// The new cost of the builtin program. + pub new_cost: u64, + /// The feature gate to trigger the new cost. + pub feature_id: Pubkey, +} diff --git a/builtins/src/lib.rs b/builtins/src/lib.rs index 98dfa8c4304d7e..fd13a177e291bb 100644 --- a/builtins/src/lib.rs +++ b/builtins/src/lib.rs @@ -10,11 +10,13 @@ //! Core BPF, as well as whether or not that feature gate has been activated. pub mod core_bpf_migration; +pub mod cost_modeling; pub mod prototype; use { crate::{ core_bpf_migration::{CoreBpfMigrationConfig, CoreBpfMigrationTargetType}, + cost_modeling::CostModelingConfig, prototype::{BuiltinPrototype, StatelessBuiltinPrototype}, }, solana_feature_set as feature_set, @@ -53,6 +55,10 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ testable_prototype!(BuiltinPrototype { name: system_program, core_bpf_migration_config: None, + cost_modeling_config: CostModelingConfig { + default_cost: Some(solana_system_program::system_processor::DEFAULT_COMPUTE_UNITS), + new_cost_config: None + }, enable_feature_id: None, program_id: solana_system_program::id(), entrypoint: solana_system_program::system_processor::Entrypoint::vm, @@ -60,6 +66,10 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ testable_prototype!(BuiltinPrototype { name: vote_program, core_bpf_migration_config: None, + cost_modeling_config: CostModelingConfig { + default_cost: Some(solana_vote_program::vote_processor::DEFAULT_COMPUTE_UNITS), + new_cost_config: None + }, enable_feature_id: None, program_id: solana_vote_program::id(), entrypoint: solana_vote_program::vote_processor::Entrypoint::vm, @@ -73,6 +83,10 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ migration_target: CoreBpfMigrationTargetType::Builtin, datapoint_name: "migrate_builtin_to_core_bpf_stake_program", }), + cost_modeling_config: CostModelingConfig { + default_cost: Some(solana_stake_program::stake_instruction::DEFAULT_COMPUTE_UNITS), + new_cost_config: None, + }, enable_feature_id: None, program_id: solana_stake_program::id(), entrypoint: solana_stake_program::stake_instruction::Entrypoint::vm, @@ -86,6 +100,10 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ migration_target: CoreBpfMigrationTargetType::Builtin, datapoint_name: "migrate_builtin_to_core_bpf_config_program", }), + cost_modeling_config: CostModelingConfig { + default_cost: Some(solana_config_program::config_processor::DEFAULT_COMPUTE_UNITS), + new_cost_config: None, + }, enable_feature_id: None, program_id: solana_config_program::id(), entrypoint: solana_config_program::config_processor::Entrypoint::vm, @@ -93,6 +111,10 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ testable_prototype!(BuiltinPrototype { name: solana_bpf_loader_deprecated_program, core_bpf_migration_config: None, + cost_modeling_config: CostModelingConfig { + default_cost: Some(solana_bpf_loader_program::DEPRECATED_LOADER_COMPUTE_UNITS), + new_cost_config: None + }, enable_feature_id: None, program_id: bpf_loader_deprecated::id(), entrypoint: solana_bpf_loader_program::Entrypoint::vm, @@ -100,6 +122,10 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ testable_prototype!(BuiltinPrototype { name: solana_bpf_loader_program, core_bpf_migration_config: None, + cost_modeling_config: CostModelingConfig { + default_cost: Some(solana_bpf_loader_program::DEFAULT_LOADER_COMPUTE_UNITS), + new_cost_config: None + }, enable_feature_id: None, program_id: bpf_loader::id(), entrypoint: solana_bpf_loader_program::Entrypoint::vm, @@ -107,6 +133,10 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ testable_prototype!(BuiltinPrototype { name: solana_bpf_loader_upgradeable_program, core_bpf_migration_config: None, + cost_modeling_config: CostModelingConfig { + default_cost: Some(solana_bpf_loader_program::UPGRADEABLE_LOADER_COMPUTE_UNITS), + new_cost_config: None + }, enable_feature_id: None, program_id: bpf_loader_upgradeable::id(), entrypoint: solana_bpf_loader_program::Entrypoint::vm, @@ -114,6 +144,10 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ testable_prototype!(BuiltinPrototype { name: compute_budget_program, core_bpf_migration_config: None, + cost_modeling_config: CostModelingConfig { + default_cost: Some(solana_compute_budget_program::DEFAULT_COMPUTE_UNITS), + new_cost_config: None + }, enable_feature_id: None, program_id: solana_sdk_ids::compute_budget::id(), entrypoint: solana_compute_budget_program::Entrypoint::vm, @@ -127,6 +161,12 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ migration_target: CoreBpfMigrationTargetType::Builtin, datapoint_name: "migrate_builtin_to_core_bpf_address_lookup_table_program", }), + cost_modeling_config: CostModelingConfig { + default_cost: Some( + solana_address_lookup_table_program::processor::DEFAULT_COMPUTE_UNITS, + ), + new_cost_config: None, + }, enable_feature_id: None, program_id: solana_sdk_ids::address_lookup_table::id(), entrypoint: solana_address_lookup_table_program::processor::Entrypoint::vm, @@ -134,6 +174,10 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ testable_prototype!(BuiltinPrototype { name: zk_token_proof_program, core_bpf_migration_config: None, + cost_modeling_config: CostModelingConfig { + default_cost: None, // CUs are allocated per-instruction. + new_cost_config: None + }, enable_feature_id: Some(feature_set::zk_token_sdk_enabled::id()), program_id: solana_sdk_ids::zk_token_proof_program::id(), entrypoint: solana_zk_token_proof_program::Entrypoint::vm, @@ -141,6 +185,10 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ testable_prototype!(BuiltinPrototype { name: loader_v4, core_bpf_migration_config: None, + cost_modeling_config: CostModelingConfig { + default_cost: Some(solana_loader_v4_program::DEFAULT_COMPUTE_UNITS), + new_cost_config: None + }, enable_feature_id: Some(feature_set::enable_program_runtime_v2_and_loader_v4::id()), program_id: solana_sdk_ids::loader_v4::id(), entrypoint: solana_loader_v4_program::Entrypoint::vm, @@ -148,6 +196,10 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ testable_prototype!(BuiltinPrototype { name: zk_elgamal_proof_program, core_bpf_migration_config: None, + cost_modeling_config: CostModelingConfig { + default_cost: None, // CUs are allocated per-instruction. + new_cost_config: None + }, enable_feature_id: Some(feature_set::zk_elgamal_proof_program_enabled::id()), program_id: solana_sdk_ids::zk_elgamal_proof_program::id(), entrypoint: solana_zk_elgamal_proof_program::Entrypoint::vm, diff --git a/builtins/src/prototype.rs b/builtins/src/prototype.rs index 2b76dd5c353fec..b9147dd07a5ff5 100644 --- a/builtins/src/prototype.rs +++ b/builtins/src/prototype.rs @@ -1,14 +1,17 @@ //! Prototype layouts for builtins. use { - crate::core_bpf_migration::CoreBpfMigrationConfig, - solana_program_runtime::invoke_context::BuiltinFunctionWithContext, solana_pubkey::Pubkey, + crate::{core_bpf_migration::CoreBpfMigrationConfig, cost_modeling::CostModelingConfig}, + solana_program_runtime::invoke_context::BuiltinFunctionWithContext, + solana_pubkey::Pubkey, }; /// Transitions of built-in programs at epoch boundaries when features are activated. pub struct BuiltinPrototype { /// Configurations for migrating the builtin to Core BPF. pub core_bpf_migration_config: Option, + /// Configurations for cost modeling. + pub cost_modeling_config: CostModelingConfig, /// Feature ID that enables the builtin program. /// If None, the built-in program is always enabled. pub enable_feature_id: Option, @@ -27,6 +30,7 @@ impl std::fmt::Debug for BuiltinPrototype { builder.field("name", &self.name); builder.field("enable_feature_id", &self.enable_feature_id); builder.field("core_bpf_migration_config", &self.core_bpf_migration_config); + builder.field("cost_modeling_config", &self.cost_modeling_config); builder.finish() } }