Skip to content

Commit

Permalink
use new feature gate for cu depletion (solana-labs#3994)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry authored Dec 11, 2024
1 parent 695b3f4 commit 11467d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ pub fn execute<'a, 'b: 'a>(
ProgramResult::Err(mut error) => {
if invoke_context
.get_feature_set()
.is_active(&solana_feature_set::apply_cost_tracker_during_replay::id())
.is_active(&solana_feature_set::deplete_cu_meter_on_vm_failure::id())
&& !matches!(error, EbpfError::SyscallError(_))
{
// when an exception is thrown during the execution of a
Expand Down
16 changes: 8 additions & 8 deletions programs/sbf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4642,13 +4642,13 @@ fn test_deplete_cost_meter_with_access_violation() {
..
} = create_genesis_config(100_123_456_789);

for apply_cost_tracker in [false, true] {
for deplete_cu_meter_on_vm_failure in [false, true] {
let mut bank = Bank::new_for_tests(&genesis_config);
let feature_set = Arc::make_mut(&mut bank.feature_set);
// by default test banks have all features enabled, so we only need to
// disable when needed
if !apply_cost_tracker {
feature_set.deactivate(&feature_set::apply_cost_tracker_during_replay::id());
if !deplete_cu_meter_on_vm_failure {
feature_set.deactivate(&feature_set::deplete_cu_meter_on_vm_failure::id());
}
let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests();
let mut bank_client = BankClient::new_shared(bank.clone());
Expand Down Expand Up @@ -4696,7 +4696,7 @@ fn test_deplete_cost_meter_with_access_violation() {
TransactionError::InstructionError(1, InstructionError::ReadonlyDataModified)
);

if apply_cost_tracker {
if deplete_cu_meter_on_vm_failure {
assert_eq!(result.executed_units, u64::from(compute_unit_limit));
} else {
assert!(result.executed_units < u64::from(compute_unit_limit));
Expand All @@ -4715,13 +4715,13 @@ fn test_program_sbf_deplete_cost_meter_with_divide_by_zero() {
..
} = create_genesis_config(50);

for apply_cost_tracker in [false, true] {
for deplete_cu_meter_on_vm_failure in [false, true] {
let mut bank = Bank::new_for_tests(&genesis_config);
let feature_set = Arc::make_mut(&mut bank.feature_set);
// by default test banks have all features enabled, so we only need to
// disable when needed
if !apply_cost_tracker {
feature_set.deactivate(&feature_set::apply_cost_tracker_during_replay::id());
if !deplete_cu_meter_on_vm_failure {
feature_set.deactivate(&feature_set::deplete_cu_meter_on_vm_failure::id());
}
let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests();
let mut bank_client = BankClient::new_shared(bank.clone());
Expand Down Expand Up @@ -4752,7 +4752,7 @@ fn test_program_sbf_deplete_cost_meter_with_divide_by_zero() {
TransactionError::InstructionError(1, InstructionError::ProgramFailedToComplete)
);

if apply_cost_tracker {
if deplete_cu_meter_on_vm_failure {
assert_eq!(result.executed_units, u64::from(compute_unit_limit));
} else {
assert!(result.executed_units < u64::from(compute_unit_limit));
Expand Down
7 changes: 6 additions & 1 deletion sdk/feature-set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ pub mod delay_visibility_of_program_deployment {
}

pub mod apply_cost_tracker_during_replay {
solana_pubkey::declare_id!("B7H2caeia4ZFcpE3QcgMqbiWiBtWrdBRBSJ1DY6Ktxbq");
solana_pubkey::declare_id!("2ry7ygxiYURULZCrypHhveanvP5tzZ4toRwVp89oCNSj");
}
pub mod bpf_account_data_direct_mapping {
solana_pubkey::declare_id!("GJVDwRkUPNdk9QaK4VsU4g1N41QNxhy1hevjf8kz45Mq");
Expand Down Expand Up @@ -892,6 +892,10 @@ pub mod migrate_stake_program_to_core_bpf {
solana_pubkey::declare_id!("6M4oQ6eXneVhtLoiAr4yRYQY43eVLjrKbiDZDJc892yk");
}

pub mod deplete_cu_meter_on_vm_failure {
solana_pubkey::declare_id!("B7H2caeia4ZFcpE3QcgMqbiWiBtWrdBRBSJ1DY6Ktxbq");
}

pub mod reserve_minimal_cus_for_builtin_instructions {
solana_pubkey::declare_id!("C9oAhLxDBm3ssWtJx1yBGzPY55r2rArHmN1pbQn6HogH");
}
Expand Down Expand Up @@ -1114,6 +1118,7 @@ lazy_static! {
(accounts_lt_hash::id(), "enables lattice-based accounts hash #3333"),
(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"),
(reserve_minimal_cus_for_builtin_instructions::id(), "Reserve minimal CUs for builtin instructions SIMD-170 #2562"),
/*************** ADD NEW FEATURES HERE ***************/
]
Expand Down

0 comments on commit 11467d9

Please sign in to comment.