diff --git a/core/lib/vm/src/implementation/execution.rs b/core/lib/vm/src/implementation/execution.rs index 7c12ad14181e..ff22abf615a9 100644 --- a/core/lib/vm/src/implementation/execution.rs +++ b/core/lib/vm/src/implementation/execution.rs @@ -37,11 +37,8 @@ impl Vm { execution_mode: VmExecutionMode, with_refund_tracer: bool, ) -> (VmExecutionStopReason, VmExecutionResultAndLogs) { - let refund_tracers = if with_refund_tracer { - Some(RefundsTracer::new(self.batch_env.clone())) - } else { - None - }; + let refund_tracers = + with_refund_tracer.then_some(RefundsTracer::new(self.batch_env.clone())); let mut tx_tracer: DefaultExecutionTracer = DefaultExecutionTracer::new( self.system_env.default_validation_computational_gas_limit, execution_mode, @@ -73,11 +70,10 @@ impl Vm { let result = tx_tracer.result_tracer.into_result(); - let refunds = if let Some(refund_tracer) = tx_tracer.refund_tracer { - refund_tracer.get_refunds() - } else { - Default::default() - }; + let refunds = tx_tracer + .refund_tracer + .map(|x| x.get_refunds()) + .unwrap_or_default(); let result = VmExecutionResultAndLogs { result, diff --git a/core/lib/vm/src/tracers/default_tracers.rs b/core/lib/vm/src/tracers/default_tracers.rs index 3bbdb702add5..1278990964a5 100644 --- a/core/lib/vm/src/tracers/default_tracers.rs +++ b/core/lib/vm/src/tracers/default_tracers.rs @@ -40,6 +40,9 @@ pub(crate) struct DefaultExecutionTracer { in_account_validation: bool, final_batch_info_requested: bool, pub(crate) result_tracer: ResultTracer, + // This tracer is designed specifically for calculating refunds. Its separation from the custom tracer + // ensures static dispatch, enhancing performance by avoiding dynamic dispatch overhead. + // Additionally, being an internal tracer, it saves the results directly to VmResultAndLogs. pub(crate) refund_tracer: Option, pub(crate) custom_tracers: Vec>>, ret_from_the_bootloader: Option, @@ -209,17 +212,13 @@ impl DefaultExecutionTracer { fn should_stop_execution(&self) -> TracerExecutionStatus { match self.execution_mode { - VmExecutionMode::OneTx => { - if self.tx_has_been_processed() { - return TracerExecutionStatus::Stop(TracerExecutionStopReason::Finish); - } + VmExecutionMode::OneTx if self.tx_has_been_processed() => { + return TracerExecutionStatus::Stop(TracerExecutionStopReason::Finish); } - VmExecutionMode::Bootloader => { - if self.ret_from_the_bootloader == Some(RetOpcode::Ok) { - return TracerExecutionStatus::Stop(TracerExecutionStopReason::Finish); - } + VmExecutionMode::Bootloader if self.ret_from_the_bootloader == Some(RetOpcode::Ok) => { + return TracerExecutionStatus::Stop(TracerExecutionStopReason::Finish); } - VmExecutionMode::Batch => {} + _ => {} }; if self.validation_run_out_of_gas() { return TracerExecutionStatus::Stop(TracerExecutionStopReason::Abort(