Skip to content

Commit 057244e

Browse files
apfitzgemergify[bot]
authored andcommitted
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) # Conflicts: # cost-model/src/block_cost_limits.rs # runtime/src/bank.rs # sdk/feature-set/src/lib.rs
1 parent 8a652ac commit 057244e

File tree

5 files changed

+193
-0
lines changed

5 files changed

+193
-0
lines changed

cost-model/src/block_cost_limits.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,23 @@ pub const INSTRUCTION_DATA_BYTES_COST: u64 = 140 /*bytes per us*/ / COMPUTE_UNIT
3333
/// accumulated by Transactions added to it; A transaction's compute units are
3434
/// calculated by cost_model, based on transaction's signatures, write locks,
3535
/// data size and built-in and SBF instructions.
36+
<<<<<<< HEAD
3637
pub const MAX_BLOCK_UNITS: u64 =
3738
MAX_BLOCK_REPLAY_TIME_US * COMPUTE_UNIT_TO_US_RATIO * MAX_CONCURRENCY;
3839

3940
#[cfg(test)]
4041
static_assertions::const_assert_eq!(MAX_BLOCK_UNITS, 48_000_000);
42+
=======
43+
pub const MAX_BLOCK_UNITS: u64 = 48_000_000;
44+
pub const MAX_BLOCK_UNITS_SIMD_0207: u64 = 50_000_000;
45+
>>>>>>> 9e59baae7 (SIMD-0207: Raise block limit to 50M (#4112))
4146

4247
/// Number of compute units that a writable account in a block is allowed. The
4348
/// limit is to prevent too many transactions write to same account, therefore
4449
/// reduce block's parallelism.
4550
pub const MAX_WRITABLE_ACCOUNT_UNITS: u64 = MAX_BLOCK_REPLAY_TIME_US * COMPUTE_UNIT_TO_US_RATIO;
4651

52+
<<<<<<< HEAD
4753
#[cfg(test)]
4854
static_assertions::const_assert_eq!(MAX_WRITABLE_ACCOUNT_UNITS, 12_000_000);
4955

@@ -54,6 +60,21 @@ pub const MAX_VOTE_UNITS: u64 = (MAX_BLOCK_UNITS as f64 * 0.75_f64) as u64;
5460
#[cfg(test)]
5561
static_assertions::const_assert_eq!(MAX_VOTE_UNITS, 36_000_000);
5662

63+
=======
64+
>>>>>>> 9e59baae7 (SIMD-0207: Raise block limit to 50M (#4112))
5765
/// The maximum allowed size, in bytes, that accounts data can grow, per block.
5866
/// This can also be thought of as the maximum size of new allocations per block.
5967
pub const MAX_BLOCK_ACCOUNTS_DATA_SIZE_DELTA: u64 = 100_000_000;
68+
69+
/// Return the block limits that will be used upon activation of SIMD-0207.
70+
/// Returns as
71+
/// (account_limit, block_limit, vote_limit)
72+
// ^ Above order is used to be consistent with the order of
73+
// `CostTracker::set_limits`.
74+
pub const fn simd_0207_block_limits() -> (u64, u64, u64) {
75+
(
76+
MAX_WRITABLE_ACCOUNT_UNITS,
77+
MAX_BLOCK_UNITS_SIMD_0207,
78+
MAX_VOTE_UNITS,
79+
)
80+
}

cost-model/src/cost_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ impl CostTracker {
129129
self.in_flight_transaction_count = 0;
130130
}
131131

132+
/// Get the overall block limit.
133+
pub fn get_block_limit(&self) -> u64 {
134+
self.block_cost_limit
135+
}
136+
132137
/// allows to adjust limits initiated during construction
133138
pub fn set_limits(
134139
&mut self,

runtime/src/bank.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ use {
9696
create_program_runtime_environment_v1, create_program_runtime_environment_v2,
9797
},
9898
solana_compute_budget::compute_budget::ComputeBudget,
99+
<<<<<<< HEAD
99100
solana_cost_model::cost_tracker::CostTracker,
101+
=======
102+
solana_compute_budget_instruction::instructions_processor::process_compute_budget_instructions,
103+
solana_cost_model::{block_cost_limits::simd_0207_block_limits, cost_tracker::CostTracker},
104+
>>>>>>> 9e59baae7 (SIMD-0207: Raise block limit to 50M (#4112))
100105
solana_feature_set::{
101106
self as feature_set, remove_rounding_in_fee_calculation, reward_full_priority_fee,
102107
FeatureSet,
@@ -5066,6 +5071,22 @@ impl Bank {
50665071
debug_do_not_add_builtins,
50675072
);
50685073

5074+
// Cost-Tracker is not serialized in snapshot or any configs.
5075+
// We must apply previously activated features related to limits here
5076+
// so that the initial bank state is consistent with the feature set.
5077+
// Cost-tracker limits are propagated through children banks.
5078+
if self
5079+
.feature_set
5080+
.is_active(&feature_set::raise_block_limits_to_50m::id())
5081+
{
5082+
let (account_cost_limit, block_cost_limit, vote_cost_limit) = simd_0207_block_limits();
5083+
self.write_cost_tracker().unwrap().set_limits(
5084+
account_cost_limit,
5085+
block_cost_limit,
5086+
vote_cost_limit,
5087+
);
5088+
}
5089+
50695090
if !debug_do_not_add_builtins {
50705091
for builtin in BUILTINS
50715092
.iter()
@@ -6639,6 +6660,63 @@ impl Bank {
66396660
if new_feature_activations.contains(&feature_set::update_hashes_per_tick6::id()) {
66406661
self.apply_updated_hashes_per_tick(UPDATED_HASHES_PER_TICK6);
66416662
}
6663+
<<<<<<< HEAD
6664+
=======
6665+
6666+
if new_feature_activations.contains(&feature_set::accounts_lt_hash::id()) {
6667+
// Activating the accounts lt hash feature means we need to have an accounts lt hash
6668+
// value at the end of this if-block. If the cli arg has been used, that means we
6669+
// already have an accounts lt hash and do not need to recalculate it.
6670+
if self
6671+
.rc
6672+
.accounts
6673+
.accounts_db
6674+
.is_experimental_accumulator_hash_enabled()
6675+
{
6676+
// We already have an accounts lt hash value, so no need to recalculate it.
6677+
// Nothing else to do here.
6678+
} else {
6679+
let parent_slot = self.parent_slot;
6680+
info!(
6681+
"Calculating the accounts lt hash for slot {parent_slot} \
6682+
as part of feature activation; this may take some time...",
6683+
);
6684+
// We must calculate the accounts lt hash now as part of feature activation.
6685+
// Note, this bank is *not* frozen yet, which means it will later call
6686+
// `update_accounts_lt_hash()`. Therefore, we calculate the accounts lt hash based
6687+
// on *our parent*, not us!
6688+
let parent_ancestors = {
6689+
let mut ancestors = self.ancestors.clone();
6690+
ancestors.remove(&self.slot());
6691+
ancestors
6692+
};
6693+
let (parent_accounts_lt_hash, duration) = meas_dur!({
6694+
self.rc
6695+
.accounts
6696+
.accounts_db
6697+
.calculate_accounts_lt_hash_at_startup_from_index(
6698+
&parent_ancestors,
6699+
parent_slot,
6700+
)
6701+
});
6702+
*self.accounts_lt_hash.get_mut().unwrap() = parent_accounts_lt_hash;
6703+
info!(
6704+
"Calculating the accounts lt hash for slot {parent_slot} \
6705+
completed in {duration:?}, accounts_lt_hash checksum: {}",
6706+
self.accounts_lt_hash.get_mut().unwrap().0.checksum(),
6707+
);
6708+
}
6709+
}
6710+
6711+
if new_feature_activations.contains(&feature_set::raise_block_limits_to_50m::id()) {
6712+
let (account_cost_limit, block_cost_limit, vote_cost_limit) = simd_0207_block_limits();
6713+
self.write_cost_tracker().unwrap().set_limits(
6714+
account_cost_limit,
6715+
block_cost_limit,
6716+
vote_cost_limit,
6717+
);
6718+
}
6719+
>>>>>>> 9e59baae7 (SIMD-0207: Raise block limit to 50M (#4112))
66426720
}
66436721

66446722
fn apply_updated_hashes_per_tick(&mut self, hashes_per_tick: u64) {

runtime/src/bank/tests.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use {
3838
compute_budget_limits::{self, MAX_COMPUTE_UNIT_LIMIT},
3939
prioritization_fee::{PrioritizationFeeDetails, PrioritizationFeeType},
4040
},
41+
solana_cost_model::block_cost_limits::{MAX_BLOCK_UNITS, MAX_BLOCK_UNITS_SIMD_0207},
4142
solana_feature_set::{self as feature_set, FeatureSet},
4243
solana_inline_spl::token,
4344
solana_logger,
@@ -7999,6 +8000,73 @@ fn test_reserved_account_keys() {
79998000
);
80008001
}
80018002

8003+
#[test]
8004+
fn test_block_limits() {
8005+
let (bank0, _bank_forks) = create_simple_test_arc_bank(100_000);
8006+
let mut bank = Bank::new_from_parent(bank0, &Pubkey::default(), 1);
8007+
assert!(!bank
8008+
.feature_set
8009+
.is_active(&feature_set::raise_block_limits_to_50m::id()));
8010+
assert_eq!(
8011+
bank.read_cost_tracker().unwrap().get_block_limit(),
8012+
MAX_BLOCK_UNITS,
8013+
"before activating the feature, bank should have old/default limit"
8014+
);
8015+
8016+
// Activate `raise_block_limits_to_50m` feature
8017+
bank.store_account(
8018+
&feature_set::raise_block_limits_to_50m::id(),
8019+
&feature::create_account(&Feature::default(), 42),
8020+
);
8021+
// apply_feature_activations for `FinishInit` will not cause the block limit to be updated
8022+
bank.apply_feature_activations(ApplyFeatureActivationsCaller::FinishInit, true);
8023+
assert_eq!(
8024+
bank.read_cost_tracker().unwrap().get_block_limit(),
8025+
MAX_BLOCK_UNITS,
8026+
"before activating the feature, bank should have old/default limit"
8027+
);
8028+
8029+
// apply_feature_activations for `NewFromParent` will cause feature to be activated
8030+
bank.apply_feature_activations(ApplyFeatureActivationsCaller::NewFromParent, true);
8031+
assert_eq!(
8032+
bank.read_cost_tracker().unwrap().get_block_limit(),
8033+
MAX_BLOCK_UNITS_SIMD_0207,
8034+
"after activating the feature, bank should have new limit"
8035+
);
8036+
8037+
// Make sure the limits propagate to the child-bank.
8038+
let bank = Bank::new_from_parent(Arc::new(bank), &Pubkey::default(), 2);
8039+
assert_eq!(
8040+
bank.read_cost_tracker().unwrap().get_block_limit(),
8041+
MAX_BLOCK_UNITS_SIMD_0207,
8042+
"child bank should have new limit"
8043+
);
8044+
8045+
// Test starting from a genesis config with and without feature account
8046+
let (mut genesis_config, _keypair) = create_genesis_config(100_000);
8047+
// Without feature account in genesis, old limits are used.
8048+
let bank = Bank::new_for_tests(&genesis_config);
8049+
assert_eq!(
8050+
bank.read_cost_tracker().unwrap().get_block_limit(),
8051+
MAX_BLOCK_UNITS,
8052+
"before activating the feature, bank should have old/default limit"
8053+
);
8054+
8055+
activate_feature(
8056+
&mut genesis_config,
8057+
feature_set::raise_block_limits_to_50m::id(),
8058+
);
8059+
let bank = Bank::new_for_tests(&genesis_config);
8060+
assert!(bank
8061+
.feature_set
8062+
.is_active(&feature_set::raise_block_limits_to_50m::id()));
8063+
assert_eq!(
8064+
bank.read_cost_tracker().unwrap().get_block_limit(),
8065+
MAX_BLOCK_UNITS_SIMD_0207,
8066+
"bank created from genesis config should have new limit"
8067+
);
8068+
}
8069+
80028070
#[test]
80038071
fn test_program_replacement() {
80048072
let mut bank = create_simple_test_bank(0);

sdk/feature-set/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,21 @@ pub mod migrate_stake_program_to_core_bpf {
881881
solana_pubkey::declare_id!("6M4oQ6eXneVhtLoiAr4yRYQY43eVLjrKbiDZDJc892yk");
882882
}
883883

884+
<<<<<<< HEAD
885+
=======
886+
pub mod deplete_cu_meter_on_vm_failure {
887+
solana_pubkey::declare_id!("B7H2caeia4ZFcpE3QcgMqbiWiBtWrdBRBSJ1DY6Ktxbq");
888+
}
889+
890+
pub mod reserve_minimal_cus_for_builtin_instructions {
891+
solana_pubkey::declare_id!("C9oAhLxDBm3ssWtJx1yBGzPY55r2rArHmN1pbQn6HogH");
892+
}
893+
894+
pub mod raise_block_limits_to_50m {
895+
solana_pubkey::declare_id!("5oMCU3JPaFLr8Zr4ct7yFA7jdk6Mw1RmB8K4u9ZbS42z");
896+
}
897+
898+
>>>>>>> 9e59baae7 (SIMD-0207: Raise block limit to 50M (#4112))
884899
lazy_static! {
885900
/// Map of feature identifiers to user-visible description
886901
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
@@ -1096,6 +1111,12 @@ lazy_static! {
10961111
(disable_account_loader_special_case::id(), "Disable account loader special case #3513"),
10971112
(enable_secp256r1_precompile::id(), "Enable secp256r1 precompile SIMD-0075"),
10981113
(migrate_stake_program_to_core_bpf::id(), "Migrate Stake program to Core BPF SIMD-0196 #3655"),
1114+
<<<<<<< HEAD
1115+
=======
1116+
(deplete_cu_meter_on_vm_failure::id(), "Deplete compute meter for vm errors SIMD-0182 #3993"),
1117+
(reserve_minimal_cus_for_builtin_instructions::id(), "Reserve minimal CUs for builtin instructions SIMD-170 #2562"),
1118+
(raise_block_limits_to_50m::id(), "Raise block limit to 50M SIMD-0207"),
1119+
>>>>>>> 9e59baae7 (SIMD-0207: Raise block limit to 50M (#4112))
10991120
/*************** ADD NEW FEATURES HERE ***************/
11001121
]
11011122
.iter()

0 commit comments

Comments
 (0)