Skip to content

Commit

Permalink
chore: small update
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Oct 17, 2024
1 parent 2a262be commit fab9dfc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 4 additions & 0 deletions crates/rollup/src/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ where
}
} else {
// TODO: implement engine api validation here. if successful, extract next attributes
if let Err(err) = self.engine.validate_payload_fcu(derived_attributes).await {
error!("Failed to validate payload attributes: {:?}", err);
return false;
}
pipeline.next().expect("Peeked attributes must be available");
}

Expand Down
22 changes: 15 additions & 7 deletions crates/rollup/src/engine.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Deref;

use alloy::{
network::AnyNetwork, primitives::Bytes, providers::RootProvider, rpc::client::RpcClient,
};
Expand All @@ -17,20 +19,17 @@ use tower::ServiceBuilder;
use tracing::warn;
use url::Url;

/// A hyper client with a JWT auth layer middleware.
/// A Hyper HTTP client with a JWT authentication layer.
type HyperAuthClient<B = Full<Bytes>> = HyperClient<B, AuthService<Client<HttpConnector, B>>>;

/// EngineApiValidator
///
/// Validates the [`OpAttributesWithParent`] by sending the attributes to an L2 engine API.
/// The engine API will return a `VALID` or `INVALID` response.
/// The [`Engine`] is responsible for interacting with an L2 Engine API server.
#[derive(Debug, Clone)]
pub struct Engine {
provider: RootProvider<Http<HyperAuthClient>, AnyNetwork>,
}

impl Engine {
/// Creates a new [`EngineApiValidator`] from the provided [Url] and [JwtSecret].
/// Creates a new [`Engine`] from the provided [Url] and [JwtSecret].
pub fn new_http(url: Url, jwt: JwtSecret) -> Self {
let hyper_client = Client::builder(TokioExecutor::new()).build_http::<Full<Bytes>>();

Expand All @@ -45,7 +44,8 @@ impl Engine {
Self { provider }
}

async fn validate_payload_fcu(&self, attributes: &OpAttributesWithParent) -> Result<bool> {
/// Validates the payload using the Fork Choice Update API.
pub async fn validate_payload_fcu(&self, attributes: &OpAttributesWithParent) -> Result<bool> {
// TODO: use the correct values
let fork_choice_state = ForkchoiceState {
head_block_hash: attributes.parent.block_info.hash,
Expand All @@ -64,3 +64,11 @@ impl Engine {
}
}
}

impl Deref for Engine {
type Target = RootProvider<Http<HyperAuthClient>, AnyNetwork>;

fn deref(&self) -> &Self::Target {
&self.provider
}
}

0 comments on commit fab9dfc

Please sign in to comment.