Skip to content

Commit

Permalink
v2.0: use new feature gate for cu depletion (backport of solana-labs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Jan 6, 2025
1 parent 9a78950 commit d642903
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use {
clock::Slot,
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
feature_set::{
apply_cost_tracker_during_replay, bpf_account_data_direct_mapping,
bpf_account_data_direct_mapping, deplete_cu_meter_on_vm_failure,
enable_bpf_loader_set_authority_checked_ix,
},
instruction::{AccountMeta, InstructionError},
Expand Down Expand Up @@ -1436,7 +1436,7 @@ fn execute<'a, 'b: 'a>(
ProgramResult::Err(mut error) => {
if invoke_context
.get_feature_set()
.is_active(&apply_cost_tracker_during_replay::id())
.is_active(&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 @@ -4631,13 +4631,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 @@ -4685,7 +4685,7 @@ fn test_deplete_cost_meter_with_access_violation() {
TransactionError::InstructionError(1, InstructionError::ExecutableDataModified)
);

if apply_cost_tracker {
if deplete_cu_meter_on_vm_failure {
assert_eq!(executed_units, u64::from(compute_unit_limit));
} else {
assert!(executed_units < u64::from(compute_unit_limit));
Expand All @@ -4704,13 +4704,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 @@ -4741,7 +4741,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!(executed_units, u64::from(compute_unit_limit));
} else {
assert!(executed_units < u64::from(compute_unit_limit));
Expand Down
7 changes: 6 additions & 1 deletion sdk/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ pub mod delay_visibility_of_program_deployment {
}

pub mod apply_cost_tracker_during_replay {
solana_sdk::declare_id!("B7H2caeia4ZFcpE3QcgMqbiWiBtWrdBRBSJ1DY6Ktxbq");
solana_sdk::declare_id!("2ry7ygxiYURULZCrypHhveanvP5tzZ4toRwVp89oCNSj");
}

pub mod bpf_account_data_direct_mapping {
Expand Down Expand Up @@ -862,6 +862,10 @@ pub mod disable_account_loader_special_case {
solana_program::declare_id!("EQUMpNFr7Nacb1sva56xn1aLfBxppEoSBH8RRVdkcD1x");
}

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

lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
Expand Down Expand Up @@ -1072,6 +1076,7 @@ lazy_static! {
(enable_turbine_extended_fanout_experiments::id(), "enable turbine extended fanout experiments #2373"),
(deprecate_legacy_vote_ixs::id(), "Deprecate legacy vote instructions"),
(disable_account_loader_special_case::id(), "Disable account loader special case"),
(deplete_cu_meter_on_vm_failure::id(), "Deplete compute meter for vm errors SIMD-0182 #3993"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()
Expand Down

0 comments on commit d642903

Please sign in to comment.