Skip to content

Commit

Permalink
fix(derive): hoist types out of traits (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Nov 5, 2024
1 parent ac96fc2 commit 4fc1ef6
Show file tree
Hide file tree
Showing 40 changed files with 236 additions and 213 deletions.
6 changes: 3 additions & 3 deletions bin/client/src/l1/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ use alloy_rlp::Decodable;
use core::fmt::Debug;
use kona_derive::{
attributes::StatefulAttributesBuilder,
errors::{PipelineError, PipelineErrorKind, PipelineResult, ResetError},
errors::{PipelineError, PipelineErrorKind, ResetError},
pipeline::{DerivationPipeline, PipelineBuilder},
sources::EthereumDataSource,
stages::{
AttributesQueue, BatchProvider, BatchStream, ChannelProvider, ChannelReader, FrameQueue,
L1Retrieval, L1Traversal,
},
traits::{
ActivationSignal, BlobProvider, ChainProvider, L2ChainProvider, OriginProvider, Pipeline,
ResetSignal, Signal, SignalReceiver, StepResult,
BlobProvider, ChainProvider, L2ChainProvider, OriginProvider, Pipeline, SignalReceiver,
},
types::{ActivationSignal, PipelineResult, ResetSignal, Signal, StepResult},
};
use kona_executor::{KonaHandleRegister, StatelessL2BlockExecutor};
use kona_mpt::{TrieHinter, TrieProvider};
Expand Down
5 changes: 2 additions & 3 deletions crates/derive/src/attributes/stateful.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! The [`AttributesBuilder`] and it's default implementation.
use crate::{
errors::{
BuilderError, PipelineEncodingError, PipelineError, PipelineErrorKind, PipelineResult,
},
errors::{BuilderError, PipelineEncodingError, PipelineError, PipelineErrorKind},
traits::{AttributesBuilder, ChainProvider, L2ChainProvider},
types::PipelineResult,
};
use alloc::{boxed::Box, fmt::Debug, string::ToString, sync::Arc, vec, vec::Vec};
use alloy_consensus::{Eip658Value, Receipt};
Expand Down
4 changes: 1 addition & 3 deletions crates/derive/src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ mod stages;
pub use stages::BatchDecompressionError;

mod pipeline;
pub use pipeline::{
PipelineEncodingError, PipelineError, PipelineErrorKind, PipelineResult, ResetError,
};
pub use pipeline::{PipelineEncodingError, PipelineError, PipelineErrorKind, ResetError};

mod sources;
pub use sources::{BlobDecodingError, BlobProviderError};
3 changes: 0 additions & 3 deletions crates/derive/src/errors/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ use alloy_primitives::B256;
use op_alloy_genesis::system::SystemConfigUpdateError;
use op_alloy_protocol::{DepositError, SpanBatchError};

/// A result type for the derivation pipeline stages.
pub type PipelineResult<T> = Result<T, PipelineErrorKind>;

/// [crate::ensure] is a short-hand for bubbling up errors in the case of a condition not being met.
#[macro_export]
macro_rules! ensure {
Expand Down
1 change: 1 addition & 0 deletions crates/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod pipeline;
pub mod sources;
pub mod stages;
pub mod traits;
pub mod types;

#[cfg(any(test, feature = "test-utils"))]
pub mod test_utils;
14 changes: 5 additions & 9 deletions crates/derive/src/pipeline/core.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Contains the core derivation pipeline.
use crate::{
errors::{PipelineError, PipelineErrorKind, PipelineResult},
errors::{PipelineError, PipelineErrorKind},
traits::{
ActivationSignal, L2ChainProvider, NextAttributes, OriginAdvancer, OriginProvider,
Pipeline, ResetSignal, Signal, SignalReceiver, StepResult,
L2ChainProvider, NextAttributes, OriginAdvancer, OriginProvider, Pipeline, SignalReceiver,
},
types::{ActivationSignal, PipelineResult, ResetSignal, Signal, StepResult},
};
use alloc::{boxed::Box, collections::VecDeque, sync::Arc};
use async_trait::async_trait;
Expand Down Expand Up @@ -172,12 +172,8 @@ where

#[cfg(test)]
mod tests {
use crate::{
errors::PipelineError,
pipeline::DerivationPipeline,
test_utils::*,
traits::{ActivationSignal, Pipeline, ResetSignal, Signal, SignalReceiver, StepResult},
};
use super::*;
use crate::{pipeline::DerivationPipeline, test_utils::*};
use alloc::{string::ToString, sync::Arc};
use alloy_rpc_types_engine::PayloadAttributes;
use op_alloy_genesis::{RollupConfig, SystemConfig};
Expand Down
3 changes: 2 additions & 1 deletion crates/derive/src/sources/blobs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Blob Data Source
use crate::{
errors::{BlobDecodingError, BlobProviderError, PipelineError, PipelineResult},
errors::{BlobDecodingError, BlobProviderError, PipelineError},
traits::{AsyncIterator, BlobProvider, ChainProvider},
types::PipelineResult,
};
use alloc::{boxed::Box, string::ToString, vec, vec::Vec};
use alloy_consensus::{Transaction, TxEip4844Variant, TxEnvelope, TxType};
Expand Down
3 changes: 2 additions & 1 deletion crates/derive/src/sources/calldata.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! CallData Source
use crate::{
errors::{PipelineError, PipelineResult},
errors::PipelineError,
traits::{AsyncIterator, ChainProvider},
types::PipelineResult,
};
use alloc::{boxed::Box, collections::VecDeque};
use alloy_consensus::{Transaction, TxEnvelope};
Expand Down
2 changes: 1 addition & 1 deletion crates/derive/src/sources/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//! [DataAvailabilityProvider] trait for the Ethereum protocol.
use crate::{
errors::PipelineResult,
sources::{BlobSource, CalldataSource, EthereumDataSourceVariant},
traits::{BlobProvider, ChainProvider, DataAvailabilityProvider},
types::PipelineResult,
};
use alloc::{boxed::Box, fmt::Debug};
use alloy_primitives::{Address, Bytes};
Expand Down
2 changes: 1 addition & 1 deletion crates/derive/src/sources/variant.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Data source
use crate::{
errors::PipelineResult,
sources::{BlobSource, CalldataSource},
traits::{AsyncIterator, BlobProvider, ChainProvider},
types::PipelineResult,
};
use alloc::boxed::Box;
use alloy_primitives::Bytes;
Expand Down
7 changes: 4 additions & 3 deletions crates/derive/src/stages/attributes_queue.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Contains the logic for the `AttributesQueue` stage.
use crate::{
errors::{PipelineError, PipelineResult, ResetError},
errors::{PipelineError, ResetError},
traits::{
AttributesBuilder, AttributesProvider, NextAttributes, OriginAdvancer, OriginProvider,
Signal, SignalReceiver,
SignalReceiver,
},
types::{PipelineResult, Signal},
};
use alloc::{boxed::Box, sync::Arc};
use async_trait::async_trait;
Expand Down Expand Up @@ -198,7 +199,7 @@ mod tests {
use crate::{
errors::{BuilderError, PipelineErrorKind},
test_utils::{new_test_attributes_provider, TestAttributesBuilder, TestAttributesProvider},
traits::ResetSignal,
types::ResetSignal,
};
use alloc::{sync::Arc, vec, vec::Vec};
use alloy_primitives::{b256, Address, Bytes, B256};
Expand Down
10 changes: 5 additions & 5 deletions crates/derive/src/stages/batch/batch_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
use super::NextBatchProvider;
use crate::{
errors::{PipelineError, PipelineResult},
errors::PipelineError,
stages::{BatchQueue, BatchValidator},
traits::{
AttributesProvider, L2ChainProvider, OriginAdvancer, OriginProvider, Signal, SignalReceiver,
},
traits::{AttributesProvider, L2ChainProvider, OriginAdvancer, OriginProvider, SignalReceiver},
types::{PipelineResult, Signal},
};
use alloc::{boxed::Box, sync::Arc};
use async_trait::async_trait;
Expand Down Expand Up @@ -179,7 +178,8 @@ mod test {
use super::BatchProvider;
use crate::{
test_utils::{TestL2ChainProvider, TestNextBatchProvider},
traits::{OriginProvider, ResetSignal, SignalReceiver},
traits::{OriginProvider, SignalReceiver},
types::ResetSignal,
};
use alloc::{sync::Arc, vec};
use op_alloy_genesis::RollupConfig;
Expand Down
8 changes: 3 additions & 5 deletions crates/derive/src/stages/batch/batch_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
use super::NextBatchProvider;
use crate::{
errors::{PipelineEncodingError, PipelineError, PipelineErrorKind, PipelineResult, ResetError},
traits::{
AttributesProvider, L2ChainProvider, OriginAdvancer, OriginProvider, ResetSignal, Signal,
SignalReceiver,
},
errors::{PipelineEncodingError, PipelineError, PipelineErrorKind, ResetError},
traits::{AttributesProvider, L2ChainProvider, OriginAdvancer, OriginProvider, SignalReceiver},
types::{PipelineResult, ResetSignal, Signal},
};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use async_trait::async_trait;
Expand Down
7 changes: 4 additions & 3 deletions crates/derive/src/stages/batch/batch_stream.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! This module contains the `BatchStream` stage.
use crate::{
errors::{PipelineEncodingError, PipelineError, PipelineResult},
errors::{PipelineEncodingError, PipelineError},
stages::NextBatchProvider,
traits::{L2ChainProvider, OriginAdvancer, OriginProvider, Signal, SignalReceiver},
traits::{L2ChainProvider, OriginAdvancer, OriginProvider, SignalReceiver},
types::{PipelineResult, Signal},
};
use alloc::{boxed::Box, collections::VecDeque, sync::Arc};
use async_trait::async_trait;
Expand Down Expand Up @@ -222,7 +223,7 @@ mod test {
use super::*;
use crate::{
test_utils::{CollectingLayer, TestBatchStreamProvider, TestL2ChainProvider, TraceStorage},
traits::ResetSignal,
types::ResetSignal,
};
use alloc::vec;
use op_alloy_protocol::{SingleBatch, SpanBatchElement};
Expand Down
10 changes: 6 additions & 4 deletions crates/derive/src/stages/batch/batch_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
use super::NextBatchProvider;
use crate::{
errors::{PipelineResult, ResetError},
errors::ResetError,
prelude::{OriginProvider, PipelineError, PipelineErrorKind},
traits::{AttributesProvider, OriginAdvancer, ResetSignal, Signal, SignalReceiver},
traits::{AttributesProvider, OriginAdvancer, SignalReceiver},
types::{PipelineResult, ResetSignal, Signal},
};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use async_trait::async_trait;
Expand Down Expand Up @@ -310,10 +311,11 @@ where
#[cfg(test)]
mod test {
use crate::{
errors::{PipelineError, PipelineErrorKind, PipelineResult, ResetError},
errors::{PipelineError, PipelineErrorKind, ResetError},
stages::{BatchValidator, NextBatchProvider},
test_utils::{CollectingLayer, TestNextBatchProvider, TraceStorage},
traits::{AttributesProvider, OriginAdvancer, ResetSignal, Signal, SignalReceiver},
traits::{AttributesProvider, OriginAdvancer, SignalReceiver},
types::{PipelineResult, ResetSignal, Signal},
};
use alloc::{sync::Arc, vec, vec::Vec};
use alloy_eips::{BlockNumHash, NumHash};
Expand Down
2 changes: 1 addition & 1 deletion crates/derive/src/stages/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! [ChannelReader]: crate::stages::channel::ChannelReader
//! [AttributesQueue]: crate::stages::attributes_queue::AttributesQueue
use crate::errors::PipelineResult;
use crate::types::PipelineResult;
use alloc::boxed::Box;
use async_trait::async_trait;
use op_alloy_protocol::{Batch, BlockInfo, L2BlockInfo};
Expand Down
4 changes: 2 additions & 2 deletions crates/derive/src/stages/channel/channel_assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
use super::{ChannelReaderProvider, NextFrameProvider};
use crate::{
errors::PipelineResult,
prelude::{OriginProvider, PipelineError},
traits::{OriginAdvancer, Signal, SignalReceiver},
traits::{OriginAdvancer, SignalReceiver},
types::{PipelineResult, Signal},
};
use alloc::{boxed::Box, sync::Arc};
use alloy_primitives::{hex, Bytes};
Expand Down
7 changes: 4 additions & 3 deletions crates/derive/src/stages/channel/channel_bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
use super::NextFrameProvider;
use crate::{
errors::{PipelineError, PipelineErrorKind, PipelineResult},
errors::{PipelineError, PipelineErrorKind},
stages::ChannelReaderProvider,
traits::{OriginAdvancer, OriginProvider, Signal, SignalReceiver},
traits::{OriginAdvancer, OriginProvider, SignalReceiver},
types::{PipelineResult, Signal},
};
use alloc::{boxed::Box, collections::VecDeque, sync::Arc};
use alloy_primitives::{hex, map::HashMap, Bytes};
Expand Down Expand Up @@ -245,7 +246,7 @@ mod tests {
use super::*;
use crate::{
test_utils::{CollectingLayer, TestNextFrameProvider, TraceStorage},
traits::ResetSignal,
types::ResetSignal,
};
use alloc::{vec, vec::Vec};
use op_alloy_genesis::{BASE_MAINNET_CONFIG, OP_MAINNET_CONFIG};
Expand Down
8 changes: 5 additions & 3 deletions crates/derive/src/stages/channel/channel_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
use super::{ChannelAssembler, ChannelBank, ChannelReaderProvider, NextFrameProvider};
use crate::{
errors::{PipelineError, PipelineResult},
traits::{OriginAdvancer, OriginProvider, Signal, SignalReceiver},
errors::PipelineError,
traits::{OriginAdvancer, OriginProvider, SignalReceiver},
types::{PipelineResult, Signal},
};
use alloc::{boxed::Box, sync::Arc};
use alloy_primitives::Bytes;
Expand Down Expand Up @@ -158,7 +159,8 @@ mod test {
prelude::{OriginProvider, PipelineError},
stages::ChannelReaderProvider,
test_utils::TestNextFrameProvider,
traits::{ResetSignal, SignalReceiver},
traits::SignalReceiver,
types::ResetSignal,
};
use alloc::{sync::Arc, vec};
use op_alloy_genesis::RollupConfig;
Expand Down
7 changes: 4 additions & 3 deletions crates/derive/src/stages/channel/channel_reader.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! This module contains the `ChannelReader` struct.
use crate::{
errors::{PipelineError, PipelineResult},
errors::PipelineError,
stages::{decompress_brotli, BatchStreamProvider},
traits::{OriginAdvancer, OriginProvider, Signal, SignalReceiver},
traits::{OriginAdvancer, OriginProvider, SignalReceiver},
types::{PipelineResult, Signal},
};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use alloy_primitives::Bytes;
Expand Down Expand Up @@ -257,7 +258,7 @@ impl BatchReader {
mod test {
use super::*;
use crate::{
errors::PipelineErrorKind, test_utils::TestChannelReaderProvider, traits::ResetSignal,
errors::PipelineErrorKind, test_utils::TestChannelReaderProvider, types::ResetSignal,
};
use alloc::vec;

Expand Down
2 changes: 1 addition & 1 deletion crates/derive/src/stages/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! [FrameQueue]: crate::stages::FrameQueue
//! [BatchQueue]: crate::stages::BatchQueue
use crate::errors::PipelineResult;
use crate::types::PipelineResult;
use alloc::boxed::Box;
use async_trait::async_trait;
use op_alloy_protocol::Frame;
Expand Down
7 changes: 4 additions & 3 deletions crates/derive/src/stages/frame_queue.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! This module contains the [FrameQueue] stage of the derivation pipeline.
use crate::{
errors::{PipelineError, PipelineResult},
errors::PipelineError,
stages::NextFrameProvider,
traits::{OriginAdvancer, OriginProvider, Signal, SignalReceiver},
traits::{OriginAdvancer, OriginProvider, SignalReceiver},
types::{PipelineResult, Signal},
};
use alloc::{boxed::Box, collections::VecDeque, sync::Arc};
use alloy_primitives::Bytes;
Expand Down Expand Up @@ -193,7 +194,7 @@ where
#[cfg(test)]
pub(crate) mod tests {
use super::*;
use crate::{test_utils::TestFrameQueueProvider, traits::ResetSignal};
use crate::{test_utils::TestFrameQueueProvider, types::ResetSignal};
use alloc::vec;

#[tokio::test]
Expand Down
6 changes: 3 additions & 3 deletions crates/derive/src/stages/l1_retrieval.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Contains the [L1Retrieval] stage of the derivation pipeline.
use crate::{
errors::{PipelineError, PipelineErrorKind, PipelineResult},
errors::{PipelineError, PipelineErrorKind},
stages::FrameQueueProvider,
traits::{
ActivationSignal, AsyncIterator, DataAvailabilityProvider, OriginAdvancer, OriginProvider,
ResetSignal, Signal, SignalReceiver,
AsyncIterator, DataAvailabilityProvider, OriginAdvancer, OriginProvider, SignalReceiver,
},
types::{ActivationSignal, PipelineResult, ResetSignal, Signal},
};
use alloc::boxed::Box;
use alloy_primitives::Address;
Expand Down
8 changes: 3 additions & 5 deletions crates/derive/src/stages/l1_traversal.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
//! Contains the [L1Traversal] stage of the derivation pipeline.
use crate::{
errors::{PipelineError, PipelineResult, ResetError},
errors::{PipelineError, ResetError},
stages::L1RetrievalProvider,
traits::{
ActivationSignal, ChainProvider, OriginAdvancer, OriginProvider, ResetSignal, Signal,
SignalReceiver,
},
traits::{ChainProvider, OriginAdvancer, OriginProvider, SignalReceiver},
types::{ActivationSignal, PipelineResult, ResetSignal, Signal},
};
use alloc::{boxed::Box, sync::Arc};
use alloy_primitives::Address;
Expand Down
Loading

0 comments on commit 4fc1ef6

Please sign in to comment.