Skip to content

Commit

Permalink
chore: move sparse errors to reth-execution-errors (#13101)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Dec 3, 2024
1 parent 8f61af0 commit 39f936e
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 78 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion crates/engine/tree/src/tree/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
59 changes: 57 additions & 2 deletions crates/evm/execution-errors/src/trie.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
#[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum TrieWitnessError {
Expand Down
3 changes: 2 additions & 1 deletion crates/trie/sparse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/trie/sparse/src/blinded.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
61 changes: 0 additions & 61 deletions crates/trie/sparse/src/errors.rs

This file was deleted.

10 changes: 7 additions & 3 deletions crates/trie/sparse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
3 changes: 2 additions & 1 deletion crates/trie/sparse/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::{
blinded::{BlindedProvider, BlindedProviderFactory, DefaultBlindedProviderFactory},
RevealedSparseTrie, SparseStateTrieError, SparseStateTrieResult, SparseTrie, SparseTrieError,
RevealedSparseTrie, SparseTrie,
};
use alloy_primitives::{
hex,
map::{HashMap, HashSet},
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::{
Expand Down
6 changes: 2 additions & 4 deletions crates/trie/sparse/src/trie.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
6 changes: 2 additions & 4 deletions crates/trie/trie/src/proof/blinded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 39f936e

Please sign in to comment.