Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add and use EvmContext::take_error #1264

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading