Skip to content

Commit

Permalink
Add builtins crate (#3866)
Browse files Browse the repository at this point in the history
* init builtins crate

* port over migration configs

* port over prototypes

* port over builtins list

* runtime: remove unnecessary dependencies

* update crate comment

* add some more doc comments
  • Loading branch information
buffalojoec authored Dec 10, 2024
1 parent 2705f5e commit 6c6c26e
Show file tree
Hide file tree
Showing 16 changed files with 594 additions and 491 deletions.
29 changes: 22 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
"bench-tps",
"bloom",
"bucket_map",
"builtins",
"builtins-default-costs",
"cargo-registry",
"clap-utils",
Expand Down Expand Up @@ -442,6 +443,7 @@ solana-bn254 = { path = "curves/bn254", version = "=2.2.0" }
solana-borsh = { path = "sdk/borsh", version = "=2.2.0" }
solana-bpf-loader-program = { path = "programs/bpf_loader", version = "=2.2.0" }
solana-bucket-map = { path = "bucket_map", version = "=2.2.0" }
solana-builtins = { path = "builtins", version = "=2.2.0" }
solana-builtins-default-costs = { path = "builtins-default-costs", version = "=2.2.0" }
agave-cargo-registry = { path = "cargo-registry", version = "=2.2.0" }
solana-clap-utils = { path = "clap-utils", version = "=2.2.0" }
Expand Down
32 changes: 32 additions & 0 deletions builtins/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "solana-builtins"
description = "Solana builtin programs"
documentation = "https://docs.rs/solana-builtins"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[features]
dev-context-only-utils = []

[dependencies]
solana-address-lookup-table-program = { workspace = true }
solana-bpf-loader-program = { workspace = true }
solana-compute-budget-program = { workspace = true }
solana-config-program = { workspace = true }
solana-feature-set = { workspace = true }
solana-loader-v4-program = { workspace = true }
solana-program-runtime = { workspace = true }
solana-pubkey = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-stake-program = { workspace = true }
solana-system-program = { workspace = true }
solana-vote-program = { workspace = true }
solana-zk-elgamal-proof-program = { workspace = true }
solana-zk-token-proof-program = { workspace = true }

[lints]
workspace = true
40 changes: 40 additions & 0 deletions builtins/src/core_bpf_migration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use solana_pubkey::Pubkey;

/// Identifies the type of built-in program targeted for Core BPF migration.
/// The type of target determines whether the program should have a program
/// account or not, which is checked before migration.
#[allow(dead_code)] // Remove after first migration is configured.
#[derive(Debug, PartialEq)]
pub enum CoreBpfMigrationTargetType {
/// A standard (stateful) builtin program must have a program account.
Builtin,
/// A stateless builtin must not have a program account.
Stateless,
}

/// Configuration for migrating a built-in program to Core BPF.
#[derive(Debug, PartialEq)]
pub struct CoreBpfMigrationConfig {
/// The address of the source buffer account to be used to replace the
/// builtin.
pub source_buffer_address: Pubkey,
/// The authority to be used as the BPF program's upgrade authority.
///
/// Note: If this value is set to `None`, then the migration will ignore
/// the source buffer account's authority. If it's set to any `Some(..)`
/// value, then the migration will perform a sanity check to ensure the
/// source buffer account's authority matches the provided value.
pub upgrade_authority_address: Option<Pubkey>,
/// The feature gate to trigger the migration to Core BPF.
/// Note: This feature gate should never be the same as any builtin's
/// `enable_feature_id`. It should always be a feature gate that will be
/// activated after the builtin is already enabled.
pub feature_id: Pubkey,
/// The type of target to replace.
pub migration_target: CoreBpfMigrationTargetType,
/// Static message used to emit datapoint logging.
/// This is used to identify the migration in the logs.
/// Should be unique to the migration, ie:
/// "migrate_{builtin/stateless}_to_core_bpf_{program_name}".
pub datapoint_name: &'static str,
}
Loading

0 comments on commit 6c6c26e

Please sign in to comment.