From ad0be4ca06e9bcd4650ee57be88af7c7f74d66b3 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:46:39 +0200 Subject: [PATCH] refactor: replace `BatchBlockExecutionOutput` by `BundleStateWithReceipts` (#8709) --- Cargo.lock | 3 +- .../src/commands/debug_cmd/build_block.rs | 10 ++++- .../commands/debug_cmd/in_memory_merkle.rs | 9 +++- bin/reth/src/commands/debug_cmd/merkle.rs | 10 ++--- bin/reth/src/commands/import_receipts_op.rs | 7 +++- crates/blockchain-tree/src/chain.rs | 7 +++- crates/consensus/auto-seal/src/lib.rs | 9 +++- crates/ethereum/evm/Cargo.toml | 1 + crates/ethereum/evm/src/execute.rs | 11 ++--- crates/ethereum/payload/src/lib.rs | 8 +++- crates/evm/Cargo.toml | 1 + crates/evm/execution-types/Cargo.toml | 1 - crates/evm/execution-types/src/bundle.rs | 41 ++++++++---------- crates/evm/execution-types/src/chain.rs | 2 + crates/evm/src/either.rs | 10 ++--- crates/evm/src/execute.rs | 42 ++----------------- crates/evm/src/noop.rs | 6 +-- crates/evm/src/test_utils.rs | 12 +++--- crates/optimism/evm/src/execute.rs | 11 ++--- crates/optimism/payload/src/builder.rs | 8 +++- crates/rpc/rpc/src/eth/api/pending_block.rs | 8 +++- crates/stages/stages/src/stages/execution.rs | 6 +-- crates/storage/db-common/src/init.rs | 1 + .../bundle_state_with_receipts.rs | 27 +++++++----- .../src/providers/database/provider.rs | 1 + .../storage/provider/src/test_utils/blocks.rs | 5 +++ examples/exex/op-bridge/src/main.rs | 1 + 27 files changed, 138 insertions(+), 120 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee64320b2..f9600585a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6938,6 +6938,7 @@ dependencies = [ "futures-util", "parking_lot 0.12.3", "reth-execution-errors", + "reth-execution-types", "reth-primitives", "reth-prune-types", "reth-storage-errors", @@ -6953,6 +6954,7 @@ dependencies = [ "alloy-sol-types", "reth-ethereum-consensus", "reth-evm", + "reth-execution-types", "reth-primitives", "reth-prune-types", "reth-revm", @@ -6995,7 +6997,6 @@ dependencies = [ name = "reth-execution-types" version = "0.2.0-beta.9" dependencies = [ - "reth-evm", "reth-execution-errors", "reth-primitives", "reth-trie", diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index b1f3bd1c2..e74108f44 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -271,9 +271,15 @@ impl Command { let db = StateProviderDatabase::new(blockchain_db.latest()?); let executor = block_executor!(provider_factory.chain_spec()).executor(db); - let BlockExecutionOutput { state, receipts, .. } = + let BlockExecutionOutput { state, receipts, requests, .. } = executor.execute((&block_with_senders.clone().unseal(), U256::MAX).into())?; - let state = BundleStateWithReceipts::new(state, receipts.into(), block.number); + let state = BundleStateWithReceipts::new( + state, + receipts.into(), + block.number, + vec![requests.into()], + ); + debug!(target: "reth::cli", ?state, "Executed block"); let hashed_state = state.hash_state_slow(); diff --git a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs index 803ce3f5d..37b320096 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -135,7 +135,7 @@ impl Command { let merkle_block_td = provider.header_td_by_number(merkle_block_number)?.unwrap_or_default(); - let BlockExecutionOutput { state, receipts, .. } = executor.execute( + let BlockExecutionOutput { state, receipts, requests, .. } = executor.execute( ( &block .clone() @@ -146,7 +146,12 @@ impl Command { ) .into(), )?; - let block_state = BundleStateWithReceipts::new(state, receipts.into(), block.number); + let block_state = BundleStateWithReceipts::new( + state, + receipts.into(), + block.number, + vec![requests.into()], + ); // Unpacked `BundleState::state_root_slow` function let (in_memory_state_root, in_memory_updates) = diff --git a/bin/reth/src/commands/debug_cmd/merkle.rs b/bin/reth/src/commands/debug_cmd/merkle.rs index cbc6f84aa..33904d5b0 100644 --- a/bin/reth/src/commands/debug_cmd/merkle.rs +++ b/bin/reth/src/commands/debug_cmd/merkle.rs @@ -14,14 +14,14 @@ use reth_config::Config; use reth_consensus::Consensus; use reth_db::{tables, DatabaseEnv}; use reth_db_api::{cursor::DbCursorRO, transaction::DbTx}; -use reth_evm::execute::{BatchBlockExecutionOutput, BatchExecutor, BlockExecutorProvider}; +use reth_evm::execute::{BatchExecutor, BlockExecutorProvider}; use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; use reth_network_p2p::full_block::FullBlockClient; use reth_primitives::{stage::StageCheckpoint, BlockHashOrNumber}; use reth_provider::{ - BlockNumReader, BlockWriter, BundleStateWithReceipts, ChainSpecProvider, HeaderProvider, - LatestStateProviderRef, OriginalValuesKnown, ProviderError, ProviderFactory, StateWriter, + BlockNumReader, BlockWriter, ChainSpecProvider, HeaderProvider, LatestStateProviderRef, + OriginalValuesKnown, ProviderError, ProviderFactory, StateWriter, }; use reth_prune_types::PruneModes; use reth_revm::database::StateProviderDatabase; @@ -161,9 +161,7 @@ impl Command { PruneModes::none(), ); executor.execute_and_verify_one((&sealed_block.clone().unseal(), td).into())?; - let BatchBlockExecutionOutput { bundle, receipts, requests: _, first_block } = - executor.finalize(); - BundleStateWithReceipts::new(bundle, receipts, first_block).write_to_storage( + executor.finalize().write_to_storage( provider_rw.tx_ref(), None, OriginalValuesKnown::Yes, diff --git a/bin/reth/src/commands/import_receipts_op.rs b/bin/reth/src/commands/import_receipts_op.rs index c6da03519..a3be119db 100644 --- a/bin/reth/src/commands/import_receipts_op.rs +++ b/bin/reth/src/commands/import_receipts_op.rs @@ -132,7 +132,12 @@ where // We're reusing receipt writing code internal to // `BundleStateWithReceipts::write_to_storage`, so we just use a default empty // `BundleState`. - let bundled_state = BundleStateWithReceipts::new(Default::default(), receipts, first_block); + let bundled_state = BundleStateWithReceipts::new( + Default::default(), + receipts, + first_block, + Default::default(), + ); let static_file_producer = static_file_provider.get_writer(first_block, StaticFileSegment::Receipts)?; diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index ba0cb727f..9f4ae936b 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -214,7 +214,12 @@ impl AppendableChain { .consensus .validate_block_post_execution(&block, PostExecutionInput::new(&receipts, &requests))?; - let bundle_state = BundleStateWithReceipts::new(state, receipts.into(), block.number); + let bundle_state = BundleStateWithReceipts::new( + state, + receipts.into(), + block.number, + vec![requests.into()], + ); // check state root if the block extends the canonical chain __and__ if state root // validation was requested. diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index d2e8941e4..0ea51ae49 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -389,9 +389,14 @@ impl StorageInner { ); // execute the block - let BlockExecutionOutput { state, receipts, .. } = + let BlockExecutionOutput { state, receipts, requests: block_execution_requests, .. } = executor.executor(&mut db).execute((&block, U256::ZERO).into())?; - let bundle_state = BundleStateWithReceipts::new(state, receipts.into(), block.number); + let bundle_state = BundleStateWithReceipts::new( + state, + receipts.into(), + block.number, + vec![block_execution_requests.into()], + ); // todo(onbjerg): we should not pass requests around as this is building a block, which // means we need to extract the requests from the execution output and compute the requests diff --git a/crates/ethereum/evm/Cargo.toml b/crates/ethereum/evm/Cargo.toml index 84060cd1b..410750c80 100644 --- a/crates/ethereum/evm/Cargo.toml +++ b/crates/ethereum/evm/Cargo.toml @@ -17,6 +17,7 @@ reth-primitives.workspace = true reth-revm.workspace = true reth-ethereum-consensus.workspace = true reth-prune-types.workspace = true +reth-execution-types.workspace = true # Ethereum revm-primitives.workspace = true diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index 457f15428..a9f0babae 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -7,11 +7,12 @@ use crate::{ use reth_ethereum_consensus::validate_block_post_execution; use reth_evm::{ execute::{ - BatchBlockExecutionOutput, BatchExecutor, BlockExecutionError, BlockExecutionInput, - BlockExecutionOutput, BlockExecutorProvider, BlockValidationError, Executor, ProviderError, + BatchExecutor, BlockExecutionError, BlockExecutionInput, BlockExecutionOutput, + BlockExecutorProvider, BlockValidationError, Executor, ProviderError, }, ConfigureEvm, }; +use reth_execution_types::BundleStateWithReceipts; use reth_primitives::{ BlockNumber, BlockWithSenders, ChainSpec, Hardfork, Header, Receipt, Request, Withdrawals, MAINNET, U256, @@ -405,7 +406,7 @@ where DB: Database, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BatchBlockExecutionOutput; + type Output = BundleStateWithReceipts; type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error> { @@ -435,11 +436,11 @@ where fn finalize(mut self) -> Self::Output { self.stats.log_debug(); - BatchBlockExecutionOutput::new( + BundleStateWithReceipts::new( self.executor.state.take_bundle(), self.batch_record.take_receipts(), - self.batch_record.take_requests(), self.batch_record.first_block().unwrap_or_default(), + self.batch_record.take_requests(), ) } diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index dc2655c6a..7ce426478 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -444,8 +444,12 @@ where // and 4788 contract call db.merge_transitions(BundleRetention::PlainState); - let bundle = - BundleStateWithReceipts::new(db.take_bundle(), vec![receipts].into(), block_number); + let bundle = BundleStateWithReceipts::new( + db.take_bundle(), + vec![receipts].into(), + block_number, + vec![requests.clone().unwrap_or_default()], + ); let receipts_root = bundle.receipts_root_slow(block_number).expect("Number is in range"); let logs_bloom = bundle.block_logs_bloom(block_number).expect("Number is in range"); diff --git a/crates/evm/Cargo.toml b/crates/evm/Cargo.toml index 3de203f7c..e83614810 100644 --- a/crates/evm/Cargo.toml +++ b/crates/evm/Cargo.toml @@ -17,6 +17,7 @@ reth-primitives.workspace = true revm-primitives.workspace = true reth-prune-types.workspace = true reth-storage-errors.workspace = true +reth-execution-types.workspace = true revm.workspace = true diff --git a/crates/evm/execution-types/Cargo.toml b/crates/evm/execution-types/Cargo.toml index f24c84be3..8c3ce4dc0 100644 --- a/crates/evm/execution-types/Cargo.toml +++ b/crates/evm/execution-types/Cargo.toml @@ -14,7 +14,6 @@ workspace = true reth-primitives.workspace = true reth-execution-errors.workspace = true reth-trie.workspace = true -reth-evm.workspace = true revm.workspace = true diff --git a/crates/evm/execution-types/src/bundle.rs b/crates/evm/execution-types/src/bundle.rs index 5eb60fc80..524a7ae88 100644 --- a/crates/evm/execution-types/src/bundle.rs +++ b/crates/evm/execution-types/src/bundle.rs @@ -1,9 +1,8 @@ -use reth_evm::execute::BatchBlockExecutionOutput; use reth_primitives::{ logs_bloom, revm::compat::{into_reth_acc, into_revm_acc}, - Account, Address, BlockNumber, Bloom, Bytecode, Log, Receipt, Receipts, StorageEntry, B256, - U256, + Account, Address, BlockNumber, Bloom, Bytecode, Log, Receipt, Receipts, Requests, StorageEntry, + B256, U256, }; use reth_trie::HashedPostState; use revm::{ @@ -27,23 +26,13 @@ pub struct BundleStateWithReceipts { pub receipts: Receipts, /// First block of bundle state. pub first_block: BlockNumber, -} - -// TODO(mattsse): unify the types, currently there's a cyclic dependency between -impl From for BundleStateWithReceipts { - fn from(value: BatchBlockExecutionOutput) -> Self { - let BatchBlockExecutionOutput { bundle, receipts, requests: _, first_block } = value; - Self { bundle, receipts, first_block } - } -} - -// TODO(mattsse): unify the types, currently there's a cyclic dependency between -impl From for BatchBlockExecutionOutput { - fn from(value: BundleStateWithReceipts) -> Self { - let BundleStateWithReceipts { bundle, receipts, first_block } = value; - // TODO(alexey): add requests - Self { bundle, receipts, requests: Vec::default(), first_block } - } + /// The collection of EIP-7685 requests. + /// Outer vector stores requests for each block sequentially. + /// The inner vector stores requests ordered by transaction number. + /// + /// A transaction may have zero or more requests, so the length of the inner vector is not + /// guaranteed to be the same as the number of transactions. + pub requests: Vec, } /// Type used to initialize revms bundle state. @@ -58,8 +47,13 @@ pub type RevertsInit = HashMap> impl BundleStateWithReceipts { /// Create Bundle State. - pub const fn new(bundle: BundleState, receipts: Receipts, first_block: BlockNumber) -> Self { - Self { bundle, receipts, first_block } + pub const fn new( + bundle: BundleState, + receipts: Receipts, + first_block: BlockNumber, + requests: Vec, + ) -> Self { + Self { bundle, receipts, first_block, requests } } /// Create new bundle state with receipts. @@ -69,6 +63,7 @@ impl BundleStateWithReceipts { contracts_init: Vec<(B256, Bytecode)>, receipts: Receipts, first_block: BlockNumber, + requests: Vec, ) -> Self { // sort reverts by block number let mut reverts = revert_init.into_iter().collect::>(); @@ -97,7 +92,7 @@ impl BundleStateWithReceipts { contracts_init.into_iter().map(|(code_hash, bytecode)| (code_hash, bytecode.0)), ); - Self { bundle, receipts, first_block } + Self { bundle, receipts, first_block, requests } } /// Return revm bundle state. diff --git a/crates/evm/execution-types/src/chain.rs b/crates/evm/execution-types/src/chain.rs index 994bf634c..243530522 100644 --- a/crates/evm/execution-types/src/chain.rs +++ b/crates/evm/execution-types/src/chain.rs @@ -526,6 +526,7 @@ mod tests { ), vec![vec![]].into(), 1, + vec![], ); let block_state2 = BundleStateWithReceipts::new( @@ -541,6 +542,7 @@ mod tests { ), vec![vec![]].into(), 2, + vec![], ); let mut block1 = SealedBlockWithSenders::default(); diff --git a/crates/evm/src/either.rs b/crates/evm/src/either.rs index 2d9f68c9e..9889e4456 100644 --- a/crates/evm/src/either.rs +++ b/crates/evm/src/either.rs @@ -1,10 +1,10 @@ //! Helper type that represents one of two possible executor types use crate::execute::{ - BatchBlockExecutionOutput, BatchExecutor, BlockExecutionInput, BlockExecutionOutput, - BlockExecutorProvider, Executor, + BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor, }; use reth_execution_errors::BlockExecutionError; +use reth_execution_types::BundleStateWithReceipts; use reth_primitives::{BlockNumber, BlockWithSenders, Receipt}; use reth_prune_types::PruneModes; use reth_storage_errors::provider::ProviderError; @@ -76,19 +76,19 @@ where A: for<'a> BatchExecutor< DB, Input<'a> = BlockExecutionInput<'a, BlockWithSenders>, - Output = BatchBlockExecutionOutput, + Output = BundleStateWithReceipts, Error = BlockExecutionError, >, B: for<'a> BatchExecutor< DB, Input<'a> = BlockExecutionInput<'a, BlockWithSenders>, - Output = BatchBlockExecutionOutput, + Output = BundleStateWithReceipts, Error = BlockExecutionError, >, DB: Database, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BatchBlockExecutionOutput; + type Output = BundleStateWithReceipts; type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error> { diff --git a/crates/evm/src/execute.rs b/crates/evm/src/execute.rs index f6c217299..a026849d6 100644 --- a/crates/evm/src/execute.rs +++ b/crates/evm/src/execute.rs @@ -1,6 +1,7 @@ //! Traits for execution. -use reth_primitives::{BlockNumber, BlockWithSenders, Receipt, Receipts, Request, Requests, U256}; +use reth_execution_types::BundleStateWithReceipts; +use reth_primitives::{BlockNumber, BlockWithSenders, Receipt, Request, U256}; use reth_prune_types::PruneModes; use revm::db::BundleState; use revm_primitives::db::Database; @@ -103,40 +104,6 @@ pub struct BlockExecutionOutput { pub gas_used: u64, } -/// The output of a batch of ethereum blocks. -#[derive(Debug)] -pub struct BatchBlockExecutionOutput { - /// Bundle state with reverts. - pub bundle: BundleState, - /// The collection of receipts. - /// Outer vector stores receipts for each block sequentially. - /// The inner vector stores receipts ordered by transaction number. - /// - /// If receipt is None it means it is pruned. - pub receipts: Receipts, - /// The collection of EIP-7685 requests. - /// Outer vector stores requests for each block sequentially. - /// The inner vector stores requests ordered by transaction number. - /// - /// A transaction may have zero or more requests, so the length of the inner vector is not - /// guaranteed to be the same as the number of transactions. - pub requests: Vec, - /// First block of bundle state. - pub first_block: BlockNumber, -} - -impl BatchBlockExecutionOutput { - /// Create Bundle State. - pub fn new( - bundle: BundleState, - receipts: Receipts, - requests: Vec, - first_block: BlockNumber, - ) -> Self { - Self { bundle, receipts, requests, first_block } - } -} - /// A helper type for ethereum block inputs that consists of a block and the total difficulty. #[derive(Debug)] pub struct BlockExecutionInput<'a, Block> { @@ -183,8 +150,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static { type BatchExecutor>: for<'a> BatchExecutor< DB, Input<'a> = BlockExecutionInput<'a, BlockWithSenders>, - // TODO: change to bundle state with receipts - Output = BatchBlockExecutionOutput, + Output = BundleStateWithReceipts, Error = BlockExecutionError, >; @@ -250,7 +216,7 @@ mod tests { impl BatchExecutor for TestExecutor { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BatchBlockExecutionOutput; + type Output = BundleStateWithReceipts; type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, _input: Self::Input<'_>) -> Result<(), Self::Error> { diff --git a/crates/evm/src/noop.rs b/crates/evm/src/noop.rs index d6a419bf2..fa6cc25cb 100644 --- a/crates/evm/src/noop.rs +++ b/crates/evm/src/noop.rs @@ -1,14 +1,14 @@ //! A no operation block executor implementation. use reth_execution_errors::BlockExecutionError; +use reth_execution_types::BundleStateWithReceipts; use reth_primitives::{BlockNumber, BlockWithSenders, Receipt}; use reth_prune_types::PruneModes; use reth_storage_errors::provider::ProviderError; use revm_primitives::db::Database; use crate::execute::{ - BatchBlockExecutionOutput, BatchExecutor, BlockExecutionInput, BlockExecutionOutput, - BlockExecutorProvider, Executor, + BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor, }; const UNAVAILABLE_FOR_NOOP: &str = "execution unavailable for noop"; @@ -50,7 +50,7 @@ impl Executor for NoopBlockExecutorProvider { impl BatchExecutor for NoopBlockExecutorProvider { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BatchBlockExecutionOutput; + type Output = BundleStateWithReceipts; type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, _: Self::Input<'_>) -> Result<(), Self::Error> { diff --git a/crates/evm/src/test_utils.rs b/crates/evm/src/test_utils.rs index 20f7282c7..abb983979 100644 --- a/crates/evm/src/test_utils.rs +++ b/crates/evm/src/test_utils.rs @@ -1,11 +1,11 @@ //! Helpers for testing. use crate::execute::{ - BatchBlockExecutionOutput, BatchExecutor, BlockExecutionInput, BlockExecutionOutput, - BlockExecutorProvider, Executor, + BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor, }; use parking_lot::Mutex; use reth_execution_errors::BlockExecutionError; +use reth_execution_types::BundleStateWithReceipts; use reth_primitives::{BlockNumber, BlockWithSenders, Receipt}; use reth_prune_types::PruneModes; use reth_storage_errors::provider::ProviderError; @@ -15,12 +15,12 @@ use std::sync::Arc; /// A [`BlockExecutorProvider`] that returns mocked execution results. #[derive(Clone, Debug, Default)] pub struct MockExecutorProvider { - exec_results: Arc>>, + exec_results: Arc>>, } impl MockExecutorProvider { /// Extend the mocked execution results - pub fn extend(&self, results: impl IntoIterator>) { + pub fn extend(&self, results: impl IntoIterator>) { self.exec_results.lock().extend(results.into_iter().map(Into::into)); } } @@ -51,7 +51,7 @@ impl Executor for MockExecutorProvider { type Error = BlockExecutionError; fn execute(self, _: Self::Input<'_>) -> Result { - let BatchBlockExecutionOutput { bundle, receipts, requests, first_block: _ } = + let BundleStateWithReceipts { bundle, receipts, requests, first_block: _ } = self.exec_results.lock().pop().unwrap(); Ok(BlockExecutionOutput { state: bundle, @@ -64,7 +64,7 @@ impl Executor for MockExecutorProvider { impl BatchExecutor for MockExecutorProvider { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BatchBlockExecutionOutput; + type Output = BundleStateWithReceipts; type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, _: Self::Input<'_>) -> Result<(), Self::Error> { diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 344768e6a..051fa7e5b 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -3,8 +3,8 @@ use crate::{l1::ensure_create2_deployer, OptimismBlockExecutionError, OptimismEvmConfig}; use reth_evm::{ execute::{ - BatchBlockExecutionOutput, BatchExecutor, BlockExecutionError, BlockExecutionInput, - BlockExecutionOutput, BlockExecutorProvider, BlockValidationError, Executor, ProviderError, + BatchExecutor, BlockExecutionError, BlockExecutionInput, BlockExecutionOutput, + BlockExecutorProvider, BlockValidationError, Executor, ProviderError, }, ConfigureEvm, }; @@ -13,6 +13,7 @@ use reth_primitives::{ BlockNumber, BlockWithSenders, ChainSpec, Hardfork, Header, Receipt, Receipts, TxType, Withdrawals, U256, }; +use reth_provider::BundleStateWithReceipts; use reth_prune_types::PruneModes; use reth_revm::{ batch::{BlockBatchRecord, BlockExecutorStats}, @@ -396,7 +397,7 @@ where DB: Database, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BatchBlockExecutionOutput; + type Output = BundleStateWithReceipts; type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error> { @@ -423,11 +424,11 @@ where fn finalize(mut self) -> Self::Output { self.stats.log_debug(); - BatchBlockExecutionOutput::new( + BundleStateWithReceipts::new( self.executor.state.take_bundle(), self.batch_record.take_receipts(), - self.batch_record.take_requests(), self.batch_record.first_block().unwrap_or_default(), + self.batch_record.take_requests(), ) } diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 9286a91b0..0df437bfe 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -506,8 +506,12 @@ where // and 4788 contract call db.merge_transitions(BundleRetention::PlainState); - let bundle = - BundleStateWithReceipts::new(db.take_bundle(), vec![receipts].into(), block_number); + let bundle = BundleStateWithReceipts::new( + db.take_bundle(), + vec![receipts].into(), + block_number, + Vec::new(), + ); let receipts_root = bundle .optimism_receipts_root_slow( block_number, diff --git a/crates/rpc/rpc/src/eth/api/pending_block.rs b/crates/rpc/rpc/src/eth/api/pending_block.rs index ec9d100d0..9d9081e40 100644 --- a/crates/rpc/rpc/src/eth/api/pending_block.rs +++ b/crates/rpc/rpc/src/eth/api/pending_block.rs @@ -220,8 +220,12 @@ impl PendingBlockEnv { // merge all transitions into bundle state. db.merge_transitions(BundleRetention::PlainState); - let bundle = - BundleStateWithReceipts::new(db.take_bundle(), vec![receipts].into(), block_number); + let bundle = BundleStateWithReceipts::new( + db.take_bundle(), + vec![receipts].into(), + block_number, + Vec::new(), + ); #[cfg(feature = "optimism")] let receipts_root = bundle diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index 58ab34718..c61d96b5e 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -3,7 +3,7 @@ use num_traits::Zero; use reth_config::config::ExecutionConfig; use reth_db::{static_file::HeaderMask, tables}; use reth_db_api::{cursor::DbCursorRO, database::Database, transaction::DbTx}; -use reth_evm::execute::{BatchBlockExecutionOutput, BatchExecutor, BlockExecutorProvider}; +use reth_evm::execute::{BatchExecutor, BlockExecutorProvider}; use reth_exex::{ExExManagerHandle, ExExNotification}; use reth_primitives::{ stage::{ @@ -289,9 +289,9 @@ where } } let time = Instant::now(); - let BatchBlockExecutionOutput { bundle, receipts, requests: _, first_block } = + let BundleStateWithReceipts { bundle, receipts, requests, first_block } = executor.finalize(); - let state = BundleStateWithReceipts::new(bundle, receipts, first_block); + let state = BundleStateWithReceipts::new(bundle, receipts, first_block, requests); let write_preparation_duration = time.elapsed(); // Check if we should send a [`ExExNotification`] to execution extensions. diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index 0575ee13a..a15c56dfc 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -199,6 +199,7 @@ pub fn insert_state<'a, 'b, DB: Database>( contracts.into_iter().collect(), Receipts::default(), block, + Vec::new(), ); bundle.write_to_storage(tx, None, OriginalValuesKnown::Yes)?; diff --git a/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs b/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs index 0419bbaca..69d22292a 100644 --- a/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs +++ b/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs @@ -288,7 +288,7 @@ mod tests { state.merge_transitions(BundleRetention::Reverts); - BundleStateWithReceipts::new(state.take_bundle(), Receipts::default(), 1) + BundleStateWithReceipts::new(state.take_bundle(), Receipts::default(), 1, Vec::new()) .write_to_storage(provider.tx_ref(), None, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -386,7 +386,7 @@ mod tests { )])); state.merge_transitions(BundleRetention::Reverts); - BundleStateWithReceipts::new(state.take_bundle(), Receipts::default(), 2) + BundleStateWithReceipts::new(state.take_bundle(), Receipts::default(), 2, Vec::new()) .write_to_storage(provider.tx_ref(), None, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -450,7 +450,7 @@ mod tests { }, )])); init_state.merge_transitions(BundleRetention::Reverts); - BundleStateWithReceipts::new(init_state.take_bundle(), Receipts::default(), 0) + BundleStateWithReceipts::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()) .write_to_storage(provider.tx_ref(), None, OriginalValuesKnown::Yes) .expect("Could not write init bundle state to DB"); @@ -592,7 +592,7 @@ mod tests { let bundle = state.take_bundle(); - BundleStateWithReceipts::new(bundle, Receipts::default(), 1) + BundleStateWithReceipts::new(bundle, Receipts::default(), 1, Vec::new()) .write_to_storage(provider.tx_ref(), None, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -755,7 +755,7 @@ mod tests { }, )])); init_state.merge_transitions(BundleRetention::Reverts); - BundleStateWithReceipts::new(init_state.take_bundle(), Receipts::default(), 0) + BundleStateWithReceipts::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()) .write_to_storage(provider.tx_ref(), None, OriginalValuesKnown::Yes) .expect("Could not write init bundle state to DB"); @@ -800,7 +800,7 @@ mod tests { // Commit block #1 changes to the database. state.merge_transitions(BundleRetention::Reverts); - BundleStateWithReceipts::new(state.take_bundle(), Receipts::default(), 1) + BundleStateWithReceipts::new(state.take_bundle(), Receipts::default(), 1, Vec::new()) .write_to_storage(provider.tx_ref(), None, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -834,6 +834,7 @@ mod tests { bundle: BundleState::default(), receipts: vec![vec![Some(Receipt::default()); 2]; 7].into(), first_block: 10, + requests: Vec::new(), }; let mut this = base.clone(); @@ -895,10 +896,15 @@ mod tests { let assert_state_root = |state: &State, expected: &PreState, msg| { assert_eq!( - BundleStateWithReceipts::new(state.bundle_state.clone(), Receipts::default(), 0) - .hash_state_slow() - .state_root(&tx) - .unwrap(), + BundleStateWithReceipts::new( + state.bundle_state.clone(), + Receipts::default(), + 0, + Vec::new() + ) + .hash_state_slow() + .state_root(&tx) + .unwrap(), state_root(expected.clone().into_iter().map(|(address, (account, storage))| ( address, (account, storage.into_iter()) @@ -1045,6 +1051,7 @@ mod tests { bundle: present_state, receipts: vec![vec![Some(Receipt::default()); 2]; 1].into(), first_block: 2, + requests: Vec::new(), }; test.prepend_state(previous_state); diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 5548e25a7..b8a9beda8 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -539,6 +539,7 @@ impl DatabaseProvider { Vec::new(), receipts.into(), start_block_number, + Vec::new(), )) } diff --git a/crates/storage/provider/src/test_utils/blocks.rs b/crates/storage/provider/src/test_utils/blocks.rs index cb962bdc6..4cc1e39c9 100644 --- a/crates/storage/provider/src/test_utils/blocks.rs +++ b/crates/storage/provider/src/test_utils/blocks.rs @@ -166,6 +166,7 @@ fn block1(number: BlockNumber) -> (SealedBlockWithSenders, BundleStateWithReceip })]] .into(), number, + Vec::new(), ); let state_root = bundle_state_root(&bundle); @@ -225,6 +226,7 @@ fn block2( })]] .into(), number, + Vec::new(), ); let mut extended = prev_state.clone(); @@ -294,6 +296,7 @@ fn block3( })]] .into(), number, + Vec::new(), ); let mut extended = prev_state.clone(); @@ -384,6 +387,7 @@ fn block4( })]] .into(), number, + Vec::new(), ); let mut extended = prev_state.clone(); @@ -469,6 +473,7 @@ fn block5( })]] .into(), number, + Vec::new(), ); let mut extended = prev_state.clone(); diff --git a/examples/exex/op-bridge/src/main.rs b/examples/exex/op-bridge/src/main.rs index f03601d33..61c44c019 100644 --- a/examples/exex/op-bridge/src/main.rs +++ b/examples/exex/op-bridge/src/main.rs @@ -345,6 +345,7 @@ mod tests { BundleState::default(), vec![deposit_tx_receipt, withdrawal_tx_receipt].into(), block.number, + vec![block.requests.clone().unwrap_or_default()], ), None, );