diff --git a/crates/interfaces/src/error.rs b/crates/interfaces/src/error.rs index ef14d1211..58bef122b 100644 --- a/crates/interfaces/src/error.rs +++ b/crates/interfaces/src/error.rs @@ -1,3 +1,13 @@ +use crate::{ + blockchain_tree::error::{BlockchainTreeError, CanonicalError}, + consensus::ConsensusError, + db::DatabaseError, + executor::BlockExecutionError, + provider::ProviderError, +}; +use reth_network_api::NetworkError; +use reth_primitives::fs::FsPathError; + /// Result alias for [`RethError`]. pub type RethResult = Result; @@ -6,47 +16,55 @@ pub type RethResult = Result; #[allow(missing_docs)] pub enum RethError { #[error(transparent)] - Execution(#[from] crate::executor::BlockExecutionError), + Execution(#[from] BlockExecutionError), #[error(transparent)] - Consensus(#[from] crate::consensus::ConsensusError), + Consensus(#[from] ConsensusError), #[error(transparent)] - Database(#[from] crate::db::DatabaseError), + Database(#[from] DatabaseError), #[error(transparent)] - Provider(#[from] crate::provider::ProviderError), + Provider(#[from] ProviderError), #[error(transparent)] - Network(#[from] reth_network_api::NetworkError), + Network(#[from] NetworkError), #[error(transparent)] - Canonical(#[from] crate::blockchain_tree::error::CanonicalError), + Canonical(#[from] CanonicalError), #[error("{0}")] Custom(String), } -impl From for RethError { - fn from(error: crate::blockchain_tree::error::BlockchainTreeError) -> Self { - RethError::Canonical(error.into()) +impl From for RethError { + fn from(error: BlockchainTreeError) -> Self { + RethError::Canonical(CanonicalError::BlockchainTree(error)) } } -impl From for RethError { - fn from(err: reth_primitives::fs::FsPathError) -> Self { +impl From for RethError { + fn from(err: FsPathError) -> Self { RethError::Custom(err.to_string()) } } -// We don't want these types to be too large because they're used in a lot of places. -const _SIZE_ASSERTIONS: () = { - // Main error. - let _: [(); 64] = [(); std::mem::size_of::()]; +// Some types are used a lot. Make sure they don't unintentionally get bigger. +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] +mod size_asserts { + use super::*; - // Biggest variant. - let _: [(); 64] = [(); std::mem::size_of::()]; + macro_rules! static_assert_size { + ($t:ty, $sz:expr) => { + const _: [(); $sz] = [(); std::mem::size_of::<$t>()]; + }; + } - // Other common types. - let _: [(); 16] = [(); std::mem::size_of::()]; -}; + static_assert_size!(RethError, 56); + static_assert_size!(BlockExecutionError, 48); + static_assert_size!(ConsensusError, 48); + static_assert_size!(DatabaseError, 16); + static_assert_size!(ProviderError, 48); + static_assert_size!(NetworkError, 0); + static_assert_size!(CanonicalError, 48); +} diff --git a/crates/interfaces/src/provider.rs b/crates/interfaces/src/provider.rs index c2137b4b7..9fad40efd 100644 --- a/crates/interfaces/src/provider.rs +++ b/crates/interfaces/src/provider.rs @@ -29,19 +29,21 @@ pub enum ProviderError { /// A block body is missing. #[error("block meta not found for block #{0}")] BlockBodyIndicesNotFound(BlockNumber), - /// The transition id was found for the given address and storage key, but the changeset was + /// The transition ID was found for the given address and storage key, but the changeset was /// not found. - #[error("storage ChangeSet address: ({address} key: {storage_key:?}) for block #{block_number} does not exist")] + #[error("storage change set for address {address} and key {storage_key} at block #{block_number} does not exist")] StorageChangesetNotFound { /// The block number found for the address and storage key. block_number: BlockNumber, /// The account address. address: Address, /// The storage key. - storage_key: B256, + // NOTE: This is a Box only because otherwise this variant is 16 bytes larger than the + // second largest (which uses `BlockHashOrNumber`). + storage_key: Box, }, /// The block number was found for the given address, but the changeset was not found. - #[error("account {address} ChangeSet for block #{block_number} does not exist")] + #[error("account change set for address {address} at block #{block_number} does not exist")] AccountChangesetNotFound { /// Block number found for the address. block_number: BlockNumber, diff --git a/crates/storage/provider/src/providers/state/historical.rs b/crates/storage/provider/src/providers/state/historical.rs index c76ea75d5..dbdba8f98 100644 --- a/crates/storage/provider/src/providers/state/historical.rs +++ b/crates/storage/provider/src/providers/state/historical.rs @@ -217,10 +217,10 @@ impl<'b, TX: DbTx> StateProvider for HistoricalStateProviderRef<'b, TX> { .cursor_dup_read::()? .seek_by_key_subkey((changeset_block_number, address).into(), storage_key)? .filter(|entry| entry.key == storage_key) - .ok_or(ProviderError::StorageChangesetNotFound { + .ok_or_else(|| ProviderError::StorageChangesetNotFound { block_number: changeset_block_number, address, - storage_key, + storage_key: Box::new(storage_key), })? .value, )),