diff --git a/Cargo.lock b/Cargo.lock index 37d0f13ac3a801..8ba41e517b9d6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6294,28 +6294,6 @@ dependencies = [ "solana-zk-token-proof-program", ] -[[package]] -name = "solana-builtins-default-costs" -version = "2.2.0" -dependencies = [ - "ahash 0.8.11", - "lazy_static", - "log", - "rand 0.8.5", - "solana-address-lookup-table-program", - "solana-bpf-loader-program", - "solana-compute-budget-program", - "solana-config-program", - "solana-feature-set", - "solana-frozen-abi", - "solana-loader-v4-program", - "solana-pubkey", - "solana-sdk-ids", - "solana-stake-program", - "solana-system-program", - "solana-vote-program", -] - [[package]] name = "solana-cargo-build-sbf" version = "2.2.0" @@ -6762,7 +6740,7 @@ dependencies = [ "solana-accounts-db", "solana-address-lookup-table-program", "solana-bloom", - "solana-builtins-default-costs", + "solana-builtins", "solana-client", "solana-compute-budget", "solana-compute-budget-program", @@ -6833,7 +6811,7 @@ dependencies = [ "lazy_static", "log", "rand 0.8.5", - "solana-builtins-default-costs", + "solana-builtins", "solana-compute-budget", "solana-compute-budget-program", "solana-cost-model", @@ -8640,7 +8618,7 @@ dependencies = [ "criterion", "log", "rand 0.8.5", - "solana-builtins-default-costs", + "solana-builtins", "solana-compute-budget", "solana-program", "solana-pubkey", diff --git a/Cargo.toml b/Cargo.toml index f523b220afa0a6..040d80b5b9681f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ members = [ "bloom", "bucket_map", "builtins", - "builtins-default-costs", "cargo-registry", "clap-utils", "clap-v3-utils", @@ -444,7 +443,6 @@ 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" } solana-clap-v3-utils = { path = "clap-v3-utils", version = "=2.2.0" } diff --git a/builtins-default-costs/Cargo.toml b/builtins-default-costs/Cargo.toml deleted file mode 100644 index 9c0a1e0753a799..00000000000000 --- a/builtins-default-costs/Cargo.toml +++ /dev/null @@ -1,49 +0,0 @@ -[package] -name = "solana-builtins-default-costs" -description = "Solana builtins default costs" -documentation = "https://docs.rs/solana-builtins-default-costs" -version = { workspace = true } -authors = { workspace = true } -repository = { workspace = true } -homepage = { workspace = true } -license = { workspace = true } -edition = { workspace = true } - -[dependencies] -ahash = { workspace = true } -lazy_static = { workspace = true } -log = { workspace = true } -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-frozen-abi = { workspace = true, optional = true, features = [ - "frozen-abi", -] } -solana-loader-v4-program = { 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 } -# Add additional builtin programs here - -[lib] -crate-type = ["lib"] -name = "solana_builtins_default_costs" - -[dev-dependencies] -rand = "0.8.5" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[features] -frozen-abi = [ - "dep:solana-frozen-abi", - "solana-vote-program/frozen-abi", -] - -[lints] -workspace = true diff --git a/builtins-default-costs/benches/builtin_instruction_costs.rs b/builtins-default-costs/benches/builtin_instruction_costs.rs deleted file mode 100644 index 71618852be5ef5..00000000000000 --- a/builtins-default-costs/benches/builtin_instruction_costs.rs +++ /dev/null @@ -1,74 +0,0 @@ -#![feature(test)] -extern crate test; -use { - rand::Rng, - solana_builtins_default_costs::get_builtin_instruction_cost, - solana_feature_set::FeatureSet, - solana_pubkey::Pubkey, - solana_sdk_ids::{ - address_lookup_table, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, - compute_budget, config, ed25519_program, loader_v4, secp256k1_program, stake, - system_program, vote, - }, - test::Bencher, -}; - -struct BenchSetup { - pubkeys: [Pubkey; 12], - feature_set: FeatureSet, -} - -const NUM_TRANSACTIONS_PER_ITER: usize = 1024; - -fn setup(all_features_enabled: bool) -> BenchSetup { - let pubkeys: [Pubkey; 12] = [ - stake::id(), - config::id(), - vote::id(), - system_program::id(), - compute_budget::id(), - address_lookup_table::id(), - bpf_loader_upgradeable::id(), - bpf_loader_deprecated::id(), - bpf_loader::id(), - loader_v4::id(), - secp256k1_program::id(), - ed25519_program::id(), - ]; - - let feature_set = if all_features_enabled { - FeatureSet::all_enabled() - } else { - FeatureSet::default() - }; - - BenchSetup { - pubkeys, - feature_set, - } -} - -fn do_hash_find(setup: &BenchSetup) { - for _t in 0..NUM_TRANSACTIONS_PER_ITER { - let idx = rand::thread_rng().gen_range(0..setup.pubkeys.len()); - get_builtin_instruction_cost(&setup.pubkeys[idx], &setup.feature_set); - } -} - -#[bench] -fn bench_hash_find_builtins_not_migrated(bencher: &mut Bencher) { - let bench_setup = setup(false); - - bencher.iter(|| { - do_hash_find(&bench_setup); - }); -} - -#[bench] -fn bench_hash_find_builtins_migrated(bencher: &mut Bencher) { - let bench_setup = setup(true); - - bencher.iter(|| { - do_hash_find(&bench_setup); - }); -} diff --git a/builtins-default-costs/src/lib.rs b/builtins-default-costs/src/lib.rs deleted file mode 100644 index 3150e799c42969..00000000000000 --- a/builtins-default-costs/src/lib.rs +++ /dev/null @@ -1,203 +0,0 @@ -#![cfg_attr(feature = "frozen-abi", feature(min_specialization))] -#![allow(clippy::arithmetic_side_effects)] -use { - ahash::AHashMap, - lazy_static::lazy_static, - solana_feature_set::{self as feature_set, FeatureSet}, - solana_pubkey::Pubkey, - solana_sdk_ids::{ - address_lookup_table, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, - compute_budget, config, ed25519_program, loader_v4, secp256k1_program, stake, - system_program, vote, - }, -}; - -/// DEVELOPER: when a builtin is migrated to sbpf, please add its corresponding -/// migration feature ID to BUILTIN_INSTRUCTION_COSTS, so the builtin's default -/// cost can be determined properly based on feature status. -/// When migration completed, eg the feature gate is enabled everywhere, please -/// remove that builtin entry from BUILTIN_INSTRUCTION_COSTS. -#[derive(Clone)] -struct BuiltinCost { - native_cost: u64, - core_bpf_migration_feature: Option, -} - -lazy_static! { - /// Number of compute units for each built-in programs - /// - /// DEVELOPER WARNING: This map CANNOT be modified without causing a - /// consensus failure because this map is used to calculate the compute - /// limit for transactions that don't specify a compute limit themselves as - /// of https://github.com/anza-xyz/agave/issues/2212. It's also used to - /// calculate the cost of a transaction which is used in replay to enforce - /// block cost limits as of - /// https://github.com/solana-labs/solana/issues/29595. - static ref BUILTIN_INSTRUCTION_COSTS: AHashMap = [ - ( - stake::id(), - BuiltinCost { - native_cost: solana_stake_program::stake_instruction::DEFAULT_COMPUTE_UNITS, - core_bpf_migration_feature: Some(feature_set::migrate_stake_program_to_core_bpf::id()), - }, - ), - ( - config::id(), - BuiltinCost { - native_cost: solana_config_program::config_processor::DEFAULT_COMPUTE_UNITS, - core_bpf_migration_feature: Some(feature_set::migrate_config_program_to_core_bpf::id()), - }, - ), - ( - vote::id(), - BuiltinCost { - native_cost: solana_vote_program::vote_processor::DEFAULT_COMPUTE_UNITS, - core_bpf_migration_feature: None, - }, - ), - ( - system_program::id(), - BuiltinCost { - native_cost: solana_system_program::system_processor::DEFAULT_COMPUTE_UNITS, - core_bpf_migration_feature: None, - }, - ), - ( - compute_budget::id(), - BuiltinCost { - native_cost: solana_compute_budget_program::DEFAULT_COMPUTE_UNITS, - core_bpf_migration_feature: None, - }, - ), - ( - address_lookup_table::id(), - BuiltinCost { - native_cost: solana_address_lookup_table_program::processor::DEFAULT_COMPUTE_UNITS, - core_bpf_migration_feature: Some( - feature_set::migrate_address_lookup_table_program_to_core_bpf::id(), - ), - }, - ), - ( - bpf_loader_upgradeable::id(), - BuiltinCost { - native_cost: solana_bpf_loader_program::UPGRADEABLE_LOADER_COMPUTE_UNITS, - core_bpf_migration_feature: None, - }, - ), - ( - bpf_loader_deprecated::id(), - BuiltinCost { - native_cost: solana_bpf_loader_program::DEPRECATED_LOADER_COMPUTE_UNITS, - core_bpf_migration_feature: None, - }, - ), - ( - bpf_loader::id(), - BuiltinCost { - native_cost: solana_bpf_loader_program::DEFAULT_LOADER_COMPUTE_UNITS, - core_bpf_migration_feature: None, - }, - ), - ( - loader_v4::id(), - BuiltinCost { - native_cost: solana_loader_v4_program::DEFAULT_COMPUTE_UNITS, - core_bpf_migration_feature: None, - }, - ), - // Note: These are precompile, run directly in bank during sanitizing; - ( - secp256k1_program::id(), - BuiltinCost { - native_cost: 0, - core_bpf_migration_feature: None, - }, - ), - ( - ed25519_program::id(), - BuiltinCost { - native_cost: 0, - core_bpf_migration_feature: None, - }, - ), - // DO NOT ADD MORE ENTRIES TO THIS MAP - ] - .iter() - .cloned() - .collect(); -} - -lazy_static! { - /// A table of 256 booleans indicates whether the first `u8` of a Pubkey exists in - /// BUILTIN_INSTRUCTION_COSTS. If the value is true, the Pubkey might be a builtin key; - /// if false, it cannot be a builtin key. This table allows for quick filtering of - /// builtin program IDs without the need for hashing. - pub static ref MAYBE_BUILTIN_KEY: [bool; 256] = { - let mut temp_table: [bool; 256] = [false; 256]; - BUILTIN_INSTRUCTION_COSTS - .keys() - .for_each(|key| temp_table[key.as_ref()[0] as usize] = true); - temp_table - }; -} - -pub fn get_builtin_instruction_cost<'a>( - program_id: &'a Pubkey, - feature_set: &'a FeatureSet, -) -> Option { - BUILTIN_INSTRUCTION_COSTS - .get(program_id) - .filter( - // Returns true if builtin program id has no core_bpf_migration_feature or feature is not activated; - // otherwise returns false because it's not considered as builtin - |builtin_cost| -> bool { - builtin_cost - .core_bpf_migration_feature - .map(|feature_id| !feature_set.is_active(&feature_id)) - .unwrap_or(true) - }, - ) - .map(|builtin_cost| builtin_cost.native_cost) -} - -#[inline] -pub fn is_builtin_program(program_id: &Pubkey) -> bool { - BUILTIN_INSTRUCTION_COSTS.contains_key(program_id) -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_get_builtin_instruction_cost() { - // use native cost if no migration planned - assert_eq!( - Some(solana_compute_budget_program::DEFAULT_COMPUTE_UNITS), - get_builtin_instruction_cost(&compute_budget::id(), &FeatureSet::all_enabled()) - ); - - // use native cost if migration is planned but not activated - assert_eq!( - Some(solana_stake_program::stake_instruction::DEFAULT_COMPUTE_UNITS), - get_builtin_instruction_cost(&solana_stake_program::id(), &FeatureSet::default()) - ); - - // None if migration is planned and activated, in which case, it's no longer builtin - assert!(get_builtin_instruction_cost( - &solana_stake_program::id(), - &FeatureSet::all_enabled() - ) - .is_none()); - - // None if not builtin - assert!( - get_builtin_instruction_cost(&Pubkey::new_unique(), &FeatureSet::default()).is_none() - ); - assert!( - get_builtin_instruction_cost(&Pubkey::new_unique(), &FeatureSet::all_enabled()) - .is_none() - ); - } -} diff --git a/core/Cargo.toml b/core/Cargo.toml index a9045d02dd09ed..fcff01e1788109 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -47,7 +47,7 @@ serde_derive = { workspace = true } slab = { workspace = true } solana-accounts-db = { workspace = true } solana-bloom = { workspace = true } -solana-builtins-default-costs = { workspace = true } +solana-builtins = { workspace = true } solana-client = { workspace = true } solana-compute-budget = { workspace = true } solana-connection-cache = { workspace = true } diff --git a/core/src/banking_stage/packet_filter.rs b/core/src/banking_stage/packet_filter.rs index b9176c9b8ac91d..b87624d8abd86f 100644 --- a/core/src/banking_stage/packet_filter.rs +++ b/core/src/banking_stage/packet_filter.rs @@ -1,7 +1,7 @@ use { super::immutable_deserialized_packet::ImmutableDeserializedPacket, lazy_static::lazy_static, - solana_builtins_default_costs::get_builtin_instruction_cost, + solana_builtins::cost_modeling::get_builtin_instruction_cost, solana_sdk::{ ed25519_program, feature_set::FeatureSet, saturating_add_assign, secp256k1_program, }, diff --git a/cost-model/Cargo.toml b/cost-model/Cargo.toml index d6e9e5b6e2bd46..8dc2b9ba34ccbc 100644 --- a/cost-model/Cargo.toml +++ b/cost-model/Cargo.toml @@ -13,7 +13,7 @@ edition = { workspace = true } ahash = { workspace = true } lazy_static = { workspace = true } log = { workspace = true } -solana-builtins-default-costs = { workspace = true } +solana-builtins = { workspace = true } solana-compute-budget = { workspace = true } solana-feature-set = { workspace = true } solana-frozen-abi = { workspace = true, optional = true, features = [ diff --git a/cost-model/src/cost_model.rs b/cost-model/src/cost_model.rs index 612492b8b1126f..819481ffe62f05 100644 --- a/cost-model/src/cost_model.rs +++ b/cost-model/src/cost_model.rs @@ -7,7 +7,7 @@ use { crate::{block_cost_limits::*, transaction_cost::*}, - solana_builtins_default_costs::get_builtin_instruction_cost, + solana_builtins::cost_modeling::get_builtin_instruction_cost, solana_compute_budget::compute_budget_limits::{ DEFAULT_HEAP_COST, DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_LIMIT, }, diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index a2ab6f24415be6..ef3776056ae86b 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5179,26 +5179,6 @@ dependencies = [ "solana-zk-token-proof-program", ] -[[package]] -name = "solana-builtins-default-costs" -version = "2.2.0" -dependencies = [ - "ahash 0.8.11", - "lazy_static", - "log", - "solana-address-lookup-table-program", - "solana-bpf-loader-program", - "solana-compute-budget-program", - "solana-config-program", - "solana-feature-set", - "solana-loader-v4-program", - "solana-pubkey", - "solana-sdk-ids", - "solana-stake-program", - "solana-system-program", - "solana-vote-program", -] - [[package]] name = "solana-clap-utils" version = "2.2.0" @@ -5455,7 +5435,7 @@ dependencies = [ "slab", "solana-accounts-db", "solana-bloom", - "solana-builtins-default-costs", + "solana-builtins", "solana-client", "solana-compute-budget", "solana-connection-cache", @@ -5512,7 +5492,7 @@ dependencies = [ "ahash 0.8.11", "lazy_static", "log", - "solana-builtins-default-costs", + "solana-builtins", "solana-compute-budget", "solana-feature-set", "solana-metrics", @@ -6815,7 +6795,7 @@ version = "2.2.0" dependencies = [ "agave-transaction-view", "log", - "solana-builtins-default-costs", + "solana-builtins", "solana-compute-budget", "solana-pubkey", "solana-sdk", diff --git a/runtime-transaction/Cargo.toml b/runtime-transaction/Cargo.toml index 7f925bda81a7bb..83f21c6cba2aee 100644 --- a/runtime-transaction/Cargo.toml +++ b/runtime-transaction/Cargo.toml @@ -12,7 +12,7 @@ edition = { workspace = true } [dependencies] agave-transaction-view = { workspace = true } log = { workspace = true } -solana-builtins-default-costs = { workspace = true } +solana-builtins = { workspace = true } solana-compute-budget = { workspace = true } solana-pubkey = { workspace = true } solana-sdk = { workspace = true } diff --git a/runtime-transaction/src/builtin_programs_filter.rs b/runtime-transaction/src/builtin_programs_filter.rs index fc935a023cfbf8..8e3d4e06250e18 100644 --- a/runtime-transaction/src/builtin_programs_filter.rs +++ b/runtime-transaction/src/builtin_programs_filter.rs @@ -1,6 +1,6 @@ use { agave_transaction_view::static_account_keys_frame::MAX_STATIC_ACCOUNTS_PER_PACKET as FILTER_SIZE, - solana_builtins_default_costs::{is_builtin_program, MAYBE_BUILTIN_KEY}, + solana_builtins::cost_modeling::{is_builtin_program, MAYBE_BUILTIN_KEY}, solana_sdk::pubkey::Pubkey, }; diff --git a/runtime-transaction/src/compute_budget_program_id_filter.rs b/runtime-transaction/src/compute_budget_program_id_filter.rs index 59c6144a091229..dd4ef09cb67612 100644 --- a/runtime-transaction/src/compute_budget_program_id_filter.rs +++ b/runtime-transaction/src/compute_budget_program_id_filter.rs @@ -1,7 +1,7 @@ // static account keys has max use { agave_transaction_view::static_account_keys_frame::MAX_STATIC_ACCOUNTS_PER_PACKET as FILTER_SIZE, - solana_builtins_default_costs::MAYBE_BUILTIN_KEY, solana_sdk::pubkey::Pubkey, + solana_builtins::cost_modeling::MAYBE_BUILTIN_KEY, solana_sdk::pubkey::Pubkey, }; pub(crate) struct ComputeBudgetProgramIdFilter { diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index af0d3cdb49afc8..eadb5502d8f1c7 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -5030,26 +5030,6 @@ dependencies = [ "solana-zk-token-proof-program", ] -[[package]] -name = "solana-builtins-default-costs" -version = "2.2.0" -dependencies = [ - "ahash 0.8.11", - "lazy_static", - "log", - "solana-address-lookup-table-program", - "solana-bpf-loader-program", - "solana-compute-budget-program", - "solana-config-program", - "solana-feature-set", - "solana-loader-v4-program", - "solana-pubkey", - "solana-sdk-ids", - "solana-stake-program", - "solana-system-program", - "solana-vote-program", -] - [[package]] name = "solana-clap-utils" version = "2.2.0" @@ -5306,7 +5286,7 @@ dependencies = [ "slab", "solana-accounts-db", "solana-bloom", - "solana-builtins-default-costs", + "solana-builtins", "solana-client", "solana-compute-budget", "solana-connection-cache", @@ -5363,7 +5343,7 @@ dependencies = [ "ahash 0.8.11", "lazy_static", "log", - "solana-builtins-default-costs", + "solana-builtins", "solana-compute-budget", "solana-feature-set", "solana-metrics", @@ -6634,7 +6614,7 @@ version = "2.2.0" dependencies = [ "agave-transaction-view", "log", - "solana-builtins-default-costs", + "solana-builtins", "solana-compute-budget", "solana-pubkey", "solana-sdk",