diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 9f62c4f036f5ab..53f4b57cbc4105 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -1473,6 +1473,25 @@ pub fn execute<'a, 'b: 'a>( Err(Box::new(error) as Box) } ProgramResult::Err(mut error) => { + if invoke_context + .get_feature_set() + .is_active(&solana_feature_set::apply_cost_tracker_during_replay::id()) + { + if !matches!(error, EbpfError::SyscallError(_)) { + // when an exception is thrown during the execution of a + // Basic Block (e.g., a null memory dereference or other + // faults), determining the exact number of CUs consumed + // up to the point of failure requires additional effort + // and is unnecessary since these cases are rare. + // + // In order to simplify CU tracking, simply consume all + // remaining compute units so that the block cost + // tracker uses the full requested compute unit cost for + // this failed transaction. + invoke_context.consume(invoke_context.get_remaining()); + } + } + if direct_mapping { if let EbpfError::AccessViolation( AccessType::Store,