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): Refactor out Online Providers #569

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion bin/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/host/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion bin/host/src/fetcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 4 additions & 20 deletions crates/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -69,6 +63,10 @@ serde_json.workspace = true

[features]
default = ["serde"]
metrics = [
"dep:prometheus",
"dep:lazy_static",
]
serde = [
"dep:serde",
"kona-primitives/serde",
Expand All @@ -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",
Expand Down
16 changes: 12 additions & 4 deletions crates/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
23 changes: 0 additions & 23 deletions crates/derive/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
63 changes: 63 additions & 0 deletions crates/providers-alloy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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",
]
5 changes: 5 additions & 0 deletions crates/providers-alloy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## `kona-providers-alloy`

_Notice: Requires an `std` environment._

Alloy providers for `kona-derive`.
Original file line number Diff line number Diff line change
@@ -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},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<APIConfigResponse, Self::Error>;
Expand Down
Loading