Skip to content

Commit

Permalink
v2.1: SIMD-0207: Raise block limit to 50M (backport of #4112) (#4145)
Browse files Browse the repository at this point in the history
* SIMD-0207: Raise block limit to 50M (#4112)

* SIMD-0207: Raise block limit to 50M (#4026)

* Fix loading from snapshots/genesis

(cherry picked from commit 9e59baa)

* resolve conflicts

* Add deplete_cu_meter_on_vm_failure back in

deplete-cu-meter existed in master prior to 50M-cu feature. However,
50M-cu was marked for v2.1 BP before deplete-cu-meter. So, the merge
resolution had to remove that out. deplete-cu-meter has since been BP'd
to v2.1, so this PR now needs to keep it again

---------

Co-authored-by: Andrew Fitzgerald <[email protected]>
Co-authored-by: steviez <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent bc18e44 commit df063a8
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cost-model/src/block_cost_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub const MAX_BLOCK_UNITS: u64 =

#[cfg(test)]
static_assertions::const_assert_eq!(MAX_BLOCK_UNITS, 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
Expand All @@ -57,3 +58,16 @@ static_assertions::const_assert_eq!(MAX_VOTE_UNITS, 36_000_000);
/// 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,
)
}
5 changes: 5 additions & 0 deletions cost-model/src/cost_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 26 additions & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ use {
create_program_runtime_environment_v1, create_program_runtime_environment_v2,
},
solana_compute_budget::compute_budget::ComputeBudget,
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,
Expand Down Expand Up @@ -5066,6 +5066,22 @@ impl Bank {
debug_do_not_add_builtins,
);

// Cost-Tracker is not serialized in snapshot or any configs.
// We must apply previously activated features related to limits here
// so that the initial bank state is consistent with the feature set.
// Cost-tracker limits are propagated through children banks.
if self
.feature_set
.is_active(&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,
);
}

if !debug_do_not_add_builtins {
for builtin in BUILTINS
.iter()
Expand Down Expand Up @@ -6639,6 +6655,15 @@ impl Bank {
if new_feature_activations.contains(&feature_set::update_hashes_per_tick6::id()) {
self.apply_updated_hashes_per_tick(UPDATED_HASHES_PER_TICK6);
}

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) {
Expand Down
68 changes: 68 additions & 0 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use {
compute_budget_limits::{self, MAX_COMPUTE_UNIT_LIMIT},
prioritization_fee::{PrioritizationFeeDetails, PrioritizationFeeType},
},
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,
Expand Down Expand Up @@ -7999,6 +8000,73 @@ 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);
assert!(!bank
.feature_set
.is_active(&feature_set::raise_block_limits_to_50m::id()));
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),
);
// apply_feature_activations for `FinishInit` will not cause the block limit to be updated
bank.apply_feature_activations(ApplyFeatureActivationsCaller::FinishInit, true);
assert_eq!(
bank.read_cost_tracker().unwrap().get_block_limit(),
MAX_BLOCK_UNITS,
"before activating the feature, bank should have old/default limit"
);

// apply_feature_activations for `NewFromParent` will cause feature to be activated
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 starting from a genesis config with and without feature account
let (mut genesis_config, _keypair) = create_genesis_config(100_000);
// Without feature account in genesis, old limits are used.
let bank = Bank::new_for_tests(&genesis_config);
assert_eq!(
bank.read_cost_tracker().unwrap().get_block_limit(),
MAX_BLOCK_UNITS,
"before activating the feature, bank should have old/default limit"
);

activate_feature(
&mut genesis_config,
feature_set::raise_block_limits_to_50m::id(),
);
let bank = Bank::new_for_tests(&genesis_config);
assert!(bank
.feature_set
.is_active(&feature_set::raise_block_limits_to_50m::id()));
assert_eq!(
bank.read_cost_tracker().unwrap().get_block_limit(),
MAX_BLOCK_UNITS_SIMD_0207,
"bank created from genesis config should have new limit"
);
}

#[test]
fn test_program_replacement() {
let mut bank = create_simple_test_bank(0);
Expand Down
5 changes: 5 additions & 0 deletions sdk/feature-set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,10 @@ pub mod deplete_cu_meter_on_vm_failure {
solana_pubkey::declare_id!("B7H2caeia4ZFcpE3QcgMqbiWiBtWrdBRBSJ1DY6Ktxbq");
}

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: HashMap<Pubkey, &'static str> = [
Expand Down Expand Up @@ -1101,6 +1105,7 @@ lazy_static! {
(enable_secp256r1_precompile::id(), "Enable secp256r1 precompile SIMD-0075"),
(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"),
(raise_block_limits_to_50m::id(), "Raise block limit to 50M SIMD-0207"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()
Expand Down

0 comments on commit df063a8

Please sign in to comment.