Skip to content

Commit

Permalink
add a helper type
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed May 13, 2024
1 parent daedecb commit f50b10c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
26 changes: 18 additions & 8 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ where
}
}

/// Helper type for the output of executing a block.
#[derive(Debug, Clone)]
struct EthExecuteOutput {
receipts: Vec<Receipt>,
requests: Vec<Request>,
gas_used: u64,
}

/// Helper container type for EVM with chain spec.
#[derive(Debug, Clone)]
struct EthEvmExecutor<EvmConfig> {
Expand All @@ -120,7 +128,8 @@ impl<EvmConfig> EthEvmExecutor<EvmConfig>
where
EvmConfig: ConfigureEvm,
{
/// Executes the transactions in the block and returns the receipts.
/// Executes the transactions in the block and returns the receipts of the transactions in the
/// block, the total gas used and the list of EIP-7685 [requests](Request).
///
/// This applies the pre-execution and post-execution changes that require an [EVM](Evm), and
/// executes the transactions.
Expand All @@ -133,7 +142,7 @@ where
&self,
block: &BlockWithSenders,
evm: &mut Evm<'_, Ext, &mut State<DB>>,
) -> Result<(Vec<Receipt>, Vec<Request>, u64), BlockExecutionError>
) -> Result<EthExecuteOutput, BlockExecutionError>
where
DB: Database<Error = ProviderError>,
{
Expand Down Expand Up @@ -207,7 +216,7 @@ where
post_block_withdrawal_requests(&self.chain_spec, block.timestamp, evm)?;
let requests = withdrawal_requests;

Ok((receipts, requests, cumulative_gas_used))
Ok(EthExecuteOutput { receipts, requests, gas_used: cumulative_gas_used })
}
}

Expand Down Expand Up @@ -276,13 +285,13 @@ where
&mut self,
block: &BlockWithSenders,
total_difficulty: U256,
) -> Result<(Vec<Receipt>, Vec<Request>, u64), BlockExecutionError> {
) -> Result<EthExecuteOutput, BlockExecutionError> {
// 1. prepare state on new block
self.on_new_block(&block.header);

// 2. configure the evm and execute
let env = self.evm_env_for_block(&block.header, total_difficulty);
let (receipts, requests, gas_used) = {
let EthExecuteOutput { receipts, requests, gas_used } = {
let mut evm = self.executor.evm_config.evm_with_env(&mut self.state, env);
self.executor.execute_state_transitions(block, &mut evm)
}?;
Expand All @@ -305,7 +314,7 @@ where
};
}

Ok((receipts, requests, gas_used))
Ok(EthExecuteOutput { receipts, requests, gas_used })
}

/// Apply settings before a new block is executed.
Expand Down Expand Up @@ -373,7 +382,8 @@ where
/// State changes are committed to the database.
fn execute(mut self, input: Self::Input<'_>) -> Result<Self::Output, Self::Error> {
let BlockExecutionInput { block, total_difficulty } = input;
let (receipts, requests, gas_used) = self.execute_and_verify(block, total_difficulty)?;
let EthExecuteOutput { receipts, requests, gas_used } =
self.execute_and_verify(block, total_difficulty)?;

// NOTE: we need to merge keep the reverts for the bundle retention
self.state.merge_transitions(BundleRetention::Reverts);
Expand Down Expand Up @@ -415,7 +425,7 @@ where

fn execute_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error> {
let BlockExecutionInput { block, total_difficulty } = input;
let (receipts, requests, _gas_used) =
let EthExecuteOutput { receipts, requests, gas_used: _ } =
self.executor.execute_and_verify(block, total_difficulty)?;

// prepare the state according to the prune mode
Expand Down
10 changes: 5 additions & 5 deletions crates/ethereum/evm/src/instructions/eip3074.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ fn auth_instruction<EXT, DB: Database>(
ctx.remove(AUTHORIZED_VAR_NAME);
push!(interp, B256::ZERO.into());
interp.instruction_result = InstructionResult::Continue;
return;
return
}
acc
}
Err(_) => {
interp.instruction_result = InstructionResult::Revert;
return;
return
}
};
let nonce = authority_account.0.info.nonce;
Expand All @@ -132,7 +132,7 @@ fn auth_instruction<EXT, DB: Database>(
Ok(signer) => signer,
Err(_) => {
interp.instruction_result = InstructionResult::Revert;
return;
return
}
};

Expand Down Expand Up @@ -164,7 +164,7 @@ fn authcall_instruction<EXT, DB: Database>(
Some(address) => Address::from_slice(&address),
None => {
interp.instruction_result = InstructionResult::Revert;
return;
return
}
};

Expand All @@ -181,7 +181,7 @@ fn authcall_instruction<EXT, DB: Database>(
pop!(interp, value);
if interp.is_static && value != U256::ZERO {
interp.instruction_result = InstructionResult::CallNotAllowedInsideStatic;
return;
return
}

let Some((input, return_memory_offset)) = get_memory_input_and_out_ranges(interp) else {
Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use reth_revm::{
};
use revm_primitives::{
db::{Database, DatabaseCommit},
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState,
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, Requests, ResultAndState,
};
use std::sync::Arc;
use tracing::{debug, trace};
Expand Down Expand Up @@ -392,7 +392,7 @@ where
state: self.state.take_bundle(),
receipts,
gas_used,
requests: vec![],
requests: Requests::default(),
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use reth_interfaces::provider::{ProviderError, ProviderResult};
use reth_primitives::{
logs_bloom,
revm::compat::{into_reth_acc, into_revm_acc},
Account, Address, BlockNumber, Bloom, Bytecode, Log, Receipt, Receipts, StaticFileSegment,
StorageEntry, B256, U256,
Account, Address, BlockNumber, Bloom, Bytecode, Log, Receipt, Receipts, Requests,
StaticFileSegment, StorageEntry, B256, U256,
};
use reth_trie::HashedPostState;
pub use revm::db::states::OriginalValuesKnown;
Expand Down Expand Up @@ -49,7 +49,7 @@ impl From<BundleStateWithReceipts> for BatchBlockExecutionOutput {
fn from(value: BundleStateWithReceipts) -> Self {
let BundleStateWithReceipts { bundle, receipts, first_block } = value;
// TODO(alexey): add requests
Self { bundle, receipts, requests: vec![], first_block }
Self { bundle, receipts, requests: Requests::default(), first_block }
}
}

Expand Down

0 comments on commit f50b10c

Please sign in to comment.