-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(derive): Online Blob Provider (#117)
* feat(derive): online blob provider * feat(derive): stash blob sidecar progress * feat(derive): blobs * feat(derive): blobs * feat(derive): c_kzg import * fix(derive): remove .DS_Store * fix(derive): gitignore .DS_Store * fix(derive): impl sidecar fetching and fix c-kzg online feat flag * feat(derive): blob provider tests * fix(derive): add revm-primitives as a dependency for kzg points * feat(derive): blob testdata and provider tests * fix(derive): cargo toml nit
- Loading branch information
Showing
16 changed files
with
1,031 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ target | |
|
||
# Example targets | ||
examples/**/target | ||
|
||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//! Contains an online implementation of the [BeaconClient] trait. | ||
use crate::types::{ | ||
APIConfigResponse, APIGenesisResponse, APIGetBlobSidecarsResponse, IndexedBlobHash, | ||
}; | ||
use alloc::{boxed::Box, string::String}; | ||
use alloy_provider::Provider; | ||
use alloy_transport_http::Http; | ||
use async_trait::async_trait; | ||
use reqwest::Client; | ||
|
||
/// The node version engine api method. | ||
pub(crate) const VERSION_METHOD: &str = "eth/v1/node/version"; | ||
|
||
/// The config spec engine api method. | ||
pub(crate) const SPEC_METHOD: &str = "eth/v1/config/spec"; | ||
|
||
/// The beacon genesis engine api method. | ||
pub(crate) const GENESIS_METHOD: &str = "eth/v1/beacon/genesis"; | ||
|
||
/// The blob sidecars engine api method prefix. | ||
pub(crate) const SIDECARS_METHOD_PREFIX: &str = "eth/v1/beacon/blob_sidecars/"; | ||
|
||
/// The [BeaconClient] is a thin wrapper around the Beacon API. | ||
#[async_trait] | ||
pub trait BeaconClient { | ||
/// Returns the node version. | ||
async fn node_version(&self) -> anyhow::Result<String>; | ||
|
||
/// Returns the config spec. | ||
async fn config_spec(&self) -> anyhow::Result<APIConfigResponse>; | ||
|
||
/// Returns the beacon genesis. | ||
async fn beacon_genesis(&self) -> anyhow::Result<APIGenesisResponse>; | ||
|
||
/// Fetches blob sidecars that were confirmed in the specified L1 block with the given indexed | ||
/// hashes. Order of the returned sidecars is guaranteed to be that of the hashes. Blob data is | ||
/// not checked for validity. | ||
async fn beacon_blob_side_cars( | ||
&self, | ||
fetch_all_sidecars: bool, | ||
slot: u64, | ||
hashes: &[IndexedBlobHash], | ||
) -> anyhow::Result<APIGetBlobSidecarsResponse>; | ||
} | ||
|
||
/// An online implementation of the [BeaconClient] trait. | ||
#[derive(Debug)] | ||
pub struct OnlineBeaconClient<T: Provider<Http<Client>>> { | ||
/// The inner Ethereum JSON-RPC provider. | ||
inner: T, | ||
} | ||
|
||
impl<T: Provider<Http<Client>>> OnlineBeaconClient<T> { | ||
/// Creates a new instance of the [OnlineBeaconClient]. | ||
pub fn new(inner: T) -> Self { | ||
Self { inner } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<T: Provider<Http<Client>> + Send> BeaconClient for OnlineBeaconClient<T> { | ||
async fn node_version(&self) -> anyhow::Result<String> { | ||
self.inner.client().request(VERSION_METHOD, ()).await.map_err(|e| anyhow::anyhow!(e)) | ||
} | ||
|
||
async fn config_spec(&self) -> anyhow::Result<APIConfigResponse> { | ||
self.inner.client().request(SPEC_METHOD, ()).await.map_err(|e| anyhow::anyhow!(e)) | ||
} | ||
|
||
async fn beacon_genesis(&self) -> anyhow::Result<APIGenesisResponse> { | ||
self.inner.client().request(GENESIS_METHOD, ()).await.map_err(|e| anyhow::anyhow!(e)) | ||
} | ||
|
||
async fn beacon_blob_side_cars( | ||
&self, | ||
fetch_all_sidecars: bool, | ||
slot: u64, | ||
hashes: &[IndexedBlobHash], | ||
) -> anyhow::Result<APIGetBlobSidecarsResponse> { | ||
let method = alloc::format!("{}{}", SIDECARS_METHOD_PREFIX, slot); | ||
self.inner | ||
.client() | ||
.request(method, (fetch_all_sidecars, hashes)) | ||
.await | ||
.map_err(|e| anyhow::anyhow!(e)) | ||
} | ||
} |
Oops, something went wrong.