Skip to content

Commit

Permalink
feat(rollup): create rollup pipeline from kona_derive
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Aug 25, 2024
1 parent 8be7253 commit 12b593c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/rollup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions crates/rollup/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
64 changes: 64 additions & 0 deletions crates/rollup/src/pipeline.rs
Original file line number Diff line number Diff line change
@@ -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<CP, BP> = FrameQueue<L1Retrieval<EthereumDataSource<CP, BP>, L1Traversal<CP>>>;

/// A concrete [NextAttributes](kona_derive::traits::NextAttributes) stage implementation that
/// accepts batches from the [BatchQueue] stage and transforms them into payload attributes.
type L1AttributesQueue<CP, BP, L2CP> = AttributesQueue<
BatchQueue<ChannelReader<ChannelBank<L1FrameQueue<CP, BP>>>, L2CP>,
StatefulAttributesBuilder<CP, L2CP>,
>;

/// 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<CP, BP, L2CP> = DerivationPipeline<L1AttributesQueue<CP, BP, L2CP>, L2CP>;

/// Creates a new [RollupPipeline] from the given components.
#[allow(unused)]
pub fn new_rollup_pipeline<CP, BP, L2CP>(
cfg: Arc<RollupConfig>,
chain_provider: CP,
blob_provider: BP,
l2_chain_provider: L2CP,
origin: BlockInfo,
) -> RollupPipeline<CP, BP, L2CP>
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()
}

0 comments on commit 12b593c

Please sign in to comment.