diff --git a/Cargo.lock b/Cargo.lock index 1c37c9da02..84303359ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -280,9 +280,9 @@ dependencies = [ [[package]] name = "alloy-eip7702" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d319bb544ca6caeab58c39cea8921c55d924d4f68f2c60f24f914673f9a74a" +checksum = "ea59dc42102bc9a1905dc57901edc6dd48b9f38115df86c7d252acba70d71d04" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -2338,18 +2338,15 @@ dependencies = [ "alloy-eips", "alloy-node-bindings", "alloy-primitives", - "alloy-provider", "alloy-rlp", "alloy-rpc-client", "alloy-rpc-types-engine", - "alloy-transport", "alloy-transport-http", "anyhow", "async-trait", "brotli", "kona-primitives", "lazy_static", - "lru", "miniz_oxide", "op-alloy-consensus", "op-alloy-genesis", @@ -2357,7 +2354,6 @@ dependencies = [ "op-alloy-rpc-types-engine", "prometheus", "proptest", - "reqwest", "serde", "serde_json", "spin", @@ -2411,10 +2407,10 @@ dependencies = [ "futures", "kona-client", "kona-common", - "kona-derive", "kona-mpt", "kona-preimage", "kona-primitives", + "kona-providers-alloy", "op-alloy-genesis", "op-alloy-protocol", "os_pipe", @@ -2485,6 +2481,34 @@ dependencies = [ "tracing", ] +[[package]] +name = "kona-providers-alloy" +version = "0.0.1" +dependencies = [ + "alloy-consensus", + "alloy-eips", + "alloy-node-bindings", + "alloy-primitives", + "alloy-provider", + "alloy-rlp", + "alloy-rpc-client", + "alloy-transport", + "alloy-transport-http", + "async-trait", + "kona-derive", + "kona-primitives", + "lazy_static", + "lru", + "op-alloy-genesis", + "op-alloy-protocol", + "prometheus", + "reqwest", + "serde_json", + "thiserror 1.0.64 (git+https://github.com/quartiq/thiserror?branch=no-std)", + "tokio", + "tracing", +] + [[package]] name = "language-tags" version = "0.3.2" @@ -3561,9 +3585,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.7" +version = "0.12.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", @@ -3860,11 +3884,10 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "2.1.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" dependencies = [ - "base64", "rustls-pki-types", ] @@ -4753,8 +4776,8 @@ dependencies = [ "alloy-transport", "anyhow", "clap", - "kona-derive", "kona-primitives", + "kona-providers-alloy", "lazy_static", "op-alloy-genesis", "op-alloy-rpc-types-engine", diff --git a/Cargo.toml b/Cargo.toml index fe83c42342..f75285bf2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ kona-executor = { path = "crates/executor", version = "0.0.2" } kona-common-proc = { path = "crates/common-proc", version = "0.0.3" } kona-derive = { path = "crates/derive", version = "0.0.3", default-features = false } kona-primitives = { path = "crates/primitives", version = "0.0.2", default-features = false } +kona-providers-alloy = { path = "crates/providers-alloy", version = "0.0.1", default-features = false } # General anyhow = { version = "1.0.89", default-features = false } diff --git a/bin/host/Cargo.toml b/bin/host/Cargo.toml index 75431b8aba..67288674bc 100644 --- a/bin/host/Cargo.toml +++ b/bin/host/Cargo.toml @@ -17,7 +17,7 @@ kona-mpt.workspace = true kona-client.workspace = true kona-common.workspace = true kona-preimage.workspace = true -kona-derive = { workspace = true, features = ["online"] } +kona-providers-alloy.workspace = true kona-primitives = { workspace = true, features = ["online"] } # Alloy & Revm diff --git a/bin/host/src/cli/mod.rs b/bin/host/src/cli/mod.rs index e772ef3fcd..942fb49bd9 100644 --- a/bin/host/src/cli/mod.rs +++ b/bin/host/src/cli/mod.rs @@ -14,7 +14,7 @@ use clap::{ builder::styling::{AnsiColor, Color, Style}, ArgAction, Parser, }; -use kona_derive::online::{OnlineBeaconClient, OnlineBlobProvider, SimpleSlotDerivation}; +use kona_providers_alloy::{OnlineBeaconClient, OnlineBlobProvider, SimpleSlotDerivation}; use op_alloy_genesis::RollupConfig; use serde::Serialize; use std::{path::PathBuf, sync::Arc}; diff --git a/bin/host/src/fetcher/mod.rs b/bin/host/src/fetcher/mod.rs index 7ef9c15628..4ebaed38c2 100644 --- a/bin/host/src/fetcher/mod.rs +++ b/bin/host/src/fetcher/mod.rs @@ -12,9 +12,9 @@ use alloy_rpc_types::{ }; use anyhow::{anyhow, Result}; use kona_client::HintType; -use kona_derive::online::{OnlineBeaconClient, OnlineBlobProvider, SimpleSlotDerivation}; use kona_preimage::{PreimageKey, PreimageKeyType}; use kona_primitives::IndexedBlobHash; +use kona_providers_alloy::{OnlineBeaconClient, OnlineBlobProvider, SimpleSlotDerivation}; use op_alloy_protocol::BlockInfo; use std::sync::Arc; use tokio::sync::RwLock; diff --git a/crates/derive/Cargo.toml b/crates/derive/Cargo.toml index 0704497bdb..58bf02d716 100644 --- a/crates/derive/Cargo.toml +++ b/crates/derive/Cargo.toml @@ -38,12 +38,6 @@ kona-primitives.workspace = true # `serde` feature dependencies serde = { workspace = true, optional = true } -# `online` feature dependencies -lru = { workspace = true, optional = true } -alloy-transport = { workspace = true, optional = true } -alloy-provider = { workspace = true, optional = true } -reqwest = { workspace = true, optional = true } - # `metrics` feature dependencies lazy_static = { workspace = true, optional = true } prometheus = { workspace = true, optional = true } @@ -69,6 +63,10 @@ serde_json.workspace = true [features] default = ["serde"] +metrics = [ + "dep:prometheus", + "dep:lazy_static", +] serde = [ "dep:serde", "kona-primitives/serde", @@ -79,20 +77,6 @@ serde = [ "op-alloy-genesis/serde", "op-alloy-rpc-types-engine/serde", ] -metrics = ["dep:prometheus", "dep:lazy_static"] -online = [ - "dep:alloy-provider", - "dep:alloy-transport", - "dep:reqwest", - "dep:lru", - "alloy-provider/reqwest", - "alloy-consensus/serde", - "kona-primitives/online", - "kona-primitives/serde", - "op-alloy-consensus/std", - "op-alloy-protocol/std", - "op-alloy-genesis/std", -] test-utils = [ "dep:spin", "dep:anyhow", diff --git a/crates/derive/src/lib.rs b/crates/derive/src/lib.rs index c63480914d..341b890e13 100644 --- a/crates/derive/src/lib.rs +++ b/crates/derive/src/lib.rs @@ -5,7 +5,16 @@ extern crate alloc; -mod macros; +/// Re-export commonly used types and traits. +pub mod prelude { + pub use crate::{ + attributes::StatefulAttributesBuilder, + errors::{PipelineError, PipelineErrorKind}, + pipeline::{DerivationPipeline, PipelineBuilder}, + sources::EthereumDataSource, + traits::{ChainProvider, L2ChainProvider, OriginProvider, Pipeline, StepResult}, + }; +} pub mod attributes; pub mod batch; @@ -16,8 +25,7 @@ pub mod sources; pub mod stages; pub mod traits; -#[cfg(feature = "online")] -pub mod online; - #[cfg(feature = "metrics")] pub mod metrics; + +mod macros; diff --git a/crates/derive/src/metrics.rs b/crates/derive/src/metrics.rs index 3f9d4b9433..4cea01072b 100644 --- a/crates/derive/src/metrics.rs +++ b/crates/derive/src/metrics.rs @@ -62,29 +62,6 @@ lazy_static! { "Compression ratio of batches" ).expect("Batch Compression Ratio failed to register"); - /// Tracks the number of provider method calls. - pub static ref PROVIDER_CALLS: CounterVec = register_counter_vec!( - "kona_derive_provider_calls", - "Number of provider method calls", - &["provider", "method"] - ).expect("Provider Calls failed to register"); - - /// Tracks the number of errors in provider methods. - pub static ref PROVIDER_ERRORS: CounterVec = register_counter_vec!( - "kona_derive_provider_errors", - "Number of provider errors", - &["provider", "method", "error"] - ).expect("Provider Errors failed to register"); - - /// Tracks the time taken for provider methods. - pub static ref PROVIDER_RESPONSE_TIME: HistogramVec = register_histogram_vec!( - "kona_derive_provider_response_time_seconds", - "Provider response times", - &["provider", "method"], - RESPONSE_TIME_CUSTOM_BUCKETS.to_vec() - ) - .expect("Failed to register histogram vec"); - /// Tracks the time taken for stage advance methods. pub static ref STAGE_ADVANCE_RESPONSE_TIME: HistogramVec = register_histogram_vec!( "kona_derive_stage_advance_response_time_seconds", diff --git a/crates/providers-alloy/Cargo.toml b/crates/providers-alloy/Cargo.toml new file mode 100644 index 0000000000..b4a15a27e6 --- /dev/null +++ b/crates/providers-alloy/Cargo.toml @@ -0,0 +1,63 @@ +[package] +name = "kona-providers-alloy" +description = "Alloy provider implementations for Kona" +version = "0.0.1" +edition.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true + +[lints] +workspace = true + +[dependencies] +# Alloy +alloy-eips.workspace = true +alloy-transport.workspace = true +alloy-provider = { workspace = true, features = ["reqwest"] } +alloy-rlp = { workspace = true, features = ["derive"] } +alloy-consensus = { workspace = true, features = ["k256", "serde", "std"] } +alloy-primitives = { workspace = true, features = ["rlp", "k256", "serde"] } + +# OP Alloy +op-alloy-protocol = { workspace = true, features = ["serde", "std"] } +op-alloy-genesis = { workspace = true, features = ["serde", "std"] } + +# General +lru.workspace = true +reqwest.workspace = true +tracing.workspace = true +async-trait.workspace = true + +# Workspace +kona-derive = { workspace = true, features = ["serde"] } +kona-primitives = { workspace = true, features = ["serde", "online"] } + +# `metrics` feature dependencies +lazy_static = { workspace = true, optional = true } +prometheus = { workspace = true, optional = true } + +# `test-utils` feature dependencies +thiserror = { workspace = true, optional = true } +alloy-rpc-client = { workspace = true, optional = true } +alloy-node-bindings = { workspace = true, optional = true } +alloy-transport-http = { workspace = true, optional = true, features = ["reqwest"] } + +[dev-dependencies] +tokio.workspace = true +thiserror.workspace = true +serde_json.workspace = true +alloy-rpc-client.workspace = true +alloy-node-bindings.workspace = true +alloy-transport-http.workspace = true + +[features] +default = [] +metrics = ["dep:prometheus", "dep:lazy_static"] +test-utils = [ + "dep:thiserror", + "dep:alloy-rpc-client", + "dep:alloy-node-bindings", + "dep:alloy-transport-http", +] diff --git a/crates/providers-alloy/README.md b/crates/providers-alloy/README.md new file mode 100644 index 0000000000..4220a6e7c1 --- /dev/null +++ b/crates/providers-alloy/README.md @@ -0,0 +1,5 @@ +## `kona-providers-alloy` + +_Notice: Requires an `std` environment._ + +Alloy providers for `kona-derive`. diff --git a/crates/derive/src/online/alloy_providers.rs b/crates/providers-alloy/src/alloy_providers.rs similarity index 98% rename from crates/derive/src/online/alloy_providers.rs rename to crates/providers-alloy/src/alloy_providers.rs index 9af0e7948c..87728a192c 100644 --- a/crates/derive/src/online/alloy_providers.rs +++ b/crates/providers-alloy/src/alloy_providers.rs @@ -1,19 +1,17 @@ -//! This module contains concrete implementations of the data provider traits, using an alloy -//! provider on the backend. +//! Providers that use alloy provider types on the backend. -use alloc::{boxed::Box, sync::Arc, vec::Vec}; use alloy_consensus::{Header, Receipt, ReceiptWithBloom, TxEnvelope, TxType}; use alloy_primitives::{Bytes, B256, U64}; use alloy_provider::{Provider, ReqwestProvider}; use alloy_rlp::{Buf, Decodable}; use alloy_transport::{RpcError, TransportErrorKind, TransportResult}; use async_trait::async_trait; -use core::num::NonZeroUsize; use lru::LruCache; use op_alloy_genesis::{RollupConfig, SystemConfig}; use op_alloy_protocol::{BlockInfo, L2BlockInfo}; +use std::{boxed::Box, num::NonZeroUsize, sync::Arc, vec::Vec}; -use crate::{ +use kona_derive::{ block::{Block, OpBlock}, traits::{ChainProvider, L2ChainProvider}, }; diff --git a/crates/derive/src/online/beacon_client.rs b/crates/providers-alloy/src/beacon_client.rs similarity index 96% rename from crates/derive/src/online/beacon_client.rs rename to crates/providers-alloy/src/beacon_client.rs index 8aa97a3ecc..f3bd23f7ee 100644 --- a/crates/derive/src/online/beacon_client.rs +++ b/crates/providers-alloy/src/beacon_client.rs @@ -1,19 +1,11 @@ -//! Contains an online implementation of the [BeaconClient] trait. +//! Contains an online implementation of the `BeaconClient` trait. -use alloc::{ - boxed::Box, - format, - string::{String, ToString}, - vec::Vec, -}; use async_trait::async_trait; -use core::fmt::Display; -use reqwest::Client; - use kona_primitives::{ APIBlobSidecar, APIConfigResponse, APIGenesisResponse, APIGetBlobSidecarsResponse, IndexedBlobHash, }; +use reqwest::Client; /// The config spec engine api method. pub(crate) const SPEC_METHOD: &str = "eth/v1/config/spec"; @@ -28,7 +20,7 @@ pub(crate) const SIDECARS_METHOD_PREFIX: &str = "eth/v1/beacon/blob_sidecars"; #[async_trait] pub trait BeaconClient { /// The error type for [BeaconClient] implementations. - type Error: Display + ToString; + type Error: std::fmt::Display + ToString; /// Returns the config spec. async fn config_spec(&self) -> Result; diff --git a/crates/derive/src/online/blob_provider.rs b/crates/providers-alloy/src/blob_provider.rs similarity index 98% rename from crates/derive/src/online/blob_provider.rs rename to crates/providers-alloy/src/blob_provider.rs index 1fbec0a612..9587464ca6 100644 --- a/crates/derive/src/online/blob_provider.rs +++ b/crates/providers-alloy/src/blob_provider.rs @@ -1,23 +1,15 @@ -//! Contains an online implementation of the [BlobProvider] trait. - -use crate::{ - ensure, - errors::BlobProviderError, - online::{BeaconClient, OnlineBeaconClient}, - traits::BlobProvider, -}; -use alloc::{ - boxed::Box, - string::{String, ToString}, - vec::Vec, -}; +//! Contains an online implementation of the `BlobProvider` trait. + use alloy_eips::eip4844::Blob; use async_trait::async_trait; use core::marker::PhantomData; +use kona_derive::{errors::BlobProviderError, traits::BlobProvider}; use kona_primitives::{APIBlobSidecar, BlobSidecar, IndexedBlobHash}; use op_alloy_protocol::BlockInfo; use tracing::warn; +use crate::{BeaconClient, OnlineBeaconClient}; + /// Specifies the derivation of a slot from a timestamp. pub trait SlotDerivation { /// Converts a timestamp to a slot number. @@ -130,7 +122,7 @@ pub struct SimpleSlotDerivation; impl SlotDerivation for SimpleSlotDerivation { fn slot(genesis: u64, slot_time: u64, timestamp: u64) -> Result { - ensure!(timestamp >= genesis, BlobProviderError::SlotDerivation); + crate::ensure!(timestamp >= genesis, BlobProviderError::SlotDerivation); Ok((timestamp - genesis) / slot_time) } } @@ -481,8 +473,7 @@ impl #[cfg(test)] mod tests { use super::*; - use crate::online::test_utils::MockBeaconClient; - use alloc::vec; + use crate::test_utils::MockBeaconClient; use alloy_primitives::b256; use kona_primitives::{APIConfigResponse, APIGenesisResponse, APIGetBlobSidecarsResponse}; diff --git a/crates/providers-alloy/src/lib.rs b/crates/providers-alloy/src/lib.rs new file mode 100644 index 0000000000..1a6a835c0b --- /dev/null +++ b/crates/providers-alloy/src/lib.rs @@ -0,0 +1,36 @@ +#![doc = include_str!("../README.md")] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] + +mod macros; + +#[cfg(feature = "metrics")] +pub mod metrics; +#[cfg(feature = "metrics")] +pub use metrics::*; + +#[cfg(any(test, feature = "test-utils"))] +pub mod test_utils; +#[cfg(any(test, feature = "test-utils"))] +pub use test_utils::*; + +/// Re-export commonly used types and traits. +pub mod prelude { + pub use super::*; + pub use kona_derive::prelude::*; +} + +pub mod pipeline; +pub use pipeline::{new_online_pipeline, OnlinePipeline}; + +pub mod alloy_providers; +pub use alloy_providers::{AlloyChainProvider, AlloyL2ChainProvider}; + +pub mod beacon_client; +pub use beacon_client::{BeaconClient, OnlineBeaconClient}; + +pub mod blob_provider; +pub use blob_provider::{ + BlobSidecarProvider, OnlineBlobProvider, OnlineBlobProviderBuilder, + OnlineBlobProviderWithFallback, SimpleSlotDerivation, SlotDerivation, +}; diff --git a/crates/providers-alloy/src/macros.rs b/crates/providers-alloy/src/macros.rs new file mode 100644 index 0000000000..05b606a13b --- /dev/null +++ b/crates/providers-alloy/src/macros.rs @@ -0,0 +1,71 @@ +//! Macros for use across derive. + +/// Ensure inlines a branch check. +#[macro_export] +macro_rules! ensure { + ($cond:expr, $msg:expr) => { + if !$cond { + return Err($msg.into()); + } + }; +} + +/// Starts the timer with a label value. +#[macro_export] +macro_rules! timer { + (START, $metric:ident, $labels:expr, $timer:ident) => { + #[cfg(feature = "metrics")] + let $timer = $crate::metrics::$metric.with_label_values($labels).start_timer(); + }; + (DISCARD, $timer:ident) => { + #[cfg(feature = "metrics")] + $timer.stop_and_discard(); + }; + (STOP, $timer:ident) => { + #[cfg(feature = "metrics")] + $timer.stop_and_record(); + }; +} + +/// Increments a metric with a label value. +#[macro_export] +macro_rules! inc { + ($metric:ident) => { + #[cfg(feature = "metrics")] + $crate::metrics::$metric.inc(); + }; + ($metric:ident, $labels:expr) => { + #[cfg(feature = "metrics")] + $crate::metrics::$metric.with_label_values($labels).inc(); + }; + ($metric:ident, $value:expr, $labels:expr) => { + #[cfg(feature = "metrics")] + $crate::metrics::$metric.with_label_values($labels).add($value); + }; +} + +/// Observes a metric with a label value. +#[macro_export] +macro_rules! observe { + ($metric:ident, $value:expr) => { + #[cfg(feature = "metrics")] + $crate::metrics::$metric.observe($value); + }; + ($metric:ident, $value:expr, $labels:expr) => { + #[cfg(feature = "metrics")] + $crate::metrics::$metric.with_label_values($label).observe($value); + }; +} + +/// Sets a metric value. +#[macro_export] +macro_rules! set { + ($metric:ident, $value:expr) => { + #[cfg(feature = "metrics")] + $crate::metrics::$metric.set($value); + }; + ($metric:ident, $value:expr, $labels:expr) => { + #[cfg(feature = "metrics")] + $crate::metrics::$metric.with_label_values($labels).set($value as f64); + }; +} diff --git a/crates/providers-alloy/src/metrics.rs b/crates/providers-alloy/src/metrics.rs new file mode 100644 index 0000000000..1b9b641b57 --- /dev/null +++ b/crates/providers-alloy/src/metrics.rs @@ -0,0 +1,35 @@ +//! Metrics for providers. + +use lazy_static::lazy_static; +use prometheus::{self, register_counter_vec, register_histogram_vec, CounterVec, HistogramVec}; +use std::{boxed::Box, string::String}; + +const RESPONSE_TIME_CUSTOM_BUCKETS: &[f64; 18] = &[ + 0.00001, 0.00005, 0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.008, 0.01, 0.02, 0.05, 0.08, + 0.1, 0.2, 0.5, 0.8, 1.0, +]; + +lazy_static! { + /// Tracks the number of provider method calls. + pub static ref PROVIDER_CALLS: CounterVec = register_counter_vec!( + "kona_derive_provider_calls", + "Number of provider method calls", + &["provider", "method"] + ).expect("Provider Calls failed to register"); + + /// Tracks the number of errors in provider methods. + pub static ref PROVIDER_ERRORS: CounterVec = register_counter_vec!( + "kona_derive_provider_errors", + "Number of provider errors", + &["provider", "method", "error"] + ).expect("Provider Errors failed to register"); + + /// Tracks the time taken for provider methods. + pub static ref PROVIDER_RESPONSE_TIME: HistogramVec = register_histogram_vec!( + "kona_derive_provider_response_time_seconds", + "Provider response times", + &["provider", "method"], + RESPONSE_TIME_CUSTOM_BUCKETS.to_vec() + ) + .expect("Failed to register histogram vec"); +} diff --git a/crates/derive/src/online/pipeline.rs b/crates/providers-alloy/src/pipeline.rs similarity index 76% rename from crates/derive/src/online/pipeline.rs rename to crates/providers-alloy/src/pipeline.rs index 4eb634400c..4b76e5f73c 100644 --- a/crates/derive/src/online/pipeline.rs +++ b/crates/providers-alloy/src/pipeline.rs @@ -1,18 +1,21 @@ -//! Contains online pipeline types. +//! Helper to construct a [DerivationPipeline] using online types. -use super::{ - AlloyChainProvider, AlloyL2ChainProvider, DerivationPipeline, EthereumDataSource, - OnlineBeaconClient, OnlineBlobProviderWithFallback, PipelineBuilder, SimpleSlotDerivation, - StatefulAttributesBuilder, +use kona_derive::{ + attributes::StatefulAttributesBuilder, + pipeline::{DerivationPipeline, PipelineBuilder}, + sources::EthereumDataSource, + stages::{ + AttributesQueue, BatchQueue, BatchStream, ChannelBank, ChannelReader, FrameQueue, + L1Retrieval, L1Traversal, + }, }; -use alloc::sync::Arc; use op_alloy_genesis::RollupConfig; use op_alloy_protocol::BlockInfo; +use std::sync::Arc; -// Pipeline internal stages aren't re-exported at the module-level. -use crate::stages::{ - AttributesQueue, BatchQueue, BatchStream, ChannelBank, ChannelReader, FrameQueue, L1Retrieval, - L1Traversal, +use crate::{ + AlloyChainProvider, AlloyL2ChainProvider, OnlineBeaconClient, OnlineBlobProviderWithFallback, + SimpleSlotDerivation, }; /// An online derivation pipeline. diff --git a/crates/derive/src/online/test_utils.rs b/crates/providers-alloy/src/test_utils.rs similarity index 59% rename from crates/derive/src/online/test_utils.rs rename to crates/providers-alloy/src/test_utils.rs index 668fcf9d3f..aa54f80ee6 100644 --- a/crates/derive/src/online/test_utils.rs +++ b/crates/providers-alloy/src/test_utils.rs @@ -1,11 +1,9 @@ //! Test Utilities for Online Providers -use alloc::{boxed::Box, string::String, vec::Vec}; use alloy_node_bindings::{Anvil, AnvilInstance}; use alloy_provider::{network::Ethereum, ReqwestProvider}; use alloy_rpc_client::RpcClient; use alloy_transport_http::Http; -use anyhow::{anyhow, Result}; use async_trait::async_trait; use kona_primitives::{ APIBlobSidecar, APIConfigResponse, APIGenesisResponse, APIGetBlobSidecarsResponse, @@ -13,8 +11,6 @@ use kona_primitives::{ }; use reqwest::Client; -use super::BeaconClient; - /// Spawns an Anvil instance and returns a provider and the instance. pub fn spawn_anvil() -> (ReqwestProvider, AnvilInstance) { let anvil = Anvil::new().try_spawn().expect("could not spawn anvil"); @@ -33,7 +29,7 @@ pub fn http_provider(url: &str) -> ReqwestProvider { ReqwestProvider::new(RpcClient::new(http, true)) } -/// A mock [BeaconClient] for testing. +/// A mock [crate::BeaconClient] for testing. #[derive(Debug, Default)] pub struct MockBeaconClient { /// The node version. @@ -46,23 +42,40 @@ pub struct MockBeaconClient { pub blob_sidecars: Option, } +/// A mock beacon client error +#[derive(Debug, thiserror::Error)] +pub enum MockBeaconClientError { + /// The config spec is not set + #[error("config_spec not set")] + ConfigSpecNotSet, + /// The beacon genesis is not set + #[error("beacon_genesis not set")] + BeaconGenesisNotSet, + /// The blob sidecars are not set + #[error("blob_sidecars not set")] + BlobSidecarsNotSet, +} + #[async_trait] -impl BeaconClient for MockBeaconClient { - type Error = anyhow::Error; +impl crate::BeaconClient for MockBeaconClient { + type Error = MockBeaconClientError; - async fn config_spec(&self) -> Result { - self.config_spec.clone().ok_or_else(|| anyhow!("config_spec not set")) + async fn config_spec(&self) -> Result { + self.config_spec.clone().ok_or_else(|| MockBeaconClientError::ConfigSpecNotSet) } - async fn beacon_genesis(&self) -> Result { - self.beacon_genesis.clone().ok_or_else(|| anyhow!("beacon_genesis not set")) + async fn beacon_genesis(&self) -> Result { + self.beacon_genesis.clone().ok_or_else(|| MockBeaconClientError::BeaconGenesisNotSet) } async fn beacon_blob_side_cars( &self, _: u64, _: &[IndexedBlobHash], - ) -> Result> { - self.blob_sidecars.clone().ok_or_else(|| anyhow!("blob_sidecars not set")).map(|r| r.data) + ) -> Result, Self::Error> { + self.blob_sidecars + .clone() + .ok_or_else(|| MockBeaconClientError::BlobSidecarsNotSet) + .map(|r| r.data) } } diff --git a/crates/derive/src/online/testdata/eth_v1_beacon_sidecars_goerli.json b/crates/providers-alloy/src/testdata/eth_v1_beacon_sidecars_goerli.json similarity index 100% rename from crates/derive/src/online/testdata/eth_v1_beacon_sidecars_goerli.json rename to crates/providers-alloy/src/testdata/eth_v1_beacon_sidecars_goerli.json diff --git a/examples/trusted-sync/Cargo.toml b/examples/trusted-sync/Cargo.toml index 0ccee72554..c63eb68282 100644 --- a/examples/trusted-sync/Cargo.toml +++ b/examples/trusted-sync/Cargo.toml @@ -12,7 +12,7 @@ homepage.workspace = true [dependencies] # Workspace kona-primitives = { workspace = true, features = ["serde"] } -kona-derive = { workspace = true, features = ["serde", "online", "metrics"] } +kona-providers-alloy = { workspace = true, features = ["metrics"] } # General anyhow.workspace = true diff --git a/examples/trusted-sync/src/main.rs b/examples/trusted-sync/src/main.rs index 2986b711b7..ccdc2b6776 100644 --- a/examples/trusted-sync/src/main.rs +++ b/examples/trusted-sync/src/main.rs @@ -1,9 +1,6 @@ use anyhow::Result; use clap::Parser; -use kona_derive::{ - errors::{PipelineError, PipelineErrorKind}, - online::*, -}; +use kona_providers_alloy::prelude::*; use std::sync::Arc; use superchain::ROLLUP_CONFIGS; use tracing::{debug, error, info, trace, warn}; diff --git a/justfile b/justfile index 29b2c7f388..0320f8cbb4 100644 --- a/justfile +++ b/justfile @@ -112,7 +112,7 @@ build-cannon *args='': --platform linux/amd64 \ -v `pwd`/:/workdir \ -w="/workdir" \ - ghcr.io/anton-rs/kona/cannon-builder:main cargo build --workspace -Zbuild-std=core,alloc $@ --exclude kona-host --exclude trusted-sync + ghcr.io/anton-rs/kona/cannon-builder:main cargo build --workspace -Zbuild-std=core,alloc $@ --exclude kona-host --exclude trusted-sync --exclude kona-providers-alloy # Build for the `asterisc` target. Any crates that require the stdlib are excluded from the build for this target. build-asterisc *args='': @@ -121,7 +121,7 @@ build-asterisc *args='': --platform linux/amd64 \ -v `pwd`/:/workdir \ -w="/workdir" \ - ghcr.io/anton-rs/kona/asterisc-builder:main cargo build --workspace -Zbuild-std=core,alloc $@ --exclude kona-host --exclude trusted-sync + ghcr.io/anton-rs/kona/asterisc-builder:main cargo build --workspace -Zbuild-std=core,alloc $@ --exclude kona-host --exclude trusted-sync --exclude kona-providers-alloy # Build the `trusted-sync` docker image docker-build-ts *args='':