From 43c2f35546fdd9c0032c9c76d7fa47418a2de7b4 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Mon, 10 Jun 2024 22:53:33 +0200 Subject: [PATCH 1/9] refactor: rename BundleStateWithReceipts to BlockExecutionOutcome --- .../src/commands/debug_cmd/build_block.rs | 4 +-- .../commands/debug_cmd/in_memory_merkle.rs | 4 +-- bin/reth/src/commands/import_receipts_op.rs | 6 ++-- crates/blockchain-tree/src/blockchain_tree.rs | 6 ++-- crates/blockchain-tree/src/bundle.rs | 10 +++--- crates/blockchain-tree/src/chain.rs | 8 ++--- crates/consensus/auto-seal/src/lib.rs | 6 ++-- crates/consensus/beacon/src/engine/sync.rs | 6 ++-- .../consensus/beacon/src/engine/test_utils.rs | 8 ++--- crates/ethereum/evm/src/execute.rs | 6 ++-- crates/ethereum/payload/src/lib.rs | 4 +-- crates/evm/execution-types/src/bundle.rs | 20 ++++++++--- crates/evm/execution-types/src/chain.rs | 24 ++++++------- crates/evm/src/either.rs | 8 ++--- crates/evm/src/execute.rs | 8 ++--- crates/evm/src/noop.rs | 4 +-- crates/evm/src/test_utils.rs | 10 +++--- crates/optimism/evm/src/execute.rs | 6 ++-- crates/optimism/payload/src/builder.rs | 4 +-- crates/rpc/rpc/src/eth/api/pending_block.rs | 4 +-- crates/stages/stages/src/stages/execution.rs | 6 ++-- crates/stages/stages/src/stages/headers.rs | 4 +-- crates/storage/db-common/src/init.rs | 4 +-- .../bundle_state_with_receipts.rs | 20 +++++------ .../storage/provider/src/bundle_state/mod.rs | 2 +- .../src/providers/bundle_state_provider.rs | 2 +- .../src/providers/database/provider.rs | 12 +++---- .../storage/provider/src/test_utils/blocks.rs | 34 +++++++++---------- crates/storage/provider/src/traits/block.rs | 4 +-- crates/storage/provider/src/traits/chain.rs | 2 +- crates/storage/provider/src/traits/state.rs | 2 +- crates/storage/storage-api/src/state.rs | 12 +++---- crates/transaction-pool/src/maintain.rs | 4 +-- examples/exex/in-memory-state/src/main.rs | 4 +-- examples/exex/minimal/src/main.rs | 4 +-- examples/exex/op-bridge/src/main.rs | 4 +-- 36 files changed, 143 insertions(+), 133 deletions(-) diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index e74108f446f2..ce303dd4efe8 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -31,7 +31,7 @@ use reth_primitives::{ }; use reth_provider::{ providers::BlockchainProvider, BlockHashReader, BlockReader, BlockWriter, - BundleStateWithReceipts, ChainSpecProvider, ProviderFactory, StageCheckpointReader, + BlockExecutionOutcome, ChainSpecProvider, ProviderFactory, StageCheckpointReader, StateProviderFactory, }; use reth_revm::database::StateProviderDatabase; @@ -273,7 +273,7 @@ impl Command { let BlockExecutionOutput { state, receipts, requests, .. } = executor.execute((&block_with_senders.clone().unseal(), U256::MAX).into())?; - let state = BundleStateWithReceipts::new( + let state = BlockExecutionOutcome::new( state, receipts.into(), block.number, 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 37b320096f86..89ae7d4dd716 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -17,7 +17,7 @@ use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; use reth_primitives::{stage::StageId, BlockHashOrNumber}; use reth_provider::{ - AccountExtReader, BundleStateWithReceipts, ChainSpecProvider, HashingWriter, HeaderProvider, + AccountExtReader, BlockExecutionOutcome, ChainSpecProvider, HashingWriter, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StateWriter, StaticFileProviderFactory, StorageReader, }; @@ -146,7 +146,7 @@ impl Command { ) .into(), )?; - let block_state = BundleStateWithReceipts::new( + let block_state = BlockExecutionOutcome::new( state, receipts.into(), block.number, diff --git a/bin/reth/src/commands/import_receipts_op.rs b/bin/reth/src/commands/import_receipts_op.rs index a3be119db2d4..caadec3729f0 100644 --- a/bin/reth/src/commands/import_receipts_op.rs +++ b/bin/reth/src/commands/import_receipts_op.rs @@ -13,7 +13,7 @@ use reth_node_core::version::SHORT_VERSION; use reth_optimism_primitives::bedrock_import::is_dup_tx; use reth_primitives::{stage::StageId, Receipts, StaticFileSegment}; use reth_provider::{ - BundleStateWithReceipts, OriginalValuesKnown, ProviderFactory, StageCheckpointReader, + BlockExecutionOutcome, OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StateWriter, StaticFileProviderFactory, StaticFileWriter, StatsReader, }; use std::path::{Path, PathBuf}; @@ -130,9 +130,9 @@ where ); // We're reusing receipt writing code internal to - // `BundleStateWithReceipts::write_to_storage`, so we just use a default empty + // `BlockExecutionOutcome::write_to_storage`, so we just use a default empty // `BundleState`. - let bundled_state = BundleStateWithReceipts::new( + let bundled_state = BlockExecutionOutcome::new( Default::default(), receipts, first_block, diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 5fd4af084f84..14fee2944689 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -18,7 +18,7 @@ use reth_primitives::{ SealedBlockWithSenders, SealedHeader, StaticFileSegment, B256, U256, }; use reth_provider::{ - BlockExecutionWriter, BlockNumReader, BlockWriter, BundleStateWithReceipts, + BlockExecutionWriter, BlockNumReader, BlockWriter, BlockExecutionOutcome, CanonStateNotification, CanonStateNotificationSender, CanonStateNotifications, Chain, ChainSpecProvider, ChainSplit, ChainSplitTarget, DisplayBlocksChain, HeaderProvider, ProviderError, StaticFileProviderFactory, @@ -303,7 +303,7 @@ where trace!(target: "blockchain_tree", %block_hash, "Constructing post state data based on canonical chain"); return Some(BundleStateData { canonical_fork: ForkBlock { number: canonical_number, hash: block_hash }, - state: BundleStateWithReceipts::default(), + state: BlockExecutionOutcome::default(), parent_block_hashes: canonical_chain.inner().clone(), }) } @@ -1398,7 +1398,7 @@ mod tests { use std::collections::HashMap; fn setup_externals( - exec_res: Vec, + exec_res: Vec, ) -> TreeExternals>, MockExecutorProvider> { let chain_spec = Arc::new( ChainSpecBuilder::default() diff --git a/crates/blockchain-tree/src/bundle.rs b/crates/blockchain-tree/src/bundle.rs index 4dc3b9604806..bc1cc6a3035c 100644 --- a/crates/blockchain-tree/src/bundle.rs +++ b/crates/blockchain-tree/src/bundle.rs @@ -1,14 +1,14 @@ //! [`BundleStateDataProvider`] implementations used by the tree. use reth_primitives::{BlockHash, BlockNumber, ForkBlock}; -use reth_provider::{BundleStateDataProvider, BundleStateForkProvider, BundleStateWithReceipts}; +use reth_provider::{BundleStateDataProvider, BundleStateForkProvider, BlockExecutionOutcome}; use std::collections::BTreeMap; /// Structure that combines references of required data to be a [`BundleStateDataProvider`]. #[derive(Clone, Debug)] pub struct BundleStateDataRef<'a> { /// The wrapped state after execution of one or more transactions and/or blocks. - pub state: &'a BundleStateWithReceipts, + pub state: &'a BlockExecutionOutcome, /// The blocks in the sidechain. pub sidechain_block_hashes: &'a BTreeMap, /// The blocks in the canonical chain. @@ -18,7 +18,7 @@ pub struct BundleStateDataRef<'a> { } impl<'a> BundleStateDataProvider for BundleStateDataRef<'a> { - fn state(&self) -> &BundleStateWithReceipts { + fn state(&self) -> &BlockExecutionOutcome { self.state } @@ -42,7 +42,7 @@ impl<'a> BundleStateForkProvider for BundleStateDataRef<'a> { #[derive(Clone, Debug)] pub struct BundleStateData { /// Post state with changes - pub state: BundleStateWithReceipts, + pub state: BlockExecutionOutcome, /// Parent block hashes needs for evm BLOCKHASH opcode. /// NOTE: it does not mean that all hashes are there but all until finalized are there. /// Other hashes can be obtained from provider @@ -52,7 +52,7 @@ pub struct BundleStateData { } impl BundleStateDataProvider for BundleStateData { - fn state(&self) -> &BundleStateWithReceipts { + fn state(&self) -> &BlockExecutionOutcome { &self.state } diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index 9f4ae936bb48..918287c9935a 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -18,7 +18,7 @@ use reth_primitives::{ }; use reth_provider::{ providers::{BundleStateProvider, ConsistentDbView}, - BundleStateWithReceipts, Chain, FullBundleStateDataProvider, ProviderError, StateRootProvider, + BlockExecutionOutcome, Chain, FullBundleStateDataProvider, ProviderError, StateRootProvider, }; use reth_revm::database::StateProviderDatabase; use reth_trie::updates::TrieUpdates; @@ -78,7 +78,7 @@ impl AppendableChain { DB: Database + Clone, E: BlockExecutorProvider, { - let state = BundleStateWithReceipts::default(); + let state = BlockExecutionOutcome::default(); let empty = BTreeMap::new(); let state_provider = BundleStateDataRef { @@ -173,7 +173,7 @@ impl AppendableChain { externals: &TreeExternals, block_attachment: BlockAttachment, block_validation_kind: BlockValidationKind, - ) -> Result<(BundleStateWithReceipts, Option), BlockExecutionError> + ) -> Result<(BlockExecutionOutcome, Option), BlockExecutionError> where BSDP: FullBundleStateDataProvider, DB: Database + Clone, @@ -214,7 +214,7 @@ impl AppendableChain { .consensus .validate_block_post_execution(&block, PostExecutionInput::new(&receipts, &requests))?; - let bundle_state = BundleStateWithReceipts::new( + let bundle_state = BlockExecutionOutcome::new( state, receipts.into(), block.number, diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index 0ea51ae49b8f..848f6938c5ce 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -27,7 +27,7 @@ use reth_primitives::{ U256, }; use reth_provider::{ - BlockReaderIdExt, BundleStateWithReceipts, StateProviderFactory, StateRootProvider, + BlockReaderIdExt, BlockExecutionOutcome, StateProviderFactory, StateRootProvider, }; use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::TransactionPool; @@ -349,7 +349,7 @@ impl StorageInner { provider: &Provider, chain_spec: Arc, executor: &Executor, - ) -> Result<(SealedHeader, BundleStateWithReceipts), BlockExecutionError> + ) -> Result<(SealedHeader, BlockExecutionOutcome), BlockExecutionError> where Executor: BlockExecutorProvider, Provider: StateProviderFactory, @@ -391,7 +391,7 @@ impl StorageInner { // execute the block let BlockExecutionOutput { state, receipts, requests: block_execution_requests, .. } = executor.executor(&mut db).execute((&block, U256::ZERO).into())?; - let bundle_state = BundleStateWithReceipts::new( + let bundle_state = BlockExecutionOutcome::new( state, receipts.into(), block.number, diff --git a/crates/consensus/beacon/src/engine/sync.rs b/crates/consensus/beacon/src/engine/sync.rs index 74c6ea118c85..3b3f41a56bc4 100644 --- a/crates/consensus/beacon/src/engine/sync.rs +++ b/crates/consensus/beacon/src/engine/sync.rs @@ -435,7 +435,7 @@ mod tests { Header, SealedHeader, MAINNET, }; use reth_provider::{ - test_utils::create_test_provider_factory_with_chain_spec, BundleStateWithReceipts, + test_utils::create_test_provider_factory_with_chain_spec, BlockExecutionOutcome, }; use reth_prune_types::PruneModes; use reth_stages::{test_utils::TestStages, ExecOutput, StageError}; @@ -446,7 +446,7 @@ mod tests { struct TestPipelineBuilder { pipeline_exec_outputs: VecDeque>, - executor_results: Vec, + executor_results: Vec, max_block: Option, } @@ -471,7 +471,7 @@ mod tests { /// Set the executor results to use for the test consensus engine. #[allow(dead_code)] - fn with_executor_results(mut self, executor_results: Vec) -> Self { + fn with_executor_results(mut self, executor_results: Vec) -> Self { self.executor_results = executor_results; self } diff --git a/crates/consensus/beacon/src/engine/test_utils.rs b/crates/consensus/beacon/src/engine/test_utils.rs index 67afe5fc703a..80ecbc02f4ea 100644 --- a/crates/consensus/beacon/src/engine/test_utils.rs +++ b/crates/consensus/beacon/src/engine/test_utils.rs @@ -25,7 +25,7 @@ use reth_payload_builder::test_utils::spawn_test_payload_service; use reth_primitives::{BlockNumber, ChainSpec, B256}; use reth_provider::{ providers::BlockchainProvider, test_utils::create_test_provider_factory_with_chain_spec, - BundleStateWithReceipts, HeaderSyncMode, + BlockExecutionOutcome, HeaderSyncMode, }; use reth_prune::Pruner; use reth_prune_types::PruneModes; @@ -142,7 +142,7 @@ impl Default for TestPipelineConfig { #[derive(Debug)] enum TestExecutorConfig { /// Test executor results. - Test(Vec), + Test(Vec), /// Real executor configuration. Real, } @@ -188,7 +188,7 @@ impl TestConsensusEngineBuilder { } /// Set the executor results to use for the test consensus engine. - pub fn with_executor_results(mut self, executor_results: Vec) -> Self { + pub fn with_executor_results(mut self, executor_results: Vec) -> Self { self.executor_config = TestExecutorConfig::Test(executor_results); self } @@ -272,7 +272,7 @@ where /// Set the executor results to use for the test consensus engine. #[allow(dead_code)] - pub fn with_executor_results(mut self, executor_results: Vec) -> Self { + pub fn with_executor_results(mut self, executor_results: Vec) -> Self { self.base_config.executor_config = TestExecutorConfig::Test(executor_results); self } diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index a9f0babae83d..b7c239367881 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -12,7 +12,7 @@ use reth_evm::{ }, ConfigureEvm, }; -use reth_execution_types::BundleStateWithReceipts; +use reth_execution_types::BlockExecutionOutcome; use reth_primitives::{ BlockNumber, BlockWithSenders, ChainSpec, Hardfork, Header, Receipt, Request, Withdrawals, MAINNET, U256, @@ -406,7 +406,7 @@ where DB: Database, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BundleStateWithReceipts; + type Output = BlockExecutionOutcome; type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error> { @@ -436,7 +436,7 @@ where fn finalize(mut self) -> Self::Output { self.stats.log_debug(); - BundleStateWithReceipts::new( + BlockExecutionOutcome::new( self.executor.state.take_bundle(), self.batch_record.take_receipts(), self.batch_record.first_block().unwrap_or_default(), diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index 7ce4264786a8..7140abbdb4ff 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -29,7 +29,7 @@ use reth_primitives::{ revm::env::tx_env_with_recovered, Block, Header, IntoRecoveredTransaction, Receipt, EMPTY_OMMER_ROOT_HASH, U256, }; -use reth_provider::{BundleStateWithReceipts, StateProviderFactory}; +use reth_provider::{BlockExecutionOutcome, StateProviderFactory}; use reth_revm::{database::StateProviderDatabase, state_change::apply_blockhashes_update}; use reth_transaction_pool::{BestTransactionsAttributes, TransactionPool}; use revm::{ @@ -444,7 +444,7 @@ where // and 4788 contract call db.merge_transitions(BundleRetention::PlainState); - let bundle = BundleStateWithReceipts::new( + let bundle = BlockExecutionOutcome::new( db.take_bundle(), vec![receipts].into(), block_number, diff --git a/crates/evm/execution-types/src/bundle.rs b/crates/evm/execution-types/src/bundle.rs index 524a7ae8806a..fc256882e4b2 100644 --- a/crates/evm/execution-types/src/bundle.rs +++ b/crates/evm/execution-types/src/bundle.rs @@ -15,7 +15,7 @@ use std::collections::HashMap; /// /// Aggregates the changes over an arbitrary number of blocks. #[derive(Default, Debug, Clone, PartialEq, Eq)] -pub struct BundleStateWithReceipts { +pub struct BlockExecutionOutcome { /// Bundle state with reverts. pub bundle: BundleState, /// The collection of receipts. @@ -45,8 +45,8 @@ pub type AccountRevertInit = (Option>, Vec); /// Type used to initialize revms reverts. pub type RevertsInit = HashMap>; -impl BundleStateWithReceipts { - /// Create Bundle State. +impl BlockExecutionOutcome { + /// Create a new block execution outcome. pub const fn new( bundle: BundleState, receipts: Receipts, @@ -56,7 +56,7 @@ impl BundleStateWithReceipts { Self { bundle, receipts, first_block, requests } } - /// Create new bundle state with receipts. + /// Create a new block execution outcome. pub fn new_init( state_init: BundleStateInit, revert_init: RevertsInit, @@ -298,4 +298,16 @@ impl BundleStateWithReceipts { // swap bundles std::mem::swap(&mut self.bundle, &mut other) } + + /// Create a new instance with updated receipts. + pub fn with_receipts(mut self, receipts: Receipts) -> Self { + self.receipts = receipts; + self + } + + /// Create a new instance with updated requests. + pub fn with_requests(mut self, requests: Vec) -> Self { + self.requests = requests; + self + } } diff --git a/crates/evm/execution-types/src/chain.rs b/crates/evm/execution-types/src/chain.rs index 24353052275b..c3eadfdd3470 100644 --- a/crates/evm/execution-types/src/chain.rs +++ b/crates/evm/execution-types/src/chain.rs @@ -1,6 +1,6 @@ //! Contains [Chain], a chain of blocks and their final state. -use crate::BundleStateWithReceipts; +use crate::BlockExecutionOutcome; use reth_execution_errors::BlockExecutionError; use reth_primitives::{ Address, BlockHash, BlockNumHash, BlockNumber, ForkBlock, Receipt, SealedBlock, @@ -28,7 +28,7 @@ pub struct Chain { /// [`Chain::first`] to [`Chain::tip`], inclusive. /// /// This state also contains the individual changes that lead to the current state. - state: BundleStateWithReceipts, + state: BlockExecutionOutcome, /// State trie updates after block is added to the chain. /// NOTE: Currently, trie updates are present only for /// single-block chains that extend the canonical chain. @@ -43,7 +43,7 @@ impl Chain { /// A chain of blocks should not be empty. pub fn new( blocks: impl IntoIterator, - state: BundleStateWithReceipts, + state: BlockExecutionOutcome, trie_updates: Option, ) -> Self { let blocks = BTreeMap::from_iter(blocks.into_iter().map(|b| (b.number, b))); @@ -55,7 +55,7 @@ impl Chain { /// Create new Chain from a single block and its state. pub fn from_block( block: SealedBlockWithSenders, - state: BundleStateWithReceipts, + state: BlockExecutionOutcome, trie_updates: Option, ) -> Self { Self::new([block], state, trie_updates) @@ -87,7 +87,7 @@ impl Chain { } /// Get post state of this chain - pub const fn state(&self) -> &BundleStateWithReceipts { + pub const fn state(&self) -> &BlockExecutionOutcome { &self.state } @@ -118,7 +118,7 @@ impl Chain { } /// Return post state of the block at the `block_number` or None if block is not known - pub fn state_at_block(&self, block_number: BlockNumber) -> Option { + pub fn state_at_block(&self, block_number: BlockNumber) -> Option { if self.tip().number == block_number { return Some(self.state.clone()) } @@ -133,15 +133,13 @@ impl Chain { /// Destructure the chain into its inner components, the blocks and the state at the tip of the /// chain. - pub fn into_inner( - self, - ) -> (ChainBlocks<'static>, BundleStateWithReceipts, Option) { + pub fn into_inner(self) -> (ChainBlocks<'static>, BlockExecutionOutcome, Option) { (ChainBlocks { blocks: Cow::Owned(self.blocks) }, self.state, self.trie_updates) } /// Destructure the chain into its inner components, the blocks and the state at the tip of the /// chain. - pub const fn inner(&self) -> (ChainBlocks<'_>, &BundleStateWithReceipts) { + pub const fn inner(&self) -> (ChainBlocks<'_>, &BlockExecutionOutcome) { (ChainBlocks { blocks: Cow::Borrowed(&self.blocks) }, &self.state) } @@ -231,7 +229,7 @@ impl Chain { /// Append a single block with state to the chain. /// This method assumes that blocks attachment to the chain has already been validated. - pub fn append_block(&mut self, block: SealedBlockWithSenders, state: BundleStateWithReceipts) { + pub fn append_block(&mut self, block: SealedBlockWithSenders, state: BlockExecutionOutcome) { self.blocks.insert(block.number, block); self.state.extend(state); self.trie_updates.take(); // reset @@ -513,7 +511,7 @@ mod tests { #[test] fn test_number_split() { - let block_state1 = BundleStateWithReceipts::new( + let block_state1 = BlockExecutionOutcome::new( BundleState::new( vec![( Address::new([2; 20]), @@ -529,7 +527,7 @@ mod tests { vec![], ); - let block_state2 = BundleStateWithReceipts::new( + let block_state2 = BlockExecutionOutcome::new( BundleState::new( vec![( Address::new([3; 20]), diff --git a/crates/evm/src/either.rs b/crates/evm/src/either.rs index 9889e44566e0..923759622bca 100644 --- a/crates/evm/src/either.rs +++ b/crates/evm/src/either.rs @@ -4,7 +4,7 @@ use crate::execute::{ BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor, }; use reth_execution_errors::BlockExecutionError; -use reth_execution_types::BundleStateWithReceipts; +use reth_execution_types::BlockExecutionOutcome; 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 = BundleStateWithReceipts, + Output = BlockExecutionOutcome, Error = BlockExecutionError, >, B: for<'a> BatchExecutor< DB, Input<'a> = BlockExecutionInput<'a, BlockWithSenders>, - Output = BundleStateWithReceipts, + Output = BlockExecutionOutcome, Error = BlockExecutionError, >, DB: Database, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BundleStateWithReceipts; + type Output = BlockExecutionOutcome; 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 a026849d635d..fba58247acbe 100644 --- a/crates/evm/src/execute.rs +++ b/crates/evm/src/execute.rs @@ -1,6 +1,6 @@ //! Traits for execution. -use reth_execution_types::BundleStateWithReceipts; +use reth_execution_types::BlockExecutionOutcome; use reth_primitives::{BlockNumber, BlockWithSenders, Receipt, Request, U256}; use reth_prune_types::PruneModes; use revm::db::BundleState; @@ -91,7 +91,7 @@ pub trait BatchExecutor { /// /// Contains the state changes, transaction receipts, and total gas used in the block. /// -/// TODO(mattsse): combine with `BundleStateWithReceipts` +/// TODO(mattsse): combine with `BlockExecutionOutcome` #[derive(Debug)] pub struct BlockExecutionOutput { /// The changed state of the block after execution. @@ -150,7 +150,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static { type BatchExecutor>: for<'a> BatchExecutor< DB, Input<'a> = BlockExecutionInput<'a, BlockWithSenders>, - Output = BundleStateWithReceipts, + Output = BlockExecutionOutcome, Error = BlockExecutionError, >; @@ -216,7 +216,7 @@ mod tests { impl BatchExecutor for TestExecutor { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BundleStateWithReceipts; + type Output = BlockExecutionOutcome; 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 fa6cc25cbb89..388d46e160e8 100644 --- a/crates/evm/src/noop.rs +++ b/crates/evm/src/noop.rs @@ -1,7 +1,7 @@ //! A no operation block executor implementation. use reth_execution_errors::BlockExecutionError; -use reth_execution_types::BundleStateWithReceipts; +use reth_execution_types::BlockExecutionOutcome; use reth_primitives::{BlockNumber, BlockWithSenders, Receipt}; use reth_prune_types::PruneModes; use reth_storage_errors::provider::ProviderError; @@ -50,7 +50,7 @@ impl Executor for NoopBlockExecutorProvider { impl BatchExecutor for NoopBlockExecutorProvider { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BundleStateWithReceipts; + type Output = BlockExecutionOutcome; 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 abb983979f60..0695945b055a 100644 --- a/crates/evm/src/test_utils.rs +++ b/crates/evm/src/test_utils.rs @@ -5,7 +5,7 @@ use crate::execute::{ }; use parking_lot::Mutex; use reth_execution_errors::BlockExecutionError; -use reth_execution_types::BundleStateWithReceipts; +use reth_execution_types::BlockExecutionOutcome; 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 BundleStateWithReceipts { bundle, receipts, requests, first_block: _ } = + let BlockExecutionOutcome { 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 = BundleStateWithReceipts; + type Output = BlockExecutionOutcome; 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 051fa7e5b3e8..4f7c971768d7 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -13,7 +13,7 @@ use reth_primitives::{ BlockNumber, BlockWithSenders, ChainSpec, Hardfork, Header, Receipt, Receipts, TxType, Withdrawals, U256, }; -use reth_provider::BundleStateWithReceipts; +use reth_provider::BlockExecutionOutcome; use reth_prune_types::PruneModes; use reth_revm::{ batch::{BlockBatchRecord, BlockExecutorStats}, @@ -397,7 +397,7 @@ where DB: Database, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BundleStateWithReceipts; + type Output = BlockExecutionOutcome; type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error> { @@ -424,7 +424,7 @@ where fn finalize(mut self) -> Self::Output { self.stats.log_debug(); - BundleStateWithReceipts::new( + BlockExecutionOutcome::new( self.executor.state.take_bundle(), self.batch_record.take_receipts(), self.batch_record.first_block().unwrap_or_default(), diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 0df437bfe80a..0c439fb94aeb 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -15,7 +15,7 @@ use reth_primitives::{ Block, ChainSpec, Hardfork, Header, IntoRecoveredTransaction, Receipt, TxType, EMPTY_OMMER_ROOT_HASH, U256, }; -use reth_provider::{BundleStateWithReceipts, StateProviderFactory}; +use reth_provider::{BlockExecutionOutcome, StateProviderFactory}; use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::{BestTransactionsAttributes, TransactionPool}; use revm::{ @@ -506,7 +506,7 @@ where // and 4788 contract call db.merge_transitions(BundleRetention::PlainState); - let bundle = BundleStateWithReceipts::new( + let bundle = BlockExecutionOutcome::new( db.take_bundle(), vec![receipts].into(), 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 9d9081e408cf..bfb558d976b0 100644 --- a/crates/rpc/rpc/src/eth/api/pending_block.rs +++ b/crates/rpc/rpc/src/eth/api/pending_block.rs @@ -12,7 +12,7 @@ use reth_primitives::{ Block, BlockId, BlockNumberOrTag, ChainSpec, Header, IntoRecoveredTransaction, Receipt, Requests, SealedBlockWithSenders, SealedHeader, B256, EMPTY_OMMER_ROOT_HASH, U256, }; -use reth_provider::{BundleStateWithReceipts, ChainSpecProvider, StateProviderFactory}; +use reth_provider::{BlockExecutionOutcome, ChainSpecProvider, StateProviderFactory}; use reth_revm::{ database::StateProviderDatabase, state_change::{ @@ -220,7 +220,7 @@ impl PendingBlockEnv { // merge all transitions into bundle state. db.merge_transitions(BundleRetention::PlainState); - let bundle = BundleStateWithReceipts::new( + let bundle = BlockExecutionOutcome::new( db.take_bundle(), vec![receipts].into(), block_number, diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index c61d96b5eb11..5fac6086aa7a 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -13,7 +13,7 @@ use reth_primitives::{ }; use reth_provider::{ providers::{StaticFileProvider, StaticFileProviderRWRefMut, StaticFileWriter}, - BlockReader, BundleStateWithReceipts, Chain, DatabaseProviderRW, HeaderProvider, + BlockReader, BlockExecutionOutcome, Chain, DatabaseProviderRW, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderError, StateWriter, StatsReader, TransactionVariant, }; @@ -289,9 +289,9 @@ where } } let time = Instant::now(); - let BundleStateWithReceipts { bundle, receipts, requests, first_block } = + let BlockExecutionOutcome { bundle, receipts, requests, first_block } = executor.finalize(); - let state = BundleStateWithReceipts::new(bundle, receipts, first_block, requests); + let state = BlockExecutionOutcome::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/stages/stages/src/stages/headers.rs b/crates/stages/stages/src/stages/headers.rs index fbd956eb79da..201e074d0b0d 100644 --- a/crates/stages/stages/src/stages/headers.rs +++ b/crates/stages/stages/src/stages/headers.rs @@ -384,7 +384,7 @@ mod tests { stage::StageUnitCheckpoint, BlockBody, SealedBlock, SealedBlockWithSenders, B256, }; use reth_provider::{ - BlockWriter, BundleStateWithReceipts, ProviderFactory, StaticFileProviderFactory, + BlockWriter, BlockExecutionOutcome, ProviderFactory, StaticFileProviderFactory, }; use reth_testing_utils::generators::{self, random_header, random_header_range}; use reth_trie::{updates::TrieUpdates, HashedPostState}; @@ -634,7 +634,7 @@ mod tests { provider .append_blocks_with_state( sealed_blocks, - BundleStateWithReceipts::default(), + BlockExecutionOutcome::default(), HashedPostState::default(), TrieUpdates::default(), None, diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index a15c56dfc64e..23c9ffb2bfff 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -14,7 +14,7 @@ use reth_provider::{ bundle_state::{BundleStateInit, RevertsInit}, errors::provider::ProviderResult, providers::{StaticFileProvider, StaticFileWriter}, - BlockHashReader, BlockNumReader, BundleStateWithReceipts, ChainSpecProvider, + BlockHashReader, BlockNumReader, BlockExecutionOutcome, ChainSpecProvider, DatabaseProviderRW, HashingWriter, HistoryWriter, OriginalValuesKnown, ProviderError, ProviderFactory, StageCheckpointWriter, StateWriter, StaticFileProviderFactory, }; @@ -193,7 +193,7 @@ pub fn insert_state<'a, 'b, DB: Database>( } let all_reverts_init: RevertsInit = HashMap::from([(block, reverts_init)]); - let bundle = BundleStateWithReceipts::new_init( + let bundle = BlockExecutionOutcome::new_init( state_init, all_reverts_init, contracts.into_iter().collect(), 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 69d22292a38d..56589c9953ee 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 @@ -9,7 +9,7 @@ use reth_primitives::StaticFileSegment; use reth_storage_errors::provider::{ProviderError, ProviderResult}; pub use revm::db::states::OriginalValuesKnown; -impl StateWriter for BundleStateWithReceipts { +impl StateWriter for BlockExecutionOutcome { fn write_to_storage( self, tx: &TX, @@ -288,7 +288,7 @@ mod tests { state.merge_transitions(BundleRetention::Reverts); - BundleStateWithReceipts::new(state.take_bundle(), Receipts::default(), 1, Vec::new()) + BlockExecutionOutcome::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, Vec::new()) + BlockExecutionOutcome::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, Vec::new()) + BlockExecutionOutcome::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, Vec::new()) + BlockExecutionOutcome::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, Vec::new()) + BlockExecutionOutcome::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, Vec::new()) + BlockExecutionOutcome::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"); @@ -830,7 +830,7 @@ mod tests { #[test] fn revert_to_indices() { - let base = BundleStateWithReceipts { + let base = BlockExecutionOutcome { bundle: BundleState::default(), receipts: vec![vec![Some(Receipt::default()); 2]; 7].into(), first_block: 10, @@ -896,7 +896,7 @@ mod tests { let assert_state_root = |state: &State, expected: &PreState, msg| { assert_eq!( - BundleStateWithReceipts::new( + BlockExecutionOutcome::new( state.bundle_state.clone(), Receipts::default(), 0, @@ -1047,7 +1047,7 @@ mod tests { .build(); assert_eq!(previous_state.reverts.len(), 1); - let mut test = BundleStateWithReceipts { + let mut test = BlockExecutionOutcome { bundle: present_state, receipts: vec![vec![Some(Receipt::default()); 2]; 1].into(), first_block: 2, diff --git a/crates/storage/provider/src/bundle_state/mod.rs b/crates/storage/provider/src/bundle_state/mod.rs index 5df4a213aaf9..4fcf22ce0b61 100644 --- a/crates/storage/provider/src/bundle_state/mod.rs +++ b/crates/storage/provider/src/bundle_state/mod.rs @@ -6,7 +6,7 @@ mod state_changes; mod state_reverts; pub use bundle_state_with_receipts::{ - AccountRevertInit, BundleStateInit, BundleStateWithReceipts, OriginalValuesKnown, RevertsInit, + AccountRevertInit, BundleStateInit, BlockExecutionOutcome, OriginalValuesKnown, RevertsInit, }; pub use hashed_state_changes::HashedStateChanges; pub use state_changes::StateChanges; diff --git a/crates/storage/provider/src/providers/bundle_state_provider.rs b/crates/storage/provider/src/providers/bundle_state_provider.rs index 98f2242992db..983817c4a33c 100644 --- a/crates/storage/provider/src/providers/bundle_state_provider.rs +++ b/crates/storage/provider/src/providers/bundle_state_provider.rs @@ -6,7 +6,7 @@ use reth_storage_errors::provider::{ProviderError, ProviderResult}; use reth_trie::updates::TrieUpdates; use revm::db::BundleState; -/// A state provider that either resolves to data in a wrapped [`crate::BundleStateWithReceipts`], +/// A state provider that either resolves to data in a wrapped [`crate::BlockExecutionOutcome`], /// or an underlying state provider. #[derive(Debug)] pub struct BundleStateProvider { diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index b8a9beda853b..410f528dde53 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -1,5 +1,5 @@ use crate::{ - bundle_state::{BundleStateInit, BundleStateWithReceipts, HashedStateChanges, RevertsInit}, + bundle_state::{BundleStateInit, BlockExecutionOutcome, HashedStateChanges, RevertsInit}, providers::{database::metrics, static_file::StaticFileWriter, StaticFileProvider}, to_range, traits::{ @@ -366,7 +366,7 @@ impl DatabaseProvider { } // TODO(joshie) TEMPORARY should be moved to trait providers - /// Unwind or peek at last N blocks of state recreating the [`BundleStateWithReceipts`]. + /// Unwind or peek at last N blocks of state recreating the [`BlockExecutionOutcome`]. /// /// If UNWIND it set to true tip and latest state will be unwind /// and returned back with all the blocks @@ -393,9 +393,9 @@ impl DatabaseProvider { pub fn unwind_or_peek_state( &self, range: RangeInclusive, - ) -> ProviderResult { + ) -> ProviderResult { if range.is_empty() { - return Ok(BundleStateWithReceipts::default()) + return Ok(BlockExecutionOutcome::default()) } let start_block_number = *range.start(); @@ -533,7 +533,7 @@ impl DatabaseProvider { receipts.push(block_receipts); } - Ok(BundleStateWithReceipts::new_init( + Ok(BlockExecutionOutcome::new_init( state, reverts, Vec::new(), @@ -2673,7 +2673,7 @@ impl BlockWriter for DatabaseProvider { fn append_blocks_with_state( &self, blocks: Vec, - state: BundleStateWithReceipts, + state: BlockExecutionOutcome, hashed_state: HashedPostState, trie_updates: TrieUpdates, prune_modes: Option<&PruneModes>, diff --git a/crates/storage/provider/src/test_utils/blocks.rs b/crates/storage/provider/src/test_utils/blocks.rs index 4cc1e39c9dcf..f46451b8ca30 100644 --- a/crates/storage/provider/src/test_utils/blocks.rs +++ b/crates/storage/provider/src/test_utils/blocks.rs @@ -1,5 +1,5 @@ //! Dummy blocks and data for tests -use crate::{BundleStateWithReceipts, DatabaseProviderRW}; +use crate::{BlockExecutionOutcome, DatabaseProviderRW}; use alloy_primitives::Log; use alloy_rlp::Decodable; use reth_db::tables; @@ -68,7 +68,7 @@ pub struct BlockchainTestData { /// Genesis pub genesis: SealedBlock, /// Blocks with its execution result - pub blocks: Vec<(SealedBlockWithSenders, BundleStateWithReceipts)>, + pub blocks: Vec<(SealedBlockWithSenders, BlockExecutionOutcome)>, } impl BlockchainTestData { @@ -114,7 +114,7 @@ pub fn genesis() -> SealedBlock { } } -fn bundle_state_root(state: &BundleStateWithReceipts) -> B256 { +fn bundle_state_root(state: &BlockExecutionOutcome) -> B256 { state_root_unhashed(state.bundle_accounts_iter().filter_map(|(address, account)| { account.info.as_ref().map(|info| { ( @@ -135,14 +135,14 @@ fn bundle_state_root(state: &BundleStateWithReceipts) -> B256 { } /// Block one that points to genesis -fn block1(number: BlockNumber) -> (SealedBlockWithSenders, BundleStateWithReceipts) { +fn block1(number: BlockNumber) -> (SealedBlockWithSenders, BlockExecutionOutcome) { // block changes let account1: Address = [0x60; 20].into(); let account2: Address = [0x61; 20].into(); let slot = U256::from(5); let info = AccountInfo { nonce: 1, balance: U256::from(10), ..Default::default() }; - let bundle = BundleStateWithReceipts::new( + let bundle = BlockExecutionOutcome::new( BundleState::builder(number..=number) .state_present_account_info(account1, info.clone()) .revert_account_info(number, account1, Some(None)) @@ -190,13 +190,13 @@ fn block1(number: BlockNumber) -> (SealedBlockWithSenders, BundleStateWithReceip fn block2( number: BlockNumber, parent_hash: B256, - prev_state: &BundleStateWithReceipts, -) -> (SealedBlockWithSenders, BundleStateWithReceipts) { + prev_state: &BlockExecutionOutcome, +) -> (SealedBlockWithSenders, BlockExecutionOutcome) { // block changes let account: Address = [0x60; 20].into(); let slot = U256::from(5); - let bundle = BundleStateWithReceipts::new( + let bundle = BlockExecutionOutcome::new( BundleState::builder(number..=number) .state_present_account_info( account, @@ -254,8 +254,8 @@ fn block2( fn block3( number: BlockNumber, parent_hash: B256, - prev_state: &BundleStateWithReceipts, -) -> (SealedBlockWithSenders, BundleStateWithReceipts) { + prev_state: &BlockExecutionOutcome, +) -> (SealedBlockWithSenders, BlockExecutionOutcome) { let address_range = 1..=20; let slot_range = 1..=100; @@ -278,7 +278,7 @@ fn block3( .revert_account_info(number, address, Some(None)) .revert_storage(number, address, Vec::new()); } - let bundle = BundleStateWithReceipts::new( + let bundle = BlockExecutionOutcome::new( bundle_state_builder.build(), vec![vec![Some(Receipt { tx_type: TxType::Eip1559, @@ -319,8 +319,8 @@ fn block3( fn block4( number: BlockNumber, parent_hash: B256, - prev_state: &BundleStateWithReceipts, -) -> (SealedBlockWithSenders, BundleStateWithReceipts) { + prev_state: &BlockExecutionOutcome, +) -> (SealedBlockWithSenders, BlockExecutionOutcome) { let address_range = 1..=20; let slot_range = 1..=100; @@ -369,7 +369,7 @@ fn block4( Vec::from_iter(slot_range.clone().map(|slot| (U256::from(slot), U256::from(slot)))), ); } - let bundle = BundleStateWithReceipts::new( + let bundle = BlockExecutionOutcome::new( bundle_state_builder.build(), vec![vec![Some(Receipt { tx_type: TxType::Eip1559, @@ -410,8 +410,8 @@ fn block4( fn block5( number: BlockNumber, parent_hash: B256, - prev_state: &BundleStateWithReceipts, -) -> (SealedBlockWithSenders, BundleStateWithReceipts) { + prev_state: &BlockExecutionOutcome, +) -> (SealedBlockWithSenders, BlockExecutionOutcome) { let address_range = 1..=20; let slot_range = 1..=100; @@ -455,7 +455,7 @@ fn block5( bundle_state_builder.revert_address(number, address) }; } - let bundle = BundleStateWithReceipts::new( + let bundle = BlockExecutionOutcome::new( bundle_state_builder.build(), vec![vec![Some(Receipt { tx_type: TxType::Eip1559, diff --git a/crates/storage/provider/src/traits/block.rs b/crates/storage/provider/src/traits/block.rs index f457587e8ee3..677e208a2ff8 100644 --- a/crates/storage/provider/src/traits/block.rs +++ b/crates/storage/provider/src/traits/block.rs @@ -1,4 +1,4 @@ -use crate::{BundleStateWithReceipts, Chain}; +use crate::{BlockExecutionOutcome, Chain}; use reth_db_api::models::StoredBlockBodyIndices; use reth_primitives::{BlockNumber, SealedBlockWithSenders}; use reth_prune_types::PruneModes; @@ -65,7 +65,7 @@ pub trait BlockWriter: Send + Sync { fn append_blocks_with_state( &self, blocks: Vec, - state: BundleStateWithReceipts, + state: BlockExecutionOutcome, hashed_state: HashedPostState, trie_updates: TrieUpdates, prune_modes: Option<&PruneModes>, diff --git a/crates/storage/provider/src/traits/chain.rs b/crates/storage/provider/src/traits/chain.rs index 407c80fa05a5..82ba4db5007f 100644 --- a/crates/storage/provider/src/traits/chain.rs +++ b/crates/storage/provider/src/traits/chain.rs @@ -60,7 +60,7 @@ impl Stream for CanonStateNotificationStream { } /// Chain action that is triggered when a new block is imported or old block is reverted. -/// and will return all [`crate::BundleStateWithReceipts`] and +/// and will return all [`crate::BlockExecutionOutcome`] and /// [`reth_primitives::SealedBlockWithSenders`] of both reverted and committed blocks. #[derive(Clone, Debug)] pub enum CanonStateNotification { diff --git a/crates/storage/provider/src/traits/state.rs b/crates/storage/provider/src/traits/state.rs index c9279ab83d9f..7fc7501b3e23 100644 --- a/crates/storage/provider/src/traits/state.rs +++ b/crates/storage/provider/src/traits/state.rs @@ -3,7 +3,7 @@ use reth_db_api::transaction::{DbTx, DbTxMut}; use reth_storage_errors::provider::ProviderResult; use revm::db::OriginalValuesKnown; -/// A helper trait for [`BundleStateWithReceipts`](reth_execution_types::BundleStateWithReceipts) to +/// A helper trait for [`BlockExecutionOutcome`](reth_execution_types::BlockExecutionOutcome) to /// write state and receipts to storage. pub trait StateWriter { /// Write the data and receipts to the database or static files if `static_file_producer` is diff --git a/crates/storage/storage-api/src/state.rs b/crates/storage/storage-api/src/state.rs index d40f5ad646f6..9089c630a68c 100644 --- a/crates/storage/storage-api/src/state.rs +++ b/crates/storage/storage-api/src/state.rs @@ -1,6 +1,6 @@ use super::{AccountReader, BlockHashReader, BlockIdReader, StateRootProvider}; use auto_impl::auto_impl; -use reth_execution_types::BundleStateWithReceipts; +use reth_execution_types::BlockExecutionOutcome; use reth_primitives::{ proofs::AccountProof, Address, BlockHash, BlockId, BlockNumHash, BlockNumber, BlockNumberOrTag, Bytecode, StorageKey, StorageValue, B256, KECCAK_EMPTY, U256, @@ -207,18 +207,18 @@ pub trait BlockchainTreePendingStateProvider: Send + Sync { /// Post state data needed for execution on it. /// /// State contains: -/// * [`BundleStateWithReceipts`] contains all changed of accounts and storage of pending chain +/// * [`BlockExecutionOutcome`] contains all changed of accounts and storage of pending chain /// * block hashes of pending chain and canonical blocks. #[auto_impl(&, Box)] pub trait BundleStateDataProvider: Send + Sync { /// Return post state - fn state(&self) -> &BundleStateWithReceipts; + fn state(&self) -> &BlockExecutionOutcome; /// Return block hash by block number of pending or canonical chain. fn block_hash(&self, block_number: BlockNumber) -> Option; } -impl BundleStateDataProvider for BundleStateWithReceipts { - fn state(&self) -> &BundleStateWithReceipts { +impl BundleStateDataProvider for BlockExecutionOutcome { + fn state(&self) -> &BlockExecutionOutcome { self } @@ -245,7 +245,7 @@ pub trait BundleStateForkProvider { /// This trait is a combination of [`BundleStateDataProvider`] and [`BundleStateForkProvider`]. /// /// Pending state contains: -/// * [`BundleStateWithReceipts`] contains all changed of accounts and storage of pending chain +/// * [`BlockExecutionOutcome`] contains all changed of accounts and storage of pending chain /// * block hashes of pending chain and canonical blocks. /// * canonical fork, the block on what pending chain was forked from. pub trait FullBundleStateDataProvider: BundleStateDataProvider + BundleStateForkProvider {} diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 8302524605cf..1aca9d960878 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -18,7 +18,7 @@ use reth_primitives::{ TryFromRecoveredTransaction, }; use reth_provider::{ - BlockReaderIdExt, BundleStateWithReceipts, CanonStateNotification, ChainSpecProvider, + BlockReaderIdExt, BlockExecutionOutcome, CanonStateNotification, ChainSpecProvider, ProviderError, StateProviderFactory, }; use reth_tasks::TaskSpawner; @@ -556,7 +556,7 @@ where /// Extracts all changed accounts from the `BundleState` fn changed_accounts_iter( - state: &BundleStateWithReceipts, + state: &BlockExecutionOutcome, ) -> impl Iterator + '_ { state .accounts_iter() diff --git a/examples/exex/in-memory-state/src/main.rs b/examples/exex/in-memory-state/src/main.rs index 451bb9c42924..0c7cad603a37 100644 --- a/examples/exex/in-memory-state/src/main.rs +++ b/examples/exex/in-memory-state/src/main.rs @@ -1,6 +1,6 @@ #![warn(unused_crate_dependencies)] -use reth::providers::BundleStateWithReceipts; +use reth::providers::BlockExecutionOutcome; use reth_exex::{ExExContext, ExExEvent, ExExNotification}; use reth_node_api::FullNodeComponents; use reth_node_ethereum::EthereumNode; @@ -9,7 +9,7 @@ use reth_tracing::tracing::info; /// An ExEx that keeps track of the entire state in memory async fn track_state(mut ctx: ExExContext) -> eyre::Result<()> { // keeps the entire plain state of the chain in memory - let mut state = BundleStateWithReceipts::default(); + let mut state = BlockExecutionOutcome::default(); while let Some(notification) = ctx.notifications.recv().await { match ¬ification { diff --git a/examples/exex/minimal/src/main.rs b/examples/exex/minimal/src/main.rs index 4ea00b1809e9..1cdb7f017fb2 100644 --- a/examples/exex/minimal/src/main.rs +++ b/examples/exex/minimal/src/main.rs @@ -56,7 +56,7 @@ fn main() -> eyre::Result<()> { mod tests { use std::pin::pin; - use reth::providers::{BundleStateWithReceipts, Chain}; + use reth::providers::{BlockExecutionOutcome, Chain}; use reth_exex_test_utils::{test_exex_context, PollOnce}; #[tokio::test] @@ -71,7 +71,7 @@ mod tests { handle .send_notification_chain_committed(Chain::from_block( handle.genesis.clone(), - BundleStateWithReceipts::default(), + BlockExecutionOutcome::default(), None, )) .await?; diff --git a/examples/exex/op-bridge/src/main.rs b/examples/exex/op-bridge/src/main.rs index 61c44c019a5e..2a50c7df4dbd 100644 --- a/examples/exex/op-bridge/src/main.rs +++ b/examples/exex/op-bridge/src/main.rs @@ -264,7 +264,7 @@ mod tests { Address, Block, Header, Log, Receipt, Transaction, TransactionSigned, TxKind, TxLegacy, TxType, U256, }; - use reth_provider::{BundleStateWithReceipts, Chain}; + use reth_provider::{BlockExecutionOutcome, Chain}; use reth_testing_utils::generators::sign_tx_with_random_key_pair; use rusqlite::Connection; @@ -341,7 +341,7 @@ mod tests { // Construct a chain let chain = Chain::new( vec![block.clone()], - BundleStateWithReceipts::new( + BlockExecutionOutcome::new( BundleState::default(), vec![deposit_tx_receipt, withdrawal_tx_receipt].into(), block.number, From 27c24edb516df76da2aa0bd7e4442d6ba617e808 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Mon, 10 Jun 2024 22:56:37 +0200 Subject: [PATCH 2/9] clean: fmt --- bin/reth/src/commands/debug_cmd/build_block.rs | 5 ++--- bin/reth/src/commands/debug_cmd/in_memory_merkle.rs | 8 ++------ crates/blockchain-tree/src/blockchain_tree.rs | 2 +- crates/blockchain-tree/src/bundle.rs | 2 +- crates/blockchain-tree/src/chain.rs | 8 ++------ crates/consensus/auto-seal/src/lib.rs | 2 +- crates/stages/stages/src/stages/execution.rs | 5 ++--- crates/stages/stages/src/stages/headers.rs | 2 +- crates/storage/db-common/src/init.rs | 6 +++--- crates/storage/provider/src/bundle_state/mod.rs | 2 +- .../storage/provider/src/providers/database/provider.rs | 2 +- crates/transaction-pool/src/maintain.rs | 2 +- 12 files changed, 18 insertions(+), 28 deletions(-) diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index ce303dd4efe8..6d2972b1418d 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -30,9 +30,8 @@ use reth_primitives::{ SealedBlock, SealedBlockWithSenders, Transaction, TransactionSigned, TxEip4844, B256, U256, }; use reth_provider::{ - providers::BlockchainProvider, BlockHashReader, BlockReader, BlockWriter, - BlockExecutionOutcome, ChainSpecProvider, ProviderFactory, StageCheckpointReader, - StateProviderFactory, + providers::BlockchainProvider, BlockExecutionOutcome, BlockHashReader, BlockReader, + BlockWriter, ChainSpecProvider, ProviderFactory, StageCheckpointReader, StateProviderFactory, }; use reth_revm::database::StateProviderDatabase; use reth_rpc_types::engine::{BlobsBundleV1, PayloadAttributes}; 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 89ae7d4dd716..950b59598e42 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -146,12 +146,8 @@ impl Command { ) .into(), )?; - let block_state = BlockExecutionOutcome::new( - state, - receipts.into(), - block.number, - vec![requests.into()], - ); + let block_state = + BlockExecutionOutcome::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/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 14fee2944689..d9e024c21565 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -18,7 +18,7 @@ use reth_primitives::{ SealedBlockWithSenders, SealedHeader, StaticFileSegment, B256, U256, }; use reth_provider::{ - BlockExecutionWriter, BlockNumReader, BlockWriter, BlockExecutionOutcome, + BlockExecutionOutcome, BlockExecutionWriter, BlockNumReader, BlockWriter, CanonStateNotification, CanonStateNotificationSender, CanonStateNotifications, Chain, ChainSpecProvider, ChainSplit, ChainSplitTarget, DisplayBlocksChain, HeaderProvider, ProviderError, StaticFileProviderFactory, diff --git a/crates/blockchain-tree/src/bundle.rs b/crates/blockchain-tree/src/bundle.rs index bc1cc6a3035c..360efc932b68 100644 --- a/crates/blockchain-tree/src/bundle.rs +++ b/crates/blockchain-tree/src/bundle.rs @@ -1,7 +1,7 @@ //! [`BundleStateDataProvider`] implementations used by the tree. use reth_primitives::{BlockHash, BlockNumber, ForkBlock}; -use reth_provider::{BundleStateDataProvider, BundleStateForkProvider, BlockExecutionOutcome}; +use reth_provider::{BlockExecutionOutcome, BundleStateDataProvider, BundleStateForkProvider}; use std::collections::BTreeMap; /// Structure that combines references of required data to be a [`BundleStateDataProvider`]. diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index 918287c9935a..6daae71f5f73 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -214,12 +214,8 @@ impl AppendableChain { .consensus .validate_block_post_execution(&block, PostExecutionInput::new(&receipts, &requests))?; - let bundle_state = BlockExecutionOutcome::new( - state, - receipts.into(), - block.number, - vec![requests.into()], - ); + let bundle_state = + BlockExecutionOutcome::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 848f6938c5ce..548d83428afc 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -27,7 +27,7 @@ use reth_primitives::{ U256, }; use reth_provider::{ - BlockReaderIdExt, BlockExecutionOutcome, StateProviderFactory, StateRootProvider, + BlockExecutionOutcome, BlockReaderIdExt, StateProviderFactory, StateRootProvider, }; use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::TransactionPool; diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index 5fac6086aa7a..1c2469e3527c 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -13,7 +13,7 @@ use reth_primitives::{ }; use reth_provider::{ providers::{StaticFileProvider, StaticFileProviderRWRefMut, StaticFileWriter}, - BlockReader, BlockExecutionOutcome, Chain, DatabaseProviderRW, HeaderProvider, + BlockExecutionOutcome, BlockReader, Chain, DatabaseProviderRW, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderError, StateWriter, StatsReader, TransactionVariant, }; @@ -289,8 +289,7 @@ where } } let time = Instant::now(); - let BlockExecutionOutcome { bundle, receipts, requests, first_block } = - executor.finalize(); + let BlockExecutionOutcome { bundle, receipts, requests, first_block } = executor.finalize(); let state = BlockExecutionOutcome::new(bundle, receipts, first_block, requests); let write_preparation_duration = time.elapsed(); diff --git a/crates/stages/stages/src/stages/headers.rs b/crates/stages/stages/src/stages/headers.rs index 201e074d0b0d..934cd6d29eb2 100644 --- a/crates/stages/stages/src/stages/headers.rs +++ b/crates/stages/stages/src/stages/headers.rs @@ -384,7 +384,7 @@ mod tests { stage::StageUnitCheckpoint, BlockBody, SealedBlock, SealedBlockWithSenders, B256, }; use reth_provider::{ - BlockWriter, BlockExecutionOutcome, ProviderFactory, StaticFileProviderFactory, + BlockExecutionOutcome, BlockWriter, ProviderFactory, StaticFileProviderFactory, }; use reth_testing_utils::generators::{self, random_header, random_header_range}; use reth_trie::{updates::TrieUpdates, HashedPostState}; diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index 23c9ffb2bfff..bc1145d41174 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -14,9 +14,9 @@ use reth_provider::{ bundle_state::{BundleStateInit, RevertsInit}, errors::provider::ProviderResult, providers::{StaticFileProvider, StaticFileWriter}, - BlockHashReader, BlockNumReader, BlockExecutionOutcome, ChainSpecProvider, - DatabaseProviderRW, HashingWriter, HistoryWriter, OriginalValuesKnown, ProviderError, - ProviderFactory, StageCheckpointWriter, StateWriter, StaticFileProviderFactory, + BlockExecutionOutcome, BlockHashReader, BlockNumReader, ChainSpecProvider, DatabaseProviderRW, + HashingWriter, HistoryWriter, OriginalValuesKnown, ProviderError, ProviderFactory, + StageCheckpointWriter, StateWriter, StaticFileProviderFactory, }; use reth_trie::{IntermediateStateRootState, StateRoot as StateRootComputer, StateRootProgress}; use serde::{Deserialize, Serialize}; diff --git a/crates/storage/provider/src/bundle_state/mod.rs b/crates/storage/provider/src/bundle_state/mod.rs index 4fcf22ce0b61..e41d284a7d09 100644 --- a/crates/storage/provider/src/bundle_state/mod.rs +++ b/crates/storage/provider/src/bundle_state/mod.rs @@ -6,7 +6,7 @@ mod state_changes; mod state_reverts; pub use bundle_state_with_receipts::{ - AccountRevertInit, BundleStateInit, BlockExecutionOutcome, OriginalValuesKnown, RevertsInit, + AccountRevertInit, BlockExecutionOutcome, BundleStateInit, OriginalValuesKnown, RevertsInit, }; pub use hashed_state_changes::HashedStateChanges; pub use state_changes::StateChanges; diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 410f528dde53..e92dba8c4a16 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -1,5 +1,5 @@ use crate::{ - bundle_state::{BundleStateInit, BlockExecutionOutcome, HashedStateChanges, RevertsInit}, + bundle_state::{BlockExecutionOutcome, BundleStateInit, HashedStateChanges, RevertsInit}, providers::{database::metrics, static_file::StaticFileWriter, StaticFileProvider}, to_range, traits::{ diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 1aca9d960878..49072cfc6345 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -18,7 +18,7 @@ use reth_primitives::{ TryFromRecoveredTransaction, }; use reth_provider::{ - BlockReaderIdExt, BlockExecutionOutcome, CanonStateNotification, ChainSpecProvider, + BlockExecutionOutcome, BlockReaderIdExt, CanonStateNotification, ChainSpecProvider, ProviderError, StateProviderFactory, }; use reth_tasks::TaskSpawner; From 8150aa3d228c3edb62b792911fdb8eea3a252446 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Tue, 11 Jun 2024 00:10:59 +0200 Subject: [PATCH 3/9] clean: improve naming around BlockExecutionOutcome --- .../src/commands/debug_cmd/build_block.rs | 12 +- .../commands/debug_cmd/in_memory_merkle.rs | 10 +- bin/reth/src/commands/import_receipts_op.rs | 4 +- crates/blockchain-tree/src/blockchain_tree.rs | 26 ++-- crates/blockchain-tree/src/bundle.rs | 36 +++--- crates/blockchain-tree/src/chain.rs | 39 +++--- crates/blockchain-tree/src/lib.rs | 2 +- crates/consensus/auto-seal/src/lib.rs | 8 +- crates/ethereum/payload/src/lib.rs | 10 +- crates/evm/execution-types/src/bundle.rs | 17 ++- crates/evm/execution-types/src/chain.rs | 113 +++++++++++------- crates/optimism/payload/src/builder.rs | 9 +- crates/payload/basic/src/lib.rs | 4 +- crates/rpc/rpc/src/eth/api/pending_block.rs | 12 +- crates/storage/db-common/src/init.rs | 4 +- .../src/providers/bundle_state_provider.rs | 58 +++++---- .../src/providers/database/provider.rs | 4 +- .../storage/provider/src/test_utils/blocks.rs | 95 +++++++++------ crates/storage/provider/src/traits/block.rs | 2 +- crates/storage/storage-api/src/state.rs | 37 ++++-- crates/transaction-pool/src/maintain.rs | 4 +- examples/exex/in-memory-state/src/main.rs | 12 +- examples/exex/minimal/src/main.rs | 3 +- 23 files changed, 304 insertions(+), 217 deletions(-) diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index 6d2972b1418d..687e38b35633 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -272,17 +272,17 @@ impl Command { let BlockExecutionOutput { state, receipts, requests, .. } = executor.execute((&block_with_senders.clone().unseal(), U256::MAX).into())?; - let state = BlockExecutionOutcome::new( + let block_execution_outcome = BlockExecutionOutcome::new( state, receipts.into(), block.number, vec![requests.into()], ); - debug!(target: "reth::cli", ?state, "Executed block"); + debug!(target: "reth::cli", ?block_execution_outcome, "Executed block"); - let hashed_state = state.hash_state_slow(); - let (state_root, trie_updates) = state + let hashed_post_state = block_execution_outcome.hash_state_slow(); + let (state_root, trie_updates) = block_execution_outcome .hash_state_slow() .state_root_with_updates(provider_factory.provider()?.tx_ref())?; @@ -298,8 +298,8 @@ impl Command { let provider_rw = provider_factory.provider_rw()?; provider_rw.append_blocks_with_state( Vec::from([block_with_senders]), - state, - hashed_state, + block_execution_outcome, + hashed_post_state, trie_updates, None, )?; 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 950b59598e42..f9361fe8ec6e 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -146,12 +146,12 @@ impl Command { ) .into(), )?; - let block_state = + let block_execution_outcome = BlockExecutionOutcome::new(state, receipts.into(), block.number, vec![requests.into()]); // Unpacked `BundleState::state_root_slow` function let (in_memory_state_root, in_memory_updates) = - block_state.hash_state_slow().state_root_with_updates(provider.tx_ref())?; + block_execution_outcome.hash_state_slow().state_root_with_updates(provider.tx_ref())?; if in_memory_state_root == block.state_root { info!(target: "reth::cli", state_root = ?in_memory_state_root, "Computed in-memory state root matches"); @@ -168,7 +168,11 @@ impl Command { .map_err(|_| BlockValidationError::SenderRecoveryError)?, None, )?; - block_state.write_to_storage(provider_rw.tx_ref(), None, OriginalValuesKnown::No)?; + block_execution_outcome.write_to_storage( + provider_rw.tx_ref(), + None, + OriginalValuesKnown::No, + )?; let storage_lists = provider_rw.changed_storages_with_range(block.number..=block.number)?; let storages = provider_rw.plain_state_storages(storage_lists)?; provider_rw.insert_storage_for_hashing(storages)?; diff --git a/bin/reth/src/commands/import_receipts_op.rs b/bin/reth/src/commands/import_receipts_op.rs index caadec3729f0..273d3f60a0b8 100644 --- a/bin/reth/src/commands/import_receipts_op.rs +++ b/bin/reth/src/commands/import_receipts_op.rs @@ -132,7 +132,7 @@ where // We're reusing receipt writing code internal to // `BlockExecutionOutcome::write_to_storage`, so we just use a default empty // `BundleState`. - let bundled_state = BlockExecutionOutcome::new( + let block_execution_outcome = BlockExecutionOutcome::new( Default::default(), receipts, first_block, @@ -143,7 +143,7 @@ where static_file_provider.get_writer(first_block, StaticFileSegment::Receipts)?; // finally, write the receipts - bundled_state.write_to_storage::( + block_execution_outcome.write_to_storage::( &tx, Some(static_file_producer), OriginalValuesKnown::Yes, diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index d9e024c21565..a0d30295de8e 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -3,7 +3,7 @@ use crate::{ metrics::{MakeCanonicalAction, MakeCanonicalDurationsRecorder, TreeMetrics}, state::{BlockchainId, TreeState}, - AppendableChain, BlockIndices, BlockchainTreeConfig, BundleStateData, TreeExternals, + AppendableChain, BlockExecutionData, BlockIndices, BlockchainTreeConfig, TreeExternals, }; use reth_blockchain_tree_api::{ error::{BlockchainTreeError, CanonicalError, InsertBlockError, InsertBlockErrorKind}, @@ -264,7 +264,7 @@ where /// * block unknown. /// * `chain_id` not present in state. /// * there are no parent hashes stored. - pub fn post_state_data(&self, block_hash: BlockHash) -> Option { + pub fn post_state_data(&self, block_hash: BlockHash) -> Option { trace!(target: "blockchain_tree", ?block_hash, "Searching for post state data"); let canonical_chain = self.state.block_indices.canonical_chain(); @@ -278,7 +278,7 @@ where return None; }; let block_number = chain.block_number(block_hash)?; - let state = chain.state_at_block(block_number)?; + let block_execution_outcome = chain.block_execution_outcome_at_block(block_number)?; // get parent hashes let mut parent_block_hashes = self.all_chain_hashes(chain_id); @@ -295,15 +295,19 @@ where // get canonical fork. let canonical_fork = self.canonical_fork(chain_id)?; - return Some(BundleStateData { state, parent_block_hashes, canonical_fork }) + return Some(BlockExecutionData { + block_execution_outcome, + parent_block_hashes, + canonical_fork, + }) } // check if there is canonical block if let Some(canonical_number) = canonical_chain.canonical_number(&block_hash) { trace!(target: "blockchain_tree", %block_hash, "Constructing post state data based on canonical chain"); - return Some(BundleStateData { + return Some(BlockExecutionData { canonical_fork: ForkBlock { number: canonical_number, hash: block_hash }, - state: BlockExecutionOutcome::default(), + block_execution_outcome: BlockExecutionOutcome::default(), parent_block_hashes: canonical_chain.inner().clone(), }) } @@ -629,8 +633,8 @@ where let chains_to_bump = self.find_all_dependent_chains(&hash); if !chains_to_bump.is_empty() { // if there is such chain, revert state to this block. - let mut cloned_state = chain.state().clone(); - cloned_state.revert_to(*number); + let mut cloned_block_execution_outcome = chain.block_execution_outcome().clone(); + cloned_block_execution_outcome.revert_to(*number); // prepend state to all chains that fork from this block. for chain_id in chains_to_bump { @@ -645,7 +649,7 @@ where chain_tip = ?chain.tip().num_hash(), "Prepend unwound block state to blockchain tree chain"); - chain.prepend_state(cloned_state.state().clone()) + chain.prepend_state(cloned_block_execution_outcome.state().clone()) } } } @@ -1961,12 +1965,12 @@ mod tests { ])) .assert(&tree); // chain 0 has two blocks so receipts and reverts len is 2 - let chain0 = tree.state.chains.get(&0.into()).unwrap().state(); + let chain0 = tree.state.chains.get(&0.into()).unwrap().block_execution_outcome(); assert_eq!(chain0.receipts().len(), 2); assert_eq!(chain0.state().reverts.len(), 2); assert_eq!(chain0.first_block(), block1.number); // chain 1 has one block so receipts and reverts len is 1 - let chain1 = tree.state.chains.get(&1.into()).unwrap().state(); + let chain1 = tree.state.chains.get(&1.into()).unwrap().block_execution_outcome(); assert_eq!(chain1.receipts().len(), 1); assert_eq!(chain1.state().reverts.len(), 1); assert_eq!(chain1.first_block(), block2.number); diff --git a/crates/blockchain-tree/src/bundle.rs b/crates/blockchain-tree/src/bundle.rs index 360efc932b68..bf5237180d05 100644 --- a/crates/blockchain-tree/src/bundle.rs +++ b/crates/blockchain-tree/src/bundle.rs @@ -1,14 +1,16 @@ -//! [`BundleStateDataProvider`] implementations used by the tree. +//! [`BlockExecutionDataProvider`] implementations used by the tree. use reth_primitives::{BlockHash, BlockNumber, ForkBlock}; -use reth_provider::{BlockExecutionOutcome, BundleStateDataProvider, BundleStateForkProvider}; +use reth_provider::{ + BlockExecutionDataProvider, BlockExecutionForkProvider, BlockExecutionOutcome, +}; use std::collections::BTreeMap; -/// Structure that combines references of required data to be a [`BundleStateDataProvider`]. +/// Structure that combines references of required data to be a [`BlockExecutionDataProvider`]. #[derive(Clone, Debug)] pub struct BundleStateDataRef<'a> { - /// The wrapped state after execution of one or more transactions and/or blocks. - pub state: &'a BlockExecutionOutcome, + /// The block execution outcome after execution of one or more transactions and/or blocks. + pub block_execution_outcome: &'a BlockExecutionOutcome, /// The blocks in the sidechain. pub sidechain_block_hashes: &'a BTreeMap, /// The blocks in the canonical chain. @@ -17,9 +19,9 @@ pub struct BundleStateDataRef<'a> { pub canonical_fork: ForkBlock, } -impl<'a> BundleStateDataProvider for BundleStateDataRef<'a> { - fn state(&self) -> &BlockExecutionOutcome { - self.state +impl<'a> BlockExecutionDataProvider for BundleStateDataRef<'a> { + fn block_execution_outcome(&self) -> &BlockExecutionOutcome { + self.block_execution_outcome } fn block_hash(&self, block_number: BlockNumber) -> Option { @@ -32,17 +34,17 @@ impl<'a> BundleStateDataProvider for BundleStateDataRef<'a> { } } -impl<'a> BundleStateForkProvider for BundleStateDataRef<'a> { +impl<'a> BlockExecutionForkProvider for BundleStateDataRef<'a> { fn canonical_fork(&self) -> ForkBlock { self.canonical_fork } } -/// Structure that owns the relevant data needs to be a [`BundleStateDataProvider`] +/// Structure that owns the relevant data needs to be a [`BlockExecutionDataProvider`] #[derive(Clone, Debug)] -pub struct BundleStateData { - /// Post state with changes - pub state: BlockExecutionOutcome, +pub struct BlockExecutionData { + /// Block execution outcome. + pub block_execution_outcome: BlockExecutionOutcome, /// Parent block hashes needs for evm BLOCKHASH opcode. /// NOTE: it does not mean that all hashes are there but all until finalized are there. /// Other hashes can be obtained from provider @@ -51,9 +53,9 @@ pub struct BundleStateData { pub canonical_fork: ForkBlock, } -impl BundleStateDataProvider for BundleStateData { - fn state(&self) -> &BlockExecutionOutcome { - &self.state +impl BlockExecutionDataProvider for BlockExecutionData { + fn block_execution_outcome(&self) -> &BlockExecutionOutcome { + &self.block_execution_outcome } fn block_hash(&self, block_number: BlockNumber) -> Option { @@ -61,7 +63,7 @@ impl BundleStateDataProvider for BundleStateData { } } -impl BundleStateForkProvider for BundleStateData { +impl BlockExecutionForkProvider for BlockExecutionData { fn canonical_fork(&self) -> ForkBlock { self.canonical_fork } diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index 6daae71f5f73..ba4fa93cc453 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -78,11 +78,11 @@ impl AppendableChain { DB: Database + Clone, E: BlockExecutorProvider, { - let state = BlockExecutionOutcome::default(); + let block_execution_outcome = BlockExecutionOutcome::default(); let empty = BTreeMap::new(); let state_provider = BundleStateDataRef { - state: &state, + block_execution_outcome: &block_execution_outcome, sidechain_block_hashes: &empty, canonical_block_hashes, canonical_fork, @@ -122,14 +122,14 @@ impl AppendableChain { BlockchainTreeError::BlockNumberNotFoundInChain { block_number: parent_number }, )?; - let mut state = self.state().clone(); + let mut block_execution_outcome = self.block_execution_outcome().clone(); // Revert state to the state after execution of the parent block - state.revert_to(parent.number); + block_execution_outcome.revert_to(parent.number); // Revert changesets to get the state of the parent that we need to apply the change. let bundle_state_data = BundleStateDataRef { - state: &state, + block_execution_outcome: &block_execution_outcome, sidechain_block_hashes: &side_chain_block_hashes, canonical_block_hashes, canonical_fork, @@ -144,17 +144,17 @@ impl AppendableChain { )?; // extending will also optimize few things, mostly related to selfdestruct and wiping of // storage. - state.extend(block_state); + block_execution_outcome.extend(block_state); // remove all receipts and reverts (except the last one), as they belong to the chain we // forked from and not the new chain we are creating. - let size = state.receipts().len(); - state.receipts_mut().drain(0..size - 1); - state.state_mut().take_n_reverts(size - 1); - state.set_first_block(block.number); + let size = block_execution_outcome.receipts().len(); + block_execution_outcome.receipts_mut().drain(0..size - 1); + block_execution_outcome.state_mut().take_n_reverts(size - 1); + block_execution_outcome.set_first_block(block.number); // If all is okay, return new chain back. Present chain is not modified. - Ok(Self { chain: Chain::from_block(block, state, None) }) + Ok(Self { chain: Chain::from_block(block, block_execution_outcome, None) }) } /// Validate and execute the given block that _extends the canonical chain_, validating its @@ -214,7 +214,7 @@ impl AppendableChain { .consensus .validate_block_post_execution(&block, PostExecutionInput::new(&receipts, &requests))?; - let bundle_state = + let block_execution_outcome = BlockExecutionOutcome::new(state, receipts.into(), block.number, vec![requests.into()]); // check state root if the block extends the canonical chain __and__ if state root @@ -223,15 +223,16 @@ impl AppendableChain { // calculate and check state root let start = Instant::now(); let (state_root, trie_updates) = if block_attachment.is_canonical() { - let mut state = provider.bundle_state_data_provider.state().clone(); - state.extend(bundle_state.clone()); - let hashed_state = state.hash_state_slow(); + let mut block_execution_outcome = + provider.block_execution_data_provider.block_execution_outcome().clone(); + block_execution_outcome.extend(block_execution_outcome.clone()); + let hashed_state = block_execution_outcome.hash_state_slow(); ParallelStateRoot::new(consistent_view, hashed_state) .incremental_root_with_updates() .map(|(root, updates)| (root, Some(updates))) .map_err(ProviderError::from)? } else { - (provider.state_root(bundle_state.state())?, None) + (provider.state_root(block_execution_outcome.state())?, None) }; if block.state_root != state_root { return Err(ConsensusError::BodyStateRootDiff( @@ -248,9 +249,9 @@ impl AppendableChain { "Validated state root" ); - Ok((bundle_state, trie_updates)) + Ok((block_execution_outcome, trie_updates)) } else { - Ok((bundle_state, None)) + Ok((block_execution_outcome, None)) } } @@ -284,7 +285,7 @@ impl AppendableChain { let parent_block = self.chain.tip(); let bundle_state_data = BundleStateDataRef { - state: self.state(), + block_execution_outcome: self.block_execution_outcome(), sidechain_block_hashes: &side_chain_block_hashes, canonical_block_hashes, canonical_fork, diff --git a/crates/blockchain-tree/src/lib.rs b/crates/blockchain-tree/src/lib.rs index 6d5a017eb3ae..7c6714082f84 100644 --- a/crates/blockchain-tree/src/lib.rs +++ b/crates/blockchain-tree/src/lib.rs @@ -40,7 +40,7 @@ pub mod shareable; pub use shareable::ShareableBlockchainTree; mod bundle; -pub use bundle::{BundleStateData, BundleStateDataRef}; +pub use bundle::{BlockExecutionData, BundleStateDataRef}; /// Buffer of not executed blocks. pub mod block_buffer; diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index 548d83428afc..2d315334df4e 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -391,7 +391,7 @@ impl StorageInner { // execute the block let BlockExecutionOutput { state, receipts, requests: block_execution_requests, .. } = executor.executor(&mut db).execute((&block, U256::ZERO).into())?; - let bundle_state = BlockExecutionOutcome::new( + let block_execution_outcome = BlockExecutionOutcome::new( state, receipts.into(), block.number, @@ -405,10 +405,10 @@ impl StorageInner { let Block { mut header, body, .. } = block.block; let body = BlockBody { transactions: body, ommers, withdrawals, requests }; - trace!(target: "consensus::auto", ?bundle_state, ?header, ?body, "executed block, calculating state root and completing header"); + trace!(target: "consensus::auto", ?block_execution_outcome, ?header, ?body, "executed block, calculating state root and completing header"); // calculate the state root - header.state_root = db.state_root(bundle_state.state())?; + header.state_root = db.state_root(block_execution_outcome.state())?; trace!(target: "consensus::auto", root=?header.state_root, ?body, "calculated root"); // finally insert into storage @@ -417,6 +417,6 @@ impl StorageInner { // set new header with hash that should have been updated by insert_new_block let new_header = header.seal(self.best_hash); - Ok((new_header, bundle_state)) + Ok((new_header, block_execution_outcome)) } } diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index 7140abbdb4ff..7ef9f16a8327 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -444,19 +444,21 @@ where // and 4788 contract call db.merge_transitions(BundleRetention::PlainState); - let bundle = BlockExecutionOutcome::new( + let block_execution_outcome = BlockExecutionOutcome::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"); + let receipts_root = + block_execution_outcome.receipts_root_slow(block_number).expect("Number is in range"); + let logs_bloom = + block_execution_outcome.block_logs_bloom(block_number).expect("Number is in range"); // calculate the state root let state_root = { let state_provider = db.database.0.inner.borrow_mut(); - state_provider.db.state_root(bundle.state())? + state_provider.db.state_root(block_execution_outcome.state())? }; // create the block header diff --git a/crates/evm/execution-types/src/bundle.rs b/crates/evm/execution-types/src/bundle.rs index fc256882e4b2..ed3bf5f79c18 100644 --- a/crates/evm/execution-types/src/bundle.rs +++ b/crates/evm/execution-types/src/bundle.rs @@ -11,9 +11,10 @@ use revm::{ }; use std::collections::HashMap; -/// Bundle state of post execution changes and reverts. +/// Represents the outcome of block execution, including post-execution changes and reverts. /// -/// Aggregates the changes over an arbitrary number of blocks. +/// The `BlockExecutionOutcome` structure aggregates the state changes over an arbitrary number of +/// blocks, capturing the resulting state, receipts, and requests following the execution. #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct BlockExecutionOutcome { /// Bundle state with reverts. @@ -46,7 +47,10 @@ pub type AccountRevertInit = (Option>, Vec); pub type RevertsInit = HashMap>; impl BlockExecutionOutcome { - /// Create a new block execution outcome. + /// Creates a new `BlockExecutionOutcome`. + /// + /// This constructor initializes a new `BlockExecutionOutcome` instance with the provided + /// bundle state, receipts, first block number, and EIP-7685 requests. pub const fn new( bundle: BundleState, receipts: Receipts, @@ -56,7 +60,10 @@ impl BlockExecutionOutcome { Self { bundle, receipts, first_block, requests } } - /// Create a new block execution outcome. + /// Creates a new `BlockExecutionOutcome` from initialization parameters. + /// + /// This constructor initializes a new `BlockExecutionOutcome` instance using detailed + /// initialization parameters. pub fn new_init( state_init: BundleStateInit, revert_init: RevertsInit, @@ -137,7 +144,7 @@ impl BlockExecutionOutcome { self.bundle.bytecode(code_hash).map(Bytecode) } - /// Returns [`HashedPostState`] for this bundle state. + /// Returns [`HashedPostState`] for this block execution outcome. /// See [`HashedPostState::from_bundle_state`] for more info. pub fn hash_state_slow(&self) -> HashedPostState { HashedPostState::from_bundle_state(&self.bundle.state) diff --git a/crates/evm/execution-types/src/chain.rs b/crates/evm/execution-types/src/chain.rs index c3eadfdd3470..fc2bad2780b8 100644 --- a/crates/evm/execution-types/src/chain.rs +++ b/crates/evm/execution-types/src/chain.rs @@ -24,11 +24,13 @@ use std::{borrow::Cow, collections::BTreeMap, fmt, ops::RangeInclusive}; pub struct Chain { /// All blocks in this chain. blocks: BTreeMap, - /// The state of all accounts after execution of the _all_ blocks in this chain's range from - /// [`Chain::first`] to [`Chain::tip`], inclusive. + /// The outcome of block execution for this chain. /// - /// This state also contains the individual changes that lead to the current state. - state: BlockExecutionOutcome, + /// This field contains the state of all accounts after the execution of all blocks in this + /// chain, ranging from the [`Chain::first`] block to the [`Chain::tip`] block, inclusive. + /// + /// Additionally, it includes the individual state changes that led to the current state. + block_execution_outcome: BlockExecutionOutcome, /// State trie updates after block is added to the chain. /// NOTE: Currently, trie updates are present only for /// single-block chains that extend the canonical chain. @@ -43,22 +45,22 @@ impl Chain { /// A chain of blocks should not be empty. pub fn new( blocks: impl IntoIterator, - state: BlockExecutionOutcome, + block_execution_outcome: BlockExecutionOutcome, trie_updates: Option, ) -> Self { let blocks = BTreeMap::from_iter(blocks.into_iter().map(|b| (b.number, b))); debug_assert!(!blocks.is_empty(), "Chain should have at least one block"); - Self { blocks, state, trie_updates } + Self { blocks, block_execution_outcome, trie_updates } } /// Create new Chain from a single block and its state. pub fn from_block( block: SealedBlockWithSenders, - state: BlockExecutionOutcome, + block_execution_outcome: BlockExecutionOutcome, trie_updates: Option, ) -> Self { - Self::new([block], state, trie_updates) + Self::new([block], block_execution_outcome, trie_updates) } /// Get the blocks in this chain. @@ -86,14 +88,14 @@ impl Chain { self.trie_updates.take(); } - /// Get post state of this chain - pub const fn state(&self) -> &BlockExecutionOutcome { - &self.state + /// Get block execution outcome of this chain + pub const fn block_execution_outcome(&self) -> &BlockExecutionOutcome { + &self.block_execution_outcome } /// Prepends the given state to the current state. pub fn prepend_state(&mut self, state: BundleState) { - self.state.prepend_state(state); + self.block_execution_outcome.prepend_state(state); self.trie_updates.take(); // invalidate cached trie updates } @@ -117,35 +119,45 @@ impl Chain { self.blocks.iter().find_map(|(_num, block)| (block.hash() == block_hash).then_some(block)) } - /// Return post state of the block at the `block_number` or None if block is not known - pub fn state_at_block(&self, block_number: BlockNumber) -> Option { + /// Return block execution outcome at the `block_number` or None if block is not known + pub fn block_execution_outcome_at_block( + &self, + block_number: BlockNumber, + ) -> Option { if self.tip().number == block_number { - return Some(self.state.clone()) + return Some(self.block_execution_outcome.clone()) } if self.blocks.contains_key(&block_number) { - let mut state = self.state.clone(); - state.revert_to(block_number); - return Some(state) + let mut block_execution_outcome = self.block_execution_outcome.clone(); + block_execution_outcome.revert_to(block_number); + return Some(block_execution_outcome) } None } - /// Destructure the chain into its inner components, the blocks and the state at the tip of the - /// chain. + /// Destructure the chain into its inner components: + /// 1. The blocks contained in the chain. + /// 2. The execution outcome representing the final state. + /// 3. The optional trie updates. pub fn into_inner(self) -> (ChainBlocks<'static>, BlockExecutionOutcome, Option) { - (ChainBlocks { blocks: Cow::Owned(self.blocks) }, self.state, self.trie_updates) + ( + ChainBlocks { blocks: Cow::Owned(self.blocks) }, + self.block_execution_outcome, + self.trie_updates, + ) } - /// Destructure the chain into its inner components, the blocks and the state at the tip of the - /// chain. + /// Destructure the chain into its inner components: + /// 1. A reference to the blocks contained in the chain. + /// 2. A reference to the execution outcome representing the final state. pub const fn inner(&self) -> (ChainBlocks<'_>, &BlockExecutionOutcome) { - (ChainBlocks { blocks: Cow::Borrowed(&self.blocks) }, &self.state) + (ChainBlocks { blocks: Cow::Borrowed(&self.blocks) }, &self.block_execution_outcome) } /// Returns an iterator over all the receipts of the blocks in the chain. pub fn block_receipts_iter(&self) -> impl Iterator>> + '_ { - self.state.receipts().iter() + self.block_execution_outcome.receipts().iter() } /// Returns an iterator over all blocks in the chain with increasing block number. @@ -204,7 +216,7 @@ impl Chain { /// Get all receipts for the given block. pub fn receipts_by_block_hash(&self, block_hash: BlockHash) -> Option> { let num = self.block_number(block_hash)?; - self.state.receipts_by_block(num).iter().map(Option::as_ref).collect() + self.block_execution_outcome.receipts_by_block(num).iter().map(Option::as_ref).collect() } /// Get all receipts with attachment. @@ -212,7 +224,8 @@ impl Chain { /// Attachment includes block number, block hash, transaction hash and transaction index. pub fn receipts_with_attachment(&self) -> Vec { let mut receipt_attach = Vec::new(); - for ((block_num, block), receipts) in self.blocks().iter().zip(self.state.receipts().iter()) + for ((block_num, block), receipts) in + self.blocks().iter().zip(self.block_execution_outcome.receipts().iter()) { let mut tx_receipts = Vec::new(); for (tx, receipt) in block.body.iter().zip(receipts.iter()) { @@ -229,9 +242,13 @@ impl Chain { /// Append a single block with state to the chain. /// This method assumes that blocks attachment to the chain has already been validated. - pub fn append_block(&mut self, block: SealedBlockWithSenders, state: BlockExecutionOutcome) { + pub fn append_block( + &mut self, + block: SealedBlockWithSenders, + block_execution_outcome: BlockExecutionOutcome, + ) { self.blocks.insert(block.number, block); - self.state.extend(state); + self.block_execution_outcome.extend(block_execution_outcome); self.trie_updates.take(); // reset } @@ -250,7 +267,7 @@ impl Chain { // Insert blocks from other chain self.blocks.extend(other.blocks); - self.state.extend(other.state); + self.block_execution_outcome.extend(other.block_execution_outcome); self.trie_updates.take(); // reset Ok(()) @@ -307,19 +324,20 @@ impl Chain { let split_at = block_number + 1; let higher_number_blocks = self.blocks.split_off(&split_at); - let state = std::mem::take(&mut self.state); - let (canonical_state, pending_state) = state.split_at(split_at); + let block_execution_outcome = std::mem::take(&mut self.block_execution_outcome); + let (canonical_block_exec_outcome, pending_block_exec_outcome) = + block_execution_outcome.split_at(split_at); // TODO: Currently, trie updates are reset on chain split. // Add tests ensuring that it is valid to leave updates in the pending chain. ChainSplit::Split { canonical: Self { - state: canonical_state.expect("split in range"), + block_execution_outcome: canonical_block_exec_outcome.expect("split in range"), blocks: self.blocks, trie_updates: None, }, pending: Self { - state: pending_state, + block_execution_outcome: pending_block_exec_outcome, blocks: higher_number_blocks, trie_updates: None, }, @@ -511,7 +529,7 @@ mod tests { #[test] fn test_number_split() { - let block_state1 = BlockExecutionOutcome::new( + let block_execution_outcome1 = BlockExecutionOutcome::new( BundleState::new( vec![( Address::new([2; 20]), @@ -527,7 +545,7 @@ mod tests { vec![], ); - let block_state2 = BlockExecutionOutcome::new( + let block_execution_outcome2 = BlockExecutionOutcome::new( BundleState::new( vec![( Address::new([3; 20]), @@ -555,30 +573,37 @@ mod tests { block2.set_hash(block2_hash); block2.senders.push(Address::new([4; 20])); - let mut block_state_extended = block_state1; - block_state_extended.extend(block_state2); + let mut block_state_extended = block_execution_outcome1; + block_state_extended.extend(block_execution_outcome2); let chain = Chain::new(vec![block1.clone(), block2.clone()], block_state_extended, None); - let (split1_state, split2_state) = chain.state.clone().split_at(2); + let (split1_block_execution_outcome, split2_block_execution_outcome) = + chain.block_execution_outcome.clone().split_at(2); let chain_split1 = Chain { - state: split1_state.unwrap(), + block_execution_outcome: split1_block_execution_outcome.unwrap(), blocks: BTreeMap::from([(1, block1.clone())]), trie_updates: None, }; let chain_split2 = Chain { - state: split2_state, + block_execution_outcome: split2_block_execution_outcome, blocks: BTreeMap::from([(2, block2.clone())]), trie_updates: None, }; // return tip state - assert_eq!(chain.state_at_block(block2.number), Some(chain.state.clone())); - assert_eq!(chain.state_at_block(block1.number), Some(chain_split1.state.clone())); + assert_eq!( + chain.block_execution_outcome_at_block(block2.number), + Some(chain.block_execution_outcome.clone()) + ); + assert_eq!( + chain.block_execution_outcome_at_block(block1.number), + Some(chain_split1.block_execution_outcome.clone()) + ); // state at unknown block - assert_eq!(chain.state_at_block(100), None); + assert_eq!(chain.block_execution_outcome_at_block(100), None); // split in two assert_eq!( diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 0c439fb94aeb..87509e737f01 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -506,25 +506,26 @@ where // and 4788 contract call db.merge_transitions(BundleRetention::PlainState); - let bundle = BlockExecutionOutcome::new( + let block_execution_outcome = BlockExecutionOutcome::new( db.take_bundle(), vec![receipts].into(), block_number, Vec::new(), ); - let receipts_root = bundle + let receipts_root = block_execution_outcome .optimism_receipts_root_slow( block_number, chain_spec.as_ref(), attributes.payload_attributes.timestamp, ) .expect("Number is in range"); - let logs_bloom = bundle.block_logs_bloom(block_number).expect("Number is in range"); + let logs_bloom = + block_execution_outcome.block_logs_bloom(block_number).expect("Number is in range"); // calculate the state root let state_root = { let state_provider = db.database.0.inner.borrow_mut(); - state_provider.db.state_root(bundle.state())? + state_provider.db.state_root(block_execution_outcome.state())? }; // create the block header diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index 9954b39a8011..61564afd1faa 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -206,8 +206,8 @@ where // extract the state from the notification and put it into the cache let committed = new_state.committed(); - let new_state = committed.state(); - for (addr, acc) in new_state.bundle_accounts_iter() { + let new_block_execution_outcome = committed.block_execution_outcome(); + for (addr, acc) in new_block_execution_outcome.bundle_accounts_iter() { if let Some(info) = acc.info.clone() { // we want pre cache existing accounts and their storage // this only includes changed accounts and storage but is better than nothing diff --git a/crates/rpc/rpc/src/eth/api/pending_block.rs b/crates/rpc/rpc/src/eth/api/pending_block.rs index bfb558d976b0..daaa2850a1e5 100644 --- a/crates/rpc/rpc/src/eth/api/pending_block.rs +++ b/crates/rpc/rpc/src/eth/api/pending_block.rs @@ -220,7 +220,7 @@ impl PendingBlockEnv { // merge all transitions into bundle state. db.merge_transitions(BundleRetention::PlainState); - let bundle = BlockExecutionOutcome::new( + let block_execution_outcome = BlockExecutionOutcome::new( db.take_bundle(), vec![receipts].into(), block_number, @@ -228,7 +228,7 @@ impl PendingBlockEnv { ); #[cfg(feature = "optimism")] - let receipts_root = bundle + let receipts_root = block_execution_outcome .optimism_receipts_root_slow( block_number, chain_spec.as_ref(), @@ -237,13 +237,15 @@ impl PendingBlockEnv { .expect("Block is present"); #[cfg(not(feature = "optimism"))] - let receipts_root = bundle.receipts_root_slow(block_number).expect("Block is present"); + let receipts_root = + block_execution_outcome.receipts_root_slow(block_number).expect("Block is present"); - let logs_bloom = bundle.block_logs_bloom(block_number).expect("Block is present"); + let logs_bloom = + block_execution_outcome.block_logs_bloom(block_number).expect("Block is present"); // calculate the state root let state_provider = &db.database; - let state_root = state_provider.state_root(bundle.state())?; + let state_root = state_provider.state_root(block_execution_outcome.state())?; // create the block header let transactions_root = proofs::calculate_transaction_root(&executed_txs); diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index bc1145d41174..f5992441a6f3 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -193,7 +193,7 @@ pub fn insert_state<'a, 'b, DB: Database>( } let all_reverts_init: RevertsInit = HashMap::from([(block, reverts_init)]); - let bundle = BlockExecutionOutcome::new_init( + let block_execution_outcome = BlockExecutionOutcome::new_init( state_init, all_reverts_init, contracts.into_iter().collect(), @@ -202,7 +202,7 @@ pub fn insert_state<'a, 'b, DB: Database>( Vec::new(), ); - bundle.write_to_storage(tx, None, OriginalValuesKnown::Yes)?; + block_execution_outcome.write_to_storage(tx, None, OriginalValuesKnown::Yes)?; trace!(target: "reth::cli", "Inserted state"); diff --git a/crates/storage/provider/src/providers/bundle_state_provider.rs b/crates/storage/provider/src/providers/bundle_state_provider.rs index 983817c4a33c..6ac5fa41104c 100644 --- a/crates/storage/provider/src/providers/bundle_state_provider.rs +++ b/crates/storage/provider/src/providers/bundle_state_provider.rs @@ -1,35 +1,39 @@ use crate::{ - AccountReader, BlockHashReader, BundleStateDataProvider, StateProvider, StateRootProvider, + AccountReader, BlockExecutionDataProvider, BlockHashReader, StateProvider, StateRootProvider, }; use reth_primitives::{proofs::AccountProof, Account, Address, BlockNumber, Bytecode, B256}; use reth_storage_errors::provider::{ProviderError, ProviderResult}; use reth_trie::updates::TrieUpdates; use revm::db::BundleState; -/// A state provider that either resolves to data in a wrapped [`crate::BlockExecutionOutcome`], +/// A state provider that resolves to data from either a wrapped [`crate::BlockExecutionOutcome`] /// or an underlying state provider. +/// +/// This struct combines two sources of state data: the block execution outcome and an underlying +/// state provider. It can provide state information by leveraging both the post-block execution +/// changes and the pre-existing state data. #[derive(Debug)] -pub struct BundleStateProvider { +pub struct BundleStateProvider { /// The inner state provider. pub state_provider: SP, - /// Bundle state data. - pub bundle_state_data_provider: BSDP, + /// Block execution data. + pub block_execution_data_provider: BEDP, } -impl BundleStateProvider { +impl BundleStateProvider { /// Create new bundle state provider - pub const fn new(state_provider: SP, bundle_state_data_provider: BSDP) -> Self { - Self { state_provider, bundle_state_data_provider } + pub const fn new(state_provider: SP, block_execution_data_provider: BEDP) -> Self { + Self { state_provider, block_execution_data_provider } } } /* Implement StateProvider traits */ -impl BlockHashReader - for BundleStateProvider +impl BlockHashReader + for BundleStateProvider { fn block_hash(&self, block_number: BlockNumber) -> ProviderResult> { - let block_hash = self.bundle_state_data_provider.block_hash(block_number); + let block_hash = self.block_execution_data_provider.block_hash(block_number); if block_hash.is_some() { return Ok(block_hash) } @@ -45,11 +49,13 @@ impl BlockHashReader } } -impl AccountReader - for BundleStateProvider +impl AccountReader + for BundleStateProvider { fn basic_account(&self, address: Address) -> ProviderResult> { - if let Some(account) = self.bundle_state_data_provider.state().account(&address) { + if let Some(account) = + self.block_execution_data_provider.block_execution_outcome().account(&address) + { Ok(account) } else { self.state_provider.basic_account(address) @@ -57,11 +63,12 @@ impl AccountReader } } -impl StateRootProvider - for BundleStateProvider +impl StateRootProvider + for BundleStateProvider { fn state_root(&self, bundle_state: &BundleState) -> ProviderResult { - let mut state = self.bundle_state_data_provider.state().state().clone(); + let mut state = + self.block_execution_data_provider.block_execution_outcome().state().clone(); state.extend(bundle_state.clone()); self.state_provider.state_root(&state) } @@ -70,14 +77,15 @@ impl StateRootProvider &self, bundle_state: &BundleState, ) -> ProviderResult<(B256, TrieUpdates)> { - let mut state = self.bundle_state_data_provider.state().state().clone(); + let mut state = + self.block_execution_data_provider.block_execution_outcome().state().clone(); state.extend(bundle_state.clone()); self.state_provider.state_root_with_updates(&state) } } -impl StateProvider - for BundleStateProvider +impl StateProvider + for BundleStateProvider { fn storage( &self, @@ -85,8 +93,10 @@ impl StateProvider storage_key: reth_primitives::StorageKey, ) -> ProviderResult> { let u256_storage_key = storage_key.into(); - if let Some(value) = - self.bundle_state_data_provider.state().storage(&account, u256_storage_key) + if let Some(value) = self + .block_execution_data_provider + .block_execution_outcome() + .storage(&account, u256_storage_key) { return Ok(Some(value)) } @@ -95,7 +105,9 @@ impl StateProvider } fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult> { - if let Some(bytecode) = self.bundle_state_data_provider.state().bytecode(&code_hash) { + if let Some(bytecode) = + self.block_execution_data_provider.block_execution_outcome().bytecode(&code_hash) + { return Ok(Some(bytecode)) } diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index e92dba8c4a16..bafb208b468e 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -2673,7 +2673,7 @@ impl BlockWriter for DatabaseProvider { fn append_blocks_with_state( &self, blocks: Vec, - state: BlockExecutionOutcome, + block_execution_outcome: BlockExecutionOutcome, hashed_state: HashedPostState, trie_updates: TrieUpdates, prune_modes: Option<&PruneModes>, @@ -2698,7 +2698,7 @@ impl BlockWriter for DatabaseProvider { // Write state and changesets to the database. // Must be written after blocks because of the receipt lookup. - state.write_to_storage(self.tx_ref(), None, OriginalValuesKnown::No)?; + block_execution_outcome.write_to_storage(self.tx_ref(), None, OriginalValuesKnown::No)?; durations_recorder.record_relative(metrics::Action::InsertState); // insert hashes and intermediate merkle nodes diff --git a/crates/storage/provider/src/test_utils/blocks.rs b/crates/storage/provider/src/test_utils/blocks.rs index f46451b8ca30..2cd6255c3bfb 100644 --- a/crates/storage/provider/src/test_utils/blocks.rs +++ b/crates/storage/provider/src/test_utils/blocks.rs @@ -114,24 +114,26 @@ pub fn genesis() -> SealedBlock { } } -fn bundle_state_root(state: &BlockExecutionOutcome) -> B256 { - state_root_unhashed(state.bundle_accounts_iter().filter_map(|(address, account)| { - account.info.as_ref().map(|info| { - ( - address, +fn bundle_state_root(block_execution_outcome: &BlockExecutionOutcome) -> B256 { + state_root_unhashed(block_execution_outcome.bundle_accounts_iter().filter_map( + |(address, account)| { + account.info.as_ref().map(|info| { ( - into_reth_acc(info.clone()), - storage_root_unhashed( - account - .storage - .iter() - .filter(|(_, value)| !value.present_value.is_zero()) - .map(|(slot, value)| ((*slot).into(), value.present_value)), + address, + ( + into_reth_acc(info.clone()), + storage_root_unhashed( + account + .storage + .iter() + .filter(|(_, value)| !value.present_value.is_zero()) + .map(|(slot, value)| ((*slot).into(), value.present_value)), + ), ), - ), - ) - }) - })) + ) + }) + }, + )) } /// Block one that points to genesis @@ -142,7 +144,7 @@ fn block1(number: BlockNumber) -> (SealedBlockWithSenders, BlockExecutionOutcome let slot = U256::from(5); let info = AccountInfo { nonce: 1, balance: U256::from(10), ..Default::default() }; - let bundle = BlockExecutionOutcome::new( + let block_execution_outcome = BlockExecutionOutcome::new( BundleState::builder(number..=number) .state_present_account_info(account1, info.clone()) .revert_account_info(number, account1, Some(None)) @@ -169,7 +171,7 @@ fn block1(number: BlockNumber) -> (SealedBlockWithSenders, BlockExecutionOutcome Vec::new(), ); - let state_root = bundle_state_root(&bundle); + let state_root = bundle_state_root(&block_execution_outcome); assert_eq!( state_root, b256!("5d035ccb3e75a9057452ff060b773b213ec1fc353426174068edfc3971a0b6bd") @@ -183,20 +185,23 @@ fn block1(number: BlockNumber) -> (SealedBlockWithSenders, BlockExecutionOutcome header.parent_hash = B256::ZERO; block.header = header.seal_slow(); - (SealedBlockWithSenders { block, senders: vec![Address::new([0x30; 20])] }, bundle) + ( + SealedBlockWithSenders { block, senders: vec![Address::new([0x30; 20])] }, + block_execution_outcome, + ) } /// Block two that points to block 1 fn block2( number: BlockNumber, parent_hash: B256, - prev_state: &BlockExecutionOutcome, + prev_block_execution_outcome: &BlockExecutionOutcome, ) -> (SealedBlockWithSenders, BlockExecutionOutcome) { // block changes let account: Address = [0x60; 20].into(); let slot = U256::from(5); - let bundle = BlockExecutionOutcome::new( + let block_execution_outcome = BlockExecutionOutcome::new( BundleState::builder(number..=number) .state_present_account_info( account, @@ -229,8 +234,8 @@ fn block2( Vec::new(), ); - let mut extended = prev_state.clone(); - extended.extend(bundle.clone()); + let mut extended = prev_block_execution_outcome.clone(); + extended.extend(block_execution_outcome.clone()); let state_root = bundle_state_root(&extended); assert_eq!( state_root, @@ -247,14 +252,17 @@ fn block2( header.parent_hash = parent_hash; block.header = header.seal_slow(); - (SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, bundle) + ( + SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, + block_execution_outcome, + ) } /// Block three that points to block 2 fn block3( number: BlockNumber, parent_hash: B256, - prev_state: &BlockExecutionOutcome, + prev_block_execution_outcome: &BlockExecutionOutcome, ) -> (SealedBlockWithSenders, BlockExecutionOutcome) { let address_range = 1..=20; let slot_range = 1..=100; @@ -278,7 +286,7 @@ fn block3( .revert_account_info(number, address, Some(None)) .revert_storage(number, address, Vec::new()); } - let bundle = BlockExecutionOutcome::new( + let block_execution_outcome = BlockExecutionOutcome::new( bundle_state_builder.build(), vec![vec![Some(Receipt { tx_type: TxType::Eip1559, @@ -299,8 +307,8 @@ fn block3( Vec::new(), ); - let mut extended = prev_state.clone(); - extended.extend(bundle.clone()); + let mut extended = prev_block_execution_outcome.clone(); + extended.extend(block_execution_outcome.clone()); let state_root = bundle_state_root(&extended); let mut block = SealedBlock::decode(&mut BLOCK_RLP.as_slice()).unwrap(); @@ -312,14 +320,17 @@ fn block3( header.parent_hash = parent_hash; block.header = header.seal_slow(); - (SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, bundle) + ( + SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, + block_execution_outcome, + ) } /// Block four that points to block 3 fn block4( number: BlockNumber, parent_hash: B256, - prev_state: &BlockExecutionOutcome, + prev_block_execution_outcome: &BlockExecutionOutcome, ) -> (SealedBlockWithSenders, BlockExecutionOutcome) { let address_range = 1..=20; let slot_range = 1..=100; @@ -369,7 +380,7 @@ fn block4( Vec::from_iter(slot_range.clone().map(|slot| (U256::from(slot), U256::from(slot)))), ); } - let bundle = BlockExecutionOutcome::new( + let block_execution_outcome = BlockExecutionOutcome::new( bundle_state_builder.build(), vec![vec![Some(Receipt { tx_type: TxType::Eip1559, @@ -390,8 +401,8 @@ fn block4( Vec::new(), ); - let mut extended = prev_state.clone(); - extended.extend(bundle.clone()); + let mut extended = prev_block_execution_outcome.clone(); + extended.extend(block_execution_outcome.clone()); let state_root = bundle_state_root(&extended); let mut block = SealedBlock::decode(&mut BLOCK_RLP.as_slice()).unwrap(); @@ -403,14 +414,17 @@ fn block4( header.parent_hash = parent_hash; block.header = header.seal_slow(); - (SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, bundle) + ( + SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, + block_execution_outcome, + ) } /// Block five that points to block 4 fn block5( number: BlockNumber, parent_hash: B256, - prev_state: &BlockExecutionOutcome, + prev_block_execution_outcome: &BlockExecutionOutcome, ) -> (SealedBlockWithSenders, BlockExecutionOutcome) { let address_range = 1..=20; let slot_range = 1..=100; @@ -455,7 +469,7 @@ fn block5( bundle_state_builder.revert_address(number, address) }; } - let bundle = BlockExecutionOutcome::new( + let block_execution_outcome = BlockExecutionOutcome::new( bundle_state_builder.build(), vec![vec![Some(Receipt { tx_type: TxType::Eip1559, @@ -476,8 +490,8 @@ fn block5( Vec::new(), ); - let mut extended = prev_state.clone(); - extended.extend(bundle.clone()); + let mut extended = prev_block_execution_outcome.clone(); + extended.extend(block_execution_outcome.clone()); let state_root = bundle_state_root(&extended); let mut block = SealedBlock::decode(&mut BLOCK_RLP.as_slice()).unwrap(); @@ -489,5 +503,8 @@ fn block5( header.parent_hash = parent_hash; block.header = header.seal_slow(); - (SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, bundle) + ( + SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, + block_execution_outcome, + ) } diff --git a/crates/storage/provider/src/traits/block.rs b/crates/storage/provider/src/traits/block.rs index 677e208a2ff8..f6a9081ac3a1 100644 --- a/crates/storage/provider/src/traits/block.rs +++ b/crates/storage/provider/src/traits/block.rs @@ -65,7 +65,7 @@ pub trait BlockWriter: Send + Sync { fn append_blocks_with_state( &self, blocks: Vec, - state: BlockExecutionOutcome, + block_execution_outcome: BlockExecutionOutcome, hashed_state: HashedPostState, trie_updates: TrieUpdates, prune_modes: Option<&PruneModes>, diff --git a/crates/storage/storage-api/src/state.rs b/crates/storage/storage-api/src/state.rs index 9089c630a68c..58b46ce7823c 100644 --- a/crates/storage/storage-api/src/state.rs +++ b/crates/storage/storage-api/src/state.rs @@ -204,21 +204,25 @@ pub trait BlockchainTreePendingStateProvider: Send + Sync { ) -> Option>; } -/// Post state data needed for execution on it. +/// Provides data required for post-block execution. /// -/// State contains: -/// * [`BlockExecutionOutcome`] contains all changed of accounts and storage of pending chain -/// * block hashes of pending chain and canonical blocks. +/// This trait offers methods to access essential post-execution data, including the state changes +/// in accounts and storage, as well as block hashes for both the pending and canonical chains. +/// +/// The trait includes: +/// * [`BlockExecutionOutcome`] - Captures all account and storage changes in the pending chain. +/// * Block hashes - Provides access to the block hashes of both the pending chain and canonical +/// blocks. #[auto_impl(&, Box)] -pub trait BundleStateDataProvider: Send + Sync { - /// Return post state - fn state(&self) -> &BlockExecutionOutcome; +pub trait BlockExecutionDataProvider: Send + Sync { + /// Return the block execution outcome. + fn block_execution_outcome(&self) -> &BlockExecutionOutcome; /// Return block hash by block number of pending or canonical chain. fn block_hash(&self, block_number: BlockNumber) -> Option; } -impl BundleStateDataProvider for BlockExecutionOutcome { - fn state(&self) -> &BlockExecutionOutcome { +impl BlockExecutionDataProvider for BlockExecutionOutcome { + fn block_execution_outcome(&self) -> &BlockExecutionOutcome { self } @@ -232,7 +236,7 @@ impl BundleStateDataProvider for BlockExecutionOutcome { /// /// It contains a canonical fork, the block on what pending chain was forked from. #[auto_impl(&, Box)] -pub trait BundleStateForkProvider { +pub trait BlockExecutionForkProvider { /// Return canonical fork, the block on what post state was forked from. /// /// Needed to create state provider. @@ -242,12 +246,19 @@ pub trait BundleStateForkProvider { /// Full post state data needed for execution on it. /// This trait is used to create a state provider over pending state. /// -/// This trait is a combination of [`BundleStateDataProvider`] and [`BundleStateForkProvider`]. +/// This trait is a combination of [`BlockExecutionDataProvider`] and +/// [`BlockExecutionForkProvider`]. /// /// Pending state contains: /// * [`BlockExecutionOutcome`] contains all changed of accounts and storage of pending chain /// * block hashes of pending chain and canonical blocks. /// * canonical fork, the block on what pending chain was forked from. -pub trait FullBundleStateDataProvider: BundleStateDataProvider + BundleStateForkProvider {} +pub trait FullBundleStateDataProvider: + BlockExecutionDataProvider + BlockExecutionForkProvider +{ +} -impl FullBundleStateDataProvider for T where T: BundleStateDataProvider + BundleStateForkProvider {} +impl FullBundleStateDataProvider for T where + T: BlockExecutionDataProvider + BlockExecutionForkProvider +{ +} diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 49072cfc6345..bddc4e81717c 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -556,9 +556,9 @@ where /// Extracts all changed accounts from the `BundleState` fn changed_accounts_iter( - state: &BlockExecutionOutcome, + block_execution_outcome: &BlockExecutionOutcome, ) -> impl Iterator + '_ { - state + block_execution_outcome .accounts_iter() .filter_map(|(addr, acc)| acc.map(|acc| (addr, acc))) .map(|(address, acc)| ChangedAccount { address, nonce: acc.nonce, balance: acc.balance }) diff --git a/examples/exex/in-memory-state/src/main.rs b/examples/exex/in-memory-state/src/main.rs index 0c7cad603a37..e9c0485e1487 100644 --- a/examples/exex/in-memory-state/src/main.rs +++ b/examples/exex/in-memory-state/src/main.rs @@ -8,8 +8,8 @@ use reth_tracing::tracing::info; /// An ExEx that keeps track of the entire state in memory async fn track_state(mut ctx: ExExContext) -> eyre::Result<()> { - // keeps the entire plain state of the chain in memory - let mut state = BlockExecutionOutcome::default(); + // keeps the entire plain block execution outcome of the chain in memory + let mut block_execution_outcome = BlockExecutionOutcome::default(); while let Some(notification) = ctx.notifications.recv().await { match ¬ification { @@ -18,18 +18,18 @@ async fn track_state(mut ctx: ExExContext) -> ey } ExExNotification::ChainReorged { old, new } => { // revert to block before the reorg - state.revert_to(new.first().number - 1); + block_execution_outcome.revert_to(new.first().number - 1); info!(from_chain = ?old.range(), to_chain = ?new.range(), "Received reorg"); } ExExNotification::ChainReverted { old } => { - state.revert_to(old.first().number - 1); + block_execution_outcome.revert_to(old.first().number - 1); info!(reverted_chain = ?old.range(), "Received revert"); } }; if let Some(committed_chain) = notification.committed_chain() { - // extend the state with the new chain - state.extend(committed_chain.state().clone()); + // extend the block execution outcome with the new chain + block_execution_outcome.extend(committed_chain.block_execution_outcome().clone()); ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?; } } diff --git a/examples/exex/minimal/src/main.rs b/examples/exex/minimal/src/main.rs index 1cdb7f017fb2..a3c9d9ee421c 100644 --- a/examples/exex/minimal/src/main.rs +++ b/examples/exex/minimal/src/main.rs @@ -54,10 +54,9 @@ fn main() -> eyre::Result<()> { #[cfg(test)] mod tests { - use std::pin::pin; - use reth::providers::{BlockExecutionOutcome, Chain}; use reth_exex_test_utils::{test_exex_context, PollOnce}; + use std::pin::pin; #[tokio::test] async fn test_exex() -> eyre::Result<()> { From 6594ee8b8bafcd3cb81596b544f722dacf2fb8a8 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Tue, 11 Jun 2024 00:24:54 +0200 Subject: [PATCH 4/9] clean: rename FullBlockExecutionDataProvider --- crates/blockchain-tree/src/chain.rs | 8 +++--- crates/blockchain-tree/src/noop.rs | 4 +-- crates/blockchain-tree/src/shareable.rs | 4 +-- crates/storage/provider/src/providers/mod.rs | 6 ++--- .../storage/provider/src/test_utils/mock.rs | 4 +-- .../storage/provider/src/test_utils/noop.rs | 2 +- crates/storage/storage-api/src/state.rs | 26 +++++++++---------- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index ba4fa93cc453..b9fc033ad19d 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -18,7 +18,7 @@ use reth_primitives::{ }; use reth_provider::{ providers::{BundleStateProvider, ConsistentDbView}, - BlockExecutionOutcome, Chain, FullBundleStateDataProvider, ProviderError, StateRootProvider, + BlockExecutionOutcome, Chain, FullBlockExecutionDataProvider, ProviderError, StateRootProvider, }; use reth_revm::database::StateProviderDatabase; use reth_trie::updates::TrieUpdates; @@ -166,16 +166,16 @@ impl AppendableChain { /// - [`BlockAttachment`] represents if the block extends the canonical chain, and thus we can /// cache the trie state updates. /// - [`BlockValidationKind`] determines if the state root __should__ be validated. - fn validate_and_execute( + fn validate_and_execute( block: SealedBlockWithSenders, parent_block: &SealedHeader, - bundle_state_data_provider: BSDP, + bundle_state_data_provider: BEDP, externals: &TreeExternals, block_attachment: BlockAttachment, block_validation_kind: BlockValidationKind, ) -> Result<(BlockExecutionOutcome, Option), BlockExecutionError> where - BSDP: FullBundleStateDataProvider, + BEDP: FullBlockExecutionDataProvider, DB: Database + Clone, E: BlockExecutorProvider, { diff --git a/crates/blockchain-tree/src/noop.rs b/crates/blockchain-tree/src/noop.rs index 5efe794e4154..31b15356a61f 100644 --- a/crates/blockchain-tree/src/noop.rs +++ b/crates/blockchain-tree/src/noop.rs @@ -10,7 +10,7 @@ use reth_primitives::{ }; use reth_provider::{ BlockchainTreePendingStateProvider, CanonStateNotificationSender, CanonStateNotifications, - CanonStateSubscriptions, FullBundleStateDataProvider, + CanonStateSubscriptions, FullBlockExecutionDataProvider, }; use reth_storage_errors::provider::ProviderResult; use std::collections::BTreeMap; @@ -122,7 +122,7 @@ impl BlockchainTreePendingStateProvider for NoopBlockchainTree { fn find_pending_state_provider( &self, _block_hash: BlockHash, - ) -> Option> { + ) -> Option> { None } } diff --git a/crates/blockchain-tree/src/shareable.rs b/crates/blockchain-tree/src/shareable.rs index 3e145685efa8..07828a0198b6 100644 --- a/crates/blockchain-tree/src/shareable.rs +++ b/crates/blockchain-tree/src/shareable.rs @@ -14,7 +14,7 @@ use reth_primitives::{ SealedHeader, }; use reth_provider::{ - BlockchainTreePendingStateProvider, CanonStateSubscriptions, FullBundleStateDataProvider, + BlockchainTreePendingStateProvider, CanonStateSubscriptions, FullBlockExecutionDataProvider, ProviderError, }; use reth_storage_errors::provider::ProviderResult; @@ -177,7 +177,7 @@ where fn find_pending_state_provider( &self, block_hash: BlockHash, - ) -> Option> { + ) -> Option> { trace!(target: "blockchain_tree", ?block_hash, "Finding pending state provider"); let provider = self.tree.read().post_state_data(block_hash)?; Some(Box::new(provider)) diff --git a/crates/storage/provider/src/providers/mod.rs b/crates/storage/provider/src/providers/mod.rs index ede69cdf6eee..125f064cc44e 100644 --- a/crates/storage/provider/src/providers/mod.rs +++ b/crates/storage/provider/src/providers/mod.rs @@ -2,7 +2,7 @@ use crate::{ AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, BlockSource, BlockchainTreePendingStateProvider, CanonChainTracker, CanonStateNotifications, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader, DatabaseProviderFactory, - EvmEnvProvider, FullBundleStateDataProvider, HeaderProvider, ProviderError, + EvmEnvProvider, FullBlockExecutionDataProvider, HeaderProvider, ProviderError, PruneCheckpointReader, ReceiptProvider, ReceiptProviderIdExt, RequestsProvider, StageCheckpointReader, StateProviderBox, StateProviderFactory, StaticFileProviderFactory, TransactionVariant, TransactionsProvider, TreeViewer, WithdrawalsProvider, @@ -657,7 +657,7 @@ where fn pending_with_provider( &self, - bundle_state_data: Box, + bundle_state_data: Box, ) -> ProviderResult { let canonical_fork = bundle_state_data.canonical_fork(); trace!(target: "providers::blockchain", ?canonical_fork, "Returning post state provider"); @@ -876,7 +876,7 @@ where fn find_pending_state_provider( &self, block_hash: BlockHash, - ) -> Option> { + ) -> Option> { self.tree.find_pending_state_provider(block_hash) } } diff --git a/crates/storage/provider/src/test_utils/mock.rs b/crates/storage/provider/src/test_utils/mock.rs index 744888013e4e..1d29725d8910 100644 --- a/crates/storage/provider/src/test_utils/mock.rs +++ b/crates/storage/provider/src/test_utils/mock.rs @@ -1,7 +1,7 @@ use crate::{ traits::{BlockSource, ReceiptProvider}, AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, - ChainSpecProvider, ChangeSetReader, EvmEnvProvider, FullBundleStateDataProvider, + ChainSpecProvider, ChangeSetReader, EvmEnvProvider, FullBlockExecutionDataProvider, HeaderProvider, ReceiptProviderIdExt, RequestsProvider, StateProvider, StateProviderBox, StateProviderFactory, StateRootProvider, TransactionVariant, TransactionsProvider, WithdrawalsProvider, @@ -661,7 +661,7 @@ impl StateProviderFactory for MockEthProvider { fn pending_with_provider<'a>( &'a self, - _bundle_state_data: Box, + _bundle_state_data: Box, ) -> ProviderResult { Ok(Box::new(self.clone())) } diff --git a/crates/storage/provider/src/test_utils/noop.rs b/crates/storage/provider/src/test_utils/noop.rs index 078ef5d3dbec..135d383bcdb3 100644 --- a/crates/storage/provider/src/test_utils/noop.rs +++ b/crates/storage/provider/src/test_utils/noop.rs @@ -419,7 +419,7 @@ impl StateProviderFactory for NoopProvider { fn pending_with_provider<'a>( &'a self, - _bundle_state_data: Box, + _bundle_state_data: Box, ) -> ProviderResult { Ok(Box::new(*self)) } diff --git a/crates/storage/storage-api/src/state.rs b/crates/storage/storage-api/src/state.rs index 58b46ce7823c..28d96297f51d 100644 --- a/crates/storage/storage-api/src/state.rs +++ b/crates/storage/storage-api/src/state.rs @@ -178,7 +178,7 @@ pub trait StateProviderFactory: BlockIdReader + Send + Sync { /// Used to inspect or execute transaction on the pending state. fn pending_with_provider( &self, - bundle_state_data: Box, + bundle_state_data: Box, ) -> ProviderResult; } @@ -192,7 +192,7 @@ pub trait BlockchainTreePendingStateProvider: Send + Sync { fn pending_state_provider( &self, block_hash: BlockHash, - ) -> ProviderResult> { + ) -> ProviderResult> { self.find_pending_state_provider(block_hash) .ok_or(ProviderError::StateForHashNotFound(block_hash)) } @@ -201,7 +201,7 @@ pub trait BlockchainTreePendingStateProvider: Send + Sync { fn find_pending_state_provider( &self, block_hash: BlockHash, - ) -> Option>; + ) -> Option>; } /// Provides data required for post-block execution. @@ -243,22 +243,22 @@ pub trait BlockExecutionForkProvider { fn canonical_fork(&self) -> BlockNumHash; } -/// Full post state data needed for execution on it. -/// This trait is used to create a state provider over pending state. +/// Provides comprehensive post-execution state data required for further execution. /// -/// This trait is a combination of [`BlockExecutionDataProvider`] and -/// [`BlockExecutionForkProvider`]. +/// This trait is used to create a state provider over the pending state and is a combination of +/// [`BlockExecutionDataProvider`] and [`BlockExecutionForkProvider`]. /// -/// Pending state contains: -/// * [`BlockExecutionOutcome`] contains all changed of accounts and storage of pending chain -/// * block hashes of pending chain and canonical blocks. -/// * canonical fork, the block on what pending chain was forked from. -pub trait FullBundleStateDataProvider: +/// The pending state includes: +/// * `BlockExecutionOutcome`: Contains all changes to accounts and storage within the pending +/// chain. +/// * Block hashes: Represents hashes of both the pending chain and canonical blocks. +/// * Canonical fork: Denotes the block from which the pending chain forked. +pub trait FullBlockExecutionDataProvider: BlockExecutionDataProvider + BlockExecutionForkProvider { } -impl FullBundleStateDataProvider for T where +impl FullBlockExecutionDataProvider for T where T: BlockExecutionDataProvider + BlockExecutionForkProvider { } From be9e836c3ddb89e625238f8b20e859a1040c890e Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Tue, 11 Jun 2024 00:39:11 +0200 Subject: [PATCH 5/9] clean: extended_state to extended_execution_outcome --- .../storage/provider/src/test_utils/blocks.rs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/storage/provider/src/test_utils/blocks.rs b/crates/storage/provider/src/test_utils/blocks.rs index 2cd6255c3bfb..d69bc585ac55 100644 --- a/crates/storage/provider/src/test_utils/blocks.rs +++ b/crates/storage/provider/src/test_utils/blocks.rs @@ -75,14 +75,14 @@ impl BlockchainTestData { /// Create test data with two blocks that are connected, specifying their block numbers. pub fn default_from_number(first: BlockNumber) -> Self { let one = block1(first); - let mut extended_state = one.1.clone(); - let two = block2(first + 1, one.0.hash(), &extended_state); - extended_state.extend(two.1.clone()); - let three = block3(first + 2, two.0.hash(), &extended_state); - extended_state.extend(three.1.clone()); - let four = block4(first + 3, three.0.hash(), &extended_state); - extended_state.extend(four.1.clone()); - let five = block5(first + 4, four.0.hash(), &extended_state); + let mut extended_execution_outcome = one.1.clone(); + let two = block2(first + 1, one.0.hash(), &extended_execution_outcome); + extended_execution_outcome.extend(two.1.clone()); + let three = block3(first + 2, two.0.hash(), &extended_execution_outcome); + extended_execution_outcome.extend(three.1.clone()); + let four = block4(first + 3, three.0.hash(), &extended_execution_outcome); + extended_execution_outcome.extend(four.1.clone()); + let five = block5(first + 4, four.0.hash(), &extended_execution_outcome); Self { genesis: genesis(), blocks: vec![one, two, three, four, five] } } } @@ -90,14 +90,14 @@ impl BlockchainTestData { impl Default for BlockchainTestData { fn default() -> Self { let one = block1(1); - let mut extended_state = one.1.clone(); - let two = block2(2, one.0.hash(), &extended_state); - extended_state.extend(two.1.clone()); - let three = block3(3, two.0.hash(), &extended_state); - extended_state.extend(three.1.clone()); - let four = block4(4, three.0.hash(), &extended_state); - extended_state.extend(four.1.clone()); - let five = block5(5, four.0.hash(), &extended_state); + let mut extended_execution_outcome = one.1.clone(); + let two = block2(2, one.0.hash(), &extended_execution_outcome); + extended_execution_outcome.extend(two.1.clone()); + let three = block3(3, two.0.hash(), &extended_execution_outcome); + extended_execution_outcome.extend(three.1.clone()); + let four = block4(4, three.0.hash(), &extended_execution_outcome); + extended_execution_outcome.extend(four.1.clone()); + let five = block5(5, four.0.hash(), &extended_execution_outcome); Self { genesis: genesis(), blocks: vec![one, two, three, four, five] } } } From 1f063e6d52b234aad88ae7ce6dd4918969061e1b Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Tue, 11 Jun 2024 00:51:18 +0200 Subject: [PATCH 6/9] clean: fix naming conflicts in validate_and_execute --- crates/blockchain-tree/src/chain.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index b9fc033ad19d..c48da7522906 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -214,7 +214,7 @@ impl AppendableChain { .consensus .validate_block_post_execution(&block, PostExecutionInput::new(&receipts, &requests))?; - let block_execution_outcome = + let initial_block_execution_outcome = BlockExecutionOutcome::new(state, receipts.into(), block.number, vec![requests.into()]); // check state root if the block extends the canonical chain __and__ if state root @@ -225,14 +225,14 @@ impl AppendableChain { let (state_root, trie_updates) = if block_attachment.is_canonical() { let mut block_execution_outcome = provider.block_execution_data_provider.block_execution_outcome().clone(); - block_execution_outcome.extend(block_execution_outcome.clone()); + block_execution_outcome.extend(initial_block_execution_outcome.clone()); let hashed_state = block_execution_outcome.hash_state_slow(); ParallelStateRoot::new(consistent_view, hashed_state) .incremental_root_with_updates() .map(|(root, updates)| (root, Some(updates))) .map_err(ProviderError::from)? } else { - (provider.state_root(block_execution_outcome.state())?, None) + (provider.state_root(initial_block_execution_outcome.state())?, None) }; if block.state_root != state_root { return Err(ConsensusError::BodyStateRootDiff( @@ -249,9 +249,9 @@ impl AppendableChain { "Validated state root" ); - Ok((block_execution_outcome, trie_updates)) + Ok((initial_block_execution_outcome, trie_updates)) } else { - Ok((block_execution_outcome, None)) + Ok((initial_block_execution_outcome, None)) } } From 66aeefe1e6ba6bd23f1c9c4d3b6dc8e6651baf47 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Tue, 11 Jun 2024 17:24:23 +0200 Subject: [PATCH 7/9] clean: remove Block prefix --- .../src/commands/debug_cmd/build_block.rs | 14 +-- .../commands/debug_cmd/in_memory_merkle.rs | 14 +-- bin/reth/src/commands/import_receipts_op.rs | 16 ++-- crates/blockchain-tree/src/blockchain_tree.rs | 36 ++++---- crates/blockchain-tree/src/bundle.rs | 34 ++++--- crates/blockchain-tree/src/chain.rs | 52 +++++------ crates/blockchain-tree/src/lib.rs | 2 +- crates/blockchain-tree/src/noop.rs | 4 +- crates/blockchain-tree/src/shareable.rs | 4 +- crates/consensus/auto-seal/src/lib.rs | 12 +-- crates/consensus/beacon/src/engine/sync.rs | 6 +- .../consensus/beacon/src/engine/test_utils.rs | 8 +- crates/ethereum/evm/src/execute.rs | 6 +- crates/ethereum/payload/src/lib.rs | 11 +-- crates/evm/execution-types/src/bundle.rs | 16 ++-- crates/evm/execution-types/src/chain.rs | 92 +++++++++---------- crates/evm/src/either.rs | 8 +- crates/evm/src/execute.rs | 8 +- crates/evm/src/noop.rs | 4 +- crates/evm/src/test_utils.rs | 10 +- crates/optimism/evm/src/execute.rs | 6 +- crates/optimism/payload/src/builder.rs | 10 +- crates/payload/basic/src/lib.rs | 4 +- crates/rpc/rpc/src/eth/api/pending_block.rs | 12 +-- crates/stages/stages/src/stages/execution.rs | 6 +- crates/stages/stages/src/stages/headers.rs | 4 +- crates/storage/db-common/src/init.rs | 6 +- .../bundle_state_with_receipts.rs | 20 ++-- .../storage/provider/src/bundle_state/mod.rs | 2 +- .../src/providers/bundle_state_provider.rs | 42 ++++----- .../src/providers/database/provider.rs | 14 +-- crates/storage/provider/src/providers/mod.rs | 6 +- .../storage/provider/src/test_utils/blocks.rs | 79 +++++++--------- .../storage/provider/src/test_utils/mock.rs | 4 +- .../storage/provider/src/test_utils/noop.rs | 2 +- crates/storage/provider/src/traits/block.rs | 4 +- crates/storage/provider/src/traits/chain.rs | 2 +- crates/storage/provider/src/traits/state.rs | 2 +- crates/storage/storage-api/src/state.rs | 33 ++++--- crates/transaction-pool/src/maintain.rs | 6 +- examples/exex/in-memory-state/src/main.rs | 14 +-- examples/exex/minimal/src/main.rs | 4 +- examples/exex/op-bridge/src/main.rs | 4 +- 43 files changed, 301 insertions(+), 342 deletions(-) diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index 687e38b35633..31b51f856455 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -30,8 +30,8 @@ use reth_primitives::{ SealedBlock, SealedBlockWithSenders, Transaction, TransactionSigned, TxEip4844, B256, U256, }; use reth_provider::{ - providers::BlockchainProvider, BlockExecutionOutcome, BlockHashReader, BlockReader, - BlockWriter, ChainSpecProvider, ProviderFactory, StageCheckpointReader, StateProviderFactory, + providers::BlockchainProvider, BlockHashReader, BlockReader, BlockWriter, ChainSpecProvider, + ExecutionOutcome, ProviderFactory, StageCheckpointReader, StateProviderFactory, }; use reth_revm::database::StateProviderDatabase; use reth_rpc_types::engine::{BlobsBundleV1, PayloadAttributes}; @@ -272,17 +272,17 @@ impl Command { let BlockExecutionOutput { state, receipts, requests, .. } = executor.execute((&block_with_senders.clone().unseal(), U256::MAX).into())?; - let block_execution_outcome = BlockExecutionOutcome::new( + let execution_outcome = ExecutionOutcome::new( state, receipts.into(), block.number, vec![requests.into()], ); - debug!(target: "reth::cli", ?block_execution_outcome, "Executed block"); + debug!(target: "reth::cli", ?execution_outcome, "Executed block"); - let hashed_post_state = block_execution_outcome.hash_state_slow(); - let (state_root, trie_updates) = block_execution_outcome + let hashed_post_state = execution_outcome.hash_state_slow(); + let (state_root, trie_updates) = execution_outcome .hash_state_slow() .state_root_with_updates(provider_factory.provider()?.tx_ref())?; @@ -298,7 +298,7 @@ impl Command { let provider_rw = provider_factory.provider_rw()?; provider_rw.append_blocks_with_state( Vec::from([block_with_senders]), - block_execution_outcome, + execution_outcome, hashed_post_state, trie_updates, None, 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 f9361fe8ec6e..eb6b5305dab8 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -17,7 +17,7 @@ use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; use reth_primitives::{stage::StageId, BlockHashOrNumber}; use reth_provider::{ - AccountExtReader, BlockExecutionOutcome, ChainSpecProvider, HashingWriter, HeaderProvider, + AccountExtReader, ChainSpecProvider, ExecutionOutcome, HashingWriter, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StateWriter, StaticFileProviderFactory, StorageReader, }; @@ -146,12 +146,12 @@ impl Command { ) .into(), )?; - let block_execution_outcome = - BlockExecutionOutcome::new(state, receipts.into(), block.number, vec![requests.into()]); + let execution_outcome = + ExecutionOutcome::new(state, receipts.into(), block.number, vec![requests.into()]); // Unpacked `BundleState::state_root_slow` function let (in_memory_state_root, in_memory_updates) = - block_execution_outcome.hash_state_slow().state_root_with_updates(provider.tx_ref())?; + execution_outcome.hash_state_slow().state_root_with_updates(provider.tx_ref())?; if in_memory_state_root == block.state_root { info!(target: "reth::cli", state_root = ?in_memory_state_root, "Computed in-memory state root matches"); @@ -168,11 +168,7 @@ impl Command { .map_err(|_| BlockValidationError::SenderRecoveryError)?, None, )?; - block_execution_outcome.write_to_storage( - provider_rw.tx_ref(), - None, - OriginalValuesKnown::No, - )?; + execution_outcome.write_to_storage(provider_rw.tx_ref(), None, OriginalValuesKnown::No)?; let storage_lists = provider_rw.changed_storages_with_range(block.number..=block.number)?; let storages = provider_rw.plain_state_storages(storage_lists)?; provider_rw.insert_storage_for_hashing(storages)?; diff --git a/bin/reth/src/commands/import_receipts_op.rs b/bin/reth/src/commands/import_receipts_op.rs index 273d3f60a0b8..0e2688e79926 100644 --- a/bin/reth/src/commands/import_receipts_op.rs +++ b/bin/reth/src/commands/import_receipts_op.rs @@ -13,8 +13,8 @@ use reth_node_core::version::SHORT_VERSION; use reth_optimism_primitives::bedrock_import::is_dup_tx; use reth_primitives::{stage::StageId, Receipts, StaticFileSegment}; use reth_provider::{ - BlockExecutionOutcome, OriginalValuesKnown, ProviderFactory, StageCheckpointReader, - StateWriter, StaticFileProviderFactory, StaticFileWriter, StatsReader, + ExecutionOutcome, OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StateWriter, + StaticFileProviderFactory, StaticFileWriter, StatsReader, }; use std::path::{Path, PathBuf}; use tracing::{debug, error, info, trace}; @@ -130,20 +130,16 @@ where ); // We're reusing receipt writing code internal to - // `BlockExecutionOutcome::write_to_storage`, so we just use a default empty + // `ExecutionOutcome::write_to_storage`, so we just use a default empty // `BundleState`. - let block_execution_outcome = BlockExecutionOutcome::new( - Default::default(), - receipts, - first_block, - Default::default(), - ); + let execution_outcome = + ExecutionOutcome::new(Default::default(), receipts, first_block, Default::default()); let static_file_producer = static_file_provider.get_writer(first_block, StaticFileSegment::Receipts)?; // finally, write the receipts - block_execution_outcome.write_to_storage::( + execution_outcome.write_to_storage::( &tx, Some(static_file_producer), OriginalValuesKnown::Yes, diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index a0d30295de8e..855a458acae9 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -3,7 +3,7 @@ use crate::{ metrics::{MakeCanonicalAction, MakeCanonicalDurationsRecorder, TreeMetrics}, state::{BlockchainId, TreeState}, - AppendableChain, BlockExecutionData, BlockIndices, BlockchainTreeConfig, TreeExternals, + AppendableChain, BlockIndices, BlockchainTreeConfig, ExecutionData, TreeExternals, }; use reth_blockchain_tree_api::{ error::{BlockchainTreeError, CanonicalError, InsertBlockError, InsertBlockErrorKind}, @@ -18,10 +18,10 @@ use reth_primitives::{ SealedBlockWithSenders, SealedHeader, StaticFileSegment, B256, U256, }; use reth_provider::{ - BlockExecutionOutcome, BlockExecutionWriter, BlockNumReader, BlockWriter, - CanonStateNotification, CanonStateNotificationSender, CanonStateNotifications, Chain, - ChainSpecProvider, ChainSplit, ChainSplitTarget, DisplayBlocksChain, HeaderProvider, - ProviderError, StaticFileProviderFactory, + BlockExecutionWriter, BlockNumReader, BlockWriter, CanonStateNotification, + CanonStateNotificationSender, CanonStateNotifications, Chain, ChainSpecProvider, ChainSplit, + ChainSplitTarget, DisplayBlocksChain, ExecutionOutcome, HeaderProvider, ProviderError, + StaticFileProviderFactory, }; use reth_prune_types::PruneModes; use reth_stages_api::{MetricEvent, MetricEventsSender}; @@ -264,7 +264,7 @@ where /// * block unknown. /// * `chain_id` not present in state. /// * there are no parent hashes stored. - pub fn post_state_data(&self, block_hash: BlockHash) -> Option { + pub fn post_state_data(&self, block_hash: BlockHash) -> Option { trace!(target: "blockchain_tree", ?block_hash, "Searching for post state data"); let canonical_chain = self.state.block_indices.canonical_chain(); @@ -278,7 +278,7 @@ where return None; }; let block_number = chain.block_number(block_hash)?; - let block_execution_outcome = chain.block_execution_outcome_at_block(block_number)?; + let execution_outcome = chain.execution_outcome_at_block(block_number)?; // get parent hashes let mut parent_block_hashes = self.all_chain_hashes(chain_id); @@ -295,19 +295,15 @@ where // get canonical fork. let canonical_fork = self.canonical_fork(chain_id)?; - return Some(BlockExecutionData { - block_execution_outcome, - parent_block_hashes, - canonical_fork, - }) + return Some(ExecutionData { execution_outcome, parent_block_hashes, canonical_fork }) } // check if there is canonical block if let Some(canonical_number) = canonical_chain.canonical_number(&block_hash) { trace!(target: "blockchain_tree", %block_hash, "Constructing post state data based on canonical chain"); - return Some(BlockExecutionData { + return Some(ExecutionData { canonical_fork: ForkBlock { number: canonical_number, hash: block_hash }, - block_execution_outcome: BlockExecutionOutcome::default(), + execution_outcome: ExecutionOutcome::default(), parent_block_hashes: canonical_chain.inner().clone(), }) } @@ -633,8 +629,8 @@ where let chains_to_bump = self.find_all_dependent_chains(&hash); if !chains_to_bump.is_empty() { // if there is such chain, revert state to this block. - let mut cloned_block_execution_outcome = chain.block_execution_outcome().clone(); - cloned_block_execution_outcome.revert_to(*number); + let mut cloned_execution_outcome = chain.execution_outcome().clone(); + cloned_execution_outcome.revert_to(*number); // prepend state to all chains that fork from this block. for chain_id in chains_to_bump { @@ -649,7 +645,7 @@ where chain_tip = ?chain.tip().num_hash(), "Prepend unwound block state to blockchain tree chain"); - chain.prepend_state(cloned_block_execution_outcome.state().clone()) + chain.prepend_state(cloned_execution_outcome.state().clone()) } } } @@ -1402,7 +1398,7 @@ mod tests { use std::collections::HashMap; fn setup_externals( - exec_res: Vec, + exec_res: Vec, ) -> TreeExternals>, MockExecutorProvider> { let chain_spec = Arc::new( ChainSpecBuilder::default() @@ -1965,12 +1961,12 @@ mod tests { ])) .assert(&tree); // chain 0 has two blocks so receipts and reverts len is 2 - let chain0 = tree.state.chains.get(&0.into()).unwrap().block_execution_outcome(); + let chain0 = tree.state.chains.get(&0.into()).unwrap().execution_outcome(); assert_eq!(chain0.receipts().len(), 2); assert_eq!(chain0.state().reverts.len(), 2); assert_eq!(chain0.first_block(), block1.number); // chain 1 has one block so receipts and reverts len is 1 - let chain1 = tree.state.chains.get(&1.into()).unwrap().block_execution_outcome(); + let chain1 = tree.state.chains.get(&1.into()).unwrap().execution_outcome(); assert_eq!(chain1.receipts().len(), 1); assert_eq!(chain1.state().reverts.len(), 1); assert_eq!(chain1.first_block(), block2.number); diff --git a/crates/blockchain-tree/src/bundle.rs b/crates/blockchain-tree/src/bundle.rs index bf5237180d05..01d1d717f211 100644 --- a/crates/blockchain-tree/src/bundle.rs +++ b/crates/blockchain-tree/src/bundle.rs @@ -1,16 +1,14 @@ -//! [`BlockExecutionDataProvider`] implementations used by the tree. +//! [`ExecutionDataProvider`] implementations used by the tree. use reth_primitives::{BlockHash, BlockNumber, ForkBlock}; -use reth_provider::{ - BlockExecutionDataProvider, BlockExecutionForkProvider, BlockExecutionOutcome, -}; +use reth_provider::{BlockExecutionForkProvider, ExecutionDataProvider, ExecutionOutcome}; use std::collections::BTreeMap; -/// Structure that combines references of required data to be a [`BlockExecutionDataProvider`]. +/// Structure that combines references of required data to be a [`ExecutionDataProvider`]. #[derive(Clone, Debug)] pub struct BundleStateDataRef<'a> { - /// The block execution outcome after execution of one or more transactions and/or blocks. - pub block_execution_outcome: &'a BlockExecutionOutcome, + /// The execution outcome after execution of one or more transactions and/or blocks. + pub execution_outcome: &'a ExecutionOutcome, /// The blocks in the sidechain. pub sidechain_block_hashes: &'a BTreeMap, /// The blocks in the canonical chain. @@ -19,9 +17,9 @@ pub struct BundleStateDataRef<'a> { pub canonical_fork: ForkBlock, } -impl<'a> BlockExecutionDataProvider for BundleStateDataRef<'a> { - fn block_execution_outcome(&self) -> &BlockExecutionOutcome { - self.block_execution_outcome +impl<'a> ExecutionDataProvider for BundleStateDataRef<'a> { + fn execution_outcome(&self) -> &ExecutionOutcome { + self.execution_outcome } fn block_hash(&self, block_number: BlockNumber) -> Option { @@ -40,11 +38,11 @@ impl<'a> BlockExecutionForkProvider for BundleStateDataRef<'a> { } } -/// Structure that owns the relevant data needs to be a [`BlockExecutionDataProvider`] +/// Structure that owns the relevant data needs to be a [`ExecutionDataProvider`] #[derive(Clone, Debug)] -pub struct BlockExecutionData { - /// Block execution outcome. - pub block_execution_outcome: BlockExecutionOutcome, +pub struct ExecutionData { + /// Execution outcome. + pub execution_outcome: ExecutionOutcome, /// Parent block hashes needs for evm BLOCKHASH opcode. /// NOTE: it does not mean that all hashes are there but all until finalized are there. /// Other hashes can be obtained from provider @@ -53,9 +51,9 @@ pub struct BlockExecutionData { pub canonical_fork: ForkBlock, } -impl BlockExecutionDataProvider for BlockExecutionData { - fn block_execution_outcome(&self) -> &BlockExecutionOutcome { - &self.block_execution_outcome +impl ExecutionDataProvider for ExecutionData { + fn execution_outcome(&self) -> &ExecutionOutcome { + &self.execution_outcome } fn block_hash(&self, block_number: BlockNumber) -> Option { @@ -63,7 +61,7 @@ impl BlockExecutionDataProvider for BlockExecutionData { } } -impl BlockExecutionForkProvider for BlockExecutionData { +impl BlockExecutionForkProvider for ExecutionData { fn canonical_fork(&self) -> ForkBlock { self.canonical_fork } diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index c48da7522906..613cb59cdd34 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -18,7 +18,7 @@ use reth_primitives::{ }; use reth_provider::{ providers::{BundleStateProvider, ConsistentDbView}, - BlockExecutionOutcome, Chain, FullBlockExecutionDataProvider, ProviderError, StateRootProvider, + Chain, ExecutionOutcome, FullExecutionDataProvider, ProviderError, StateRootProvider, }; use reth_revm::database::StateProviderDatabase; use reth_trie::updates::TrieUpdates; @@ -78,11 +78,11 @@ impl AppendableChain { DB: Database + Clone, E: BlockExecutorProvider, { - let block_execution_outcome = BlockExecutionOutcome::default(); + let execution_outcome = ExecutionOutcome::default(); let empty = BTreeMap::new(); let state_provider = BundleStateDataRef { - block_execution_outcome: &block_execution_outcome, + execution_outcome: &execution_outcome, sidechain_block_hashes: &empty, canonical_block_hashes, canonical_fork, @@ -122,14 +122,14 @@ impl AppendableChain { BlockchainTreeError::BlockNumberNotFoundInChain { block_number: parent_number }, )?; - let mut block_execution_outcome = self.block_execution_outcome().clone(); + let mut execution_outcome = self.execution_outcome().clone(); // Revert state to the state after execution of the parent block - block_execution_outcome.revert_to(parent.number); + execution_outcome.revert_to(parent.number); // Revert changesets to get the state of the parent that we need to apply the change. let bundle_state_data = BundleStateDataRef { - block_execution_outcome: &block_execution_outcome, + execution_outcome: &execution_outcome, sidechain_block_hashes: &side_chain_block_hashes, canonical_block_hashes, canonical_fork, @@ -144,17 +144,17 @@ impl AppendableChain { )?; // extending will also optimize few things, mostly related to selfdestruct and wiping of // storage. - block_execution_outcome.extend(block_state); + execution_outcome.extend(block_state); // remove all receipts and reverts (except the last one), as they belong to the chain we // forked from and not the new chain we are creating. - let size = block_execution_outcome.receipts().len(); - block_execution_outcome.receipts_mut().drain(0..size - 1); - block_execution_outcome.state_mut().take_n_reverts(size - 1); - block_execution_outcome.set_first_block(block.number); + let size = execution_outcome.receipts().len(); + execution_outcome.receipts_mut().drain(0..size - 1); + execution_outcome.state_mut().take_n_reverts(size - 1); + execution_outcome.set_first_block(block.number); // If all is okay, return new chain back. Present chain is not modified. - Ok(Self { chain: Chain::from_block(block, block_execution_outcome, None) }) + Ok(Self { chain: Chain::from_block(block, execution_outcome, None) }) } /// Validate and execute the given block that _extends the canonical chain_, validating its @@ -166,16 +166,16 @@ impl AppendableChain { /// - [`BlockAttachment`] represents if the block extends the canonical chain, and thus we can /// cache the trie state updates. /// - [`BlockValidationKind`] determines if the state root __should__ be validated. - fn validate_and_execute( + fn validate_and_execute( block: SealedBlockWithSenders, parent_block: &SealedHeader, - bundle_state_data_provider: BEDP, + bundle_state_data_provider: EDP, externals: &TreeExternals, block_attachment: BlockAttachment, block_validation_kind: BlockValidationKind, - ) -> Result<(BlockExecutionOutcome, Option), BlockExecutionError> + ) -> Result<(ExecutionOutcome, Option), BlockExecutionError> where - BEDP: FullBlockExecutionDataProvider, + EDP: FullExecutionDataProvider, DB: Database + Clone, E: BlockExecutorProvider, { @@ -214,8 +214,8 @@ impl AppendableChain { .consensus .validate_block_post_execution(&block, PostExecutionInput::new(&receipts, &requests))?; - let initial_block_execution_outcome = - BlockExecutionOutcome::new(state, receipts.into(), block.number, vec![requests.into()]); + let initial_execution_outcome = + ExecutionOutcome::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. @@ -223,16 +223,16 @@ impl AppendableChain { // calculate and check state root let start = Instant::now(); let (state_root, trie_updates) = if block_attachment.is_canonical() { - let mut block_execution_outcome = - provider.block_execution_data_provider.block_execution_outcome().clone(); - block_execution_outcome.extend(initial_block_execution_outcome.clone()); - let hashed_state = block_execution_outcome.hash_state_slow(); + let mut execution_outcome = + provider.block_execution_data_provider.execution_outcome().clone(); + execution_outcome.extend(initial_execution_outcome.clone()); + let hashed_state = execution_outcome.hash_state_slow(); ParallelStateRoot::new(consistent_view, hashed_state) .incremental_root_with_updates() .map(|(root, updates)| (root, Some(updates))) .map_err(ProviderError::from)? } else { - (provider.state_root(initial_block_execution_outcome.state())?, None) + (provider.state_root(initial_execution_outcome.state())?, None) }; if block.state_root != state_root { return Err(ConsensusError::BodyStateRootDiff( @@ -249,9 +249,9 @@ impl AppendableChain { "Validated state root" ); - Ok((initial_block_execution_outcome, trie_updates)) + Ok((initial_execution_outcome, trie_updates)) } else { - Ok((initial_block_execution_outcome, None)) + Ok((initial_execution_outcome, None)) } } @@ -285,7 +285,7 @@ impl AppendableChain { let parent_block = self.chain.tip(); let bundle_state_data = BundleStateDataRef { - block_execution_outcome: self.block_execution_outcome(), + execution_outcome: self.execution_outcome(), sidechain_block_hashes: &side_chain_block_hashes, canonical_block_hashes, canonical_fork, diff --git a/crates/blockchain-tree/src/lib.rs b/crates/blockchain-tree/src/lib.rs index 7c6714082f84..3f501bead071 100644 --- a/crates/blockchain-tree/src/lib.rs +++ b/crates/blockchain-tree/src/lib.rs @@ -40,7 +40,7 @@ pub mod shareable; pub use shareable::ShareableBlockchainTree; mod bundle; -pub use bundle::{BlockExecutionData, BundleStateDataRef}; +pub use bundle::{BundleStateDataRef, ExecutionData}; /// Buffer of not executed blocks. pub mod block_buffer; diff --git a/crates/blockchain-tree/src/noop.rs b/crates/blockchain-tree/src/noop.rs index 31b15356a61f..3ff14ca04f06 100644 --- a/crates/blockchain-tree/src/noop.rs +++ b/crates/blockchain-tree/src/noop.rs @@ -10,7 +10,7 @@ use reth_primitives::{ }; use reth_provider::{ BlockchainTreePendingStateProvider, CanonStateNotificationSender, CanonStateNotifications, - CanonStateSubscriptions, FullBlockExecutionDataProvider, + CanonStateSubscriptions, FullExecutionDataProvider, }; use reth_storage_errors::provider::ProviderResult; use std::collections::BTreeMap; @@ -122,7 +122,7 @@ impl BlockchainTreePendingStateProvider for NoopBlockchainTree { fn find_pending_state_provider( &self, _block_hash: BlockHash, - ) -> Option> { + ) -> Option> { None } } diff --git a/crates/blockchain-tree/src/shareable.rs b/crates/blockchain-tree/src/shareable.rs index 07828a0198b6..0f7903cf0695 100644 --- a/crates/blockchain-tree/src/shareable.rs +++ b/crates/blockchain-tree/src/shareable.rs @@ -14,7 +14,7 @@ use reth_primitives::{ SealedHeader, }; use reth_provider::{ - BlockchainTreePendingStateProvider, CanonStateSubscriptions, FullBlockExecutionDataProvider, + BlockchainTreePendingStateProvider, CanonStateSubscriptions, FullExecutionDataProvider, ProviderError, }; use reth_storage_errors::provider::ProviderResult; @@ -177,7 +177,7 @@ where fn find_pending_state_provider( &self, block_hash: BlockHash, - ) -> Option> { + ) -> Option> { trace!(target: "blockchain_tree", ?block_hash, "Finding pending state provider"); let provider = self.tree.read().post_state_data(block_hash)?; Some(Box::new(provider)) diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index 2d315334df4e..7447e9aa8d87 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -27,7 +27,7 @@ use reth_primitives::{ U256, }; use reth_provider::{ - BlockExecutionOutcome, BlockReaderIdExt, StateProviderFactory, StateRootProvider, + ExecutionOutcome, BlockReaderIdExt, StateProviderFactory, StateRootProvider, }; use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::TransactionPool; @@ -349,7 +349,7 @@ impl StorageInner { provider: &Provider, chain_spec: Arc, executor: &Executor, - ) -> Result<(SealedHeader, BlockExecutionOutcome), BlockExecutionError> + ) -> Result<(SealedHeader, ExecutionOutcome), BlockExecutionError> where Executor: BlockExecutorProvider, Provider: StateProviderFactory, @@ -391,7 +391,7 @@ impl StorageInner { // execute the block let BlockExecutionOutput { state, receipts, requests: block_execution_requests, .. } = executor.executor(&mut db).execute((&block, U256::ZERO).into())?; - let block_execution_outcome = BlockExecutionOutcome::new( + let execution_outcome = ExecutionOutcome::new( state, receipts.into(), block.number, @@ -405,10 +405,10 @@ impl StorageInner { let Block { mut header, body, .. } = block.block; let body = BlockBody { transactions: body, ommers, withdrawals, requests }; - trace!(target: "consensus::auto", ?block_execution_outcome, ?header, ?body, "executed block, calculating state root and completing header"); + trace!(target: "consensus::auto", ?execution_outcome, ?header, ?body, "executed block, calculating state root and completing header"); // calculate the state root - header.state_root = db.state_root(block_execution_outcome.state())?; + header.state_root = db.state_root(execution_outcome.state())?; trace!(target: "consensus::auto", root=?header.state_root, ?body, "calculated root"); // finally insert into storage @@ -417,6 +417,6 @@ impl StorageInner { // set new header with hash that should have been updated by insert_new_block let new_header = header.seal(self.best_hash); - Ok((new_header, block_execution_outcome)) + Ok((new_header, execution_outcome)) } } diff --git a/crates/consensus/beacon/src/engine/sync.rs b/crates/consensus/beacon/src/engine/sync.rs index 3b3f41a56bc4..5f14862bbc49 100644 --- a/crates/consensus/beacon/src/engine/sync.rs +++ b/crates/consensus/beacon/src/engine/sync.rs @@ -435,7 +435,7 @@ mod tests { Header, SealedHeader, MAINNET, }; use reth_provider::{ - test_utils::create_test_provider_factory_with_chain_spec, BlockExecutionOutcome, + test_utils::create_test_provider_factory_with_chain_spec, ExecutionOutcome, }; use reth_prune_types::PruneModes; use reth_stages::{test_utils::TestStages, ExecOutput, StageError}; @@ -446,7 +446,7 @@ mod tests { struct TestPipelineBuilder { pipeline_exec_outputs: VecDeque>, - executor_results: Vec, + executor_results: Vec, max_block: Option, } @@ -471,7 +471,7 @@ mod tests { /// Set the executor results to use for the test consensus engine. #[allow(dead_code)] - fn with_executor_results(mut self, executor_results: Vec) -> Self { + fn with_executor_results(mut self, executor_results: Vec) -> Self { self.executor_results = executor_results; self } diff --git a/crates/consensus/beacon/src/engine/test_utils.rs b/crates/consensus/beacon/src/engine/test_utils.rs index 80ecbc02f4ea..05164d010f18 100644 --- a/crates/consensus/beacon/src/engine/test_utils.rs +++ b/crates/consensus/beacon/src/engine/test_utils.rs @@ -25,7 +25,7 @@ use reth_payload_builder::test_utils::spawn_test_payload_service; use reth_primitives::{BlockNumber, ChainSpec, B256}; use reth_provider::{ providers::BlockchainProvider, test_utils::create_test_provider_factory_with_chain_spec, - BlockExecutionOutcome, HeaderSyncMode, + ExecutionOutcome, HeaderSyncMode, }; use reth_prune::Pruner; use reth_prune_types::PruneModes; @@ -142,7 +142,7 @@ impl Default for TestPipelineConfig { #[derive(Debug)] enum TestExecutorConfig { /// Test executor results. - Test(Vec), + Test(Vec), /// Real executor configuration. Real, } @@ -188,7 +188,7 @@ impl TestConsensusEngineBuilder { } /// Set the executor results to use for the test consensus engine. - pub fn with_executor_results(mut self, executor_results: Vec) -> Self { + pub fn with_executor_results(mut self, executor_results: Vec) -> Self { self.executor_config = TestExecutorConfig::Test(executor_results); self } @@ -272,7 +272,7 @@ where /// Set the executor results to use for the test consensus engine. #[allow(dead_code)] - pub fn with_executor_results(mut self, executor_results: Vec) -> Self { + pub fn with_executor_results(mut self, executor_results: Vec) -> Self { self.base_config.executor_config = TestExecutorConfig::Test(executor_results); self } diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index b7c239367881..4521f18a06ab 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -12,7 +12,7 @@ use reth_evm::{ }, ConfigureEvm, }; -use reth_execution_types::BlockExecutionOutcome; +use reth_execution_types::ExecutionOutcome; use reth_primitives::{ BlockNumber, BlockWithSenders, ChainSpec, Hardfork, Header, Receipt, Request, Withdrawals, MAINNET, U256, @@ -406,7 +406,7 @@ where DB: Database, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BlockExecutionOutcome; + type Output = ExecutionOutcome; type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error> { @@ -436,7 +436,7 @@ where fn finalize(mut self) -> Self::Output { self.stats.log_debug(); - BlockExecutionOutcome::new( + ExecutionOutcome::new( self.executor.state.take_bundle(), self.batch_record.take_receipts(), self.batch_record.first_block().unwrap_or_default(), diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index 7ef9f16a8327..c979397d7553 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -29,7 +29,7 @@ use reth_primitives::{ revm::env::tx_env_with_recovered, Block, Header, IntoRecoveredTransaction, Receipt, EMPTY_OMMER_ROOT_HASH, U256, }; -use reth_provider::{BlockExecutionOutcome, StateProviderFactory}; +use reth_provider::{ExecutionOutcome, StateProviderFactory}; use reth_revm::{database::StateProviderDatabase, state_change::apply_blockhashes_update}; use reth_transaction_pool::{BestTransactionsAttributes, TransactionPool}; use revm::{ @@ -444,21 +444,20 @@ where // and 4788 contract call db.merge_transitions(BundleRetention::PlainState); - let block_execution_outcome = BlockExecutionOutcome::new( + let execution_outcome = ExecutionOutcome::new( db.take_bundle(), vec![receipts].into(), block_number, vec![requests.clone().unwrap_or_default()], ); let receipts_root = - block_execution_outcome.receipts_root_slow(block_number).expect("Number is in range"); - let logs_bloom = - block_execution_outcome.block_logs_bloom(block_number).expect("Number is in range"); + execution_outcome.receipts_root_slow(block_number).expect("Number is in range"); + let logs_bloom = execution_outcome.block_logs_bloom(block_number).expect("Number is in range"); // calculate the state root let state_root = { let state_provider = db.database.0.inner.borrow_mut(); - state_provider.db.state_root(block_execution_outcome.state())? + state_provider.db.state_root(execution_outcome.state())? }; // create the block header diff --git a/crates/evm/execution-types/src/bundle.rs b/crates/evm/execution-types/src/bundle.rs index ed3bf5f79c18..5b3e8477594e 100644 --- a/crates/evm/execution-types/src/bundle.rs +++ b/crates/evm/execution-types/src/bundle.rs @@ -13,10 +13,10 @@ use std::collections::HashMap; /// Represents the outcome of block execution, including post-execution changes and reverts. /// -/// The `BlockExecutionOutcome` structure aggregates the state changes over an arbitrary number of +/// The `ExecutionOutcome` structure aggregates the state changes over an arbitrary number of /// blocks, capturing the resulting state, receipts, and requests following the execution. #[derive(Default, Debug, Clone, PartialEq, Eq)] -pub struct BlockExecutionOutcome { +pub struct ExecutionOutcome { /// Bundle state with reverts. pub bundle: BundleState, /// The collection of receipts. @@ -46,10 +46,10 @@ pub type AccountRevertInit = (Option>, Vec); /// Type used to initialize revms reverts. pub type RevertsInit = HashMap>; -impl BlockExecutionOutcome { - /// Creates a new `BlockExecutionOutcome`. +impl ExecutionOutcome { + /// Creates a new `ExecutionOutcome`. /// - /// This constructor initializes a new `BlockExecutionOutcome` instance with the provided + /// This constructor initializes a new `ExecutionOutcome` instance with the provided /// bundle state, receipts, first block number, and EIP-7685 requests. pub const fn new( bundle: BundleState, @@ -60,9 +60,9 @@ impl BlockExecutionOutcome { Self { bundle, receipts, first_block, requests } } - /// Creates a new `BlockExecutionOutcome` from initialization parameters. + /// Creates a new `ExecutionOutcome` from initialization parameters. /// - /// This constructor initializes a new `BlockExecutionOutcome` instance using detailed + /// This constructor initializes a new `ExecutionOutcome` instance using detailed /// initialization parameters. pub fn new_init( state_init: BundleStateInit, @@ -144,7 +144,7 @@ impl BlockExecutionOutcome { self.bundle.bytecode(code_hash).map(Bytecode) } - /// Returns [`HashedPostState`] for this block execution outcome. + /// Returns [`HashedPostState`] for this execution outcome. /// See [`HashedPostState::from_bundle_state`] for more info. pub fn hash_state_slow(&self) -> HashedPostState { HashedPostState::from_bundle_state(&self.bundle.state) diff --git a/crates/evm/execution-types/src/chain.rs b/crates/evm/execution-types/src/chain.rs index fc2bad2780b8..800d34f1068b 100644 --- a/crates/evm/execution-types/src/chain.rs +++ b/crates/evm/execution-types/src/chain.rs @@ -1,6 +1,6 @@ //! Contains [Chain], a chain of blocks and their final state. -use crate::BlockExecutionOutcome; +use crate::ExecutionOutcome; use reth_execution_errors::BlockExecutionError; use reth_primitives::{ Address, BlockHash, BlockNumHash, BlockNumber, ForkBlock, Receipt, SealedBlock, @@ -30,7 +30,7 @@ pub struct Chain { /// chain, ranging from the [`Chain::first`] block to the [`Chain::tip`] block, inclusive. /// /// Additionally, it includes the individual state changes that led to the current state. - block_execution_outcome: BlockExecutionOutcome, + execution_outcome: ExecutionOutcome, /// State trie updates after block is added to the chain. /// NOTE: Currently, trie updates are present only for /// single-block chains that extend the canonical chain. @@ -45,22 +45,22 @@ impl Chain { /// A chain of blocks should not be empty. pub fn new( blocks: impl IntoIterator, - block_execution_outcome: BlockExecutionOutcome, + execution_outcome: ExecutionOutcome, trie_updates: Option, ) -> Self { let blocks = BTreeMap::from_iter(blocks.into_iter().map(|b| (b.number, b))); debug_assert!(!blocks.is_empty(), "Chain should have at least one block"); - Self { blocks, block_execution_outcome, trie_updates } + Self { blocks, execution_outcome, trie_updates } } /// Create new Chain from a single block and its state. pub fn from_block( block: SealedBlockWithSenders, - block_execution_outcome: BlockExecutionOutcome, + execution_outcome: ExecutionOutcome, trie_updates: Option, ) -> Self { - Self::new([block], block_execution_outcome, trie_updates) + Self::new([block], execution_outcome, trie_updates) } /// Get the blocks in this chain. @@ -88,14 +88,14 @@ impl Chain { self.trie_updates.take(); } - /// Get block execution outcome of this chain - pub const fn block_execution_outcome(&self) -> &BlockExecutionOutcome { - &self.block_execution_outcome + /// Get execution outcome of this chain + pub const fn execution_outcome(&self) -> &ExecutionOutcome { + &self.execution_outcome } /// Prepends the given state to the current state. pub fn prepend_state(&mut self, state: BundleState) { - self.block_execution_outcome.prepend_state(state); + self.execution_outcome.prepend_state(state); self.trie_updates.take(); // invalidate cached trie updates } @@ -119,19 +119,19 @@ impl Chain { self.blocks.iter().find_map(|(_num, block)| (block.hash() == block_hash).then_some(block)) } - /// Return block execution outcome at the `block_number` or None if block is not known - pub fn block_execution_outcome_at_block( + /// Return execution outcome at the `block_number` or None if block is not known + pub fn execution_outcome_at_block( &self, block_number: BlockNumber, - ) -> Option { + ) -> Option { if self.tip().number == block_number { - return Some(self.block_execution_outcome.clone()) + return Some(self.execution_outcome.clone()) } if self.blocks.contains_key(&block_number) { - let mut block_execution_outcome = self.block_execution_outcome.clone(); - block_execution_outcome.revert_to(block_number); - return Some(block_execution_outcome) + let mut execution_outcome = self.execution_outcome.clone(); + execution_outcome.revert_to(block_number); + return Some(execution_outcome) } None } @@ -140,24 +140,20 @@ impl Chain { /// 1. The blocks contained in the chain. /// 2. The execution outcome representing the final state. /// 3. The optional trie updates. - pub fn into_inner(self) -> (ChainBlocks<'static>, BlockExecutionOutcome, Option) { - ( - ChainBlocks { blocks: Cow::Owned(self.blocks) }, - self.block_execution_outcome, - self.trie_updates, - ) + pub fn into_inner(self) -> (ChainBlocks<'static>, ExecutionOutcome, Option) { + (ChainBlocks { blocks: Cow::Owned(self.blocks) }, self.execution_outcome, self.trie_updates) } /// Destructure the chain into its inner components: /// 1. A reference to the blocks contained in the chain. /// 2. A reference to the execution outcome representing the final state. - pub const fn inner(&self) -> (ChainBlocks<'_>, &BlockExecutionOutcome) { - (ChainBlocks { blocks: Cow::Borrowed(&self.blocks) }, &self.block_execution_outcome) + pub const fn inner(&self) -> (ChainBlocks<'_>, &ExecutionOutcome) { + (ChainBlocks { blocks: Cow::Borrowed(&self.blocks) }, &self.execution_outcome) } /// Returns an iterator over all the receipts of the blocks in the chain. pub fn block_receipts_iter(&self) -> impl Iterator>> + '_ { - self.block_execution_outcome.receipts().iter() + self.execution_outcome.receipts().iter() } /// Returns an iterator over all blocks in the chain with increasing block number. @@ -216,7 +212,7 @@ impl Chain { /// Get all receipts for the given block. pub fn receipts_by_block_hash(&self, block_hash: BlockHash) -> Option> { let num = self.block_number(block_hash)?; - self.block_execution_outcome.receipts_by_block(num).iter().map(Option::as_ref).collect() + self.execution_outcome.receipts_by_block(num).iter().map(Option::as_ref).collect() } /// Get all receipts with attachment. @@ -225,7 +221,7 @@ impl Chain { pub fn receipts_with_attachment(&self) -> Vec { let mut receipt_attach = Vec::new(); for ((block_num, block), receipts) in - self.blocks().iter().zip(self.block_execution_outcome.receipts().iter()) + self.blocks().iter().zip(self.execution_outcome.receipts().iter()) { let mut tx_receipts = Vec::new(); for (tx, receipt) in block.body.iter().zip(receipts.iter()) { @@ -245,10 +241,10 @@ impl Chain { pub fn append_block( &mut self, block: SealedBlockWithSenders, - block_execution_outcome: BlockExecutionOutcome, + execution_outcome: ExecutionOutcome, ) { self.blocks.insert(block.number, block); - self.block_execution_outcome.extend(block_execution_outcome); + self.execution_outcome.extend(execution_outcome); self.trie_updates.take(); // reset } @@ -267,7 +263,7 @@ impl Chain { // Insert blocks from other chain self.blocks.extend(other.blocks); - self.block_execution_outcome.extend(other.block_execution_outcome); + self.execution_outcome.extend(other.execution_outcome); self.trie_updates.take(); // reset Ok(()) @@ -324,20 +320,20 @@ impl Chain { let split_at = block_number + 1; let higher_number_blocks = self.blocks.split_off(&split_at); - let block_execution_outcome = std::mem::take(&mut self.block_execution_outcome); + let execution_outcome = std::mem::take(&mut self.execution_outcome); let (canonical_block_exec_outcome, pending_block_exec_outcome) = - block_execution_outcome.split_at(split_at); + execution_outcome.split_at(split_at); // TODO: Currently, trie updates are reset on chain split. // Add tests ensuring that it is valid to leave updates in the pending chain. ChainSplit::Split { canonical: Self { - block_execution_outcome: canonical_block_exec_outcome.expect("split in range"), + execution_outcome: canonical_block_exec_outcome.expect("split in range"), blocks: self.blocks, trie_updates: None, }, pending: Self { - block_execution_outcome: pending_block_exec_outcome, + execution_outcome: pending_block_exec_outcome, blocks: higher_number_blocks, trie_updates: None, }, @@ -529,7 +525,7 @@ mod tests { #[test] fn test_number_split() { - let block_execution_outcome1 = BlockExecutionOutcome::new( + let execution_outcome1 = ExecutionOutcome::new( BundleState::new( vec![( Address::new([2; 20]), @@ -545,7 +541,7 @@ mod tests { vec![], ); - let block_execution_outcome2 = BlockExecutionOutcome::new( + let execution_outcome2 = ExecutionOutcome::new( BundleState::new( vec![( Address::new([3; 20]), @@ -573,37 +569,37 @@ mod tests { block2.set_hash(block2_hash); block2.senders.push(Address::new([4; 20])); - let mut block_state_extended = block_execution_outcome1; - block_state_extended.extend(block_execution_outcome2); + let mut block_state_extended = execution_outcome1; + block_state_extended.extend(execution_outcome2); let chain = Chain::new(vec![block1.clone(), block2.clone()], block_state_extended, None); - let (split1_block_execution_outcome, split2_block_execution_outcome) = - chain.block_execution_outcome.clone().split_at(2); + let (split1_execution_outcome, split2_execution_outcome) = + chain.execution_outcome.clone().split_at(2); let chain_split1 = Chain { - block_execution_outcome: split1_block_execution_outcome.unwrap(), + execution_outcome: split1_execution_outcome.unwrap(), blocks: BTreeMap::from([(1, block1.clone())]), trie_updates: None, }; let chain_split2 = Chain { - block_execution_outcome: split2_block_execution_outcome, + execution_outcome: split2_execution_outcome, blocks: BTreeMap::from([(2, block2.clone())]), trie_updates: None, }; // return tip state assert_eq!( - chain.block_execution_outcome_at_block(block2.number), - Some(chain.block_execution_outcome.clone()) + chain.execution_outcome_at_block(block2.number), + Some(chain.execution_outcome.clone()) ); assert_eq!( - chain.block_execution_outcome_at_block(block1.number), - Some(chain_split1.block_execution_outcome.clone()) + chain.execution_outcome_at_block(block1.number), + Some(chain_split1.execution_outcome.clone()) ); // state at unknown block - assert_eq!(chain.block_execution_outcome_at_block(100), None); + assert_eq!(chain.execution_outcome_at_block(100), None); // split in two assert_eq!( diff --git a/crates/evm/src/either.rs b/crates/evm/src/either.rs index 923759622bca..2c8edfd29265 100644 --- a/crates/evm/src/either.rs +++ b/crates/evm/src/either.rs @@ -4,7 +4,7 @@ use crate::execute::{ BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor, }; use reth_execution_errors::BlockExecutionError; -use reth_execution_types::BlockExecutionOutcome; +use reth_execution_types::ExecutionOutcome; 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 = BlockExecutionOutcome, + Output = ExecutionOutcome, Error = BlockExecutionError, >, B: for<'a> BatchExecutor< DB, Input<'a> = BlockExecutionInput<'a, BlockWithSenders>, - Output = BlockExecutionOutcome, + Output = ExecutionOutcome, Error = BlockExecutionError, >, DB: Database, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BlockExecutionOutcome; + type Output = ExecutionOutcome; 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 fba58247acbe..bf479271be06 100644 --- a/crates/evm/src/execute.rs +++ b/crates/evm/src/execute.rs @@ -1,6 +1,6 @@ //! Traits for execution. -use reth_execution_types::BlockExecutionOutcome; +use reth_execution_types::ExecutionOutcome; use reth_primitives::{BlockNumber, BlockWithSenders, Receipt, Request, U256}; use reth_prune_types::PruneModes; use revm::db::BundleState; @@ -91,7 +91,7 @@ pub trait BatchExecutor { /// /// Contains the state changes, transaction receipts, and total gas used in the block. /// -/// TODO(mattsse): combine with `BlockExecutionOutcome` +/// TODO(mattsse): combine with `ExecutionOutcome` #[derive(Debug)] pub struct BlockExecutionOutput { /// The changed state of the block after execution. @@ -150,7 +150,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static { type BatchExecutor>: for<'a> BatchExecutor< DB, Input<'a> = BlockExecutionInput<'a, BlockWithSenders>, - Output = BlockExecutionOutcome, + Output = ExecutionOutcome, Error = BlockExecutionError, >; @@ -216,7 +216,7 @@ mod tests { impl BatchExecutor for TestExecutor { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BlockExecutionOutcome; + type Output = ExecutionOutcome; 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 388d46e160e8..fdee35239369 100644 --- a/crates/evm/src/noop.rs +++ b/crates/evm/src/noop.rs @@ -1,7 +1,7 @@ //! A no operation block executor implementation. use reth_execution_errors::BlockExecutionError; -use reth_execution_types::BlockExecutionOutcome; +use reth_execution_types::ExecutionOutcome; use reth_primitives::{BlockNumber, BlockWithSenders, Receipt}; use reth_prune_types::PruneModes; use reth_storage_errors::provider::ProviderError; @@ -50,7 +50,7 @@ impl Executor for NoopBlockExecutorProvider { impl BatchExecutor for NoopBlockExecutorProvider { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BlockExecutionOutcome; + type Output = ExecutionOutcome; 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 0695945b055a..c9627933a7fc 100644 --- a/crates/evm/src/test_utils.rs +++ b/crates/evm/src/test_utils.rs @@ -5,7 +5,7 @@ use crate::execute::{ }; use parking_lot::Mutex; use reth_execution_errors::BlockExecutionError; -use reth_execution_types::BlockExecutionOutcome; +use reth_execution_types::ExecutionOutcome; 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 BlockExecutionOutcome { bundle, receipts, requests, first_block: _ } = + let ExecutionOutcome { 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 = BlockExecutionOutcome; + type Output = ExecutionOutcome; 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 4f7c971768d7..0f1ed60a17e4 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -13,7 +13,7 @@ use reth_primitives::{ BlockNumber, BlockWithSenders, ChainSpec, Hardfork, Header, Receipt, Receipts, TxType, Withdrawals, U256, }; -use reth_provider::BlockExecutionOutcome; +use reth_provider::ExecutionOutcome; use reth_prune_types::PruneModes; use reth_revm::{ batch::{BlockBatchRecord, BlockExecutorStats}, @@ -397,7 +397,7 @@ where DB: Database, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; - type Output = BlockExecutionOutcome; + type Output = ExecutionOutcome; type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error> { @@ -424,7 +424,7 @@ where fn finalize(mut self) -> Self::Output { self.stats.log_debug(); - BlockExecutionOutcome::new( + ExecutionOutcome::new( self.executor.state.take_bundle(), self.batch_record.take_receipts(), self.batch_record.first_block().unwrap_or_default(), diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 87509e737f01..09a4e82ce75d 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -15,7 +15,7 @@ use reth_primitives::{ Block, ChainSpec, Hardfork, Header, IntoRecoveredTransaction, Receipt, TxType, EMPTY_OMMER_ROOT_HASH, U256, }; -use reth_provider::{BlockExecutionOutcome, StateProviderFactory}; +use reth_provider::{ExecutionOutcome, StateProviderFactory}; use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::{BestTransactionsAttributes, TransactionPool}; use revm::{ @@ -506,13 +506,13 @@ where // and 4788 contract call db.merge_transitions(BundleRetention::PlainState); - let block_execution_outcome = BlockExecutionOutcome::new( + let execution_outcome = ExecutionOutcome::new( db.take_bundle(), vec![receipts].into(), block_number, Vec::new(), ); - let receipts_root = block_execution_outcome + let receipts_root = execution_outcome .optimism_receipts_root_slow( block_number, chain_spec.as_ref(), @@ -520,12 +520,12 @@ where ) .expect("Number is in range"); let logs_bloom = - block_execution_outcome.block_logs_bloom(block_number).expect("Number is in range"); + execution_outcome.block_logs_bloom(block_number).expect("Number is in range"); // calculate the state root let state_root = { let state_provider = db.database.0.inner.borrow_mut(); - state_provider.db.state_root(block_execution_outcome.state())? + state_provider.db.state_root(execution_outcome.state())? }; // create the block header diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index 61564afd1faa..d74bf1d77c65 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -206,8 +206,8 @@ where // extract the state from the notification and put it into the cache let committed = new_state.committed(); - let new_block_execution_outcome = committed.block_execution_outcome(); - for (addr, acc) in new_block_execution_outcome.bundle_accounts_iter() { + let new_execution_outcome = committed.execution_outcome(); + for (addr, acc) in new_execution_outcome.bundle_accounts_iter() { if let Some(info) = acc.info.clone() { // we want pre cache existing accounts and their storage // this only includes changed accounts and storage but is better than nothing diff --git a/crates/rpc/rpc/src/eth/api/pending_block.rs b/crates/rpc/rpc/src/eth/api/pending_block.rs index daaa2850a1e5..b3375e2b5554 100644 --- a/crates/rpc/rpc/src/eth/api/pending_block.rs +++ b/crates/rpc/rpc/src/eth/api/pending_block.rs @@ -12,7 +12,7 @@ use reth_primitives::{ Block, BlockId, BlockNumberOrTag, ChainSpec, Header, IntoRecoveredTransaction, Receipt, Requests, SealedBlockWithSenders, SealedHeader, B256, EMPTY_OMMER_ROOT_HASH, U256, }; -use reth_provider::{BlockExecutionOutcome, ChainSpecProvider, StateProviderFactory}; +use reth_provider::{ChainSpecProvider, ExecutionOutcome, StateProviderFactory}; use reth_revm::{ database::StateProviderDatabase, state_change::{ @@ -220,7 +220,7 @@ impl PendingBlockEnv { // merge all transitions into bundle state. db.merge_transitions(BundleRetention::PlainState); - let block_execution_outcome = BlockExecutionOutcome::new( + let execution_outcome = ExecutionOutcome::new( db.take_bundle(), vec![receipts].into(), block_number, @@ -228,7 +228,7 @@ impl PendingBlockEnv { ); #[cfg(feature = "optimism")] - let receipts_root = block_execution_outcome + let receipts_root = execution_outcome .optimism_receipts_root_slow( block_number, chain_spec.as_ref(), @@ -238,14 +238,14 @@ impl PendingBlockEnv { #[cfg(not(feature = "optimism"))] let receipts_root = - block_execution_outcome.receipts_root_slow(block_number).expect("Block is present"); + execution_outcome.receipts_root_slow(block_number).expect("Block is present"); let logs_bloom = - block_execution_outcome.block_logs_bloom(block_number).expect("Block is present"); + execution_outcome.block_logs_bloom(block_number).expect("Block is present"); // calculate the state root let state_provider = &db.database; - let state_root = state_provider.state_root(block_execution_outcome.state())?; + let state_root = state_provider.state_root(execution_outcome.state())?; // create the block header let transactions_root = proofs::calculate_transaction_root(&executed_txs); diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index 1c2469e3527c..8b62ffeb5dbc 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -13,7 +13,7 @@ use reth_primitives::{ }; use reth_provider::{ providers::{StaticFileProvider, StaticFileProviderRWRefMut, StaticFileWriter}, - BlockExecutionOutcome, BlockReader, Chain, DatabaseProviderRW, HeaderProvider, + ExecutionOutcome, BlockReader, Chain, DatabaseProviderRW, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderError, StateWriter, StatsReader, TransactionVariant, }; @@ -289,8 +289,8 @@ where } } let time = Instant::now(); - let BlockExecutionOutcome { bundle, receipts, requests, first_block } = executor.finalize(); - let state = BlockExecutionOutcome::new(bundle, receipts, first_block, requests); + let ExecutionOutcome { bundle, receipts, requests, first_block } = executor.finalize(); + let state = ExecutionOutcome::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/stages/stages/src/stages/headers.rs b/crates/stages/stages/src/stages/headers.rs index 934cd6d29eb2..0864da06e6c9 100644 --- a/crates/stages/stages/src/stages/headers.rs +++ b/crates/stages/stages/src/stages/headers.rs @@ -384,7 +384,7 @@ mod tests { stage::StageUnitCheckpoint, BlockBody, SealedBlock, SealedBlockWithSenders, B256, }; use reth_provider::{ - BlockExecutionOutcome, BlockWriter, ProviderFactory, StaticFileProviderFactory, + ExecutionOutcome, BlockWriter, ProviderFactory, StaticFileProviderFactory, }; use reth_testing_utils::generators::{self, random_header, random_header_range}; use reth_trie::{updates::TrieUpdates, HashedPostState}; @@ -634,7 +634,7 @@ mod tests { provider .append_blocks_with_state( sealed_blocks, - BlockExecutionOutcome::default(), + ExecutionOutcome::default(), HashedPostState::default(), TrieUpdates::default(), None, diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index f5992441a6f3..3440e0031c7d 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -14,7 +14,7 @@ use reth_provider::{ bundle_state::{BundleStateInit, RevertsInit}, errors::provider::ProviderResult, providers::{StaticFileProvider, StaticFileWriter}, - BlockExecutionOutcome, BlockHashReader, BlockNumReader, ChainSpecProvider, DatabaseProviderRW, + BlockHashReader, BlockNumReader, ChainSpecProvider, DatabaseProviderRW, ExecutionOutcome, HashingWriter, HistoryWriter, OriginalValuesKnown, ProviderError, ProviderFactory, StageCheckpointWriter, StateWriter, StaticFileProviderFactory, }; @@ -193,7 +193,7 @@ pub fn insert_state<'a, 'b, DB: Database>( } let all_reverts_init: RevertsInit = HashMap::from([(block, reverts_init)]); - let block_execution_outcome = BlockExecutionOutcome::new_init( + let execution_outcome = ExecutionOutcome::new_init( state_init, all_reverts_init, contracts.into_iter().collect(), @@ -202,7 +202,7 @@ pub fn insert_state<'a, 'b, DB: Database>( Vec::new(), ); - block_execution_outcome.write_to_storage(tx, None, OriginalValuesKnown::Yes)?; + execution_outcome.write_to_storage(tx, None, OriginalValuesKnown::Yes)?; trace!(target: "reth::cli", "Inserted state"); 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 56589c9953ee..81198481e26b 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 @@ -9,7 +9,7 @@ use reth_primitives::StaticFileSegment; use reth_storage_errors::provider::{ProviderError, ProviderResult}; pub use revm::db::states::OriginalValuesKnown; -impl StateWriter for BlockExecutionOutcome { +impl StateWriter for ExecutionOutcome { fn write_to_storage( self, tx: &TX, @@ -288,7 +288,7 @@ mod tests { state.merge_transitions(BundleRetention::Reverts); - BlockExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new()) + ExecutionOutcome::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); - BlockExecutionOutcome::new(state.take_bundle(), Receipts::default(), 2, Vec::new()) + ExecutionOutcome::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); - BlockExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()) + ExecutionOutcome::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(); - BlockExecutionOutcome::new(bundle, Receipts::default(), 1, Vec::new()) + ExecutionOutcome::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); - BlockExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()) + ExecutionOutcome::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); - BlockExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new()) + ExecutionOutcome::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"); @@ -830,7 +830,7 @@ mod tests { #[test] fn revert_to_indices() { - let base = BlockExecutionOutcome { + let base = ExecutionOutcome { bundle: BundleState::default(), receipts: vec![vec![Some(Receipt::default()); 2]; 7].into(), first_block: 10, @@ -896,7 +896,7 @@ mod tests { let assert_state_root = |state: &State, expected: &PreState, msg| { assert_eq!( - BlockExecutionOutcome::new( + ExecutionOutcome::new( state.bundle_state.clone(), Receipts::default(), 0, @@ -1047,7 +1047,7 @@ mod tests { .build(); assert_eq!(previous_state.reverts.len(), 1); - let mut test = BlockExecutionOutcome { + let mut test = ExecutionOutcome { bundle: present_state, receipts: vec![vec![Some(Receipt::default()); 2]; 1].into(), first_block: 2, diff --git a/crates/storage/provider/src/bundle_state/mod.rs b/crates/storage/provider/src/bundle_state/mod.rs index e41d284a7d09..1b3965a14a45 100644 --- a/crates/storage/provider/src/bundle_state/mod.rs +++ b/crates/storage/provider/src/bundle_state/mod.rs @@ -6,7 +6,7 @@ mod state_changes; mod state_reverts; pub use bundle_state_with_receipts::{ - AccountRevertInit, BlockExecutionOutcome, BundleStateInit, OriginalValuesKnown, RevertsInit, + AccountRevertInit, BundleStateInit, ExecutionOutcome, OriginalValuesKnown, RevertsInit, }; pub use hashed_state_changes::HashedStateChanges; pub use state_changes::StateChanges; diff --git a/crates/storage/provider/src/providers/bundle_state_provider.rs b/crates/storage/provider/src/providers/bundle_state_provider.rs index 6ac5fa41104c..aec1ce18284b 100644 --- a/crates/storage/provider/src/providers/bundle_state_provider.rs +++ b/crates/storage/provider/src/providers/bundle_state_provider.rs @@ -1,36 +1,36 @@ use crate::{ - AccountReader, BlockExecutionDataProvider, BlockHashReader, StateProvider, StateRootProvider, + AccountReader, BlockHashReader, ExecutionDataProvider, StateProvider, StateRootProvider, }; use reth_primitives::{proofs::AccountProof, Account, Address, BlockNumber, Bytecode, B256}; use reth_storage_errors::provider::{ProviderError, ProviderResult}; use reth_trie::updates::TrieUpdates; use revm::db::BundleState; -/// A state provider that resolves to data from either a wrapped [`crate::BlockExecutionOutcome`] +/// A state provider that resolves to data from either a wrapped [`crate::ExecutionOutcome`] /// or an underlying state provider. /// -/// This struct combines two sources of state data: the block execution outcome and an underlying +/// This struct combines two sources of state data: the execution outcome and an underlying /// state provider. It can provide state information by leveraging both the post-block execution /// changes and the pre-existing state data. #[derive(Debug)] -pub struct BundleStateProvider { +pub struct BundleStateProvider { /// The inner state provider. pub state_provider: SP, /// Block execution data. - pub block_execution_data_provider: BEDP, + pub block_execution_data_provider: EDP, } -impl BundleStateProvider { +impl BundleStateProvider { /// Create new bundle state provider - pub const fn new(state_provider: SP, block_execution_data_provider: BEDP) -> Self { + pub const fn new(state_provider: SP, block_execution_data_provider: EDP) -> Self { Self { state_provider, block_execution_data_provider } } } /* Implement StateProvider traits */ -impl BlockHashReader - for BundleStateProvider +impl BlockHashReader + for BundleStateProvider { fn block_hash(&self, block_number: BlockNumber) -> ProviderResult> { let block_hash = self.block_execution_data_provider.block_hash(block_number); @@ -49,12 +49,10 @@ impl BlockHashReader } } -impl AccountReader - for BundleStateProvider -{ +impl AccountReader for BundleStateProvider { fn basic_account(&self, address: Address) -> ProviderResult> { if let Some(account) = - self.block_execution_data_provider.block_execution_outcome().account(&address) + self.block_execution_data_provider.execution_outcome().account(&address) { Ok(account) } else { @@ -63,12 +61,11 @@ impl AccountReader } } -impl StateRootProvider - for BundleStateProvider +impl StateRootProvider + for BundleStateProvider { fn state_root(&self, bundle_state: &BundleState) -> ProviderResult { - let mut state = - self.block_execution_data_provider.block_execution_outcome().state().clone(); + let mut state = self.block_execution_data_provider.execution_outcome().state().clone(); state.extend(bundle_state.clone()); self.state_provider.state_root(&state) } @@ -77,16 +74,13 @@ impl StateRootProvider &self, bundle_state: &BundleState, ) -> ProviderResult<(B256, TrieUpdates)> { - let mut state = - self.block_execution_data_provider.block_execution_outcome().state().clone(); + let mut state = self.block_execution_data_provider.execution_outcome().state().clone(); state.extend(bundle_state.clone()); self.state_provider.state_root_with_updates(&state) } } -impl StateProvider - for BundleStateProvider -{ +impl StateProvider for BundleStateProvider { fn storage( &self, account: Address, @@ -95,7 +89,7 @@ impl StateProvider let u256_storage_key = storage_key.into(); if let Some(value) = self .block_execution_data_provider - .block_execution_outcome() + .execution_outcome() .storage(&account, u256_storage_key) { return Ok(Some(value)) @@ -106,7 +100,7 @@ impl StateProvider fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult> { if let Some(bytecode) = - self.block_execution_data_provider.block_execution_outcome().bytecode(&code_hash) + self.block_execution_data_provider.execution_outcome().bytecode(&code_hash) { return Ok(Some(bytecode)) } diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index bafb208b468e..3e4034f1c0ff 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -1,5 +1,5 @@ use crate::{ - bundle_state::{BlockExecutionOutcome, BundleStateInit, HashedStateChanges, RevertsInit}, + bundle_state::{BundleStateInit, ExecutionOutcome, HashedStateChanges, RevertsInit}, providers::{database::metrics, static_file::StaticFileWriter, StaticFileProvider}, to_range, traits::{ @@ -366,7 +366,7 @@ impl DatabaseProvider { } // TODO(joshie) TEMPORARY should be moved to trait providers - /// Unwind or peek at last N blocks of state recreating the [`BlockExecutionOutcome`]. + /// Unwind or peek at last N blocks of state recreating the [`ExecutionOutcome`]. /// /// If UNWIND it set to true tip and latest state will be unwind /// and returned back with all the blocks @@ -393,9 +393,9 @@ impl DatabaseProvider { pub fn unwind_or_peek_state( &self, range: RangeInclusive, - ) -> ProviderResult { + ) -> ProviderResult { if range.is_empty() { - return Ok(BlockExecutionOutcome::default()) + return Ok(ExecutionOutcome::default()) } let start_block_number = *range.start(); @@ -533,7 +533,7 @@ impl DatabaseProvider { receipts.push(block_receipts); } - Ok(BlockExecutionOutcome::new_init( + Ok(ExecutionOutcome::new_init( state, reverts, Vec::new(), @@ -2673,7 +2673,7 @@ impl BlockWriter for DatabaseProvider { fn append_blocks_with_state( &self, blocks: Vec, - block_execution_outcome: BlockExecutionOutcome, + execution_outcome: ExecutionOutcome, hashed_state: HashedPostState, trie_updates: TrieUpdates, prune_modes: Option<&PruneModes>, @@ -2698,7 +2698,7 @@ impl BlockWriter for DatabaseProvider { // Write state and changesets to the database. // Must be written after blocks because of the receipt lookup. - block_execution_outcome.write_to_storage(self.tx_ref(), None, OriginalValuesKnown::No)?; + execution_outcome.write_to_storage(self.tx_ref(), None, OriginalValuesKnown::No)?; durations_recorder.record_relative(metrics::Action::InsertState); // insert hashes and intermediate merkle nodes diff --git a/crates/storage/provider/src/providers/mod.rs b/crates/storage/provider/src/providers/mod.rs index 125f064cc44e..c1ad67885a16 100644 --- a/crates/storage/provider/src/providers/mod.rs +++ b/crates/storage/provider/src/providers/mod.rs @@ -2,7 +2,7 @@ use crate::{ AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, BlockSource, BlockchainTreePendingStateProvider, CanonChainTracker, CanonStateNotifications, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader, DatabaseProviderFactory, - EvmEnvProvider, FullBlockExecutionDataProvider, HeaderProvider, ProviderError, + EvmEnvProvider, FullExecutionDataProvider, HeaderProvider, ProviderError, PruneCheckpointReader, ReceiptProvider, ReceiptProviderIdExt, RequestsProvider, StageCheckpointReader, StateProviderBox, StateProviderFactory, StaticFileProviderFactory, TransactionVariant, TransactionsProvider, TreeViewer, WithdrawalsProvider, @@ -657,7 +657,7 @@ where fn pending_with_provider( &self, - bundle_state_data: Box, + bundle_state_data: Box, ) -> ProviderResult { let canonical_fork = bundle_state_data.canonical_fork(); trace!(target: "providers::blockchain", ?canonical_fork, "Returning post state provider"); @@ -876,7 +876,7 @@ where fn find_pending_state_provider( &self, block_hash: BlockHash, - ) -> Option> { + ) -> Option> { self.tree.find_pending_state_provider(block_hash) } } diff --git a/crates/storage/provider/src/test_utils/blocks.rs b/crates/storage/provider/src/test_utils/blocks.rs index d69bc585ac55..be4420fc5199 100644 --- a/crates/storage/provider/src/test_utils/blocks.rs +++ b/crates/storage/provider/src/test_utils/blocks.rs @@ -1,5 +1,5 @@ //! Dummy blocks and data for tests -use crate::{BlockExecutionOutcome, DatabaseProviderRW}; +use crate::{DatabaseProviderRW, ExecutionOutcome}; use alloy_primitives::Log; use alloy_rlp::Decodable; use reth_db::tables; @@ -68,7 +68,7 @@ pub struct BlockchainTestData { /// Genesis pub genesis: SealedBlock, /// Blocks with its execution result - pub blocks: Vec<(SealedBlockWithSenders, BlockExecutionOutcome)>, + pub blocks: Vec<(SealedBlockWithSenders, ExecutionOutcome)>, } impl BlockchainTestData { @@ -114,8 +114,8 @@ pub fn genesis() -> SealedBlock { } } -fn bundle_state_root(block_execution_outcome: &BlockExecutionOutcome) -> B256 { - state_root_unhashed(block_execution_outcome.bundle_accounts_iter().filter_map( +fn bundle_state_root(execution_outcome: &ExecutionOutcome) -> B256 { + state_root_unhashed(execution_outcome.bundle_accounts_iter().filter_map( |(address, account)| { account.info.as_ref().map(|info| { ( @@ -137,14 +137,14 @@ fn bundle_state_root(block_execution_outcome: &BlockExecutionOutcome) -> B256 { } /// Block one that points to genesis -fn block1(number: BlockNumber) -> (SealedBlockWithSenders, BlockExecutionOutcome) { +fn block1(number: BlockNumber) -> (SealedBlockWithSenders, ExecutionOutcome) { // block changes let account1: Address = [0x60; 20].into(); let account2: Address = [0x61; 20].into(); let slot = U256::from(5); let info = AccountInfo { nonce: 1, balance: U256::from(10), ..Default::default() }; - let block_execution_outcome = BlockExecutionOutcome::new( + let execution_outcome = ExecutionOutcome::new( BundleState::builder(number..=number) .state_present_account_info(account1, info.clone()) .revert_account_info(number, account1, Some(None)) @@ -171,7 +171,7 @@ fn block1(number: BlockNumber) -> (SealedBlockWithSenders, BlockExecutionOutcome Vec::new(), ); - let state_root = bundle_state_root(&block_execution_outcome); + let state_root = bundle_state_root(&execution_outcome); assert_eq!( state_root, b256!("5d035ccb3e75a9057452ff060b773b213ec1fc353426174068edfc3971a0b6bd") @@ -185,23 +185,20 @@ fn block1(number: BlockNumber) -> (SealedBlockWithSenders, BlockExecutionOutcome header.parent_hash = B256::ZERO; block.header = header.seal_slow(); - ( - SealedBlockWithSenders { block, senders: vec![Address::new([0x30; 20])] }, - block_execution_outcome, - ) + (SealedBlockWithSenders { block, senders: vec![Address::new([0x30; 20])] }, execution_outcome) } /// Block two that points to block 1 fn block2( number: BlockNumber, parent_hash: B256, - prev_block_execution_outcome: &BlockExecutionOutcome, -) -> (SealedBlockWithSenders, BlockExecutionOutcome) { + prev_execution_outcome: &ExecutionOutcome, +) -> (SealedBlockWithSenders, ExecutionOutcome) { // block changes let account: Address = [0x60; 20].into(); let slot = U256::from(5); - let block_execution_outcome = BlockExecutionOutcome::new( + let execution_outcome = ExecutionOutcome::new( BundleState::builder(number..=number) .state_present_account_info( account, @@ -234,8 +231,8 @@ fn block2( Vec::new(), ); - let mut extended = prev_block_execution_outcome.clone(); - extended.extend(block_execution_outcome.clone()); + let mut extended = prev_execution_outcome.clone(); + extended.extend(execution_outcome.clone()); let state_root = bundle_state_root(&extended); assert_eq!( state_root, @@ -252,18 +249,15 @@ fn block2( header.parent_hash = parent_hash; block.header = header.seal_slow(); - ( - SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, - block_execution_outcome, - ) + (SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, execution_outcome) } /// Block three that points to block 2 fn block3( number: BlockNumber, parent_hash: B256, - prev_block_execution_outcome: &BlockExecutionOutcome, -) -> (SealedBlockWithSenders, BlockExecutionOutcome) { + prev_execution_outcome: &ExecutionOutcome, +) -> (SealedBlockWithSenders, ExecutionOutcome) { let address_range = 1..=20; let slot_range = 1..=100; @@ -286,7 +280,7 @@ fn block3( .revert_account_info(number, address, Some(None)) .revert_storage(number, address, Vec::new()); } - let block_execution_outcome = BlockExecutionOutcome::new( + let execution_outcome = ExecutionOutcome::new( bundle_state_builder.build(), vec![vec![Some(Receipt { tx_type: TxType::Eip1559, @@ -307,8 +301,8 @@ fn block3( Vec::new(), ); - let mut extended = prev_block_execution_outcome.clone(); - extended.extend(block_execution_outcome.clone()); + let mut extended = prev_execution_outcome.clone(); + extended.extend(execution_outcome.clone()); let state_root = bundle_state_root(&extended); let mut block = SealedBlock::decode(&mut BLOCK_RLP.as_slice()).unwrap(); @@ -320,18 +314,15 @@ fn block3( header.parent_hash = parent_hash; block.header = header.seal_slow(); - ( - SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, - block_execution_outcome, - ) + (SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, execution_outcome) } /// Block four that points to block 3 fn block4( number: BlockNumber, parent_hash: B256, - prev_block_execution_outcome: &BlockExecutionOutcome, -) -> (SealedBlockWithSenders, BlockExecutionOutcome) { + prev_execution_outcome: &ExecutionOutcome, +) -> (SealedBlockWithSenders, ExecutionOutcome) { let address_range = 1..=20; let slot_range = 1..=100; @@ -380,7 +371,7 @@ fn block4( Vec::from_iter(slot_range.clone().map(|slot| (U256::from(slot), U256::from(slot)))), ); } - let block_execution_outcome = BlockExecutionOutcome::new( + let execution_outcome = ExecutionOutcome::new( bundle_state_builder.build(), vec![vec![Some(Receipt { tx_type: TxType::Eip1559, @@ -401,8 +392,8 @@ fn block4( Vec::new(), ); - let mut extended = prev_block_execution_outcome.clone(); - extended.extend(block_execution_outcome.clone()); + let mut extended = prev_execution_outcome.clone(); + extended.extend(execution_outcome.clone()); let state_root = bundle_state_root(&extended); let mut block = SealedBlock::decode(&mut BLOCK_RLP.as_slice()).unwrap(); @@ -414,18 +405,15 @@ fn block4( header.parent_hash = parent_hash; block.header = header.seal_slow(); - ( - SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, - block_execution_outcome, - ) + (SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, execution_outcome) } /// Block five that points to block 4 fn block5( number: BlockNumber, parent_hash: B256, - prev_block_execution_outcome: &BlockExecutionOutcome, -) -> (SealedBlockWithSenders, BlockExecutionOutcome) { + prev_execution_outcome: &ExecutionOutcome, +) -> (SealedBlockWithSenders, ExecutionOutcome) { let address_range = 1..=20; let slot_range = 1..=100; @@ -469,7 +457,7 @@ fn block5( bundle_state_builder.revert_address(number, address) }; } - let block_execution_outcome = BlockExecutionOutcome::new( + let execution_outcome = ExecutionOutcome::new( bundle_state_builder.build(), vec![vec![Some(Receipt { tx_type: TxType::Eip1559, @@ -490,8 +478,8 @@ fn block5( Vec::new(), ); - let mut extended = prev_block_execution_outcome.clone(); - extended.extend(block_execution_outcome.clone()); + let mut extended = prev_execution_outcome.clone(); + extended.extend(execution_outcome.clone()); let state_root = bundle_state_root(&extended); let mut block = SealedBlock::decode(&mut BLOCK_RLP.as_slice()).unwrap(); @@ -503,8 +491,5 @@ fn block5( header.parent_hash = parent_hash; block.header = header.seal_slow(); - ( - SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, - block_execution_outcome, - ) + (SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, execution_outcome) } diff --git a/crates/storage/provider/src/test_utils/mock.rs b/crates/storage/provider/src/test_utils/mock.rs index 1d29725d8910..5aa70eeeae7d 100644 --- a/crates/storage/provider/src/test_utils/mock.rs +++ b/crates/storage/provider/src/test_utils/mock.rs @@ -1,7 +1,7 @@ use crate::{ traits::{BlockSource, ReceiptProvider}, AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, - ChainSpecProvider, ChangeSetReader, EvmEnvProvider, FullBlockExecutionDataProvider, + ChainSpecProvider, ChangeSetReader, EvmEnvProvider, FullExecutionDataProvider, HeaderProvider, ReceiptProviderIdExt, RequestsProvider, StateProvider, StateProviderBox, StateProviderFactory, StateRootProvider, TransactionVariant, TransactionsProvider, WithdrawalsProvider, @@ -661,7 +661,7 @@ impl StateProviderFactory for MockEthProvider { fn pending_with_provider<'a>( &'a self, - _bundle_state_data: Box, + _bundle_state_data: Box, ) -> ProviderResult { Ok(Box::new(self.clone())) } diff --git a/crates/storage/provider/src/test_utils/noop.rs b/crates/storage/provider/src/test_utils/noop.rs index 135d383bcdb3..62422a811a9f 100644 --- a/crates/storage/provider/src/test_utils/noop.rs +++ b/crates/storage/provider/src/test_utils/noop.rs @@ -419,7 +419,7 @@ impl StateProviderFactory for NoopProvider { fn pending_with_provider<'a>( &'a self, - _bundle_state_data: Box, + _bundle_state_data: Box, ) -> ProviderResult { Ok(Box::new(*self)) } diff --git a/crates/storage/provider/src/traits/block.rs b/crates/storage/provider/src/traits/block.rs index f6a9081ac3a1..56255969e97b 100644 --- a/crates/storage/provider/src/traits/block.rs +++ b/crates/storage/provider/src/traits/block.rs @@ -1,4 +1,4 @@ -use crate::{BlockExecutionOutcome, Chain}; +use crate::{Chain, ExecutionOutcome}; use reth_db_api::models::StoredBlockBodyIndices; use reth_primitives::{BlockNumber, SealedBlockWithSenders}; use reth_prune_types::PruneModes; @@ -65,7 +65,7 @@ pub trait BlockWriter: Send + Sync { fn append_blocks_with_state( &self, blocks: Vec, - block_execution_outcome: BlockExecutionOutcome, + execution_outcome: ExecutionOutcome, hashed_state: HashedPostState, trie_updates: TrieUpdates, prune_modes: Option<&PruneModes>, diff --git a/crates/storage/provider/src/traits/chain.rs b/crates/storage/provider/src/traits/chain.rs index 82ba4db5007f..98957fcfdcc8 100644 --- a/crates/storage/provider/src/traits/chain.rs +++ b/crates/storage/provider/src/traits/chain.rs @@ -60,7 +60,7 @@ impl Stream for CanonStateNotificationStream { } /// Chain action that is triggered when a new block is imported or old block is reverted. -/// and will return all [`crate::BlockExecutionOutcome`] and +/// and will return all [`crate::ExecutionOutcome`] and /// [`reth_primitives::SealedBlockWithSenders`] of both reverted and committed blocks. #[derive(Clone, Debug)] pub enum CanonStateNotification { diff --git a/crates/storage/provider/src/traits/state.rs b/crates/storage/provider/src/traits/state.rs index 7fc7501b3e23..a774d0f5cc92 100644 --- a/crates/storage/provider/src/traits/state.rs +++ b/crates/storage/provider/src/traits/state.rs @@ -3,7 +3,7 @@ use reth_db_api::transaction::{DbTx, DbTxMut}; use reth_storage_errors::provider::ProviderResult; use revm::db::OriginalValuesKnown; -/// A helper trait for [`BlockExecutionOutcome`](reth_execution_types::BlockExecutionOutcome) to +/// A helper trait for [`ExecutionOutcome`](reth_execution_types::ExecutionOutcome) to /// write state and receipts to storage. pub trait StateWriter { /// Write the data and receipts to the database or static files if `static_file_producer` is diff --git a/crates/storage/storage-api/src/state.rs b/crates/storage/storage-api/src/state.rs index 28d96297f51d..b03eeb427c4a 100644 --- a/crates/storage/storage-api/src/state.rs +++ b/crates/storage/storage-api/src/state.rs @@ -1,6 +1,6 @@ use super::{AccountReader, BlockHashReader, BlockIdReader, StateRootProvider}; use auto_impl::auto_impl; -use reth_execution_types::BlockExecutionOutcome; +use reth_execution_types::ExecutionOutcome; use reth_primitives::{ proofs::AccountProof, Address, BlockHash, BlockId, BlockNumHash, BlockNumber, BlockNumberOrTag, Bytecode, StorageKey, StorageValue, B256, KECCAK_EMPTY, U256, @@ -178,7 +178,7 @@ pub trait StateProviderFactory: BlockIdReader + Send + Sync { /// Used to inspect or execute transaction on the pending state. fn pending_with_provider( &self, - bundle_state_data: Box, + bundle_state_data: Box, ) -> ProviderResult; } @@ -192,7 +192,7 @@ pub trait BlockchainTreePendingStateProvider: Send + Sync { fn pending_state_provider( &self, block_hash: BlockHash, - ) -> ProviderResult> { + ) -> ProviderResult> { self.find_pending_state_provider(block_hash) .ok_or(ProviderError::StateForHashNotFound(block_hash)) } @@ -201,7 +201,7 @@ pub trait BlockchainTreePendingStateProvider: Send + Sync { fn find_pending_state_provider( &self, block_hash: BlockHash, - ) -> Option>; + ) -> Option>; } /// Provides data required for post-block execution. @@ -210,19 +210,19 @@ pub trait BlockchainTreePendingStateProvider: Send + Sync { /// in accounts and storage, as well as block hashes for both the pending and canonical chains. /// /// The trait includes: -/// * [`BlockExecutionOutcome`] - Captures all account and storage changes in the pending chain. +/// * [`ExecutionOutcome`] - Captures all account and storage changes in the pending chain. /// * Block hashes - Provides access to the block hashes of both the pending chain and canonical /// blocks. #[auto_impl(&, Box)] -pub trait BlockExecutionDataProvider: Send + Sync { - /// Return the block execution outcome. - fn block_execution_outcome(&self) -> &BlockExecutionOutcome; +pub trait ExecutionDataProvider: Send + Sync { + /// Return the execution outcome. + fn execution_outcome(&self) -> &ExecutionOutcome; /// Return block hash by block number of pending or canonical chain. fn block_hash(&self, block_number: BlockNumber) -> Option; } -impl BlockExecutionDataProvider for BlockExecutionOutcome { - fn block_execution_outcome(&self) -> &BlockExecutionOutcome { +impl ExecutionDataProvider for ExecutionOutcome { + fn execution_outcome(&self) -> &ExecutionOutcome { self } @@ -246,19 +246,18 @@ pub trait BlockExecutionForkProvider { /// Provides comprehensive post-execution state data required for further execution. /// /// This trait is used to create a state provider over the pending state and is a combination of -/// [`BlockExecutionDataProvider`] and [`BlockExecutionForkProvider`]. +/// [`ExecutionDataProvider`] and [`BlockExecutionForkProvider`]. /// /// The pending state includes: -/// * `BlockExecutionOutcome`: Contains all changes to accounts and storage within the pending -/// chain. +/// * `ExecutionOutcome`: Contains all changes to accounts and storage within the pending chain. /// * Block hashes: Represents hashes of both the pending chain and canonical blocks. /// * Canonical fork: Denotes the block from which the pending chain forked. -pub trait FullBlockExecutionDataProvider: - BlockExecutionDataProvider + BlockExecutionForkProvider +pub trait FullExecutionDataProvider: + ExecutionDataProvider + BlockExecutionForkProvider { } -impl FullBlockExecutionDataProvider for T where - T: BlockExecutionDataProvider + BlockExecutionForkProvider +impl FullExecutionDataProvider for T where + T: ExecutionDataProvider + BlockExecutionForkProvider { } diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index bddc4e81717c..19177b4fd96f 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -18,7 +18,7 @@ use reth_primitives::{ TryFromRecoveredTransaction, }; use reth_provider::{ - BlockExecutionOutcome, BlockReaderIdExt, CanonStateNotification, ChainSpecProvider, + ExecutionOutcome, BlockReaderIdExt, CanonStateNotification, ChainSpecProvider, ProviderError, StateProviderFactory, }; use reth_tasks::TaskSpawner; @@ -556,9 +556,9 @@ where /// Extracts all changed accounts from the `BundleState` fn changed_accounts_iter( - block_execution_outcome: &BlockExecutionOutcome, + execution_outcome: &ExecutionOutcome, ) -> impl Iterator + '_ { - block_execution_outcome + execution_outcome .accounts_iter() .filter_map(|(addr, acc)| acc.map(|acc| (addr, acc))) .map(|(address, acc)| ChangedAccount { address, nonce: acc.nonce, balance: acc.balance }) diff --git a/examples/exex/in-memory-state/src/main.rs b/examples/exex/in-memory-state/src/main.rs index e9c0485e1487..21c8fae858ea 100644 --- a/examples/exex/in-memory-state/src/main.rs +++ b/examples/exex/in-memory-state/src/main.rs @@ -1,6 +1,6 @@ #![warn(unused_crate_dependencies)] -use reth::providers::BlockExecutionOutcome; +use reth::providers::ExecutionOutcome; use reth_exex::{ExExContext, ExExEvent, ExExNotification}; use reth_node_api::FullNodeComponents; use reth_node_ethereum::EthereumNode; @@ -8,8 +8,8 @@ use reth_tracing::tracing::info; /// An ExEx that keeps track of the entire state in memory async fn track_state(mut ctx: ExExContext) -> eyre::Result<()> { - // keeps the entire plain block execution outcome of the chain in memory - let mut block_execution_outcome = BlockExecutionOutcome::default(); + // keeps the entire plain execution outcome of the chain in memory + let mut execution_outcome = ExecutionOutcome::default(); while let Some(notification) = ctx.notifications.recv().await { match ¬ification { @@ -18,18 +18,18 @@ async fn track_state(mut ctx: ExExContext) -> ey } ExExNotification::ChainReorged { old, new } => { // revert to block before the reorg - block_execution_outcome.revert_to(new.first().number - 1); + execution_outcome.revert_to(new.first().number - 1); info!(from_chain = ?old.range(), to_chain = ?new.range(), "Received reorg"); } ExExNotification::ChainReverted { old } => { - block_execution_outcome.revert_to(old.first().number - 1); + execution_outcome.revert_to(old.first().number - 1); info!(reverted_chain = ?old.range(), "Received revert"); } }; if let Some(committed_chain) = notification.committed_chain() { - // extend the block execution outcome with the new chain - block_execution_outcome.extend(committed_chain.block_execution_outcome().clone()); + // extend the execution outcome with the new chain + execution_outcome.extend(committed_chain.execution_outcome().clone()); ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?; } } diff --git a/examples/exex/minimal/src/main.rs b/examples/exex/minimal/src/main.rs index a3c9d9ee421c..7fdf985f374c 100644 --- a/examples/exex/minimal/src/main.rs +++ b/examples/exex/minimal/src/main.rs @@ -54,7 +54,7 @@ fn main() -> eyre::Result<()> { #[cfg(test)] mod tests { - use reth::providers::{BlockExecutionOutcome, Chain}; + use reth::providers::{ExecutionOutcome, Chain}; use reth_exex_test_utils::{test_exex_context, PollOnce}; use std::pin::pin; @@ -70,7 +70,7 @@ mod tests { handle .send_notification_chain_committed(Chain::from_block( handle.genesis.clone(), - BlockExecutionOutcome::default(), + ExecutionOutcome::default(), None, )) .await?; diff --git a/examples/exex/op-bridge/src/main.rs b/examples/exex/op-bridge/src/main.rs index 2a50c7df4dbd..0e7d01202ebd 100644 --- a/examples/exex/op-bridge/src/main.rs +++ b/examples/exex/op-bridge/src/main.rs @@ -264,7 +264,7 @@ mod tests { Address, Block, Header, Log, Receipt, Transaction, TransactionSigned, TxKind, TxLegacy, TxType, U256, }; - use reth_provider::{BlockExecutionOutcome, Chain}; + use reth_provider::{ExecutionOutcome, Chain}; use reth_testing_utils::generators::sign_tx_with_random_key_pair; use rusqlite::Connection; @@ -341,7 +341,7 @@ mod tests { // Construct a chain let chain = Chain::new( vec![block.clone()], - BlockExecutionOutcome::new( + ExecutionOutcome::new( BundleState::default(), vec![deposit_tx_receipt, withdrawal_tx_receipt].into(), block.number, From 1bd67d36d87446c5a35272b70a91124b302756cb Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Tue, 11 Jun 2024 17:31:50 +0200 Subject: [PATCH 8/9] fix conflicts --- crates/evm/execution-types/src/bundle.rs | 32 ++++++++--------- examples/exex/in-memory-state/src/main.rs | 42 ++++++++++++----------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/crates/evm/execution-types/src/bundle.rs b/crates/evm/execution-types/src/bundle.rs index 0da45fabd8ed..09f950a624d5 100644 --- a/crates/evm/execution-types/src/bundle.rs +++ b/crates/evm/execution-types/src/bundle.rs @@ -377,18 +377,18 @@ mod tests { // Define the first block number let first_block = 123; - // Create a BundleStateWithReceipts object with the created bundle, receipts, requests, and + // Create a ExecutionOutcome object with the created bundle, receipts, requests, and // first_block - let exec_res = BundleStateWithReceipts { + let exec_res = ExecutionOutcome { bundle: bundle.clone(), receipts: receipts.clone(), requests: requests.clone(), first_block, }; - // Assert that creating a new BundleStateWithReceipts using the constructor matches exec_res + // Assert that creating a new ExecutionOutcome using the constructor matches exec_res assert_eq!( - BundleStateWithReceipts::new(bundle, receipts.clone(), first_block, requests.clone()), + ExecutionOutcome::new(bundle, receipts.clone(), first_block, requests.clone()), exec_res ); @@ -405,10 +405,10 @@ mod tests { let mut revert_init: RevertsInit = HashMap::new(); revert_init.insert(123, revert_inner); - // Assert that creating a new BundleStateWithReceipts using the new_init method matches + // Assert that creating a new ExecutionOutcome using the new_init method matches // exec_res assert_eq!( - BundleStateWithReceipts::new_init( + ExecutionOutcome::new_init( state_init, revert_init, vec![], @@ -439,9 +439,9 @@ mod tests { // Define the first block number let first_block = 123; - // Create a BundleStateWithReceipts object with the created bundle, receipts, requests, and + // Create a ExecutionOutcome object with the created bundle, receipts, requests, and // first_block - let exec_res = BundleStateWithReceipts { + let exec_res = ExecutionOutcome { bundle: Default::default(), receipts, requests: vec![], @@ -477,9 +477,9 @@ mod tests { // Define the first block number let first_block = 123; - // Create a BundleStateWithReceipts object with the created bundle, receipts, requests, and + // Create a ExecutionOutcome object with the created bundle, receipts, requests, and // first_block - let exec_res = BundleStateWithReceipts { + let exec_res = ExecutionOutcome { bundle: Default::default(), receipts, requests: vec![], @@ -512,9 +512,9 @@ mod tests { // Define the first block number let first_block = 123; - // Create a BundleStateWithReceipts object with the created bundle, receipts, requests, and + // Create a ExecutionOutcome object with the created bundle, receipts, requests, and // first_block - let exec_res = BundleStateWithReceipts { + let exec_res = ExecutionOutcome { bundle: Default::default(), // Default value for bundle receipts, // Include the created receipts requests: vec![], // Empty vector for requests @@ -562,9 +562,9 @@ mod tests { // Define the first block number let first_block = 123; - // Create a BundleStateWithReceipts object with the created bundle, receipts, requests, and + // Create a ExecutionOutcome object with the created bundle, receipts, requests, and // first_block - let exec_res = BundleStateWithReceipts { + let exec_res = ExecutionOutcome { bundle: Default::default(), // Default value for bundle receipts, // Include the created receipts requests: vec![], // Empty vector for requests @@ -577,8 +577,8 @@ mod tests { // Assert that exec_res is not empty assert!(!exec_res.is_empty()); - // Create a BundleStateWithReceipts object with an empty Receipts object - let exec_res_empty_receipts = BundleStateWithReceipts { + // Create a ExecutionOutcome object with an empty Receipts object + let exec_res_empty_receipts = ExecutionOutcome { bundle: Default::default(), // Default value for bundle receipts: receipts_empty, // Include the empty receipts requests: vec![], // Empty vector for requests diff --git a/examples/exex/in-memory-state/src/main.rs b/examples/exex/in-memory-state/src/main.rs index 4362e2b65a1d..cd683147ff05 100644 --- a/examples/exex/in-memory-state/src/main.rs +++ b/examples/exex/in-memory-state/src/main.rs @@ -15,14 +15,14 @@ use std::{ struct InMemoryStateExEx { /// The context of the ExEx ctx: ExExContext, - /// Entire plain state of the chain - state: BundleStateWithReceipts, + /// Execution outcome of the chain + execution_outcome: ExecutionOutcome, } impl InMemoryStateExEx { /// Create a new instance of the ExEx fn new(ctx: ExExContext) -> Self { - Self { ctx, state: BundleStateWithReceipts::default() } + Self { ctx, execution_outcome: ExecutionOutcome::default() } } } @@ -39,18 +39,18 @@ impl Future for InMemoryStateExEx { } ExExNotification::ChainReorged { old, new } => { // revert to block before the reorg - this.state.revert_to(new.first().number - 1); + this.execution_outcome.revert_to(new.first().number - 1); info!(from_chain = ?old.range(), to_chain = ?new.range(), "Received reorg"); } ExExNotification::ChainReverted { old } => { - this.state.revert_to(old.first().number - 1); + this.execution_outcome.revert_to(old.first().number - 1); info!(reverted_chain = ?old.range(), "Received revert"); } }; if let Some(committed_chain) = notification.committed_chain() { // extend the state with the new chain - this.state.extend(committed_chain.state().clone()); + this.execution_outcome.extend(committed_chain.execution_outcome().clone()); this.ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?; } } @@ -76,7 +76,7 @@ mod tests { use std::pin::pin; use reth::{ - providers::{BundleStateWithReceipts, Chain}, + providers::{Chain, ExecutionOutcome}, revm::db::BundleState, }; use reth_exex_test_utils::{test_exex_context, PollOnce}; @@ -89,60 +89,62 @@ mod tests { let (ctx, handle) = test_exex_context().await?; let mut exex = pin!(super::InMemoryStateExEx::new(ctx)); - let mut expected_state = BundleStateWithReceipts::default(); + let mut expected_state = ExecutionOutcome::default(); // Generate first block and its state let block_1 = random_block(&mut rng, 0, None, Some(1), None) .seal_with_senders() .ok_or(eyre::eyre!("failed to recover senders"))?; let block_number_1 = block_1.number; - let state_1 = BundleStateWithReceipts::new( + let execution_outcome1 = ExecutionOutcome::new( BundleState::default(), vec![random_receipt(&mut rng, &block_1.body[0], None)].into(), block_1.number, vec![], ); // Extend the expected state with the first block - expected_state.extend(state_1.clone()); + expected_state.extend(execution_outcome1.clone()); // Send a notification to the Execution Extension that the chain with the first block has // been committed - handle.send_notification_chain_committed(Chain::new(vec![block_1], state_1, None)).await?; + handle + .send_notification_chain_committed(Chain::new(vec![block_1], execution_outcome1, None)) + .await?; exex.poll_once().await?; // Assert that the state of the first block has been added to the total state - assert_eq!(exex.as_mut().state, expected_state); + assert_eq!(exex.as_mut().execution_outcome, expected_state); // Generate second block and its state let block_2 = random_block(&mut rng, 1, None, Some(2), None) .seal_with_senders() .ok_or(eyre::eyre!("failed to recover senders"))?; - let state_2 = BundleStateWithReceipts::new( + let execution_outcome2 = ExecutionOutcome::new( BundleState::default(), vec![random_receipt(&mut rng, &block_2.body[0], None)].into(), block_2.number, vec![], ); - // Extend the expected state with the second block - expected_state.extend(state_2.clone()); + // Extend the expected execution outcome with the second block + expected_state.extend(execution_outcome2.clone()); // Send a notification to the Execution Extension that the chain with the second block has // been committed - let chain_2 = Chain::new(vec![block_2], state_2, None); + let chain_2 = Chain::new(vec![block_2], execution_outcome2, None); handle.send_notification_chain_committed(chain_2.clone()).await?; exex.poll_once().await?; - // Assert that the state of the second block has been added to the total state - assert_eq!(exex.as_mut().state, expected_state); + // Assert that the execution outcome of the second block has been added to the total state + assert_eq!(exex.as_mut().execution_outcome, expected_state); // Send a notification to the Execution Extension that the chain with the second block has // been reverted handle.send_notification_chain_reverted(chain_2).await?; exex.poll_once().await?; - // Assert that the state of the second block has been reverted + // Assert that the execution outcome of the second block has been reverted expected_state.revert_to(block_number_1); - assert_eq!(exex.as_mut().state, expected_state); + assert_eq!(exex.as_mut().execution_outcome, expected_state); Ok(()) } From 03df3e2863a1d7b38c55a08bd12435ab10cd49cd Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Tue, 11 Jun 2024 17:54:16 +0200 Subject: [PATCH 9/9] fmt --- crates/consensus/auto-seal/src/lib.rs | 4 +--- crates/optimism/payload/src/builder.rs | 11 +++-------- crates/stages/stages/src/stages/execution.rs | 2 +- crates/stages/stages/src/stages/headers.rs | 2 +- crates/storage/provider/src/test_utils/mock.rs | 7 +++---- crates/storage/storage-api/src/state.rs | 10 ++-------- crates/transaction-pool/src/maintain.rs | 4 ++-- examples/exex/minimal/src/main.rs | 2 +- examples/exex/op-bridge/src/main.rs | 2 +- 9 files changed, 15 insertions(+), 29 deletions(-) diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index 7447e9aa8d87..ada2936ff1b2 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -26,9 +26,7 @@ use reth_primitives::{ ChainSpec, Header, Requests, SealedBlock, SealedHeader, TransactionSigned, Withdrawals, B256, U256, }; -use reth_provider::{ - ExecutionOutcome, BlockReaderIdExt, StateProviderFactory, StateRootProvider, -}; +use reth_provider::{BlockReaderIdExt, ExecutionOutcome, StateProviderFactory, StateRootProvider}; use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::TransactionPool; use std::{ diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 09a4e82ce75d..b21e80c53f04 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -506,12 +506,8 @@ where // and 4788 contract call db.merge_transitions(BundleRetention::PlainState); - let execution_outcome = ExecutionOutcome::new( - db.take_bundle(), - vec![receipts].into(), - block_number, - Vec::new(), - ); + let execution_outcome = + ExecutionOutcome::new(db.take_bundle(), vec![receipts].into(), block_number, Vec::new()); let receipts_root = execution_outcome .optimism_receipts_root_slow( block_number, @@ -519,8 +515,7 @@ where attributes.payload_attributes.timestamp, ) .expect("Number is in range"); - let logs_bloom = - execution_outcome.block_logs_bloom(block_number).expect("Number is in range"); + let logs_bloom = execution_outcome.block_logs_bloom(block_number).expect("Number is in range"); // calculate the state root let state_root = { diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index 9fe06d547229..0bf19cd68933 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -8,7 +8,7 @@ use reth_exex::{ExExManagerHandle, ExExNotification}; use reth_primitives::{BlockNumber, Header, StaticFileSegment}; use reth_provider::{ providers::{StaticFileProvider, StaticFileProviderRWRefMut, StaticFileWriter}, - ExecutionOutcome, BlockReader, Chain, DatabaseProviderRW, HeaderProvider, + BlockReader, Chain, DatabaseProviderRW, ExecutionOutcome, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderError, StateWriter, StatsReader, TransactionVariant, }; diff --git a/crates/stages/stages/src/stages/headers.rs b/crates/stages/stages/src/stages/headers.rs index 6aa464b89192..21d3ad4ab628 100644 --- a/crates/stages/stages/src/stages/headers.rs +++ b/crates/stages/stages/src/stages/headers.rs @@ -378,7 +378,7 @@ mod tests { use assert_matches::assert_matches; use reth_primitives::{BlockBody, SealedBlock, SealedBlockWithSenders, B256}; use reth_provider::{ - ExecutionOutcome, BlockWriter, ProviderFactory, StaticFileProviderFactory, + BlockWriter, ExecutionOutcome, ProviderFactory, StaticFileProviderFactory, }; use reth_stages_api::StageUnitCheckpoint; use reth_testing_utils::generators::{self, random_header, random_header_range}; diff --git a/crates/storage/provider/src/test_utils/mock.rs b/crates/storage/provider/src/test_utils/mock.rs index 5aa70eeeae7d..3a10c27541f6 100644 --- a/crates/storage/provider/src/test_utils/mock.rs +++ b/crates/storage/provider/src/test_utils/mock.rs @@ -1,10 +1,9 @@ use crate::{ traits::{BlockSource, ReceiptProvider}, AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, - ChainSpecProvider, ChangeSetReader, EvmEnvProvider, FullExecutionDataProvider, - HeaderProvider, ReceiptProviderIdExt, RequestsProvider, StateProvider, StateProviderBox, - StateProviderFactory, StateRootProvider, TransactionVariant, TransactionsProvider, - WithdrawalsProvider, + ChainSpecProvider, ChangeSetReader, EvmEnvProvider, FullExecutionDataProvider, HeaderProvider, + ReceiptProviderIdExt, RequestsProvider, StateProvider, StateProviderBox, StateProviderFactory, + StateRootProvider, TransactionVariant, TransactionsProvider, WithdrawalsProvider, }; use parking_lot::Mutex; use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices}; diff --git a/crates/storage/storage-api/src/state.rs b/crates/storage/storage-api/src/state.rs index b03eeb427c4a..9e258bfd1656 100644 --- a/crates/storage/storage-api/src/state.rs +++ b/crates/storage/storage-api/src/state.rs @@ -252,12 +252,6 @@ pub trait BlockExecutionForkProvider { /// * `ExecutionOutcome`: Contains all changes to accounts and storage within the pending chain. /// * Block hashes: Represents hashes of both the pending chain and canonical blocks. /// * Canonical fork: Denotes the block from which the pending chain forked. -pub trait FullExecutionDataProvider: - ExecutionDataProvider + BlockExecutionForkProvider -{ -} +pub trait FullExecutionDataProvider: ExecutionDataProvider + BlockExecutionForkProvider {} -impl FullExecutionDataProvider for T where - T: ExecutionDataProvider + BlockExecutionForkProvider -{ -} +impl FullExecutionDataProvider for T where T: ExecutionDataProvider + BlockExecutionForkProvider {} diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 19177b4fd96f..02c259f9a0a9 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -18,8 +18,8 @@ use reth_primitives::{ TryFromRecoveredTransaction, }; use reth_provider::{ - ExecutionOutcome, BlockReaderIdExt, CanonStateNotification, ChainSpecProvider, - ProviderError, StateProviderFactory, + BlockReaderIdExt, CanonStateNotification, ChainSpecProvider, ExecutionOutcome, ProviderError, + StateProviderFactory, }; use reth_tasks::TaskSpawner; use std::{ diff --git a/examples/exex/minimal/src/main.rs b/examples/exex/minimal/src/main.rs index 7fdf985f374c..7f6d4585559e 100644 --- a/examples/exex/minimal/src/main.rs +++ b/examples/exex/minimal/src/main.rs @@ -54,7 +54,7 @@ fn main() -> eyre::Result<()> { #[cfg(test)] mod tests { - use reth::providers::{ExecutionOutcome, Chain}; + use reth::providers::{Chain, ExecutionOutcome}; use reth_exex_test_utils::{test_exex_context, PollOnce}; use std::pin::pin; diff --git a/examples/exex/op-bridge/src/main.rs b/examples/exex/op-bridge/src/main.rs index 0e7d01202ebd..aebe90e193c5 100644 --- a/examples/exex/op-bridge/src/main.rs +++ b/examples/exex/op-bridge/src/main.rs @@ -264,7 +264,7 @@ mod tests { Address, Block, Header, Log, Receipt, Transaction, TransactionSigned, TxKind, TxLegacy, TxType, U256, }; - use reth_provider::{ExecutionOutcome, Chain}; + use reth_provider::{Chain, ExecutionOutcome}; use reth_testing_utils::generators::sign_tx_with_random_key_pair; use rusqlite::Connection;