Skip to content

Commit

Permalink
feat: enhance block execution input and output structures with additi…
Browse files Browse the repository at this point in the history
…onal fields
  • Loading branch information
johntaiko committed Dec 19, 2024
1 parent 6a043ba commit d3ceb71
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 284 deletions.
21 changes: 11 additions & 10 deletions crates/ethereum/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ reth-primitives = { workspace = true, features = ["reth-codec"] }
reth-revm.workspace = true
reth-ethereum-consensus.workspace = true
reth-consensus.workspace = true
reth-execution-types.workspace = true

# Ethereum
revm-primitives.workspace = true
Expand All @@ -42,14 +43,14 @@ alloy-genesis.workspace = true
[features]
default = ["std"]
std = [
"reth-consensus/std",
"reth-primitives/std",
"reth-revm/std",
"alloy-consensus/std",
"alloy-eips/std",
"alloy-genesis/std",
"alloy-primitives/std",
"revm-primitives/std",
"secp256k1/std",
"reth-ethereum-forks/std"
"reth-consensus/std",
"reth-primitives/std",
"reth-revm/std",
"alloy-consensus/std",
"alloy-eips/std",
"alloy-genesis/std",
"alloy-primitives/std",
"revm-primitives/std",
"secp256k1/std",
"reth-ethereum-forks/std",
]
7 changes: 4 additions & 3 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use reth_evm::{
system_calls::{OnStateHook, SystemCaller},
ConfigureEvm, TxEnvOverrides,
};
use reth_execution_types::BlockExecutionInput;
use reth_primitives::{BlockWithSenders, EthPrimitives, Receipt};
use reth_revm::db::State;
use revm_primitives::{
Expand Down Expand Up @@ -169,9 +170,9 @@ where

fn execute_transactions(
&mut self,
block: &BlockWithSenders,
total_difficulty: U256,
input: BlockExecutionInput<'_, BlockWithSenders>,
) -> Result<ExecuteOutput<Receipt>, Self::Error> {
let BlockExecutionInput { block, total_difficulty, .. } = input;
let env = self.evm_env_for_block(&block.header, total_difficulty);
let mut evm = self.evm_config.evm_with_env(&mut self.state, env);

Expand All @@ -186,7 +187,7 @@ where
transaction_gas_limit: transaction.gas_limit(),
block_available_gas,
}
.into())
.into());
}

self.evm_config.fill_tx_env(evm.tx_mut(), transaction, *sender);
Expand Down
8 changes: 8 additions & 0 deletions crates/evm/execution-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

extern crate alloc;

use core::error;

use alloc::{boxed::Box, string::String};
use alloy_eips::BlockNumHash;
use alloy_primitives::B256;
Expand Down Expand Up @@ -115,6 +117,12 @@ pub enum BlockValidationError {
/// [EIP-6110]: https://eips.ethereum.org/EIPS/eip-6110
#[error("failed to decode deposit requests from receipts: {_0}")]
DepositRequestDecode(String),
/// Anchor validation error
#[error("failed to validate anchor: {message}")]
AnchorValidation {
/// The error message.
message: String,
},
}

/// `BlockExecutor` Errors
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/execution-types/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy_rpc_types_eth::transaction::Transaction;
use revm::db::BundleState;

/// A helper type for ethereum block inputs that consists of a block and the total difficulty.
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub struct BlockExecutionInput<'a, Block> {
/// The block to execute.
pub block: &'a Block,
Expand Down
57 changes: 23 additions & 34 deletions crates/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use alloy_consensus::BlockHeader;
pub use reth_execution_errors::{
BlockExecutionError, BlockValidationError, InternalBlockExecutionError,
};
use reth_execution_types::TaskResult;
pub use reth_execution_types::{BlockExecutionInput, BlockExecutionOutput, ExecutionOutcome};
use reth_primitives_traits::Block as _;
pub use reth_storage_errors::provider::ProviderError;
Expand Down Expand Up @@ -193,6 +194,10 @@ pub struct ExecuteOutput<R = Receipt> {
pub receipts: Vec<R>,
/// Cumulative gas used in the block execution.
pub gas_used: u64,
/// The target list.
pub target_list: Vec<TaskResult>,
/// The skipped transactions when `BlockExecutionInput::enable_skip`.
pub skipped_list: Vec<usize>,
}

/// Defines the strategy for executing a single block.
Expand All @@ -219,8 +224,10 @@ pub trait BlockExecutionStrategy {
/// Executes all transactions in the block.
fn execute_transactions(
&mut self,
block: &BlockWithSenders<<Self::Primitives as NodePrimitives>::Block>,
total_difficulty: U256,
input: BlockExecutionInput<
'_,
BlockWithSenders<<Self::Primitives as NodePrimitives>::Block>,
>,
) -> Result<ExecuteOutput<<Self::Primitives as NodePrimitives>::Receipt>, Self::Error>;

/// Applies any necessary changes after executing the block's transactions.
Expand Down Expand Up @@ -360,20 +367,13 @@ where
let BlockExecutionInput { block, total_difficulty, .. } = input;

self.strategy.apply_pre_execution_changes(block, total_difficulty)?;
let ExecuteOutput { receipts, gas_used } =
self.strategy.execute_transactions(block, total_difficulty)?;
let ExecuteOutput { receipts, gas_used, target_list, skipped_list } =
self.strategy.execute_transactions(input)?;
let requests =
self.strategy.apply_post_execution_changes(block, total_difficulty, &receipts)?;
let state = self.strategy.finish();

Ok(BlockExecutionOutput {
state,
receipts,
requests,
gas_used,
target_list: vec![],
skipped_list: vec![],
})
Ok(BlockExecutionOutput { state, receipts, requests, gas_used, target_list, skipped_list })
}

fn execute_with_state_closure<F>(
Expand All @@ -387,23 +387,16 @@ where
let BlockExecutionInput { block, total_difficulty, .. } = input;

self.strategy.apply_pre_execution_changes(block, total_difficulty)?;
let ExecuteOutput { receipts, gas_used } =
self.strategy.execute_transactions(block, total_difficulty)?;
let ExecuteOutput { receipts, gas_used, target_list, skipped_list } =
self.strategy.execute_transactions(input)?;
let requests =
self.strategy.apply_post_execution_changes(block, total_difficulty, &receipts)?;

state(self.strategy.state_ref());

let state = self.strategy.finish();

Ok(BlockExecutionOutput {
state,
receipts,
requests,
gas_used,
target_list: vec![],
skipped_list: vec![],
})
Ok(BlockExecutionOutput { state, receipts, requests, gas_used, target_list, skipped_list })
}

fn execute_with_state_hook<H>(
Expand All @@ -419,21 +412,14 @@ where
self.strategy.with_state_hook(Some(Box::new(state_hook)));

self.strategy.apply_pre_execution_changes(block, total_difficulty)?;
let ExecuteOutput { receipts, gas_used } =
self.strategy.execute_transactions(block, total_difficulty)?;
let ExecuteOutput { receipts, gas_used, target_list, skipped_list } =
self.strategy.execute_transactions(input)?;
let requests =
self.strategy.apply_post_execution_changes(block, total_difficulty, &receipts)?;

let state = self.strategy.finish();

Ok(BlockExecutionOutput {
state,
receipts,
requests,
gas_used,
target_list: vec![],
skipped_list: vec![],
})
Ok(BlockExecutionOutput { state, receipts, requests, gas_used, target_list, skipped_list })
}
}

Expand Down Expand Up @@ -481,8 +467,7 @@ where
}

self.strategy.apply_pre_execution_changes(block, total_difficulty)?;
let ExecuteOutput { receipts, .. } =
self.strategy.execute_transactions(block, total_difficulty)?;
let ExecuteOutput { receipts, .. } = self.strategy.execute_transactions(input)?;
let requests =
self.strategy.apply_post_execution_changes(block, total_difficulty, &receipts)?;

Expand Down Expand Up @@ -774,6 +759,8 @@ mod tests {
let expected_execute_transactions_result = ExecuteOutput::<Receipt> {
receipts: expected_receipts.clone(),
gas_used: expected_gas_used,
target_list: vec![],
skipped_list: vec![],
};
let expected_apply_post_execution_changes_result = Requests::new(vec![bytes!("deadbeef")]);
let expected_finish_result = BundleState::default();
Expand Down Expand Up @@ -804,6 +791,8 @@ mod tests {
execute_transactions_result: ExecuteOutput {
receipts: vec![Receipt::default()],
gas_used: 10,
target_list: vec![],
skipped_list: vec![],
},
apply_post_execution_changes_result: Requests::new(vec![bytes!("deadbeef")]),
finish_result: BundleState::default(),
Expand Down
14 changes: 14 additions & 0 deletions crates/taiko/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use alloy_chains::Chain;
use alloy_consensus::Header;
use alloy_genesis::{ChainConfig, Genesis, GenesisAccount};
use alloy_primitives::{Address, Bytes, FixedBytes, B256, U256};
use core::str::FromStr;
use derive_more::{Constructor, Deref, Display, From, Into};
#[cfg(not(feature = "std"))]
pub(crate) use once_cell::sync::Lazy as LazyLock;
Expand Down Expand Up @@ -201,6 +202,19 @@ pub struct TaikoChainSpec {
pub inner: ChainSpec,
}

impl TaikoChainSpec {
/// Get treasury address.
pub fn treasury(&self) -> Address {
const SUFFIX: &str = "10001";
let prefix = self.chain().id().to_string();
Address::from_str(&format!(
"{prefix}{}{SUFFIX}",
"0".repeat(Address::len_bytes() * 2 - prefix.len() - SUFFIX.len())
))
.unwrap()
}
}

impl EthChainSpec for TaikoChainSpec {
type Header = Header;

Expand Down
Loading

0 comments on commit d3ceb71

Please sign in to comment.