Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(derive): Pipeline Builder #110

Closed
refcell opened this issue Apr 15, 2024 · 0 comments · Fixed by #127
Closed

feat(derive): Pipeline Builder #110

refcell opened this issue Apr 15, 2024 · 0 comments · Fixed by #127
Assignees
Labels
A-derive Area: kona-derive crate K-feature Kind: feature M-good-first-issue Meta: Good for newcomers

Comments

@refcell
Copy link
Collaborator

refcell commented Apr 15, 2024

Description

Implement a DerivationPipeline following the golang reference implementation.

The pipeline will need to chain each Stage together from the stages module, successively passing each stage into the previous one. An example of this is shown below. This would be crates/derive/src/lib.rs. Note, this may break since various constructors and stage implementation change.

use alloc::sync::Arc;
use core::fmt::Debug;
use stages::{AttributesProvider, AttributesBuilder};
use traits::{ChainProvider, DataAvailabilityProvider, L2ChainProvider, OriginProvider};
use types::RollupConfig;

mod params;
pub use params::{
    ChannelID, CHANNEL_ID_LENGTH, CONFIG_UPDATE_EVENT_VERSION_0, CONFIG_UPDATE_TOPIC,
    DERIVATION_VERSION_0, FRAME_OVERHEAD, MAX_CHANNEL_BANK_SIZE, MAX_FRAME_LEN,
    MAX_RLP_BYTES_PER_CHANNEL, MAX_SPAN_BATCH_BYTES,
};
pub mod sources;
pub mod stages;
pub mod traits;
pub mod types;

/// The derivation pipeline is responsible for deriving L2 inputs from L1 data.
#[derive(Debug, Clone, Copy)]
pub struct DerivationPipeline<P, AB>
where
    P: AttributesProvider + OriginProvider + Debug,
    AB: AttributesBuilder + Debug,
{
	/// The attributes queue to retrieve the next attributes.
	pub attributes: AttributesQueue<P, AB>,
}

impl DerivationPipeline {
    /// Creates a new instance of the [DerivationPipeline].
    pub fn new<P, DAP, F, B>(
        rollup_config: Arc<RollupConfig>,
        chain_provider: P,
		dap_source: DAP,
		fetcher: F,
		builder: B,
    ) -> Self
    where
        P: ChainProvider + Clone + Debug + Send,
		DAP: DataAvailabilityProvider + Clone + Debug + Send,
		F: L2ChainProvider + Clone + Debug + Send,
		B: AttributesBuilder + Clone + Debug + Send,
    {
		let l1_traversal = L1Traversal::new(chain_provider, rollup_config.clone());
		let l1_retrieval = L1Retrieval::new(l1_traversal, dap_source);
		let frame_queue = FrameQueue::new(l1_retrieval);
		let channel_bank = ChannelBank::new(rollup_config.clone(), frame_queue);
		let channel_reader = ChannelReader::new(channel_bank, rollup_config.clone());
		let batch_queue = BatchQueue::new(rollup_config.clone(), channel_reader, fetcher);
		let attributes_queue = AttributesQueue::new(rollup_config.clone(), batch_queue, builder);
		Self { attributes: attributes_queue }
    }
}

// TODO: implement async iterator for derivation pipeline to call `next_attributes` on the internal `AttributesQueue` stage/field.
@refcell refcell added M-good-first-issue Meta: Good for newcomers K-feature Kind: feature A-derive Area: kona-derive crate labels Apr 15, 2024
@refcell refcell added this to the Table Stakes milestone Apr 15, 2024
@refcell refcell self-assigned this Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-derive Area: kona-derive crate K-feature Kind: feature M-good-first-issue Meta: Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant