@@ -34,6 +34,21 @@ pub struct BlockExecutionResult<T> {
3434}
3535
3636/// Helper trait to encapsulate requirements for a type to be used as input for [`BlockExecutor`].
37+ ///
38+ /// This trait combines the requirements for a transaction to be executable by a block executor:
39+ /// - Must be convertible to the EVM's transaction environment via [`IntoTxEnv`]
40+ /// - Must provide access to the transaction and signer via [`RecoveredTx`]
41+ /// - Must be [`Copy`] for efficient handling during block execution (the expectation here is that
42+ /// this always passed as & reference)
43+ ///
44+ /// This trait is automatically implemented for any type that meets these requirements.
45+ /// Common implementations include:
46+ /// - [`Recovered<T>`](alloy_consensus::transaction::Recovered) where `T` is a transaction type
47+ /// - [`WithEncoded<Recovered<T>>`](alloy_eips::eip2718::WithEncoded) for transactions with encoded
48+ /// bytes
49+ ///
50+ /// The trait ensures that the block executor can both execute the transaction in the EVM
51+ /// and access the original transaction data for receipt generation.
3752pub trait ExecutableTx < E : BlockExecutor + ?Sized > :
3853 IntoTxEnv < <E :: Evm as Evm >:: Tx > + RecoveredTx < E :: Transaction > + Copy
3954{
@@ -73,17 +88,61 @@ impl CommitChanges {
7388/// relevant information about the block execution.
7489pub trait BlockExecutor {
7590 /// Input transaction type.
91+ ///
92+ /// This represents the consensus transaction type that the block executor operates on.
93+ /// It's typically a type from the consensus layer (e.g.,
94+ /// [`EthereumTxEnvelope`](alloy_consensus::EthereumTxEnvelope)) that contains
95+ /// the raw transaction data, signature, and other consensus-level information.
96+ ///
97+ /// This type is used in several contexts:
98+ /// - As the generic parameter for [`RecoveredTx<T>`](crate::RecoveredTx) in [`ExecutableTx`]
99+ /// - As the generic parameter for [`FromRecoveredTx<T>`](crate::FromRecoveredTx) and
100+ /// [`FromTxWithEncoded<T>`](crate::FromTxWithEncoded) in the EVM constraint
101+ /// - To generate receipts after transaction execution
102+ ///
103+ /// The transaction flow is:
104+ /// 1. `Self::Transaction` (consensus tx) →
105+ /// [`Recovered<Self::Transaction>`](alloy_consensus::transaction::Recovered) (with sender)
106+ /// 2. [`Recovered<Self::Transaction>`](alloy_consensus::transaction::Recovered) →
107+ /// [`TxEnv`](revm::context::TxEnv) (via [`FromRecoveredTx`])
108+ /// 3. [`TxEnv`](revm::context::TxEnv) → EVM execution → [`ExecutionResult`]
109+ /// 4. [`ExecutionResult`] + `Self::Transaction` → `Self::Receipt`
110+ ///
111+ /// Common examples:
112+ /// - [`EthereumTxEnvelope`](alloy_consensus::EthereumTxEnvelope) for all Ethereum transaction
113+ /// variants
114+ /// - `OpTxEnvelope` for opstack transaction variants
76115 type Transaction ;
77116 /// Receipt type this executor produces.
78117 type Receipt ;
79118 /// EVM used by the executor.
119+ ///
120+ /// The EVM's transaction type (`Evm::Tx`) must be able to be constructed from both:
121+ /// - [`FromRecoveredTx<Self::Transaction>`](crate::FromRecoveredTx) - for transactions with
122+ /// recovered senders
123+ /// - [`FromTxWithEncoded<Self::Transaction>`](crate::FromTxWithEncoded) - for transactions with
124+ /// encoded bytes
125+ ///
126+ /// This constraint ensures that the block executor can convert consensus transactions
127+ /// into the EVM's transaction format for execution.
80128 type Evm : Evm < Tx : FromRecoveredTx < Self :: Transaction > + FromTxWithEncoded < Self :: Transaction > > ;
81129
82130 /// Applies any necessary changes before executing the block's transactions.
83131 fn apply_pre_execution_changes ( & mut self ) -> Result < ( ) , BlockExecutionError > ;
84132
85133 /// Executes a single transaction and applies execution result to internal state.
86134 ///
135+ /// This method accepts any type implementing [`ExecutableTx`], which ensures the transaction:
136+ /// - Can be converted to the EVM's transaction environment for execution
137+ /// - Provides access to the original transaction and signer for receipt generation
138+ ///
139+ /// Common input types include:
140+ /// - `&Recovered<Transaction>` - A transaction with its recovered sender
141+ /// - `&WithEncoded<Recovered<Transaction>>` - A transaction with sender and encoded bytes
142+ ///
143+ /// The transaction is executed in the EVM, state changes are committed, and a receipt
144+ /// is generated internally.
145+ ///
87146 /// Returns the gas used by the transaction.
88147 fn execute_transaction (
89148 & mut self ,
@@ -94,6 +153,14 @@ pub trait BlockExecutor {
94153
95154 /// Executes a single transaction and applies execution result to internal state. Invokes the
96155 /// given closure with an internal [`ExecutionResult`] produced by the EVM.
156+ ///
157+ /// This method is similar to [`execute_transaction`](Self::execute_transaction) but provides
158+ /// access to the raw execution result before it's converted to a receipt. This is useful for:
159+ /// - Custom logging or metrics collection
160+ /// - Debugging transaction execution
161+ /// - Extracting additional information from the execution result
162+ ///
163+ /// The transaction is always committed after the closure is invoked.
97164 fn execute_transaction_with_result_closure (
98165 & mut self ,
99166 tx : impl ExecutableTx < Self > ,
@@ -110,7 +177,22 @@ pub trait BlockExecutor {
110177 /// given closure with an internal [`ExecutionResult`] produced by the EVM, and commits the
111178 /// transaction to the state on [`CommitChanges::Yes`].
112179 ///
113- /// Returns [`None`] if transaction was skipped via [`CommitChanges::No`].
180+ /// This is the most flexible transaction execution method, allowing conditional commitment
181+ /// based on the execution result. The closure receives the execution result and returns
182+ /// whether to commit the changes to state.
183+ ///
184+ /// Use cases:
185+ /// - Conditional execution based on transaction outcome
186+ /// - Simulating transactions without committing
187+ /// - Custom validation logic before committing
188+ ///
189+ /// The [`ExecutableTx`] constraint ensures that:
190+ /// 1. The transaction can be converted to `TxEnv` via [`IntoTxEnv`] for EVM execution
191+ /// 2. The original transaction and signer can be accessed via [`RecoveredTx`] for receipt
192+ /// generation
193+ ///
194+ /// Returns [`None`] if commiting changes from the transaction should be skipped via
195+ /// [`CommitChanges::No`], otherwise returns the gas used by the transaction.
114196 fn execute_transaction_with_commit_condition (
115197 & mut self ,
116198 tx : impl ExecutableTx < Self > ,
@@ -153,6 +235,26 @@ pub trait BlockExecutor {
153235 fn evm ( & self ) -> & Self :: Evm ;
154236
155237 /// Executes all transactions in a block, applying pre and post execution changes.
238+ ///
239+ /// This is a convenience method that orchestrates the complete block execution flow:
240+ /// 1. Applies pre-execution changes (system calls, irregular state transitions)
241+ /// 2. Executes all transactions in order
242+ /// 3. Applies post-execution changes (block rewards, system calls)
243+ ///
244+ /// Each transaction in the iterator must implement [`ExecutableTx`], ensuring it can be:
245+ /// - Converted to the EVM's transaction format for execution
246+ /// - Used to generate receipts with access to the original transaction data
247+ ///
248+ /// # Example
249+ ///
250+ /// ```ignore
251+ /// let recovered_txs: Vec<Recovered<Transaction>> = block.transactions
252+ /// .iter()
253+ /// .map(|tx| tx.recover_signer())
254+ /// .collect::<Result<_, _>>()?;
255+ ///
256+ /// let result = executor.execute_block(recovered_txs.iter())?;
257+ /// ```
156258 fn execute_block (
157259 mut self ,
158260 transactions : impl IntoIterator < Item = impl ExecutableTx < Self > > ,
@@ -221,6 +323,10 @@ pub trait BlockExecutorFactory: 'static {
221323 type ExecutionCtx < ' a > : Clone ;
222324
223325 /// Transaction type used by the executor, see [`BlockExecutor::Transaction`].
326+ ///
327+ /// This should be the same consensus transaction type that the block executor operates on.
328+ /// It represents the transaction format from your consensus layer that needs to be
329+ /// executed by the EVM.
224330 type Transaction ;
225331
226332 /// Receipt type produced by the executor, see [`BlockExecutor::Receipt`].
0 commit comments