Skip to content

Commit

Permalink
Fix some nits
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Oct 12, 2023
1 parent a3cab2c commit a8108be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
16 changes: 6 additions & 10 deletions core/lib/vm/src/implementation/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ impl<S: WriteStorage, H: HistoryMode> Vm<S, H> {
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<S, H> = DefaultExecutionTracer::new(
self.system_env.default_validation_computational_gas_limit,
execution_mode,
Expand Down Expand Up @@ -73,11 +70,10 @@ impl<S: WriteStorage, H: HistoryMode> Vm<S, H> {

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,
Expand Down
17 changes: 8 additions & 9 deletions core/lib/vm/src/tracers/default_tracers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub(crate) struct DefaultExecutionTracer<S, H: HistoryMode> {
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<RefundsTracer>,
pub(crate) custom_tracers: Vec<Box<dyn VmTracer<S, H>>>,
ret_from_the_bootloader: Option<RetOpcode>,
Expand Down Expand Up @@ -209,17 +212,13 @@ impl<S: WriteStorage, H: HistoryMode> DefaultExecutionTracer<S, H> {

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(
Expand Down
6 changes: 2 additions & 4 deletions core/lib/vm/src/tracers/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ impl TracerExecutionStatus {
pub fn stricter(&self, other: &Self) -> Self {
match (self, other) {
(Self::Continue, Self::Continue) => Self::Continue,
(Self::Stop(TracerExecutionStopReason::Abort(reason)), _) => {
Self::Stop(TracerExecutionStopReason::Abort(reason.clone()))
}
(_, Self::Stop(TracerExecutionStopReason::Abort(reason))) => {
(Self::Stop(TracerExecutionStopReason::Abort(reason)), _)
| (_, Self::Stop(TracerExecutionStopReason::Abort(reason))) => {
Self::Stop(TracerExecutionStopReason::Abort(reason.clone()))
}
(Self::Stop(TracerExecutionStopReason::Finish), _)
Expand Down

0 comments on commit a8108be

Please sign in to comment.