Skip to content

Commit

Permalink
compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu authored and samlaf committed Dec 11, 2024
1 parent 08d3bd5 commit 77d22c9
Show file tree
Hide file tree
Showing 17 changed files with 394 additions and 47 deletions.
3 changes: 3 additions & 0 deletions bin/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use kona_proof::{
executor::KonaExecutor,
l1::{OracleBlobProvider, OracleL1ChainProvider, OraclePipeline},
l2::OracleL2ChainProvider,
altda::OracleEigenDAProvider,
sync::new_pipeline_cursor,
BootInfo, CachingOracle, HintType,
};
Expand Down Expand Up @@ -74,6 +75,7 @@ where
let mut l1_provider = OracleL1ChainProvider::new(boot.clone(), oracle.clone());
let mut l2_provider = OracleL2ChainProvider::new(boot.clone(), oracle.clone());
let beacon = OracleBlobProvider::new(oracle.clone());
let eigenda_blob_provider = OracleEigenDAProvider::new(oracle.clone());

// If the claimed L2 block number is less than the safe head of the L2 chain, the claim is
// invalid.
Expand Down Expand Up @@ -115,6 +117,7 @@ where
beacon,
l1_provider.clone(),
l2_provider.clone(),
eigenda_blob_provider.clone(),
);
let executor = KonaExecutor::new(&cfg, l2_provider.clone(), l2_provider, handle_register, None);
let mut driver = Driver::new(cursor, executor, pipeline);
Expand Down
22 changes: 11 additions & 11 deletions crates/derive/src/sources/eigenda.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Contains the [EigenDADataSource], which is a concrete implementation of the
//! [DataAvailabilityProvider] trait for the EigenDA protocol.
use crate::{
sources::{BlobSource, CalldataSource, EthereumDataSource},
traits::{AltDAProvider, BlobProvider, ChainProvider, DataAvailabilityProvider},
sources::{EigenDABlobSource, BlobSource, CalldataSource, EthereumDataSource},
traits::{EigenDABlobProvider, BlobProvider, ChainProvider, DataAvailabilityProvider},
types::PipelineResult,
};
use alloc::{boxed::Box, fmt::Debug};
Expand All @@ -17,24 +17,24 @@ pub struct EigenDADataSource<C, B, A>
where
C: ChainProvider + Send + Clone,
B: BlobProvider + Send + Clone,
A: AltDAProvider + Send + Clone,
A: EigenDABlobProvider + Send + Clone,
{
/// The blob source.
pub ethereum_source: EthereumDataSource<C, B>,
/// The eigenda source.
pub eigenda_source: EigenDASource<A>,
pub eigenda_source: Option<EigenDABlobSource<A>>,
}

impl<C, B, A> EigenDADataSource<C, B, A>
where
C: ChainProvider + Send + Clone + Debug,
B: BlobProvider + Send + Clone + Debug,
A: AltDAProvider + Send + Clone + Debug,
A: EigenDABlobProvider + Send + Clone + Debug,
{
/// Instantiates a new [EigenDADataSource].
pub const fn new(
ethereum_source: EthereumDataSource<C, B>,
eigenda_source: EigenDASource<A>,
eigenda_source: Option<EigenDABlobSource<A>>,
) -> Self {
Self { ethereum_source, eigenda_source }
}
Expand All @@ -45,21 +45,21 @@ impl<C, B, A> DataAvailabilityProvider for EigenDADataSource<C, B, A>
where
C: ChainProvider + Send + Sync + Clone + Debug,
B: BlobProvider + Send + Sync + Clone + Debug,
A: AltDAProvider + Send + Sync + Clone + Debug,
A: EigenDABlobProvider + Send + Sync + Clone + Debug,
{
type Item = Bytes;

async fn next(&mut self, block_ref: &BlockInfo) -> PipelineResult<Self::Item> {
// then acutally use ethereum da to fetch. items are Bytes
let item = self.ethereum_source.next(block_ref).await?;

self.eigenda_source.next(items).await?;
//self.eigenda_source.next(&item).await
// just dump all the data out

}
todo!()
}

fn clear(&mut self) {
self.eigenda_source.clear();
//self.eigenda_source.clear();
self.ethereum_source.clear();
}
}
41 changes: 19 additions & 22 deletions crates/derive/src/sources/eigenda_blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use crate::{
errors::{BlobProviderError, PipelineError},
sources::BlobData,
traits::{BlobProvider, ChainProvider, DataAvailabilityProvider},
sources::EigenDABlobData,
traits::{BlobProvider, ChainProvider, DataAvailabilityProvider, EigenDABlobProvider},
types::PipelineResult,
};
use alloc::{boxed::Box, string::ToString, vec::Vec};
Expand All @@ -17,76 +17,73 @@ use op_alloy_protocol::BlockInfo;
#[derive(Debug, Clone)]
pub struct EigenDABlobSource<B>
where
B: AltDAProvider + Send,
B: EigenDABlobProvider + Send,
{
/// Fetches blobs.
pub alta_fetcher: B,
pub altda_fetcher: B,
/// EigenDA blobs.
pub data: Vec<Vec<Bytes>>,
pub data: Vec<EigenDABlobData>,
/// Whether the source is open.
pub open: bool,
}

impl<F, B> EigenDABlobSource<F, B>
impl<B> EigenDABlobSource<B>
where
B: BlobProvider + Send,
B: EigenDABlobProvider + Send,
{
/// Creates a new blob source.
pub const fn new(
altda_fetcher: B,
) -> Self {
Self {
altda_fetcher,
data: Vec::new(),
open: false,
}
}

fn extract_blob_data(&self, txs: Vec<TxEnvelope>) -> (Vec<BlobData>, Vec<IndexedBlobHash>) {

fn extract_blob_data(&self, txs: Vec<TxEnvelope>) -> (Vec<EigenDABlobData>, Vec<IndexedBlobHash>) {
todo!()
}

/// Loads blob data into the source if it is not open.
async fn load_blobs(&mut self, altDACommitment: &AltDACommitment) -> Result<(), BlobProviderError> {

async fn load_blobs(&mut self, altDACommitment: &Bytes) -> Result<(), BlobProviderError> {
todo!()
}

fn next_data(&mut self) -> Result<EigenDABlobData, PipelineResult<Bytes>> {
if self.open{

return Err(Err(PipelineError::Eof.temp()));
}

if self.data.is_empty() {
return Err(Err(PipelineError::Eof.temp()));
}
Ok(self.data.remove(0))
}
}

impl<AP: AltDAProvider + Send> DataAvailabilityProvider for EigenDABlobSource<AP> {
type Item = Bytes;

async fn next(&mut self, altDACommitment: &AltDACommitment) -> PipelineResult<Self::Item> {
pub async fn next(&mut self, altDACommitment: &Bytes) -> PipelineResult<Bytes> {
self.load_blobs(altDACommitment).await?;

let next_data = match self.next_data() {
Ok(d) => d,
Err(e) => return e,
};
if let Some(c) = next_data {
return Ok(c);
}

// Decode the blob data to raw bytes.
// Otherwise, ignore blob and recurse next.
match next_data.decode() {
Ok(d) => Ok(d),
Err(_) => {
warn!(target: "blob-source", "Failed to decode blob data, skipping");
self.next(block_ref).await
panic!()
// todo need to add recursion
// self.next(altDACommitment).await
}
}
}

fn clear(&mut self) {
pub fn clear(&mut self) {
self.data.clear();
self.open = false;
}
Expand Down
4 changes: 4 additions & 0 deletions crates/derive/src/sources/eigenda_data.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use alloy_primitives::{Address, Bytes};
use crate::errors::BlobDecodingError;

#[derive(Default, Clone, Debug)]
pub struct EigenDABlobData {
/// The blob data
Expand All @@ -11,6 +14,7 @@ impl EigenDABlobData {
/// Returns a [BlobDecodingError] if the blob is invalid.
pub(crate) fn decode(&self) -> Result<Bytes, BlobDecodingError> {
// where we can implement zero bytes etc.
todo!()
}

}
11 changes: 10 additions & 1 deletion crates/derive/src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@
mod blob_data;
pub use blob_data::BlobData;

mod eigenda_data;
pub use eigenda_data::EigenDABlobData;

mod ethereum;
pub use ethereum::EthereumDataSource;

mod eigenda;
pub use eigenda::EigenDADataSource;

mod eigenda_blobs;
pub use eigenda_blobs::EigenDABlobSource;

mod blobs;
pub use blobs::BlobSource;

mod calldata;
pub use calldata::CalldataSource;
pub use calldata::CalldataSource;
1 change: 1 addition & 0 deletions crates/derive/src/stages/l1_retrieval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ where
type Item = DAP::Item;

async fn next_data(&mut self) -> PipelineResult<Self::Item> {
info!(target: "l1-retrieval", "next_data");
if self.next.is_none() {
self.next = Some(
self.prev
Expand Down
10 changes: 10 additions & 0 deletions crates/derive/src/traits/data_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ pub trait BlobProvider {
) -> Result<Vec<Box<Blob>>, Self::Error>;
}

/// The EigenDAProvider trait specifies the functionality of a data source that can provide eigenda blobs.
#[async_trait]
pub trait EigenDABlobProvider {
/// The error type for the [EigenDAProvider].
type Error: Display + ToString + Into<PipelineErrorKind>;

async fn get_blob(&self, cert: Bytes) -> Result<Bytes, Self::Error>;
}


/// Describes the functionality of a data source that can provide data availability information.
#[async_trait]
pub trait DataAvailabilityProvider {
Expand Down
2 changes: 1 addition & 1 deletion crates/derive/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod attributes;
pub use attributes::{AttributesBuilder, AttributesProvider, NextAttributes};

mod data_sources;
pub use data_sources::{BlobProvider, DataAvailabilityProvider};
pub use data_sources::{BlobProvider, DataAvailabilityProvider, EigenDABlobProvider};

mod reset;
pub use reset::ResetProvider;
Expand Down
63 changes: 63 additions & 0 deletions crates/derive/®.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[package]
name = "kona-derive"
description = "A no_std derivation pipeline implementation for the OP Stack"
version = "0.1.0"
edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
homepage.workspace = true

[lints]
workspace = true

[dependencies]
# Alloy
alloy-eips.workspace = true
alloy-rpc-types-engine.workspace = true
alloy-rlp = { workspace = true, features = ["derive"] }
alloy-consensus = { workspace = true, features = ["k256"] }
alloy-primitives = { workspace = true, features = ["rlp", "k256", "map"] }

# Op Alloy
op-alloy-genesis.workspace = true
op-alloy-protocol.workspace = true
op-alloy-rpc-types-engine.workspace = true
op-alloy-consensus = { workspace = true, features = ["k256"] }

# General
tracing.workspace = true
async-trait.workspace = true
thiserror.workspace = true

# `serde` feature dependencies
serde = { workspace = true, optional = true, features = ["derive"] }

# `test-utils` feature dependencies
spin = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, optional = true, features = ["fmt"] }

[dev-dependencies]
spin.workspace = true
proptest.workspace = true
serde_json.workspace = true
op-alloy-registry.workspace = true
tokio = { workspace = true, features = ["full"] }
tracing-subscriber = { workspace = true, features = ["fmt"] }
alloy-primitives = { workspace = true, features = ["rlp", "k256", "map", "arbitrary"] }

[features]
default = ["serde"]
serde = [
"dep:serde",
"alloy-primitives/serde",
"alloy-consensus/serde",
"op-alloy-consensus/serde",
"op-alloy-protocol/serde",
"op-alloy-genesis/serde",
"op-alloy-rpc-types-engine/serde",
]
test-utils = [
"dep:spin",
"dep:tracing-subscriber",
]
60 changes: 60 additions & 0 deletions crates/proof-sdk/proof/src/altda/altda_provider.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
use crate::alloc::string::ToString;
use alloc::boxed::Box;
use alloc::sync::Arc;
use alloy_primitives::Bytes;
use async_trait::async_trait;
use kona_preimage::CommsClient;
use crate::errors::OracleProviderError;
use super::OracleEigenDAProvider;
#[derive(Debug, Clone)]
pub struct OracleAltDAProvider<T: CommsClient> {
/// The oracle eigenda provider.
eigenda_provider: OracleEigenDAProvider<T>,
}
impl<T: CommsClient> OracleAltDAProvider<T> {
/// Constructs a new oracle-backed AltDA provider.
pub fn new(eigenda_provider: OracleEigenDAProvider<T>) -> Self {
Self { eigenda_provider }
}
/// Constructs a new oracle-backed AltDA provider by constructing
/// the respective altda providers using the oracle.
pub fn new_from_oracle(oracle: Arc<T>) -> Self {
Self { eigenda_provider: OracleEigenDAProvider::new(oracle) }
}
}
#[async_trait]
impl<T: CommsClient + Send + Sync> AltDAProvider for OracleAltDAProvider<T> {
type Error = OracleProviderError;
/// Retrieves a blob from the oracle.
///
/// ## Takes
/// - `commitment`: The commitment to the blob (specific to each AltDA provider).
///
/// ## Returns
/// - `Ok(Bytes)`: The blob.
/// - `Err(e)`: The blob could not be retrieved.
async fn get_blob(&self, commitment: AltDACommitment) -> Result<Bytes, OracleProviderError> {
match commitment {
AltDACommitment::Keccak(_) => Err(OracleProviderError::AltDA(
"keccak commitments are not implemented yet".to_string(),
)),
AltDACommitment::EigenDAV1(cert) => self.eigenda_provider.get_blob_v1(cert).await,
AltDACommitment::EigenDAV2(cert) => self.eigenda_provider.get_blob_v2(cert).await,
AltDACommitment::Avail(_) => Err(OracleProviderError::AltDA(
"avail commitments are not implemented yet".to_string(),
)),
AltDACommitment::Celestia(_) => Err(OracleProviderError::AltDA(
"celestia commitments are not implemented yet".to_string(),
)),
}
}
}
*/
Loading

0 comments on commit 77d22c9

Please sign in to comment.