Skip to content

Commit 81e71e1

Browse files
prestwichclaude
andauthored
refactor: replace eyre with AliasError in oracle traits (ENG-2041) (#130)
* refactor(block-processor): replace eyre with AliasError in oracle traits (ENG-2041) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor(host-reth): use AliasError instead of eyre in oracle impls (ENG-2041) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor(host-rpc): use AliasError instead of eyre in oracle impls (ENG-2041) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: use transparent error delegation for AliasError::Internal Preserves the full error source chain for downstream error reporters. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 411a515 commit 81e71e1

7 files changed

Lines changed: 54 additions & 24 deletions

File tree

crates/block-processor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ alloy.workspace = true
2727

2828
eyre.workspace = true
2929
metrics.workspace = true
30+
thiserror.workspace = true
3031
tracing.workspace = true

crates/block-processor/src/alias.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,33 @@ use alloy::primitives::{Address, map::HashSet};
22
use core::future::{self, Future};
33
use std::sync::{Arc, Mutex};
44

5+
/// Error type for [`AliasOracle`] and [`AliasOracleFactory`] operations.
6+
///
7+
/// Implementation-specific errors are wrapped in the [`Internal`] variant.
8+
///
9+
/// [`Internal`]: AliasError::Internal
10+
#[derive(Debug, thiserror::Error)]
11+
#[non_exhaustive]
12+
pub enum AliasError {
13+
/// An implementation-specific error.
14+
#[error(transparent)]
15+
Internal(Box<dyn core::error::Error + Send + Sync>),
16+
}
17+
518
/// Simple trait to allow checking if an address should be aliased.
619
pub trait AliasOracle {
720
/// Returns true if the given address is an alias.
8-
fn should_alias(&self, address: Address) -> impl Future<Output = eyre::Result<bool>> + Send;
21+
fn should_alias(
22+
&self,
23+
address: Address,
24+
) -> impl Future<Output = Result<bool, AliasError>> + Send;
925
}
1026

1127
impl AliasOracle for HashSet<Address> {
12-
fn should_alias(&self, address: Address) -> impl Future<Output = eyre::Result<bool>> + Send {
28+
fn should_alias(
29+
&self,
30+
address: Address,
31+
) -> impl Future<Output = Result<bool, AliasError>> + Send {
1332
future::ready(Ok(self.contains(&address)))
1433
}
1534
}
@@ -28,14 +47,14 @@ pub trait AliasOracleFactory: Send + Sync + 'static {
2847
type Oracle: AliasOracle;
2948

3049
/// Create a new [`AliasOracle`].
31-
fn create(&self) -> eyre::Result<Self::Oracle>;
50+
fn create(&self) -> Result<Self::Oracle, AliasError>;
3251
}
3352

3453
/// This implementation is primarily for testing purposes.
3554
impl AliasOracleFactory for HashSet<Address> {
3655
type Oracle = HashSet<Address>;
3756

38-
fn create(&self) -> eyre::Result<Self::Oracle> {
57+
fn create(&self) -> Result<Self::Oracle, AliasError> {
3958
Ok(self.clone())
4059
}
4160
}
@@ -46,9 +65,8 @@ where
4665
{
4766
type Oracle = T::Oracle;
4867

49-
fn create(&self) -> eyre::Result<Self::Oracle> {
50-
let guard =
51-
self.lock().map_err(|_| eyre::eyre!("failed to lock AliasOracleFactory mutex"))?;
68+
fn create(&self) -> Result<Self::Oracle, AliasError> {
69+
let guard = self.lock().map_err(|e| AliasError::Internal(e.to_string().into()))?;
5270
guard.create()
5371
}
5472
}
@@ -59,7 +77,7 @@ where
5977
{
6078
type Oracle = T::Oracle;
6179

62-
fn create(&self) -> eyre::Result<Self::Oracle> {
80+
fn create(&self) -> Result<Self::Oracle, AliasError> {
6381
self.as_ref().create()
6482
}
6583
}

crates/block-processor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
pub(crate) mod metrics;
1515

1616
mod alias;
17-
pub use alias::{AliasOracle, AliasOracleFactory};
17+
pub use alias::{AliasError, AliasOracle, AliasOracleFactory};
1818

1919
mod v1;
2020
pub use v1::SignetBlockProcessor as SignetBlockProcessorV1;

crates/host-reth/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ reth-exex.workspace = true
2424
reth-node-api.workspace = true
2525
reth-stages-types.workspace = true
2626

27-
eyre.workspace = true
2827
futures-util.workspace = true
2928
thiserror.workspace = true
3029
tokio.workspace = true

crates/host-reth/src/alias.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use core::{
33
fmt,
44
future::{self, Future},
55
};
6-
use eyre::OptionExt;
76
use reth::providers::{StateProviderBox, StateProviderFactory};
8-
use signet_block_processor::{AliasOracle, AliasOracleFactory};
7+
use signet_block_processor::{AliasError, AliasOracle, AliasOracleFactory};
98

109
/// An [`AliasOracle`] backed by a reth [`StateProviderBox`].
1110
///
@@ -21,8 +20,12 @@ impl fmt::Debug for RethAliasOracle {
2120

2221
impl RethAliasOracle {
2322
/// Synchronously check whether the given address should be aliased.
24-
fn check_alias(&self, address: Address) -> eyre::Result<bool> {
25-
let Some(acct) = self.0.basic_account(&address)? else { return Ok(false) };
23+
fn check_alias(&self, address: Address) -> Result<bool, AliasError> {
24+
let Some(acct) =
25+
self.0.basic_account(&address).map_err(|e| AliasError::Internal(Box::new(e)))?
26+
else {
27+
return Ok(false);
28+
};
2629
// Get the bytecode hash for this account.
2730
let bch = match acct.bytecode_hash {
2831
Some(hash) => hash,
@@ -36,16 +39,22 @@ impl RethAliasOracle {
3639
// Fetch the code associated with this bytecode hash.
3740
let code = self
3841
.0
39-
.bytecode_by_hash(&bch)?
40-
.ok_or_eyre("code not found. This indicates a corrupted database")?;
42+
.bytecode_by_hash(&bch)
43+
.map_err(|e| AliasError::Internal(Box::new(e)))?
44+
.ok_or_else(|| {
45+
AliasError::Internal("code not found. This indicates a corrupted database".into())
46+
})?;
4147

4248
// If not a 7702 delegation contract, alias it.
4349
Ok(!code.is_eip7702())
4450
}
4551
}
4652

4753
impl AliasOracle for RethAliasOracle {
48-
fn should_alias(&self, address: Address) -> impl Future<Output = eyre::Result<bool>> + Send {
54+
fn should_alias(
55+
&self,
56+
address: Address,
57+
) -> impl Future<Output = Result<bool, AliasError>> + Send {
4958
future::ready(self.check_alias(address))
5059
}
5160
}
@@ -72,7 +81,7 @@ impl RethAliasOracleFactory {
7281
impl AliasOracleFactory for RethAliasOracleFactory {
7382
type Oracle = RethAliasOracle;
7483

75-
fn create(&self) -> eyre::Result<Self::Oracle> {
84+
fn create(&self) -> Result<Self::Oracle, AliasError> {
7685
// We use `Latest` rather than a pinned host height because pinning
7786
// would require every node to be an archive node, which is impractical.
7887
//
@@ -85,6 +94,6 @@ impl AliasOracleFactory for RethAliasOracleFactory {
8594
self.0
8695
.state_by_block_number_or_tag(alloy::eips::BlockNumberOrTag::Latest)
8796
.map(RethAliasOracle)
88-
.map_err(Into::into)
97+
.map_err(|e| AliasError::Internal(Box::new(e)))
8998
}
9099
}

crates/host-rpc/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ signet-extract.workspace = true
1616
signet-types.workspace = true
1717

1818
alloy.workspace = true
19-
eyre.workspace = true
2019
init4-bin-base.workspace = true
2120
futures-util.workspace = true
2221
metrics.workspace = true

crates/host-rpc/src/alias.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use alloy::{
33
primitives::{Address, map::HashSet},
44
providers::Provider,
55
};
6-
use signet_block_processor::{AliasOracle, AliasOracleFactory};
6+
use signet_block_processor::{AliasError, AliasOracle, AliasOracleFactory};
77
use std::sync::{Arc, RwLock};
88
use tracing::{debug, instrument};
99

@@ -60,7 +60,7 @@ fn should_alias_bytecode(code: &[u8]) -> bool {
6060

6161
impl<P: Provider + Clone + 'static> AliasOracle for RpcAliasOracle<P> {
6262
#[instrument(skip(self), fields(%address))]
63-
async fn should_alias(&self, address: Address) -> eyre::Result<bool> {
63+
async fn should_alias(&self, address: Address) -> Result<bool, AliasError> {
6464
// NOTE: `std::sync::RwLock` is safe here because guards are always
6565
// dropped before the `.await` point. Do not hold a guard across the
6666
// `get_code_at` call — it will deadlock on single-threaded runtimes.
@@ -71,7 +71,11 @@ impl<P: Provider + Clone + 'static> AliasOracle for RpcAliasOracle<P> {
7171
return Ok(true);
7272
}
7373

74-
let code = self.provider.get_code_at(address).await?;
74+
let code = self
75+
.provider
76+
.get_code_at(address)
77+
.await
78+
.map_err(|e| AliasError::Internal(Box::new(e)))?;
7579
let alias = should_alias_bytecode(&code);
7680
debug!(code_len = code.len(), alias, "resolved");
7781

@@ -86,7 +90,7 @@ impl<P: Provider + Clone + 'static> AliasOracle for RpcAliasOracle<P> {
8690
impl<P: Provider + Clone + 'static> AliasOracleFactory for RpcAliasOracle<P> {
8791
type Oracle = Self;
8892

89-
fn create(&self) -> eyre::Result<Self::Oracle> {
93+
fn create(&self) -> Result<Self::Oracle, AliasError> {
9094
Ok(self.clone())
9195
}
9296
}

0 commit comments

Comments
 (0)