Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(engine): Rename EngineApiError #134

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions crates/engine/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B = Full<Bytes>> = HyperClient<B, AuthService<Client<HttpConnector, B>>>;
Expand Down Expand Up @@ -62,24 +62,21 @@ impl EngineClient {

#[async_trait]
impl Engine for EngineClient {
type Error = EngineApiError;
type Error = EngineError;

async fn get_payload(
&self,
payload_id: PayloadId,
) -> Result<OpExecutionPayloadEnvelopeV3, Self::Error> {
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(
&self,
state: ForkchoiceState,
attr: Option<OpPayloadAttributes>,
) -> Result<ForkchoiceUpdated, Self::Error> {
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(
Expand All @@ -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(
Expand All @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/engine/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion crates/engine/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
2 changes: 1 addition & 1 deletion crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down