paradigmxyz / reth

Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol, in Rust
https://reth.rs/
Apache License 2.0
3.97k stars 1.2k forks source link

Composable Block executor #11274

Closed mattsse closed 3 weeks ago

mattsse commented 1 month ago

Currently we have a lot of semi duplicated code in both the OP and Eth (Batch)Executor

https://github.com/paradigmxyz/reth/blob/da6b1e7c64417f346b3d9e0d36d2ccee2f13425e/crates/ethereum/evm/src/execute.rs#L352-L352

https://github.com/paradigmxyz/reth/blob/da6b1e7c64417f346b3d9e0d36d2ccee2f13425e/crates/optimism/evm/src/execute.rs#L332-L332

the only thing that's really different is how system transactions are executed.

we assume block execution follows this pattern:

  1. configure environment
  2. apply pre system txs
  3. execute block txs
  4. apply post system txs

Ideally all of those are composable. if we can make this composable like have something that can execute system txs https://github.com/paradigmxyz/reth/issues/10955 then we can make the executor generic over something that only focuses on these things and we can remove a ton of boilerplate.

one idea

trait E {
  fn apply_pre
  fn execute_txs
  fn apply_post
} 

we could then create one general purpose executor that implements the Executor trait and wraps this new one. so that implementers only need to implement the raw execution functions.

perhaps we can also make some simplifications to the Executor trait itself

mattsse commented 1 month ago

ideally we can use this to validate design: https://github.com/paradigmxyz/reth/pull/9497