Skip to content

Commit

Permalink
chore: add and use EvmContext::take_error (bluealloy#1264)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Apr 5, 2024
1 parent 4d64bbc commit 5e730a6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions crates/revm/src/context/inner_evm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ impl<DB: Database> InnerEvmContext<DB> {
&mut self.env
}

/// Returns the error by replacing it with `Ok(())`, if any.
pub fn take_error(&mut self) -> Result<(), EVMError<DB::Error>> {
core::mem::replace(&mut self.error, Ok(()))
}

/// Fetch block hash from database.
#[inline]
pub fn block_hash(&mut self, number: U256) -> Result<B256, EVMError<DB::Error>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {

// take error and break the loop if there is any.
// This error is set From Interpreter when it's interacting with Host.
core::mem::replace(&mut self.context.evm.error, Ok(()))?;
self.context.evm.take_error()?;
// take shared memory back.
shared_memory = interpreter.take_memory();

Expand Down
4 changes: 2 additions & 2 deletions crates/revm/src/handler/mainnet/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn insert_call_outcome<EXT, DB: Database>(
shared_memory: &mut SharedMemory,
outcome: CallOutcome,
) -> Result<(), EVMError<DB::Error>> {
core::mem::replace(&mut context.evm.error, Ok(()))?;
context.evm.take_error()?;
frame
.frame_data_mut()
.interpreter
Expand Down Expand Up @@ -128,7 +128,7 @@ pub fn insert_create_outcome<EXT, DB: Database>(
frame: &mut Frame,
outcome: CreateOutcome,
) -> Result<(), EVMError<DB::Error>> {
core::mem::replace(&mut context.evm.error, Ok(()))?;
context.evm.take_error()?;
frame
.frame_data_mut()
.interpreter
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/handler/mainnet/post_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn output<EXT, DB: Database>(
context: &mut Context<EXT, DB>,
result: FrameResult,
) -> Result<ResultAndState, EVMError<DB::Error>> {
core::mem::replace(&mut context.evm.error, Ok(()))?;
context.evm.take_error()?;
// used gas with refund calculated.
let gas_refunded = result.gas().refunded() as u64;
let final_gas_used = result.gas().spent() - gas_refunded;
Expand Down

0 comments on commit 5e730a6

Please sign in to comment.