MCPcopy Create free account
hub / github.com/base/base / catch_error

Method catch_error

crates/common/evm/src/handler.rs:348–395  ·  view source on GitHub ↗
(
        &self,
        evm: &mut Self::Evm,
        error: Self::Error,
    )

Source from the content-addressed store, hash-verified

346 }
347
348 fn catch_error(
349 &self,
350 evm: &mut Self::Evm,
351 error: Self::Error,
352 ) -> Result<ExecutionResult<Self::HaltReason>, Self::Error> {
353 let is_deposit = evm.ctx().tx().tx_type() == DEPOSIT_TRANSACTION_TYPE;
354 let is_tx_error = error.is_tx_error();
355 let mut output = Err(error);
356
357 // Deposit transaction can't fail so we manually handle it here.
358 if is_tx_error && is_deposit {
359 let ctx = evm.ctx();
360 let tx = ctx.tx();
361 let caller = tx.caller();
362 let mint = tx.mint();
363 let gas_limit = tx.gas_limit();
364 let journal = evm.ctx().journal_mut();
365
366 // discard all changes of this transaction
367 // Default JournalCheckpoint is the first checkpoint and will wipe all changes.
368 journal.checkpoint_revert(JournalCheckpoint::default());
369
370 let mut acc = journal.load_account_mut(caller)?;
371 acc.bump_nonce();
372 acc.incr_balance(U256::from(mint.unwrap_or_default()));
373
374 drop(acc); // Drop acc to avoid borrow checker issues.
375
376 // We can now commit the changes.
377 journal.commit_tx();
378
379 // clear the journal
380 output = Ok(ExecutionResult::Halt {
381 reason: BaseHaltReason::FailedDeposit,
382 gas: ResultGas::new_with_state_gas(gas_limit, 0, 0, 0),
383 logs: Vec::new(),
384 })
385 } else {
386 evm.ctx().journal_mut().discard_tx();
387 }
388
389 // do the cleanup
390 evm.ctx().chain_mut().clear_tx_l1_cost();
391 evm.ctx().local_mut().clear();
392 evm.frame_stack().clear();
393
394 output
395 }
396}
397
398impl<EVM, ERROR> InspectorHandler for BaseHandler<EVM, ERROR, EthFrame<EthInterpreter>>

Callers

nothing calls this directly

Calls 11

ctxMethod · 0.80
is_tx_errorMethod · 0.80
clear_tx_l1_costMethod · 0.80
newFunction · 0.50
tx_typeMethod · 0.45
txMethod · 0.45
callerMethod · 0.45
mintMethod · 0.45
gas_limitMethod · 0.45
checkpoint_revertMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected