diff --git a/cost-model/src/block_cost_limits.rs b/cost-model/src/block_cost_limits.rs index e27d1991fc3348..c101979887d0b6 100644 --- a/cost-model/src/block_cost_limits.rs +++ b/cost-model/src/block_cost_limits.rs @@ -24,6 +24,7 @@ pub const INSTRUCTION_DATA_BYTES_COST: u64 = 140 /*bytes per us*/ / COMPUTE_UNIT /// calculated by cost_model, based on transaction's signatures, write locks, /// data size and built-in and SBF instructions. pub const MAX_BLOCK_UNITS: u64 = 48_000_000; +pub const MAX_BLOCK_UNITS_SIMD_0207: u64 = 50_000_000; /// Number of compute units that a writable account in a block is allowed. The /// limit is to prevent too many transactions write to same account, therefore @@ -34,9 +35,19 @@ pub const MAX_WRITABLE_ACCOUNT_UNITS: u64 = 12_000_000; /// set to less than MAX_BLOCK_UNITS to leave room for non-vote transactions pub const MAX_VOTE_UNITS: u64 = 36_000_000; -#[cfg(test)] -static_assertions::const_assert!(MAX_VOTE_UNITS < MAX_BLOCK_UNITS); - /// The maximum allowed size, in bytes, that accounts data can grow, per block. /// This can also be thought of as the maximum size of new allocations per block. pub const MAX_BLOCK_ACCOUNTS_DATA_SIZE_DELTA: u64 = 100_000_000; + +/// Return the block limits that will be used upon activation of SIMD-0207. +/// Returns as +/// (account_limit, block_limit, vote_limit) +// ^ Above order is used to be consistent with the order of +// `CostTracker::set_limits`. +pub const fn simd_0207_block_limits() -> (u64, u64, u64) { + ( + MAX_WRITABLE_ACCOUNT_UNITS, + MAX_BLOCK_UNITS_SIMD_0207, + MAX_VOTE_UNITS, + ) +} diff --git a/cost-model/src/cost_tracker.rs b/cost-model/src/cost_tracker.rs index 3ca2c84d048b98..98a6433ebdf698 100644 --- a/cost-model/src/cost_tracker.rs +++ b/cost-model/src/cost_tracker.rs @@ -129,6 +129,11 @@ impl CostTracker { self.in_flight_transaction_count = 0; } + /// Get the overall block limit. + pub fn get_block_limit(&self) -> u64 { + self.block_cost_limit + } + /// allows to adjust limits initiated during construction pub fn set_limits( &mut self, diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 4c892a8c33412f..84b1c10f1b8e5a 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -97,7 +97,7 @@ use { solana_builtins::{prototype::BuiltinPrototype, BUILTINS, STATELESS_BUILTINS}, solana_compute_budget::compute_budget::ComputeBudget, solana_compute_budget_instruction::instructions_processor::process_compute_budget_instructions, - solana_cost_model::cost_tracker::CostTracker, + solana_cost_model::{block_cost_limits::simd_0207_block_limits, cost_tracker::CostTracker}, solana_feature_set::{ self as feature_set, remove_rounding_in_fee_calculation, reward_full_priority_fee, FeatureSet, @@ -6917,6 +6917,15 @@ impl Bank { ); } } + + if new_feature_activations.contains(&feature_set::raise_block_limits_to_50m::id()) { + let (account_cost_limit, block_cost_limit, vote_cost_limit) = simd_0207_block_limits(); + self.write_cost_tracker().unwrap().set_limits( + account_cost_limit, + block_cost_limit, + vote_cost_limit, + ); + } } fn apply_updated_hashes_per_tick(&mut self, hashes_per_tick: u64) { diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 5f1f751865ebb6..210b64eb1820dc 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -37,6 +37,7 @@ use { compute_budget::ComputeBudget, compute_budget_limits::{self, ComputeBudgetLimits, MAX_COMPUTE_UNIT_LIMIT}, }, + solana_cost_model::block_cost_limits::{MAX_BLOCK_UNITS, MAX_BLOCK_UNITS_SIMD_0207}, solana_feature_set::{self as feature_set, FeatureSet}, solana_inline_spl::token, solana_logger, @@ -7999,6 +8000,39 @@ fn test_reserved_account_keys() { ); } +#[test] +fn test_block_limits() { + let (bank0, _bank_forks) = create_simple_test_arc_bank(100_000); + let mut bank = Bank::new_from_parent(bank0, &Pubkey::default(), 1); + bank.feature_set = Arc::new(FeatureSet::default()); + + assert_eq!( + bank.read_cost_tracker().unwrap().get_block_limit(), + MAX_BLOCK_UNITS, + "before activating the feature, bank should have old/default limit" + ); + + // Activate `raise_block_limits_to_50m` feature + bank.store_account( + &feature_set::raise_block_limits_to_50m::id(), + &feature::create_account(&Feature::default(), 42), + ); + bank.apply_feature_activations(ApplyFeatureActivationsCaller::NewFromParent, true); + assert_eq!( + bank.read_cost_tracker().unwrap().get_block_limit(), + MAX_BLOCK_UNITS_SIMD_0207, + "after activating the feature, bank should have new limit" + ); + + // Make sure the limits propagate to the child-bank. + let bank = Bank::new_from_parent(Arc::new(bank), &Pubkey::default(), 2); + assert_eq!( + bank.read_cost_tracker().unwrap().get_block_limit(), + MAX_BLOCK_UNITS_SIMD_0207, + "child bank should have new limit" + ); +} + #[test] fn test_program_replacement() { let mut bank = create_simple_test_bank(0); diff --git a/sdk/feature-set/src/lib.rs b/sdk/feature-set/src/lib.rs index adf6968904a256..4eefad3ce7112a 100644 --- a/sdk/feature-set/src/lib.rs +++ b/sdk/feature-set/src/lib.rs @@ -900,6 +900,10 @@ pub mod reserve_minimal_cus_for_builtin_instructions { solana_pubkey::declare_id!("C9oAhLxDBm3ssWtJx1yBGzPY55r2rArHmN1pbQn6HogH"); } +pub mod raise_block_limits_to_50m { + solana_pubkey::declare_id!("5oMCU3JPaFLr8Zr4ct7yFA7jdk6Mw1RmB8K4u9ZbS42z"); +} + lazy_static! { /// Map of feature identifiers to user-visible description pub static ref FEATURE_NAMES: AHashMap = [ @@ -1120,6 +1124,7 @@ lazy_static! { (migrate_stake_program_to_core_bpf::id(), "Migrate Stake program to Core BPF SIMD-0196 #3655"), (deplete_cu_meter_on_vm_failure::id(), "Deplete compute meter for vm errors SIMD-0182 #3993"), (reserve_minimal_cus_for_builtin_instructions::id(), "Reserve minimal CUs for builtin instructions SIMD-170 #2562"), + (raise_block_limits_to_50m::id(), "Raise block limit to 50M SIMD-0207"), /*************** ADD NEW FEATURES HERE ***************/ ] .iter()