Skip to content

Commit

Permalink
Change visibility of svm-internal structs and APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 committed Jan 14, 2025
1 parent 8a0c9b4 commit 1a2f777
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 61 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

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

9 changes: 6 additions & 3 deletions builtins-default-costs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ edition = { workspace = true }
ahash = { workspace = true }
lazy_static = { workspace = true }
log = { workspace = true }
qualifier_attr = { workspace = true }
solana-address-lookup-table-program = { workspace = true }
solana-bpf-loader-program = { workspace = true }
solana-compute-budget-program = { workspace = true }
solana-bpf-loader-program = { workspace = true, features = ["svm-internal"] }
solana-compute-budget-program = { workspace = true, features = ["svm-internal"] }
solana-config-program = { workspace = true }
solana-feature-set = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true, features = [
"frozen-abi",
] }
solana-loader-v4-program = { workspace = true }
solana-loader-v4-program = { workspace = true, features = ["svm-internal"] }
solana-pubkey = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-stake-program = { workspace = true }
Expand All @@ -35,6 +36,7 @@ name = "solana_builtins_default_costs"

[dev-dependencies]
rand = "0.8.5"
solana-builtins-default-costs = { path = ".", features = ["svm-internal"] }
static_assertions = { workspace = true }

[package.metadata.docs.rs]
Expand All @@ -46,6 +48,7 @@ frozen-abi = [
"solana-vote-program/frozen-abi",
]
dev-context-only-utils = []
svm-internal = []

[lints]
workspace = true
32 changes: 25 additions & 7 deletions builtins-default-costs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![cfg_attr(feature = "frozen-abi", feature(min_specialization))]
#![allow(clippy::arithmetic_side_effects)]
#[cfg(feature = "svm-internal")]
use qualifier_attr::qualifiers;
use {
ahash::AHashMap,
lazy_static::lazy_static,
Expand All @@ -13,7 +15,8 @@ use {
};

#[derive(Clone)]
pub struct MigratingBuiltinCost {
#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
struct MigratingBuiltinCost {
native_cost: u64,
core_bpf_migration_feature: Pubkey,
// encoding positional information explicitly for migration feature item,
Expand All @@ -24,7 +27,8 @@ pub struct MigratingBuiltinCost {
}

#[derive(Clone)]
pub struct NotMigratingBuiltinCost {
#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
struct NotMigratingBuiltinCost {
native_cost: u64,
}

Expand All @@ -35,19 +39,23 @@ pub struct NotMigratingBuiltinCost {
/// When migration completed, eg the feature gate is enabled everywhere, please
/// remove that builtin entry from MIGRATING_BUILTINS_COSTS.
#[derive(Clone)]
pub enum BuiltinCost {
#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
enum BuiltinCost {
Migrating(MigratingBuiltinCost),
NotMigrating(NotMigratingBuiltinCost),
}

impl BuiltinCost {
#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
fn native_cost(&self) -> u64 {
match self {
BuiltinCost::Migrating(MigratingBuiltinCost { native_cost, .. }) => *native_cost,
BuiltinCost::NotMigrating(NotMigratingBuiltinCost { native_cost }) => *native_cost,
}
}

#[cfg(feature = "svm-internal")]
#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
fn core_bpf_migration_feature(&self) -> Option<&Pubkey> {
match self {
BuiltinCost::Migrating(MigratingBuiltinCost {
Expand All @@ -58,13 +66,16 @@ impl BuiltinCost {
}
}

#[cfg(feature = "svm-internal")]
#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
fn position(&self) -> Option<usize> {
match self {
BuiltinCost::Migrating(MigratingBuiltinCost { position, .. }) => Some(*position),
BuiltinCost::NotMigrating(_) => None,
}
}

#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
fn has_migrated(&self, feature_set: &FeatureSet) -> bool {
match self {
BuiltinCost::Migrating(MigratingBuiltinCost {
Expand Down Expand Up @@ -109,7 +120,8 @@ static_assertions::const_assert_eq!(
TOTAL_COUNT_BUILTS
);

pub const MIGRATING_BUILTINS_COSTS: &[(Pubkey, BuiltinCost)] = &[
#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
const MIGRATING_BUILTINS_COSTS: &[(Pubkey, BuiltinCost)] = &[
(
stake::id(),
BuiltinCost::Migrating(MigratingBuiltinCost {
Expand Down Expand Up @@ -215,13 +227,17 @@ pub fn get_builtin_instruction_cost<'a>(
.map(|builtin_cost| builtin_cost.native_cost())
}

pub enum BuiltinMigrationFeatureIndex {
#[cfg(feature = "svm-internal")]
#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
enum BuiltinMigrationFeatureIndex {
NotBuiltin,
BuiltinNoMigrationFeature,
BuiltinWithMigrationFeature(usize),
}

pub fn get_builtin_migration_feature_index(program_id: &Pubkey) -> BuiltinMigrationFeatureIndex {
#[cfg(feature = "svm-internal")]
#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
fn get_builtin_migration_feature_index(program_id: &Pubkey) -> BuiltinMigrationFeatureIndex {
BUILTIN_INSTRUCTION_COSTS.get(program_id).map_or(
BuiltinMigrationFeatureIndex::NotBuiltin,
|builtin_cost| {
Expand Down Expand Up @@ -254,7 +270,9 @@ const _: () = validate_position(MIGRATING_BUILTINS_COSTS);

/// Helper function to return ref of migration feature Pubkey at position `index`
/// from MIGRATING_BUILTINS_COSTS
pub fn get_migration_feature_id(index: usize) -> &'static Pubkey {
#[cfg(feature = "svm-internal")]
#[cfg_attr(feature = "svm-internal", qualifiers(pub))]
pub(crate) fn get_migration_feature_id(index: usize) -> &'static Pubkey {
MIGRATING_BUILTINS_COSTS
.get(index)
.expect("valid index of MIGRATING_BUILTINS_COSTS")
Expand Down
4 changes: 2 additions & 2 deletions compute-budget-instruction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = { workspace = true }
[dependencies]
log = { workspace = true }
solana-borsh = { workspace = true }
solana-builtins-default-costs = { workspace = true }
solana-builtins-default-costs = { workspace = true, features = ["svm-internal"] }
solana-compute-budget = { workspace = true }
solana-compute-budget-interface = { workspace = true }
solana-feature-set = { workspace = true }
Expand All @@ -32,7 +32,7 @@ name = "solana_compute_budget_instruction"
bincode = { workspace = true }
criterion = { workspace = true }
rand = { workspace = true }
solana-builtins-default-costs = { workspace = true, features = ["dev-context-only-utils"] }
solana-builtins-default-costs = { workspace = true, features = ["dev-context-only-utils", "svm-internal"] }
solana-hash = { workspace = true }
solana-keypair = { workspace = true }
solana-message = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions programs/bpf_loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ edition = { workspace = true }
bincode = { workspace = true }
byteorder = { workspace = true }
libsecp256k1 = { workspace = true }
qualifier_attr = { workspace = true }
scopeguard = { workspace = true }
solana-account = { workspace = true }
solana-account-info = { workspace = true }
Expand Down Expand Up @@ -54,6 +55,7 @@ thiserror = { workspace = true }
assert_matches = { workspace = true }
criterion = { workspace = true }
rand = { workspace = true }
solana-bpf-loader-program = { path = ".", features = ["svm-internal"] }
solana-epoch-rewards = { workspace = true }
solana-epoch-schedule = { workspace = true }
solana-fee-calculator = { workspace = true }
Expand Down Expand Up @@ -87,3 +89,4 @@ shuttle-test = [
"solana-program-runtime/shuttle-test",
"solana-sbpf/shuttle-test"
]
svm-internal = []
Loading

0 comments on commit 1a2f777

Please sign in to comment.