Skip to content

Commit

Permalink
builtins: add cost modeling config
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Dec 10, 2024
1 parent 9eb67db commit 4a82ff1
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
23 changes: 23 additions & 0 deletions builtins/src/cost_modeling.rs
Original file line number Diff line number Diff line change
@@ -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<u64>,
/// Configuration for updating the cost of the builtin program.
/// If None, the cost is never updated.
pub new_cost_config: Option<NewCostModelingConfig>,
}

/// 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,
}
52 changes: 52 additions & 0 deletions builtins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -53,13 +55,21 @@ 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,
}),
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,
Expand All @@ -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,
Expand All @@ -86,34 +100,54 @@ 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,
},
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,
}),
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,
}),
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,
}),
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,
Expand All @@ -127,27 +161,45 @@ 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,
},
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,
}),
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,
}),
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,
Expand Down
8 changes: 6 additions & 2 deletions builtins/src/prototype.rs
Original file line number Diff line number Diff line change
@@ -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<CoreBpfMigrationConfig>,
/// 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<Pubkey>,
Expand All @@ -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()
}
}
Expand Down

0 comments on commit 4a82ff1

Please sign in to comment.