diff --git a/crates/block-processor/Cargo.toml b/crates/block-processor/Cargo.toml index c236402a..14095887 100644 --- a/crates/block-processor/Cargo.toml +++ b/crates/block-processor/Cargo.toml @@ -27,4 +27,5 @@ alloy.workspace = true eyre.workspace = true metrics.workspace = true +thiserror.workspace = true tracing.workspace = true diff --git a/crates/block-processor/src/alias.rs b/crates/block-processor/src/alias.rs index a0f84b23..833f317e 100644 --- a/crates/block-processor/src/alias.rs +++ b/crates/block-processor/src/alias.rs @@ -2,14 +2,33 @@ use alloy::primitives::{Address, map::HashSet}; use core::future::{self, Future}; use std::sync::{Arc, Mutex}; +/// Error type for [`AliasOracle`] and [`AliasOracleFactory`] operations. +/// +/// Implementation-specific errors are wrapped in the [`Internal`] variant. +/// +/// [`Internal`]: AliasError::Internal +#[derive(Debug, thiserror::Error)] +#[non_exhaustive] +pub enum AliasError { + /// An implementation-specific error. + #[error(transparent)] + Internal(Box), +} + /// Simple trait to allow checking if an address should be aliased. pub trait AliasOracle { /// Returns true if the given address is an alias. - fn should_alias(&self, address: Address) -> impl Future> + Send; + fn should_alias( + &self, + address: Address, + ) -> impl Future> + Send; } impl AliasOracle for HashSet
{ - fn should_alias(&self, address: Address) -> impl Future> + Send { + fn should_alias( + &self, + address: Address, + ) -> impl Future> + Send { future::ready(Ok(self.contains(&address))) } } @@ -28,14 +47,14 @@ pub trait AliasOracleFactory: Send + Sync + 'static { type Oracle: AliasOracle; /// Create a new [`AliasOracle`]. - fn create(&self) -> eyre::Result; + fn create(&self) -> Result; } /// This implementation is primarily for testing purposes. impl AliasOracleFactory for HashSet
{ type Oracle = HashSet
; - fn create(&self) -> eyre::Result { + fn create(&self) -> Result { Ok(self.clone()) } } @@ -46,9 +65,8 @@ where { type Oracle = T::Oracle; - fn create(&self) -> eyre::Result { - let guard = - self.lock().map_err(|_| eyre::eyre!("failed to lock AliasOracleFactory mutex"))?; + fn create(&self) -> Result { + let guard = self.lock().map_err(|e| AliasError::Internal(e.to_string().into()))?; guard.create() } } @@ -59,7 +77,7 @@ where { type Oracle = T::Oracle; - fn create(&self) -> eyre::Result { + fn create(&self) -> Result { self.as_ref().create() } } diff --git a/crates/block-processor/src/lib.rs b/crates/block-processor/src/lib.rs index 86e2f9e3..d5e3c20d 100644 --- a/crates/block-processor/src/lib.rs +++ b/crates/block-processor/src/lib.rs @@ -14,7 +14,7 @@ pub(crate) mod metrics; mod alias; -pub use alias::{AliasOracle, AliasOracleFactory}; +pub use alias::{AliasError, AliasOracle, AliasOracleFactory}; mod v1; pub use v1::SignetBlockProcessor as SignetBlockProcessorV1; diff --git a/crates/host-reth/Cargo.toml b/crates/host-reth/Cargo.toml index 977c7106..b2055fa9 100644 --- a/crates/host-reth/Cargo.toml +++ b/crates/host-reth/Cargo.toml @@ -24,7 +24,6 @@ reth-exex.workspace = true reth-node-api.workspace = true reth-stages-types.workspace = true -eyre.workspace = true futures-util.workspace = true thiserror.workspace = true tokio.workspace = true diff --git a/crates/host-reth/src/alias.rs b/crates/host-reth/src/alias.rs index 9cbad0a9..d6755d1f 100644 --- a/crates/host-reth/src/alias.rs +++ b/crates/host-reth/src/alias.rs @@ -3,9 +3,8 @@ use core::{ fmt, future::{self, Future}, }; -use eyre::OptionExt; use reth::providers::{StateProviderBox, StateProviderFactory}; -use signet_block_processor::{AliasOracle, AliasOracleFactory}; +use signet_block_processor::{AliasError, AliasOracle, AliasOracleFactory}; /// An [`AliasOracle`] backed by a reth [`StateProviderBox`]. /// @@ -21,8 +20,12 @@ impl fmt::Debug for RethAliasOracle { impl RethAliasOracle { /// Synchronously check whether the given address should be aliased. - fn check_alias(&self, address: Address) -> eyre::Result { - let Some(acct) = self.0.basic_account(&address)? else { return Ok(false) }; + fn check_alias(&self, address: Address) -> Result { + let Some(acct) = + self.0.basic_account(&address).map_err(|e| AliasError::Internal(Box::new(e)))? + else { + return Ok(false); + }; // Get the bytecode hash for this account. let bch = match acct.bytecode_hash { Some(hash) => hash, @@ -36,8 +39,11 @@ impl RethAliasOracle { // Fetch the code associated with this bytecode hash. let code = self .0 - .bytecode_by_hash(&bch)? - .ok_or_eyre("code not found. This indicates a corrupted database")?; + .bytecode_by_hash(&bch) + .map_err(|e| AliasError::Internal(Box::new(e)))? + .ok_or_else(|| { + AliasError::Internal("code not found. This indicates a corrupted database".into()) + })?; // If not a 7702 delegation contract, alias it. Ok(!code.is_eip7702()) @@ -45,7 +51,10 @@ impl RethAliasOracle { } impl AliasOracle for RethAliasOracle { - fn should_alias(&self, address: Address) -> impl Future> + Send { + fn should_alias( + &self, + address: Address, + ) -> impl Future> + Send { future::ready(self.check_alias(address)) } } @@ -72,7 +81,7 @@ impl RethAliasOracleFactory { impl AliasOracleFactory for RethAliasOracleFactory { type Oracle = RethAliasOracle; - fn create(&self) -> eyre::Result { + fn create(&self) -> Result { // We use `Latest` rather than a pinned host height because pinning // would require every node to be an archive node, which is impractical. // @@ -85,6 +94,6 @@ impl AliasOracleFactory for RethAliasOracleFactory { self.0 .state_by_block_number_or_tag(alloy::eips::BlockNumberOrTag::Latest) .map(RethAliasOracle) - .map_err(Into::into) + .map_err(|e| AliasError::Internal(Box::new(e))) } } diff --git a/crates/host-rpc/Cargo.toml b/crates/host-rpc/Cargo.toml index 45c532e9..64c3102e 100644 --- a/crates/host-rpc/Cargo.toml +++ b/crates/host-rpc/Cargo.toml @@ -16,7 +16,6 @@ signet-extract.workspace = true signet-types.workspace = true alloy.workspace = true -eyre.workspace = true init4-bin-base.workspace = true futures-util.workspace = true metrics.workspace = true diff --git a/crates/host-rpc/src/alias.rs b/crates/host-rpc/src/alias.rs index 65ef5015..153ea022 100644 --- a/crates/host-rpc/src/alias.rs +++ b/crates/host-rpc/src/alias.rs @@ -3,7 +3,7 @@ use alloy::{ primitives::{Address, map::HashSet}, providers::Provider, }; -use signet_block_processor::{AliasOracle, AliasOracleFactory}; +use signet_block_processor::{AliasError, AliasOracle, AliasOracleFactory}; use std::sync::{Arc, RwLock}; use tracing::{debug, instrument}; @@ -60,7 +60,7 @@ fn should_alias_bytecode(code: &[u8]) -> bool { impl AliasOracle for RpcAliasOracle

{ #[instrument(skip(self), fields(%address))] - async fn should_alias(&self, address: Address) -> eyre::Result { + async fn should_alias(&self, address: Address) -> Result { // NOTE: `std::sync::RwLock` is safe here because guards are always // dropped before the `.await` point. Do not hold a guard across the // `get_code_at` call — it will deadlock on single-threaded runtimes. @@ -71,7 +71,11 @@ impl AliasOracle for RpcAliasOracle

{ return Ok(true); } - let code = self.provider.get_code_at(address).await?; + let code = self + .provider + .get_code_at(address) + .await + .map_err(|e| AliasError::Internal(Box::new(e)))?; let alias = should_alias_bytecode(&code); debug!(code_len = code.len(), alias, "resolved"); @@ -86,7 +90,7 @@ impl AliasOracle for RpcAliasOracle

{ impl AliasOracleFactory for RpcAliasOracle

{ type Oracle = Self; - fn create(&self) -> eyre::Result { + fn create(&self) -> Result { Ok(self.clone()) } }