From 9f61d1856f3c8ae69066802e4c22880e9ba56c74 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 24 May 2024 12:11:08 +0200 Subject: [PATCH] chore: extract block execution errors (#8386) --- Cargo.lock | 15 +++++++++++++-- Cargo.toml | 2 ++ crates/ethereum/evm/Cargo.toml | 1 - crates/ethereum/evm/src/execute.rs | 8 ++------ crates/evm/Cargo.toml | 4 +++- crates/evm/execution-errors/Cargo.toml | 18 ++++++++++++++++++ .../execution-errors/src/lib.rs} | 15 ++++++++++++++- .../execution-errors/src/trie.rs} | 6 ++++-- crates/evm/src/either.rs | 3 ++- crates/evm/src/execute.rs | 4 +++- crates/evm/src/test_utils.rs | 3 ++- crates/interfaces/Cargo.toml | 7 ++++--- crates/interfaces/src/blockchain_tree/error.rs | 8 +++----- crates/interfaces/src/error.rs | 9 +++------ crates/interfaces/src/lib.rs | 4 ++-- crates/optimism/evm/src/error.rs | 2 +- crates/optimism/evm/src/execute.rs | 8 ++------ 17 files changed, 78 insertions(+), 39 deletions(-) create mode 100644 crates/evm/execution-errors/Cargo.toml rename crates/{interfaces/src/executor.rs => evm/execution-errors/src/lib.rs} (90%) rename crates/{interfaces/src/trie/mod.rs => evm/execution-errors/src/trie.rs} (86%) diff --git a/Cargo.lock b/Cargo.lock index bde7478c0..a32af6233 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6962,8 +6962,9 @@ version = "0.2.0-beta.7" dependencies = [ "futures-util", "parking_lot 0.12.2", - "reth-interfaces", + "reth-execution-errors", "reth-primitives", + "reth-storage-errors", "revm", "revm-primitives", ] @@ -6975,7 +6976,6 @@ dependencies = [ "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=64feb9b)", "reth-ethereum-consensus", "reth-evm", - "reth-interfaces", "reth-primitives", "reth-revm", "revm-primitives", @@ -6998,6 +6998,16 @@ dependencies = [ "tracing", ] +[[package]] +name = "reth-execution-errors" +version = "0.2.0-beta.7" +dependencies = [ + "reth-consensus", + "reth-primitives", + "reth-storage-errors", + "thiserror", +] + [[package]] name = "reth-exex" version = "0.2.0-beta.7" @@ -7032,6 +7042,7 @@ version = "0.2.0-beta.7" dependencies = [ "auto_impl", "reth-consensus", + "reth-execution-errors", "reth-fs-util", "reth-network-api", "reth-network-p2p", diff --git a/Cargo.toml b/Cargo.toml index 2fd78aeeb..b1ab9e1eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ members = [ "crates/ethereum/node", "crates/etl/", "crates/evm/", + "crates/evm/execution-errors", "crates/exex/", "crates/interfaces/", "crates/metrics/", @@ -238,6 +239,7 @@ reth-etl = { path = "crates/etl" } reth-evm = { path = "crates/evm" } reth-evm-ethereum = { path = "crates/ethereum/evm" } reth-evm-optimism = { path = "crates/optimism/evm" } +reth-execution-errors = { path = "crates/evm/execution-errors" } reth-exex = { path = "crates/exex" } reth-fs-util = { path = "crates/fs-util" } reth-interfaces = { path = "crates/interfaces" } diff --git a/crates/ethereum/evm/Cargo.toml b/crates/ethereum/evm/Cargo.toml index c4811b59f..88e5967e5 100644 --- a/crates/ethereum/evm/Cargo.toml +++ b/crates/ethereum/evm/Cargo.toml @@ -15,7 +15,6 @@ workspace = true reth-evm.workspace = true reth-primitives.workspace = true reth-revm.workspace = true -reth-interfaces.workspace = true reth-ethereum-consensus.workspace = true # Ethereum diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index 5addc45ac..999892706 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -7,15 +7,11 @@ use crate::{ use reth_ethereum_consensus::validate_block_post_execution; use reth_evm::{ execute::{ - BatchBlockExecutionOutput, BatchExecutor, BlockExecutionInput, BlockExecutionOutput, - BlockExecutorProvider, Executor, + BatchBlockExecutionOutput, BatchExecutor, BlockExecutionError, BlockExecutionInput, + BlockExecutionOutput, BlockExecutorProvider, BlockValidationError, Executor, ProviderError, }, ConfigureEvm, }; -use reth_interfaces::{ - executor::{BlockExecutionError, BlockValidationError}, - provider::ProviderError, -}; use reth_primitives::{ BlockNumber, BlockWithSenders, ChainSpec, Hardfork, Header, PruneModes, Receipt, Withdrawals, MAINNET, U256, diff --git a/crates/evm/Cargo.toml b/crates/evm/Cargo.toml index 854dcd95a..183d9f694 100644 --- a/crates/evm/Cargo.toml +++ b/crates/evm/Cargo.toml @@ -12,10 +12,12 @@ workspace = true [dependencies] # reth +reth-execution-errors.workspace = true reth-primitives.workspace = true revm-primitives.workspace = true +reth-storage-errors.workspace = true + revm.workspace = true -reth-interfaces.workspace = true futures-util.workspace = true parking_lot = { workspace = true, optional = true } diff --git a/crates/evm/execution-errors/Cargo.toml b/crates/evm/execution-errors/Cargo.toml new file mode 100644 index 000000000..c04b2b122 --- /dev/null +++ b/crates/evm/execution-errors/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "reth-execution-errors" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[lints] +workspace = true + +[dependencies] +reth-consensus.workspace = true +reth-primitives.workspace = true +reth-storage-errors.workspace = true + +thiserror.workspace = true diff --git a/crates/interfaces/src/executor.rs b/crates/evm/execution-errors/src/lib.rs similarity index 90% rename from crates/interfaces/src/executor.rs rename to crates/evm/execution-errors/src/lib.rs index 0620d032a..5013e5387 100644 --- a/crates/interfaces/src/executor.rs +++ b/crates/evm/execution-errors/src/lib.rs @@ -1,8 +1,21 @@ -use crate::{provider::ProviderError, trie::StateRootError}; +//! Commonly used error types used when doing block execution. + +#![doc( + html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png", + html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", + issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" +)] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + use reth_consensus::ConsensusError; use reth_primitives::{revm_primitives::EVMError, BlockNumHash, PruneSegmentError, B256}; +use reth_storage_errors::provider::ProviderError; use thiserror::Error; +pub mod trie; +pub use trie::{StateRootError, StorageRootError}; + /// Transaction validation errors #[derive(Error, Debug, Clone, PartialEq, Eq)] pub enum BlockValidationError { diff --git a/crates/interfaces/src/trie/mod.rs b/crates/evm/execution-errors/src/trie.rs similarity index 86% rename from crates/interfaces/src/trie/mod.rs rename to crates/evm/execution-errors/src/trie.rs index d2dba7c27..146f72f48 100644 --- a/crates/interfaces/src/trie/mod.rs +++ b/crates/evm/execution-errors/src/trie.rs @@ -1,7 +1,9 @@ -use crate::db::DatabaseError; +//! Errors when computing the state root. + +use reth_storage_errors::db::DatabaseError; use thiserror::Error; -/// State root error. +/// State root errors. #[derive(Error, Debug, PartialEq, Eq, Clone)] pub enum StateRootError { /// Internal database error. diff --git a/crates/evm/src/either.rs b/crates/evm/src/either.rs index ae1c95461..7d8320c31 100644 --- a/crates/evm/src/either.rs +++ b/crates/evm/src/either.rs @@ -4,8 +4,9 @@ use crate::execute::{ BatchBlockExecutionOutput, BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor, }; -use reth_interfaces::{executor::BlockExecutionError, provider::ProviderError}; +use reth_execution_errors::BlockExecutionError; use reth_primitives::{BlockNumber, BlockWithSenders, PruneModes, Receipt}; +use reth_storage_errors::provider::ProviderError; use revm_primitives::db::Database; // re-export Either diff --git a/crates/evm/src/execute.rs b/crates/evm/src/execute.rs index 693512268..6fdd6ebfd 100644 --- a/crates/evm/src/execute.rs +++ b/crates/evm/src/execute.rs @@ -1,10 +1,12 @@ //! Traits for execution. -use reth_interfaces::{executor::BlockExecutionError, provider::ProviderError}; use reth_primitives::{BlockNumber, BlockWithSenders, PruneModes, Receipt, Receipts, U256}; use revm::db::BundleState; use revm_primitives::db::Database; +pub use reth_execution_errors::{BlockExecutionError, BlockValidationError}; +pub use reth_storage_errors::provider::ProviderError; + /// A general purpose executor trait that executes an input (e.g. block) and produces an output /// (e.g. state changes and receipts). /// diff --git a/crates/evm/src/test_utils.rs b/crates/evm/src/test_utils.rs index 8d5b52682..910f9d08b 100644 --- a/crates/evm/src/test_utils.rs +++ b/crates/evm/src/test_utils.rs @@ -5,8 +5,9 @@ use crate::execute::{ BlockExecutorProvider, Executor, }; use parking_lot::Mutex; -use reth_interfaces::{executor::BlockExecutionError, provider::ProviderError}; +use reth_execution_errors::BlockExecutionError; use reth_primitives::{BlockNumber, BlockWithSenders, PruneModes, Receipt}; +use reth_storage_errors::provider::ProviderError; use revm_primitives::db::Database; use std::sync::Arc; diff --git a/crates/interfaces/Cargo.toml b/crates/interfaces/Cargo.toml index 6aec8a413..67891f5c7 100644 --- a/crates/interfaces/Cargo.toml +++ b/crates/interfaces/Cargo.toml @@ -11,12 +11,13 @@ repository.workspace = true workspace = true [dependencies] -reth-primitives.workspace = true +reth-consensus.workspace = true +reth-execution-errors.workspace = true reth-fs-util.workspace = true reth-network-api.workspace = true -reth-consensus.workspace = true -reth-storage-errors.workspace = true reth-network-p2p.workspace = true +reth-primitives.workspace = true +reth-storage-errors.workspace = true # misc auto_impl.workspace = true diff --git a/crates/interfaces/src/blockchain_tree/error.rs b/crates/interfaces/src/blockchain_tree/error.rs index 379b9f141..122b85743 100644 --- a/crates/interfaces/src/blockchain_tree/error.rs +++ b/crates/interfaces/src/blockchain_tree/error.rs @@ -1,12 +1,10 @@ //! Error handling for the blockchain tree -use crate::{ - executor::{BlockExecutionError, BlockValidationError}, - provider::ProviderError, - RethError, -}; +use crate::RethError; use reth_consensus::ConsensusError; +use reth_execution_errors::{BlockExecutionError, BlockValidationError}; use reth_primitives::{BlockHash, BlockNumber, SealedBlock}; +use reth_storage_errors::provider::ProviderError; /// Various error cases that can occur when a block violates tree assumptions. #[derive(Debug, Clone, Copy, thiserror::Error, Eq, PartialEq)] diff --git a/crates/interfaces/src/error.rs b/crates/interfaces/src/error.rs index ec3da8ad0..f38742ab5 100644 --- a/crates/interfaces/src/error.rs +++ b/crates/interfaces/src/error.rs @@ -1,12 +1,9 @@ -use crate::{ - blockchain_tree::error::{BlockchainTreeError, CanonicalError}, - db::DatabaseError, - executor::BlockExecutionError, - provider::ProviderError, -}; +use crate::blockchain_tree::error::{BlockchainTreeError, CanonicalError}; use reth_consensus::ConsensusError; +use reth_execution_errors::BlockExecutionError; use reth_fs_util::FsPathError; use reth_network_api::NetworkError; +use reth_storage_errors::{db::DatabaseError, provider::ProviderError}; /// Result alias for [`RethError`]. pub type RethResult = Result; diff --git a/crates/interfaces/src/lib.rs b/crates/interfaces/src/lib.rs index bd92f9d8d..dd96e2358 100644 --- a/crates/interfaces/src/lib.rs +++ b/crates/interfaces/src/lib.rs @@ -16,7 +16,7 @@ pub use reth_storage_errors::{db, provider}; /// Block Execution traits. -pub mod executor; +pub use reth_execution_errors as executor; /// Possible errors when interacting with the chain. mod error; @@ -26,7 +26,7 @@ pub use error::{RethError, RethResult}; pub use reth_network_p2p as p2p; /// Trie error -pub mod trie; +pub use reth_execution_errors::trie; /// Syncing related traits. pub mod sync; diff --git a/crates/optimism/evm/src/error.rs b/crates/optimism/evm/src/error.rs index de923d44c..1041f30c8 100644 --- a/crates/optimism/evm/src/error.rs +++ b/crates/optimism/evm/src/error.rs @@ -1,6 +1,6 @@ //! Error types for the Optimism EVM module. -use reth_interfaces::executor::BlockExecutionError; +use reth_evm::execute::BlockExecutionError; /// Optimism Block Executor Errors #[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)] diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 44bef823d..7df033dc5 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -3,15 +3,11 @@ use crate::{l1::ensure_create2_deployer, OptimismBlockExecutionError, OptimismEvmConfig}; use reth_evm::{ execute::{ - BatchBlockExecutionOutput, BatchExecutor, BlockExecutionInput, BlockExecutionOutput, - BlockExecutorProvider, Executor, + BatchBlockExecutionOutput, BatchExecutor, BlockExecutionError, BlockExecutionInput, + BlockExecutionOutput, BlockExecutorProvider, BlockValidationError, Executor, ProviderError, }, ConfigureEvm, }; -use reth_interfaces::{ - executor::{BlockExecutionError, BlockValidationError}, - provider::ProviderError, -}; use reth_optimism_consensus::validate_block_post_execution; use reth_primitives::{ BlockNumber, BlockWithSenders, ChainSpec, Hardfork, Header, PruneModes, Receipt, Receipts,