Skip to content

Commit

Permalink
chore(derive): remove previous stage trait (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Aug 12, 2024
1 parent b61a397 commit 19123e3
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 150 deletions.
2 changes: 1 addition & 1 deletion crates/derive/src/pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// Re-export trait arguments.
pub use crate::traits::{
ChainProvider, DataAvailabilityProvider, L2ChainProvider, NextAttributes, OriginAdvancer,
OriginProvider, Pipeline, PreviousStage, ResetProvider, ResettableStage, StepResult,
OriginProvider, Pipeline, ResetProvider, ResettableStage, StepResult,
};

/// Re-export stage types that are needed as inputs.
Expand Down
24 changes: 7 additions & 17 deletions crates/derive/src/stages/attributes_queue.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Contains the logic for the `AttributesQueue` stage.

use crate::{
traits::{NextAttributes, OriginAdvancer, OriginProvider, PreviousStage, ResettableStage},
traits::{NextAttributes, OriginAdvancer, OriginProvider, ResettableStage},
types::{
BlockInfo, L2AttributesWithParent, L2BlockInfo, L2PayloadAttributes, ResetError,
RollupConfig, SingleBatch, StageError, StageResult, SystemConfig,
Expand Down Expand Up @@ -45,7 +45,7 @@ pub trait AttributesProvider {
#[derive(Debug)]
pub struct AttributesQueue<P, AB>
where
P: AttributesProvider + PreviousStage + Debug,
P: AttributesProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
AB: AttributesBuilder + Debug,
{
/// The rollup config.
Expand All @@ -62,7 +62,7 @@ where

impl<P, AB> AttributesQueue<P, AB>
where
P: AttributesProvider + PreviousStage + Debug,
P: AttributesProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
AB: AttributesBuilder + Debug,
{
/// Create a new [AttributesQueue] stage.
Expand Down Expand Up @@ -153,20 +153,10 @@ where
}
}

impl<P, AB> PreviousStage for AttributesQueue<P, AB>
where
P: AttributesProvider + PreviousStage + Send + Debug,
AB: AttributesBuilder + Send + Debug,
{
fn previous(&self) -> Option<Box<&dyn PreviousStage>> {
Some(Box::new(&self.prev))
}
}

#[async_trait]
impl<P, AB> OriginAdvancer for AttributesQueue<P, AB>
where
P: AttributesProvider + PreviousStage + Debug + Send,
P: AttributesProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug + Send,
AB: AttributesBuilder + Debug + Send,
{
async fn advance_origin(&mut self) -> StageResult<()> {
Expand All @@ -177,7 +167,7 @@ where
#[async_trait]
impl<P, AB> NextAttributes for AttributesQueue<P, AB>
where
P: AttributesProvider + PreviousStage + Debug + Send,
P: AttributesProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug + Send,
AB: AttributesBuilder + Debug + Send,
{
async fn next_attributes(
Expand All @@ -190,7 +180,7 @@ where

impl<P, AB> OriginProvider for AttributesQueue<P, AB>
where
P: AttributesProvider + PreviousStage + Debug,
P: AttributesProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
AB: AttributesBuilder + Debug,
{
fn origin(&self) -> Option<BlockInfo> {
Expand All @@ -201,7 +191,7 @@ where
#[async_trait]
impl<P, AB> ResettableStage for AttributesQueue<P, AB>
where
P: AttributesProvider + PreviousStage + Send + Debug,
P: AttributesProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
AB: AttributesBuilder + Send + Debug,
{
async fn reset(
Expand Down
24 changes: 7 additions & 17 deletions crates/derive/src/stages/batch_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
stages::attributes_queue::AttributesProvider,
traits::{L2ChainProvider, OriginAdvancer, OriginProvider, PreviousStage, ResettableStage},
traits::{L2ChainProvider, OriginAdvancer, OriginProvider, ResettableStage},
types::{
Batch, BatchValidity, BatchWithInclusionBlock, BlockInfo, L2BlockInfo, RollupConfig,
SingleBatch, StageError, StageResult, SystemConfig,
Expand Down Expand Up @@ -43,7 +43,7 @@ pub trait BatchQueueProvider {
#[derive(Debug)]
pub struct BatchQueue<P, BF>
where
P: BatchQueueProvider + PreviousStage + Debug,
P: BatchQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
BF: L2ChainProvider + Debug,
{
/// The rollup config.
Expand Down Expand Up @@ -75,7 +75,7 @@ where

impl<P, BF> BatchQueue<P, BF>
where
P: BatchQueueProvider + PreviousStage + Debug,
P: BatchQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
BF: L2ChainProvider + Debug,
{
/// Creates a new [BatchQueue] stage.
Expand Down Expand Up @@ -248,7 +248,7 @@ where
#[async_trait]
impl<P, BF> OriginAdvancer for BatchQueue<P, BF>
where
P: BatchQueueProvider + PreviousStage + Send + Debug,
P: BatchQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
BF: L2ChainProvider + Send + Debug,
{
async fn advance_origin(&mut self) -> StageResult<()> {
Expand All @@ -259,7 +259,7 @@ where
#[async_trait]
impl<P, BF> AttributesProvider for BatchQueue<P, BF>
where
P: BatchQueueProvider + PreviousStage + Send + Debug,
P: BatchQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
BF: L2ChainProvider + Send + Debug,
{
/// Returns the next valid batch upon the given safe head.
Expand Down Expand Up @@ -417,28 +417,18 @@ where

impl<P, BF> OriginProvider for BatchQueue<P, BF>
where
P: BatchQueueProvider + PreviousStage + Debug,
P: BatchQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
BF: L2ChainProvider + Debug,
{
fn origin(&self) -> Option<BlockInfo> {
self.prev.origin()
}
}

impl<P, BF> PreviousStage for BatchQueue<P, BF>
where
P: BatchQueueProvider + PreviousStage + Send + Debug,
BF: L2ChainProvider + Send + Debug,
{
fn previous(&self) -> Option<Box<&dyn PreviousStage>> {
Some(Box::new(&self.prev))
}
}

#[async_trait]
impl<P, BF> ResettableStage for BatchQueue<P, BF>
where
P: BatchQueueProvider + PreviousStage + Send + Debug,
P: BatchQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
BF: L2ChainProvider + Send + Debug,
{
async fn reset(&mut self, base: BlockInfo, system_config: &SystemConfig) -> StageResult<()> {
Expand Down
23 changes: 7 additions & 16 deletions crates/derive/src/stages/channel_bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
params::{ChannelID, MAX_CHANNEL_BANK_SIZE},
stages::ChannelReaderProvider,
traits::{OriginAdvancer, OriginProvider, PreviousStage, ResettableStage},
traits::{OriginAdvancer, OriginProvider, ResettableStage},
types::{BlockInfo, Channel, Frame, RollupConfig, StageError, StageResult, SystemConfig},
};
use alloc::{boxed::Box, collections::VecDeque, sync::Arc};
Expand Down Expand Up @@ -37,7 +37,7 @@ pub trait ChannelBankProvider {
#[derive(Debug)]
pub struct ChannelBank<P>
where
P: ChannelBankProvider + PreviousStage + Debug,
P: ChannelBankProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
{
/// The rollup configuration.
cfg: Arc<RollupConfig>,
Expand All @@ -51,7 +51,7 @@ where

impl<P> ChannelBank<P>
where
P: ChannelBankProvider + PreviousStage + Debug,
P: ChannelBankProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
{
/// Create a new [ChannelBank] stage.
pub fn new(cfg: Arc<RollupConfig>, prev: P) -> Self {
Expand Down Expand Up @@ -192,7 +192,7 @@ where
#[async_trait]
impl<P> OriginAdvancer for ChannelBank<P>
where
P: ChannelBankProvider + PreviousStage + Send + Debug,
P: ChannelBankProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
{
async fn advance_origin(&mut self) -> StageResult<()> {
self.prev.advance_origin().await
Expand All @@ -202,7 +202,7 @@ where
#[async_trait]
impl<P> ChannelReaderProvider for ChannelBank<P>
where
P: ChannelBankProvider + PreviousStage + Send + Debug,
P: ChannelBankProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
{
async fn next_data(&mut self) -> StageResult<Option<Bytes>> {
crate::timer!(START, STAGE_ADVANCE_RESPONSE_TIME, &["channel_bank"], timer);
Expand Down Expand Up @@ -234,26 +234,17 @@ where

impl<P> OriginProvider for ChannelBank<P>
where
P: ChannelBankProvider + PreviousStage + Debug,
P: ChannelBankProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
{
fn origin(&self) -> Option<BlockInfo> {
self.prev.origin()
}
}

impl<P> PreviousStage for ChannelBank<P>
where
P: ChannelBankProvider + PreviousStage + Debug + Send,
{
fn previous(&self) -> Option<Box<&dyn PreviousStage>> {
Some(Box::new(&self.prev))
}
}

#[async_trait]
impl<P> ResettableStage for ChannelBank<P>
where
P: ChannelBankProvider + PreviousStage + Send + Debug,
P: ChannelBankProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
{
async fn reset(
&mut self,
Expand Down
23 changes: 7 additions & 16 deletions crates/derive/src/stages/channel_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
stages::{decompress_brotli, BatchQueueProvider},
traits::{OriginAdvancer, OriginProvider, PreviousStage, ResettableStage},
traits::{OriginAdvancer, OriginProvider, ResettableStage},
types::{Batch, BlockInfo, RollupConfig, StageError, StageResult, SystemConfig},
};

Expand Down Expand Up @@ -37,7 +37,7 @@ pub trait ChannelReaderProvider {
#[derive(Debug)]
pub struct ChannelReader<P>
where
P: ChannelReaderProvider + PreviousStage + Debug,
P: ChannelReaderProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
{
/// The previous stage of the derivation pipeline.
prev: P,
Expand All @@ -49,7 +49,7 @@ where

impl<P> ChannelReader<P>
where
P: ChannelReaderProvider + PreviousStage + Debug,
P: ChannelReaderProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
{
/// Create a new [ChannelReader] stage.
pub fn new(prev: P, cfg: Arc<RollupConfig>) -> Self {
Expand All @@ -76,7 +76,7 @@ where
#[async_trait]
impl<P> OriginAdvancer for ChannelReader<P>
where
P: ChannelReaderProvider + PreviousStage + Send + Debug,
P: ChannelReaderProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
{
async fn advance_origin(&mut self) -> StageResult<()> {
self.prev.advance_origin().await
Expand All @@ -86,7 +86,7 @@ where
#[async_trait]
impl<P> BatchQueueProvider for ChannelReader<P>
where
P: ChannelReaderProvider + PreviousStage + Send + Debug,
P: ChannelReaderProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
{
async fn next_batch(&mut self) -> StageResult<Batch> {
crate::timer!(START, STAGE_ADVANCE_RESPONSE_TIME, &["channel_reader"], timer);
Expand Down Expand Up @@ -115,7 +115,7 @@ where

impl<P> OriginProvider for ChannelReader<P>
where
P: ChannelReaderProvider + PreviousStage + Debug,
P: ChannelReaderProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
{
fn origin(&self) -> Option<BlockInfo> {
self.prev.origin()
Expand All @@ -125,7 +125,7 @@ where
#[async_trait]
impl<P> ResettableStage for ChannelReader<P>
where
P: ChannelReaderProvider + PreviousStage + Debug + Send,
P: ChannelReaderProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug + Send,
{
async fn reset(&mut self, base: BlockInfo, cfg: &SystemConfig) -> StageResult<()> {
self.prev.reset(base, cfg).await?;
Expand All @@ -135,15 +135,6 @@ where
}
}

impl<P> PreviousStage for ChannelReader<P>
where
P: ChannelReaderProvider + PreviousStage + Send + Debug,
{
fn previous(&self) -> Option<Box<&dyn PreviousStage>> {
Some(Box::new(&self.prev))
}
}

/// Batch Reader provides a function that iteratively consumes batches from the reader.
/// The L1Inclusion block is also provided at creation time.
/// Warning: the batch reader can read every batch-type.
Expand Down
23 changes: 7 additions & 16 deletions crates/derive/src/stages/frame_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
stages::ChannelBankProvider,
traits::{OriginAdvancer, OriginProvider, PreviousStage, ResettableStage},
traits::{OriginAdvancer, OriginProvider, ResettableStage},
types::{into_frames, BlockInfo, Frame, StageError, StageResult, SystemConfig},
};
use alloc::{boxed::Box, collections::VecDeque};
Expand Down Expand Up @@ -31,7 +31,7 @@ pub trait FrameQueueProvider {
#[derive(Debug)]
pub struct FrameQueue<P>
where
P: FrameQueueProvider + PreviousStage + Debug,
P: FrameQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
{
/// The previous stage in the pipeline.
pub prev: P,
Expand All @@ -41,7 +41,7 @@ where

impl<P> FrameQueue<P>
where
P: FrameQueueProvider + PreviousStage + Debug,
P: FrameQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
{
/// Create a new [FrameQueue] stage with the given previous [L1Retrieval] stage.
///
Expand All @@ -55,7 +55,7 @@ where
#[async_trait]
impl<P> OriginAdvancer for FrameQueue<P>
where
P: FrameQueueProvider + PreviousStage + Send + Debug,
P: FrameQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
{
async fn advance_origin(&mut self) -> StageResult<()> {
self.prev.advance_origin().await
Expand All @@ -65,7 +65,7 @@ where
#[async_trait]
impl<P> ChannelBankProvider for FrameQueue<P>
where
P: FrameQueueProvider + PreviousStage + Send + Debug,
P: FrameQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
{
async fn next_frame(&mut self) -> StageResult<Frame> {
if self.queue.is_empty() {
Expand Down Expand Up @@ -100,26 +100,17 @@ where

impl<P> OriginProvider for FrameQueue<P>
where
P: FrameQueueProvider + PreviousStage + Debug,
P: FrameQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Debug,
{
fn origin(&self) -> Option<BlockInfo> {
self.prev.origin()
}
}

impl<P> PreviousStage for FrameQueue<P>
where
P: FrameQueueProvider + PreviousStage + Send + Debug,
{
fn previous(&self) -> Option<Box<&dyn PreviousStage>> {
Some(Box::new(&self.prev))
}
}

#[async_trait]
impl<P> ResettableStage for FrameQueue<P>
where
P: FrameQueueProvider + PreviousStage + Send + Debug,
P: FrameQueueProvider + OriginAdvancer + OriginProvider + ResettableStage + Send + Debug,
{
async fn reset(
&mut self,
Expand Down
Loading

0 comments on commit 19123e3

Please sign in to comment.