From c4f4df7467795b33ae456f3f8bf93baa84c19bbf Mon Sep 17 00:00:00 2001 From: refcell Date: Wed, 27 Nov 2024 17:21:26 -0500 Subject: [PATCH] chore: rename engine error --- crates/engine/src/client.rs | 19 ++++++++----------- crates/engine/src/controller.rs | 4 ++-- crates/engine/src/errors.rs | 11 ++++++++++- crates/engine/src/lib.rs | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/client.rs b/crates/engine/src/client.rs index 197f575..f908628 100644 --- a/crates/engine/src/client.rs +++ b/crates/engine/src/client.rs @@ -27,7 +27,7 @@ use url::Url; use hilo_providers_alloy::AlloyL2ChainProvider; -use crate::{Engine, EngineApiError}; +use crate::{Engine, EngineError}; /// A Hyper HTTP client with a JWT authentication layer. type HyperAuthClient> = HyperClient>>; @@ -62,13 +62,13 @@ impl EngineClient { #[async_trait] impl Engine for EngineClient { - type Error = EngineApiError; + type Error = EngineError; async fn get_payload( &self, payload_id: PayloadId, ) -> Result { - self.engine.get_payload_v3(payload_id).await.map_err(|_| EngineApiError::PayloadError) + self.engine.get_payload_v3(payload_id).await.map_err(|_| EngineError::PayloadError) } async fn forkchoice_update( @@ -76,10 +76,7 @@ impl Engine for EngineClient { state: ForkchoiceState, attr: Option, ) -> Result { - self.engine - .fork_choice_updated_v2(state, attr) - .await - .map_err(|_| EngineApiError::PayloadError) + self.engine.fork_choice_updated_v2(state, attr).await.map_err(|_| EngineError::PayloadError) } async fn new_payload( @@ -90,7 +87,7 @@ impl Engine for EngineClient { self.engine .new_payload_v3(payload, parent_beacon_block_root) .await - .map_err(|_| EngineApiError::PayloadError) + .map_err(|_| EngineError::PayloadError) } async fn l2_block_ref_by_label( @@ -100,11 +97,11 @@ impl Engine for EngineClient { let number = match numtag { BlockNumberOrTag::Number(n) => n, BlockNumberOrTag::Latest => { - self.rpc.latest_block_number().await.map_err(|_| EngineApiError::PayloadError)? + self.rpc.latest_block_number().await.map_err(|_| EngineError::LatestBlockNumber)? } - _ => return Err(EngineApiError::PayloadError), + _ => return Err(EngineError::InvalidBlockTag), }; - self.rpc.l2_block_info_by_number(number).await.map_err(|_| EngineApiError::PayloadError) + self.rpc.l2_block_info_by_number(number).await.map_err(|_| EngineError::L2BlockInfoFetch) } } diff --git a/crates/engine/src/controller.rs b/crates/engine/src/controller.rs index 0dd8607..0d24ae0 100644 --- a/crates/engine/src/controller.rs +++ b/crates/engine/src/controller.rs @@ -14,7 +14,7 @@ use std::{sync::Arc, time::Duration}; use tokio::time::sleep; use url::Url; -use crate::{Engine, EngineApiError, EngineClient}; +use crate::{Engine, EngineClient, EngineError}; /// L1 epoch block #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] @@ -94,7 +94,7 @@ impl EngineController { #[async_trait] impl Executor for EngineController { - type Error = EngineApiError; + type Error = EngineError; /// Waits for the engine to be ready. async fn wait_until_ready(&mut self) { diff --git a/crates/engine/src/errors.rs b/crates/engine/src/errors.rs index 603e129..9264bf8 100644 --- a/crates/engine/src/errors.rs +++ b/crates/engine/src/errors.rs @@ -2,11 +2,20 @@ /// An error that originated from the engine api. #[derive(Debug, thiserror::Error)] -pub enum EngineApiError { +pub enum EngineError { /// An error occurred while executing the payload. #[error("An error occurred while executing the payload")] PayloadError, /// An error occurred while computing the output root. #[error("An error occurred while computing the output root")] OutputRootError, + /// Invalid block tag used to fetch the L2 block ref. + #[error("Invalid block tag. Use `latest` or a block number.")] + InvalidBlockTag, + /// Failed to fetch the latest block number from the l2 rpc provider. + #[error("Failed to fetch the latest block number from the l2 rpc provider")] + LatestBlockNumber, + /// Failed to get the `L2BlockInfo` for the given block number. + #[error("Failed to get the `L2BlockInfo` for the given block number")] + L2BlockInfoFetch, } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index f6e7231..88e5207 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -10,7 +10,7 @@ mod traits; pub use traits::Engine; mod errors; -pub use errors::EngineApiError; +pub use errors::EngineError; mod controller; pub use controller::EngineController;