mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore: shrink ProviderError size (#5482)
This commit is contained in:
@ -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<T> = Result<T, RethError>;
|
||||
|
||||
@ -6,47 +16,55 @@ pub type RethResult<T> = Result<T, RethError>;
|
||||
#[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<crate::blockchain_tree::error::BlockchainTreeError> for RethError {
|
||||
fn from(error: crate::blockchain_tree::error::BlockchainTreeError) -> Self {
|
||||
RethError::Canonical(error.into())
|
||||
impl From<BlockchainTreeError> for RethError {
|
||||
fn from(error: BlockchainTreeError) -> Self {
|
||||
RethError::Canonical(CanonicalError::BlockchainTree(error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<reth_primitives::fs::FsPathError> for RethError {
|
||||
fn from(err: reth_primitives::fs::FsPathError) -> Self {
|
||||
impl From<FsPathError> 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::<RethError>()];
|
||||
// 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::<crate::provider::ProviderError>()];
|
||||
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::<crate::db::DatabaseError>()];
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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<B256>,
|
||||
},
|
||||
/// 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,
|
||||
|
||||
@ -217,10 +217,10 @@ impl<'b, TX: DbTx> StateProvider for HistoricalStateProviderRef<'b, TX> {
|
||||
.cursor_dup_read::<tables::StorageChangeSet>()?
|
||||
.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,
|
||||
)),
|
||||
|
||||
Reference in New Issue
Block a user