From 12b593c8d30ee7a37e1f2fafffd16bbc0132bf6f Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Sun, 25 Aug 2024 17:21:00 +0200 Subject: [PATCH] feat(rollup): create rollup pipeline from kona_derive --- Cargo.lock | 2 ++ crates/rollup/Cargo.toml | 2 ++ crates/rollup/src/lib.rs | 3 ++ crates/rollup/src/pipeline.rs | 64 +++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 crates/rollup/src/pipeline.rs diff --git a/Cargo.lock b/Cargo.lock index c6918c7..558cf64 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7380,6 +7380,8 @@ dependencies = [ "async-trait", "clap", "eyre", + "kona-derive", + "kona-primitives", "reth-exex", "reth-node-api", "superchain-registry", diff --git a/crates/rollup/Cargo.toml b/crates/rollup/Cargo.toml index 33f8fbe..ce11d7b 100644 --- a/crates/rollup/Cargo.toml +++ b/crates/rollup/Cargo.toml @@ -22,6 +22,8 @@ reth-exex.workspace = true reth-node-api.workspace = true # OP Stack Dependencies +kona-derive.workspace = true +kona-primitives.workspace = true superchain-registry = { workspace = true, default-features = false } # Misc diff --git a/crates/rollup/src/lib.rs b/crates/rollup/src/lib.rs index 15105a5..f5af149 100644 --- a/crates/rollup/src/lib.rs +++ b/crates/rollup/src/lib.rs @@ -10,5 +10,8 @@ pub use driver::Driver; mod cli; pub use cli::HeraArgsExt; +mod pipeline; +pub use pipeline::{new_rollup_pipeline, RollupPipeline}; + /// The identifier of the Hera Execution Extension. pub const HERA_EXEX_ID: &str = "hera"; diff --git a/crates/rollup/src/pipeline.rs b/crates/rollup/src/pipeline.rs new file mode 100644 index 0000000..b2443c2 --- /dev/null +++ b/crates/rollup/src/pipeline.rs @@ -0,0 +1,64 @@ +//! The rollup pipeline builder + +use std::{fmt::Debug, sync::Arc}; + +use kona_derive::{ + online::{DerivationPipeline, EthereumDataSource, PipelineBuilder}, + stages::{ + AttributesQueue, BatchQueue, ChannelBank, ChannelReader, FrameQueue, L1Retrieval, + L1Traversal, StatefulAttributesBuilder, + }, + traits::{BlobProvider, ChainProvider, L2ChainProvider}, +}; +use kona_primitives::{BlockInfo, RollupConfig}; + +/// A [FrameQueue] stage implementation that takes the outputs of the [L1Retrieval] stage and +/// parses it into frames, using the [L1Traversal] stage to fetch block info for each frame. +type L1FrameQueue = FrameQueue, L1Traversal>>; + +/// A concrete [NextAttributes](kona_derive::traits::NextAttributes) stage implementation that +/// accepts batches from the [BatchQueue] stage and transforms them into payload attributes. +type L1AttributesQueue = AttributesQueue< + BatchQueue>>, L2CP>, + StatefulAttributesBuilder, +>; + +/// A derivation pipeline generic over: +/// - The L1 [ChainProvider] (CP) +/// - The L1 [BlobProvider] (BP) +/// - The [L2ChainProvider] (L2CP) +/// +/// This pipeline is a derivation pipeline that takes the outputs of the [L1FrameQueue] stage +/// and transforms them into [L2PayloadAttributes](kona_primitives::L2PayloadAttributes). +pub type RollupPipeline = DerivationPipeline, L2CP>; + +/// Creates a new [RollupPipeline] from the given components. +#[allow(unused)] +pub fn new_rollup_pipeline( + cfg: Arc, + chain_provider: CP, + blob_provider: BP, + l2_chain_provider: L2CP, + origin: BlockInfo, +) -> RollupPipeline +where + CP: ChainProvider + Send + Sync + Clone + Debug, + BP: BlobProvider + Send + Sync + Clone + Debug, + L2CP: L2ChainProvider + Send + Sync + Clone + Debug, +{ + let dap = EthereumDataSource::new(chain_provider.clone(), blob_provider.clone(), &cfg.clone()); + let attributes = StatefulAttributesBuilder::new( + cfg.clone(), + l2_chain_provider.clone(), + chain_provider.clone(), + ); + + PipelineBuilder::new() + .rollup_config(cfg) + .dap_source(dap) + .l2_chain_provider(l2_chain_provider) + .chain_provider(chain_provider) + .builder(attributes) + .origin(origin) + .build() +}