chore: move sparse errors to reth-execution-errors (#13101)

This commit is contained in:
Roman Krasiuk
2024-12-03 15:20:15 +01:00
committed by GitHub
parent 8f61af0136
commit 39f936ede2
10 changed files with 78 additions and 78 deletions

1
Cargo.lock generated
View File

@ -9537,6 +9537,7 @@ dependencies = [
"proptest", "proptest",
"proptest-arbitrary-interop", "proptest-arbitrary-interop",
"rand 0.8.5", "rand 0.8.5",
"reth-execution-errors",
"reth-primitives-traits", "reth-primitives-traits",
"reth-testing-utils", "reth-testing-utils",
"reth-tracing", "reth-tracing",

View File

@ -10,7 +10,10 @@ use reth_trie::{
}; };
use reth_trie_db::DatabaseProof; use reth_trie_db::DatabaseProof;
use reth_trie_parallel::root::ParallelStateRootError; 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 revm_primitives::{keccak256, EvmState, B256};
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,

View File

@ -1,7 +1,7 @@
//! Errors when computing the state root. //! Errors when computing the state root.
use alloc::string::ToString; use alloc::{boxed::Box, string::ToString};
use alloy_primitives::B256; use alloy_primitives::{Bytes, B256};
use nybbles::Nibbles; use nybbles::Nibbles;
use reth_storage_errors::{db::DatabaseError, provider::ProviderError}; use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
use thiserror::Error; use thiserror::Error;
@ -62,6 +62,61 @@ impl From<StateProofError> for ProviderError {
} }
} }
/// Result type with [`SparseStateTrieError`] as error.
pub type SparseStateTrieResult<Ok> = Result<Ok, SparseStateTrieError>;
/// 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<Ok> = Result<Ok, SparseTrieError>;
/// 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<dyn core::fmt::Debug>,
},
/// RLP error.
#[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
/// Other.
#[error(transparent)]
Other(#[from] Box<dyn core::error::Error>),
}
/// Trie witness errors. /// Trie witness errors.
#[derive(Error, PartialEq, Eq, Clone, Debug)] #[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum TrieWitnessError { pub enum TrieWitnessError {

View File

@ -15,6 +15,7 @@ workspace = true
[dependencies] [dependencies]
# reth # reth
reth-primitives-traits.workspace = true reth-primitives-traits.workspace = true
reth-execution-errors.workspace = true
reth-trie-common.workspace = true reth-trie-common.workspace = true
reth-tracing.workspace = true reth-tracing.workspace = true
@ -28,9 +29,9 @@ thiserror.workspace = true
[dev-dependencies] [dev-dependencies]
reth-primitives-traits = { workspace = true, features = ["arbitrary"] } reth-primitives-traits = { workspace = true, features = ["arbitrary"] }
reth-testing-utils.workspace = true
reth-trie = { workspace = true, features = ["test-utils"] } reth-trie = { workspace = true, features = ["test-utils"] }
reth-trie-common = { workspace = true, features = ["test-utils", "arbitrary"] } reth-trie-common = { workspace = true, features = ["test-utils", "arbitrary"] }
reth-testing-utils.workspace = true
arbitrary.workspace = true arbitrary.workspace = true
assert_matches.workspace = true assert_matches.workspace = true

View File

@ -1,7 +1,7 @@
//! Traits and default implementations related to retrieval of blinded trie nodes. //! Traits and default implementations related to retrieval of blinded trie nodes.
use crate::SparseTrieError;
use alloy_primitives::{Bytes, B256}; use alloy_primitives::{Bytes, B256};
use reth_execution_errors::SparseTrieError;
use reth_trie_common::Nibbles; use reth_trie_common::Nibbles;
/// Factory for instantiating blinded node providers. /// Factory for instantiating blinded node providers.

View File

@ -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<Ok> = Result<Ok, SparseStateTrieError>;
/// 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<Ok> = Result<Ok, SparseTrieError>;
/// 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<SparseNode>,
},
/// RLP error.
#[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
/// Other.
#[error(transparent)]
Other(#[from] Box<dyn std::error::Error>),
}

View File

@ -6,7 +6,11 @@ pub use state::*;
mod trie; mod trie;
pub use trie::*; pub use trie::*;
mod errors;
pub use errors::*;
pub mod blinded; pub mod blinded;
/// Re-export sparse trie error types.
pub mod errors {
pub use reth_execution_errors::{
SparseStateTrieError, SparseStateTrieResult, SparseTrieError, SparseTrieResult,
};
}

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
blinded::{BlindedProvider, BlindedProviderFactory, DefaultBlindedProviderFactory}, blinded::{BlindedProvider, BlindedProviderFactory, DefaultBlindedProviderFactory},
RevealedSparseTrie, SparseStateTrieError, SparseStateTrieResult, SparseTrie, SparseTrieError, RevealedSparseTrie, SparseTrie,
}; };
use alloy_primitives::{ use alloy_primitives::{
hex, hex,
@ -8,6 +8,7 @@ use alloy_primitives::{
Bytes, B256, Bytes, B256,
}; };
use alloy_rlp::{Decodable, Encodable}; use alloy_rlp::{Decodable, Encodable};
use reth_execution_errors::{SparseStateTrieError, SparseStateTrieResult, SparseTrieError};
use reth_primitives_traits::Account; use reth_primitives_traits::Account;
use reth_tracing::tracing::trace; use reth_tracing::tracing::trace;
use reth_trie_common::{ use reth_trie_common::{

View File

@ -1,13 +1,11 @@
use crate::{ use crate::blinded::{BlindedProvider, DefaultBlindedProvider};
blinded::{BlindedProvider, DefaultBlindedProvider},
SparseTrieError, SparseTrieResult,
};
use alloy_primitives::{ use alloy_primitives::{
hex, keccak256, hex, keccak256,
map::{HashMap, HashSet}, map::{HashMap, HashSet},
B256, B256,
}; };
use alloy_rlp::Decodable; use alloy_rlp::Decodable;
use reth_execution_errors::{SparseTrieError, SparseTrieResult};
use reth_tracing::tracing::trace; use reth_tracing::tracing::trace;
use reth_trie_common::{ use reth_trie_common::{
prefix_set::{PrefixSet, PrefixSetMut}, prefix_set::{PrefixSet, PrefixSetMut},

View File

@ -4,11 +4,9 @@ use alloy_primitives::{
map::{HashMap, HashSet}, map::{HashMap, HashSet},
Bytes, B256, Bytes, B256,
}; };
use reth_execution_errors::SparseTrieError;
use reth_trie_common::{prefix_set::TriePrefixSetsMut, Nibbles}; use reth_trie_common::{prefix_set::TriePrefixSetsMut, Nibbles};
use reth_trie_sparse::{ use reth_trie_sparse::blinded::{pad_path_to_key, BlindedProvider, BlindedProviderFactory};
blinded::{pad_path_to_key, BlindedProvider, BlindedProviderFactory},
SparseTrieError,
};
use std::sync::Arc; use std::sync::Arc;
/// Factory for instantiating providers capable of retrieving blinded trie nodes via proofs. /// Factory for instantiating providers capable of retrieving blinded trie nodes via proofs.