From 39f936ede20ee8fc08e87528dbd7215856cae726 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Tue, 3 Dec 2024 15:20:15 +0100 Subject: [PATCH] chore: move sparse errors to `reth-execution-errors` (#13101) --- Cargo.lock | 1 + crates/engine/tree/src/tree/root.rs | 5 +- crates/evm/execution-errors/src/trie.rs | 59 +++++++++++++++++++++++- crates/trie/sparse/Cargo.toml | 3 +- crates/trie/sparse/src/blinded.rs | 2 +- crates/trie/sparse/src/errors.rs | 61 ------------------------- crates/trie/sparse/src/lib.rs | 10 ++-- crates/trie/sparse/src/state.rs | 3 +- crates/trie/sparse/src/trie.rs | 6 +-- crates/trie/trie/src/proof/blinded.rs | 6 +-- 10 files changed, 78 insertions(+), 78 deletions(-) delete mode 100644 crates/trie/sparse/src/errors.rs diff --git a/Cargo.lock b/Cargo.lock index 8c290d0ea9fc..0f001fea0920 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9537,6 +9537,7 @@ dependencies = [ "proptest", "proptest-arbitrary-interop", "rand 0.8.5", + "reth-execution-errors", "reth-primitives-traits", "reth-testing-utils", "reth-tracing", diff --git a/crates/engine/tree/src/tree/root.rs b/crates/engine/tree/src/tree/root.rs index d65d1f89000a..78a8332b5ebc 100644 --- a/crates/engine/tree/src/tree/root.rs +++ b/crates/engine/tree/src/tree/root.rs @@ -10,7 +10,10 @@ use reth_trie::{ }; use reth_trie_db::DatabaseProof; use reth_trie_parallel::root::ParallelStateRootError; -use reth_trie_sparse::{SparseStateTrie, SparseStateTrieResult, SparseTrieError}; +use reth_trie_sparse::{ + errors::{SparseStateTrieResult, SparseTrieError}, + SparseStateTrie, +}; use revm_primitives::{keccak256, EvmState, B256}; use std::{ collections::BTreeMap, diff --git a/crates/evm/execution-errors/src/trie.rs b/crates/evm/execution-errors/src/trie.rs index 4d3398e41616..83210faab52f 100644 --- a/crates/evm/execution-errors/src/trie.rs +++ b/crates/evm/execution-errors/src/trie.rs @@ -1,7 +1,7 @@ //! Errors when computing the state root. -use alloc::string::ToString; -use alloy_primitives::B256; +use alloc::{boxed::Box, string::ToString}; +use alloy_primitives::{Bytes, B256}; use nybbles::Nibbles; use reth_storage_errors::{db::DatabaseError, provider::ProviderError}; use thiserror::Error; @@ -62,6 +62,61 @@ impl From for ProviderError { } } +/// Result type with [`SparseStateTrieError`] as error. +pub type SparseStateTrieResult = Result; + +/// Error encountered in `SparseStateTrie`. +#[derive(Error, Debug)] +pub enum SparseStateTrieError { + /// Encountered invalid root node. + #[error("invalid root node at {path:?}: {node:?}")] + InvalidRootNode { + /// Path to first proof node. + path: Nibbles, + /// Encoded first proof node. + node: Bytes, + }, + /// Sparse trie error. + #[error(transparent)] + Sparse(#[from] SparseTrieError), + /// RLP error. + #[error(transparent)] + Rlp(#[from] alloy_rlp::Error), +} + +/// Result type with [`SparseTrieError`] as error. +pub type SparseTrieResult = Result; + +/// Error encountered in `SparseTrie`. +#[derive(Error, Debug)] +pub enum SparseTrieError { + /// Sparse trie is still blind. Thrown on attempt to update it. + #[error("sparse trie is blind")] + Blind, + /// Encountered blinded node on update. + #[error("attempted to update blind node at {path:?}: {hash}")] + BlindedNode { + /// Blind node path. + path: Nibbles, + /// Node hash + hash: B256, + }, + /// Encountered unexpected node at path when revealing. + #[error("encountered an invalid node at path {path:?} when revealing: {node:?}")] + Reveal { + /// Path to the node. + path: Nibbles, + /// Node that was at the path when revealing. + node: Box, + }, + /// RLP error. + #[error(transparent)] + Rlp(#[from] alloy_rlp::Error), + /// Other. + #[error(transparent)] + Other(#[from] Box), +} + /// Trie witness errors. #[derive(Error, PartialEq, Eq, Clone, Debug)] pub enum TrieWitnessError { diff --git a/crates/trie/sparse/Cargo.toml b/crates/trie/sparse/Cargo.toml index efd68020ccd7..09826e410847 100644 --- a/crates/trie/sparse/Cargo.toml +++ b/crates/trie/sparse/Cargo.toml @@ -15,6 +15,7 @@ workspace = true [dependencies] # reth reth-primitives-traits.workspace = true +reth-execution-errors.workspace = true reth-trie-common.workspace = true reth-tracing.workspace = true @@ -28,9 +29,9 @@ thiserror.workspace = true [dev-dependencies] reth-primitives-traits = { workspace = true, features = ["arbitrary"] } -reth-testing-utils.workspace = true reth-trie = { workspace = true, features = ["test-utils"] } reth-trie-common = { workspace = true, features = ["test-utils", "arbitrary"] } +reth-testing-utils.workspace = true arbitrary.workspace = true assert_matches.workspace = true diff --git a/crates/trie/sparse/src/blinded.rs b/crates/trie/sparse/src/blinded.rs index 4cd88bd92a26..22471cf99ffd 100644 --- a/crates/trie/sparse/src/blinded.rs +++ b/crates/trie/sparse/src/blinded.rs @@ -1,7 +1,7 @@ //! Traits and default implementations related to retrieval of blinded trie nodes. -use crate::SparseTrieError; use alloy_primitives::{Bytes, B256}; +use reth_execution_errors::SparseTrieError; use reth_trie_common::Nibbles; /// Factory for instantiating blinded node providers. diff --git a/crates/trie/sparse/src/errors.rs b/crates/trie/sparse/src/errors.rs deleted file mode 100644 index 46102d2d4680..000000000000 --- a/crates/trie/sparse/src/errors.rs +++ /dev/null @@ -1,61 +0,0 @@ -//! Errors for sparse trie. - -use crate::SparseNode; -use alloy_primitives::{Bytes, B256}; -use reth_trie_common::Nibbles; -use thiserror::Error; - -/// Result type with [`SparseStateTrieError`] as error. -pub type SparseStateTrieResult = Result; - -/// Error encountered in [`crate::SparseStateTrie`]. -#[derive(Error, Debug)] -pub enum SparseStateTrieError { - /// Encountered invalid root node. - #[error("invalid root node at {path:?}: {node:?}")] - InvalidRootNode { - /// Path to first proof node. - path: Nibbles, - /// Encoded first proof node. - node: Bytes, - }, - /// Sparse trie error. - #[error(transparent)] - Sparse(#[from] SparseTrieError), - /// RLP error. - #[error(transparent)] - Rlp(#[from] alloy_rlp::Error), -} - -/// Result type with [`SparseTrieError`] as error. -pub type SparseTrieResult = Result; - -/// Error encountered in [`crate::SparseTrie`]. -#[derive(Error, Debug)] -pub enum SparseTrieError { - /// Sparse trie is still blind. Thrown on attempt to update it. - #[error("sparse trie is blind")] - Blind, - /// Encountered blinded node on update. - #[error("attempted to update blind node at {path:?}: {hash}")] - BlindedNode { - /// Blind node path. - path: Nibbles, - /// Node hash - hash: B256, - }, - /// Encountered unexpected node at path when revealing. - #[error("encountered an invalid node at path {path:?} when revealing: {node:?}")] - Reveal { - /// Path to the node. - path: Nibbles, - /// Node that was at the path when revealing. - node: Box, - }, - /// RLP error. - #[error(transparent)] - Rlp(#[from] alloy_rlp::Error), - /// Other. - #[error(transparent)] - Other(#[from] Box), -} diff --git a/crates/trie/sparse/src/lib.rs b/crates/trie/sparse/src/lib.rs index ec5117fdbc1f..1a0f3f73648e 100644 --- a/crates/trie/sparse/src/lib.rs +++ b/crates/trie/sparse/src/lib.rs @@ -6,7 +6,11 @@ pub use state::*; mod trie; pub use trie::*; -mod errors; -pub use errors::*; - pub mod blinded; + +/// Re-export sparse trie error types. +pub mod errors { + pub use reth_execution_errors::{ + SparseStateTrieError, SparseStateTrieResult, SparseTrieError, SparseTrieResult, + }; +} diff --git a/crates/trie/sparse/src/state.rs b/crates/trie/sparse/src/state.rs index c73eaa1736b2..85116868f336 100644 --- a/crates/trie/sparse/src/state.rs +++ b/crates/trie/sparse/src/state.rs @@ -1,6 +1,6 @@ use crate::{ blinded::{BlindedProvider, BlindedProviderFactory, DefaultBlindedProviderFactory}, - RevealedSparseTrie, SparseStateTrieError, SparseStateTrieResult, SparseTrie, SparseTrieError, + RevealedSparseTrie, SparseTrie, }; use alloy_primitives::{ hex, @@ -8,6 +8,7 @@ use alloy_primitives::{ Bytes, B256, }; use alloy_rlp::{Decodable, Encodable}; +use reth_execution_errors::{SparseStateTrieError, SparseStateTrieResult, SparseTrieError}; use reth_primitives_traits::Account; use reth_tracing::tracing::trace; use reth_trie_common::{ diff --git a/crates/trie/sparse/src/trie.rs b/crates/trie/sparse/src/trie.rs index 1b4c019b1e9a..df5dd25486c1 100644 --- a/crates/trie/sparse/src/trie.rs +++ b/crates/trie/sparse/src/trie.rs @@ -1,13 +1,11 @@ -use crate::{ - blinded::{BlindedProvider, DefaultBlindedProvider}, - SparseTrieError, SparseTrieResult, -}; +use crate::blinded::{BlindedProvider, DefaultBlindedProvider}; use alloy_primitives::{ hex, keccak256, map::{HashMap, HashSet}, B256, }; use alloy_rlp::Decodable; +use reth_execution_errors::{SparseTrieError, SparseTrieResult}; use reth_tracing::tracing::trace; use reth_trie_common::{ prefix_set::{PrefixSet, PrefixSetMut}, diff --git a/crates/trie/trie/src/proof/blinded.rs b/crates/trie/trie/src/proof/blinded.rs index adcaef46b08a..5fd3ecdc08e9 100644 --- a/crates/trie/trie/src/proof/blinded.rs +++ b/crates/trie/trie/src/proof/blinded.rs @@ -4,11 +4,9 @@ use alloy_primitives::{ map::{HashMap, HashSet}, Bytes, B256, }; +use reth_execution_errors::SparseTrieError; use reth_trie_common::{prefix_set::TriePrefixSetsMut, Nibbles}; -use reth_trie_sparse::{ - blinded::{pad_path_to_key, BlindedProvider, BlindedProviderFactory}, - SparseTrieError, -}; +use reth_trie_sparse::blinded::{pad_path_to_key, BlindedProvider, BlindedProviderFactory}; use std::sync::Arc; /// Factory for instantiating providers capable of retrieving blinded trie nodes via proofs.