Skip to content

Commit

Permalink
v2.1: feat: deplete compute meter for vm errors (backport of solana-l…
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Jan 6, 2025
1 parent 4893047 commit 709c8d9
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 @@ -1434,7 +1434,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 @@ -4641,13 +4641,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 @@ -4695,7 +4695,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!(result.executed_units, u64::from(compute_unit_limit));
} else {
assert!(result.executed_units < u64::from(compute_unit_limit));
Expand All @@ -4714,13 +4714,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 @@ -4751,7 +4751,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 @@ -615,7 +615,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 @@ -881,6 +881,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");
}

lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
Expand Down Expand Up @@ -1096,6 +1100,7 @@ lazy_static! {
(disable_account_loader_special_case::id(), "Disable account loader special case #3513"),
(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"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()
Expand Down

0 comments on commit 709c8d9

Please sign in to comment.