Skip to content

Commit

Permalink
fix(derive): bind the Pipeline trait to Iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Jun 28, 2024
1 parent f1676a1 commit a709218
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 12 additions & 5 deletions crates/derive/src/pipeline/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ where
}
}

impl<S, P> Iterator for DerivationPipeline<S, P>
where
S: NextAttributes + ResettableStage + OriginProvider + OriginAdvancer + Debug + Send + Sync,
P: L2ChainProvider + Send + Sync + Debug,
{
type Item = L2AttributesWithParent;

fn next(&mut self) -> Option<Self::Item> {
self.prepared.pop_front()
}
}

#[async_trait]
impl<S, P> Pipeline for DerivationPipeline<S, P>
where
Expand All @@ -61,11 +73,6 @@ where
self.prepared.front()
}

/// Returns the next prepared [L2AttributesWithParent] from the pipeline.
fn next(&mut self) -> Option<L2AttributesWithParent> {
self.prepared.pop_front()
}

/// Resets the pipelien by calling the [`ResettableStage::reset`] method.
/// This will bubble down the stages all the way to the `L1Traversal` stage.
async fn reset(&mut self, block_info: BlockInfo) -> anyhow::Result<()> {
Expand Down
6 changes: 2 additions & 4 deletions crates/derive/src/traits/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
use super::OriginProvider;
use alloc::boxed::Box;
use async_trait::async_trait;
use core::iter::Iterator;
use kona_primitives::{BlockInfo, L2AttributesWithParent, L2BlockInfo};

/// This trait defines the interface for interacting with the derivation pipeline.
#[async_trait]
pub trait Pipeline: OriginProvider {
pub trait Pipeline: OriginProvider + Iterator<Item = L2AttributesWithParent> {
/// Peeks at the next [L2AttributesWithParent] from the pipeline.
fn peek(&self) -> Option<&L2AttributesWithParent>;

/// Returns the next [L2AttributesWithParent] from the pipeline.
fn next(&mut self) -> Option<L2AttributesWithParent>;

/// Resets the pipeline on the next [Pipeline::step] call.
async fn reset(&mut self, origin: BlockInfo) -> anyhow::Result<()>;

Expand Down

0 comments on commit a709218

Please sign in to comment.