-
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.
- Loading branch information
Showing
9 changed files
with
172 additions
and
59 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
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,67 @@ | ||
//! Contains the `PipelineBuilder` object that is used to build a `DerivationPipeline`. | ||
use super::{DerivationPipeline, NextAttributes, OriginAdvancer, ResetProvider, ResettableStage}; | ||
use alloc::collections::VecDeque; | ||
use core::fmt::Debug; | ||
use kona_primitives::L2BlockInfo; | ||
|
||
/// The PipelineBuilder constructs a [DerivationPipeline]. | ||
#[derive(Debug)] | ||
pub struct PipelineBuilder<S, R> | ||
where | ||
S: NextAttributes + ResettableStage + OriginAdvancer + Debug + Send, | ||
R: ResetProvider + Send, | ||
{ | ||
attributes: Option<S>, | ||
reset: Option<R>, | ||
start_cursor: Option<L2BlockInfo>, | ||
} | ||
|
||
impl<S, R> PipelineBuilder<S, R> | ||
where | ||
S: NextAttributes + ResettableStage + OriginAdvancer + Debug + Send, | ||
R: ResetProvider + Send, | ||
{ | ||
/// Sets the attributes for the pipeline. | ||
pub fn attributes(mut self, attributes: S) -> Self { | ||
self.attributes = Some(attributes); | ||
self | ||
} | ||
|
||
/// Sets the reset provider for the pipeline. | ||
pub fn reset(mut self, reset: R) -> Self { | ||
self.reset = Some(reset); | ||
self | ||
} | ||
|
||
/// Sets the start cursor for the pipeline. | ||
pub fn start_cursor(mut self, cursor: L2BlockInfo) -> Self { | ||
self.start_cursor = Some(cursor); | ||
self | ||
} | ||
|
||
/// Builds the pipeline. | ||
pub fn build(self) -> DerivationPipeline<S, R> { | ||
self.into() | ||
} | ||
} | ||
|
||
impl<S, R> From<PipelineBuilder<S, R>> for DerivationPipeline<S, R> | ||
where | ||
S: NextAttributes + ResettableStage + OriginAdvancer + Debug + Send, | ||
R: ResetProvider + Send, | ||
{ | ||
fn from(builder: PipelineBuilder<S, R>) -> Self { | ||
let attributes = builder.attributes.expect("attributes must be set"); | ||
let reset = builder.reset.expect("reset must be set"); | ||
let start_cursor = builder.start_cursor.expect("start_cursor must be set"); | ||
|
||
DerivationPipeline { | ||
attributes, | ||
reset, | ||
prepared: VecDeque::new(), | ||
needs_reset: false, | ||
cursor: start_cursor, | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//! Module containing the derivation pipeline. | ||
/// Re-export trait arguments. | ||
pub use crate::traits::{NextAttributes, OriginAdvancer, Pipeline, ResettableStage}; | ||
|
||
/// Re-export commonly used types. | ||
pub use crate::types::{StageError, StageResult}; | ||
|
||
mod builder; | ||
pub use builder::PipelineBuilder; | ||
|
||
mod core; | ||
pub use core::{DerivationPipeline, ResetProvider}; |
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
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,14 @@ | ||
//! Contains traits for working with payload attributes and their providers. | ||
use crate::types::{L2AttributesWithParent, L2BlockInfo, StageResult}; | ||
use alloc::boxed::Box; | ||
use async_trait::async_trait; | ||
|
||
/// [NextAttributes] defines the interface for pulling attributes from | ||
/// the top level `AttributesQueue` stage of the pipeline. | ||
#[async_trait] | ||
pub trait NextAttributes { | ||
/// Returns the next [L2AttributesWithParent] from the current batch. | ||
async fn next_attributes(&mut self, parent: L2BlockInfo) | ||
-> StageResult<L2AttributesWithParent>; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//! Defines the interface for the core derivation pipeline. | ||
use alloc::boxed::Box; | ||
use async_trait::async_trait; | ||
use kona_primitives::{L2AttributesWithParent, L2BlockInfo}; | ||
|
||
/// This trait defines the interface for interacting with the derivation pipeline. | ||
#[async_trait] | ||
pub trait Pipeline { | ||
/// Resets the pipeline on the next [Pipeline::step] call. | ||
fn reset(&mut self); | ||
|
||
/// Attempts to progress the pipeline. | ||
async fn step(&mut self) -> anyhow::Result<()>; | ||
|
||
/// Pops the next prepared [L2AttributesWithParent] from the pipeline. | ||
fn pop(&mut self) -> Option<L2AttributesWithParent>; | ||
|
||
/// Updates the L2 Safe Head cursor of the pipeline. | ||
/// This is used when fetching the next attributes. | ||
fn update_cursor(&mut self, cursor: L2BlockInfo); | ||
} |