Skip to content

Commit

Permalink
feat(derive): From<BlobProviderError> for PipelineErrorKind (#780)
Browse files Browse the repository at this point in the history
* feat(derive): `From<BlobProviderError> for PipelineErrorKind`

* lint

lint
  • Loading branch information
clabby authored Nov 5, 2024
1 parent a6ef5ab commit ac96fc2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
5 changes: 2 additions & 3 deletions bin/client/src/l1/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
l2::OracleL2ChainProvider,
BootInfo, FlushableCache, HintType,
};
use alloc::{string::ToString, sync::Arc, vec::Vec};
use alloc::{sync::Arc, vec::Vec};
use alloy_consensus::{BlockBody, Header, Sealable, Sealed};
use alloy_primitives::B256;
use alloy_rlp::Decodable;
Expand Down Expand Up @@ -322,8 +322,7 @@ where
self.l2_safe_head.block_info.number,
self.pipeline.rollup_config.clone(),
)
.await
.map_err(|e| PipelineError::Provider(e.to_string()).temp())?;
.await?;

if matches!(e, ResetError::HoloceneActivation) {
self.pipeline
Expand Down
3 changes: 1 addition & 2 deletions crates/derive-alloy/src/blob_provider.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
//! Contains an online implementation of the `BlobProvider` trait.
use crate::{BeaconClient, OnlineBeaconClient};
use alloy_eips::eip4844::{Blob, BlobTransactionSidecarItem};
use alloy_rpc_types_beacon::sidecar::BlobData;
use async_trait::async_trait;
use kona_derive::{errors::BlobProviderError, sources::IndexedBlobHash, traits::BlobProvider};
use op_alloy_protocol::BlockInfo;
use tracing::warn;

use crate::{BeaconClient, OnlineBeaconClient};

/// An online implementation of the [BlobProvider] trait.
#[derive(Debug, Clone)]
pub struct OnlineBlobProvider<B: BeaconClient> {
Expand Down
16 changes: 15 additions & 1 deletion crates/derive/src/errors/sources.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Error types for sources.
use alloc::string::String;
use super::{PipelineError, PipelineErrorKind};
use alloc::string::{String, ToString};

/// Blob Decoding Error
#[derive(derive_more::Display, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -38,6 +39,19 @@ pub enum BlobProviderError {
Backend(String),
}

impl From<BlobProviderError> for PipelineErrorKind {
fn from(val: BlobProviderError) -> Self {
match val {
BlobProviderError::SidecarLengthMismatch(_, _) => {
PipelineError::Provider(val.to_string()).crit()
}
BlobProviderError::SlotDerivation => PipelineError::Provider(val.to_string()).crit(),
BlobProviderError::BlobDecoding(_) => PipelineError::Provider(val.to_string()).crit(),
BlobProviderError::Backend(_) => PipelineError::Provider(val.to_string()).temp(),
}
}
}

impl From<BlobDecodingError> for BlobProviderError {
fn from(err: BlobDecodingError) -> Self {
Self::BlobDecoding(err)
Expand Down
10 changes: 2 additions & 8 deletions crates/derive/src/sources/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
errors::{BlobDecodingError, BlobProviderError, PipelineError, PipelineResult},
traits::{AsyncIterator, BlobProvider, ChainProvider},
};
use alloc::{boxed::Box, format, string::ToString, vec, vec::Vec};
use alloc::{boxed::Box, string::ToString, vec, vec::Vec};
use alloy_consensus::{Transaction, TxEip4844Variant, TxEnvelope, TxType};
use alloy_eips::eip4844::{Blob, BYTES_PER_BLOB, VERSIONED_HASH_VERSION_KZG};
use alloy_primitives::{Address, Bytes, B256};
Expand Down Expand Up @@ -361,13 +361,7 @@ where
type Item = Bytes;

async fn next(&mut self) -> PipelineResult<Self::Item> {
if self.load_blobs().await.is_err() {
return Err(PipelineError::Provider(format!(
"Failed to load blobs from stream: {}",
self.block_ref.hash
))
.temp());
}
self.load_blobs().await?;

let next_data = match self.next_data() {
Ok(d) => d,
Expand Down
3 changes: 1 addition & 2 deletions crates/derive/src/test_utils/blob_provider.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! An implementation of the [BlobProvider] trait for tests.
use crate::{errors::BlobProviderError, sources::IndexedBlobHash, traits::BlobProvider};
use alloc::{boxed::Box, vec::Vec};
use alloy_eips::eip4844::Blob;
use alloy_primitives::{map::HashMap, B256};
use async_trait::async_trait;
use op_alloy_protocol::BlockInfo;

use crate::{errors::BlobProviderError, sources::IndexedBlobHash, traits::BlobProvider};

/// A mock blob provider for testing.
#[derive(Debug, Clone, Default)]
pub struct TestBlobProvider {
Expand Down
7 changes: 5 additions & 2 deletions crates/derive/src/traits/data_sources.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Contains traits that describe the functionality of various data sources used in the derivation
//! pipeline's stages.
use crate::{errors::PipelineResult, sources::IndexedBlobHash};
use crate::{
errors::{PipelineErrorKind, PipelineResult},
sources::IndexedBlobHash,
};
use alloc::{boxed::Box, fmt::Debug, string::ToString, vec::Vec};
use alloy_eips::eip4844::Blob;
use alloy_primitives::Bytes;
Expand All @@ -13,7 +16,7 @@ use op_alloy_protocol::BlockInfo;
#[async_trait]
pub trait BlobProvider {
/// The error type for the [BlobProvider].
type Error: Display + ToString;
type Error: Display + ToString + Into<PipelineErrorKind>;

/// Fetches blobs for a given block ref and the blob hashes.
async fn get_blobs(
Expand Down

0 comments on commit ac96fc2

Please sign in to comment.