diff --git a/Cargo.lock b/Cargo.lock index 3370709f..894a7bc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,7 +211,7 @@ dependencies = [ "foldhash", "hashbrown 0.15.0", "hex-literal", - "indexmap", + "indexmap 2.6.0", "itoa", "k256", "keccak-asm", @@ -320,6 +320,20 @@ dependencies = [ "serde", ] +[[package]] +name = "alloy-rpc-types-beacon" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b535781fe224c101c3d957b514cb9f438d165ff0280e5c0b2f87a0d9a2950593" +dependencies = [ + "alloy-eips", + "alloy-primitives", + "alloy-rpc-types-engine", + "serde", + "serde_with", + "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "alloy-rpc-types-engine" version = "0.5.2" @@ -403,7 +417,7 @@ dependencies = [ "alloy-sol-macro-input", "const-hex", "heck", - "indexmap", + "indexmap 2.6.0", "proc-macro-error2", "proc-macro2", "quote", @@ -488,6 +502,21 @@ dependencies = [ "tracing", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anes" version = "0.1.6" @@ -997,6 +1026,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets", +] + [[package]] name = "ciborium" version = "0.2.2" @@ -1243,6 +1285,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.79", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.79", +] + [[package]] name = "dashmap" version = "6.1.0" @@ -1276,6 +1353,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + [[package]] name = "derivative" version = "2.2.0" @@ -1673,7 +1760,7 @@ dependencies = [ "futures-core", "futures-sink", "http", - "indexmap", + "indexmap 2.6.0", "slab", "tokio", "tokio-util", @@ -1690,6 +1777,12 @@ dependencies = [ "crunchy", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hashbrown" version = "0.13.2" @@ -1868,6 +1961,35 @@ dependencies = [ "tracing", ] +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.5.0" @@ -1898,6 +2020,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + [[package]] name = "indexmap" version = "2.6.0" @@ -1917,7 +2050,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "232929e1d75fe899576a3d5c7416ad0d88dbfbb3c3d6aa00873a7408a50ddb88" dependencies = [ "ahash", - "indexmap", + "indexmap 2.6.0", "is-terminal", "itoa", "log", @@ -2248,6 +2381,7 @@ dependencies = [ "alloy-provider", "alloy-rlp", "alloy-rpc-client", + "alloy-rpc-types-beacon", "alloy-serde", "alloy-transport", "alloy-transport-http", @@ -2530,6 +2664,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-format" version = "0.4.4" @@ -2923,6 +3063,12 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "pprof" version = "0.13.0" @@ -3417,7 +3563,7 @@ dependencies = [ "bytecheck", "bytes", "hashbrown 0.14.5", - "indexmap", + "indexmap 2.6.0", "munge", "ptr_meta", "rancor", @@ -3748,7 +3894,7 @@ version = "1.0.131" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67d42a0bd4ac281beff598909bb56a86acaf979b84483e1c79c10dcaf98f8cf3" dependencies = [ - "indexmap", + "indexmap 2.6.0", "itoa", "memchr", "ryu", @@ -3778,6 +3924,36 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e28bdad6db2b8340e449f7108f020b3b092e8583a9e3fb82713e1d4e71fe817" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.6.0", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d846214a9854ef724f3da161b426242d8de7c1fc7de2f89bb1efcb154dca79d" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "sha2" version = "0.10.8" @@ -4136,6 +4312,37 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -4257,7 +4464,7 @@ version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap", + "indexmap 2.6.0", "toml_datetime", "winnow", ] @@ -4623,6 +4830,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-registry" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 402c09f7..0dabd72d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,6 +79,7 @@ alloy-rpc-client = { version = "0.5.2", default-features = false } alloy-node-bindings = { version = "0.5.2", default-features = false } alloy-transport-http = { version = "0.5.2", default-features = false } alloy-rpc-types-engine = { version = "0.5.2", default-features = false } +alloy-rpc-types-beacon = { version = "0.5.2", default-features = false } # OP Alloy op-alloy-genesis = { version = "0.5.0", default-features = false } diff --git a/crates/providers-alloy/Cargo.toml b/crates/providers-alloy/Cargo.toml index a50b0e54..42e7a3fe 100644 --- a/crates/providers-alloy/Cargo.toml +++ b/crates/providers-alloy/Cargo.toml @@ -19,6 +19,7 @@ alloy-rlp = { workspace = true, features = ["derive"] } alloy-provider = { workspace = true, features = ["reqwest"] } alloy-consensus = { workspace = true, features = ["k256", "serde", "std"] } alloy-primitives = { workspace = true, features = ["rlp", "k256", "serde"] } +alloy-rpc-types-beacon.workspace = true # OP Alloy op-alloy-consensus = { workspace = true, features = ["k256"] } diff --git a/crates/providers-alloy/src/beacon_client.rs b/crates/providers-alloy/src/beacon_client.rs index 35e69bf0..e4336c99 100644 --- a/crates/providers-alloy/src/beacon_client.rs +++ b/crates/providers-alloy/src/beacon_client.rs @@ -1,7 +1,6 @@ //! Contains an online implementation of the `BeaconClient` trait. -use alloy_eips::eip4844::BlobTransactionSidecarItem; -use alloy_primitives::FixedBytes; +use alloy_rpc_types_beacon::sidecar::{BeaconBlobBundle, BlobData}; use async_trait::async_trait; use kona_derive::sources::IndexedBlobHash; use reqwest::Client; @@ -15,54 +14,6 @@ pub(crate) const GENESIS_METHOD: &str = "eth/v1/beacon/genesis"; /// The blob sidecars engine api method prefix. pub(crate) const SIDECARS_METHOD_PREFIX: &str = "eth/v1/beacon/blob_sidecars"; -/// An API blob sidecar. -#[derive(Debug, Default, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -pub struct APIBlobSidecar { - /// The inner blob sidecar. - #[serde(flatten)] - pub inner: BlobTransactionSidecarItem, - /// The signed block header. - #[serde(rename = "signed_block_header")] - pub signed_block_header: SignedBeaconBlockHeader, - // The inclusion-proof of the blob-sidecar into the beacon-block is ignored, - // since we verify blobs by their versioned hashes against the execution-layer block instead. -} - -/// A signed beacon block header. -#[derive(Debug, Default, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -pub struct SignedBeaconBlockHeader { - /// The message. - pub message: BeaconBlockHeader, - // The signature is ignored, since we verify blobs against EL versioned-hashes -} - -/// A beacon block header. -#[derive(Debug, Default, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -pub struct BeaconBlockHeader { - /// The slot. - #[serde(with = "alloy_serde::quantity")] - pub slot: u64, - /// The proposer index. - #[serde(with = "alloy_serde::quantity")] - pub proposer_index: u64, - /// The parent root. - #[serde(rename = "parent_root")] - pub parent_root: FixedBytes<32>, - /// The state root. - #[serde(rename = "state_root")] - pub state_root: FixedBytes<32>, - /// The body root. - #[serde(rename = "body_root")] - pub body_root: FixedBytes<32>, -} - -/// An response for fetching blob sidecars. -#[derive(Debug, Default, serde::Serialize, serde::Deserialize)] -pub struct APIGetBlobSidecarsResponse { - /// The data. - pub data: Vec, -} - /// A reduced genesis data. #[derive(Debug, Default, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct ReducedGenesisData { @@ -109,16 +60,6 @@ impl APIGenesisResponse { } } -impl Clone for APIGetBlobSidecarsResponse { - fn clone(&self) -> Self { - let mut data = Vec::with_capacity(self.data.len()); - for sidecar in &self.data { - data.push(sidecar.clone()); - } - Self { data } - } -} - /// The [BeaconClient] is a thin wrapper around the Beacon API. #[async_trait] pub trait BeaconClient { @@ -138,7 +79,7 @@ pub trait BeaconClient { &self, slot: u64, hashes: &[IndexedBlobHash], - ) -> Result, Self::Error>; + ) -> Result, Self::Error>; } /// An online implementation of the [BeaconClient] trait. @@ -207,7 +148,7 @@ impl BeaconClient for OnlineBeaconClient { &self, slot: u64, hashes: &[IndexedBlobHash], - ) -> Result, Self::Error> { + ) -> Result, Self::Error> { crate::inc!(PROVIDER_CALLS, &["beacon_client", "beacon_blob_side_cars"]); crate::timer!( START, @@ -231,7 +172,7 @@ impl BeaconClient for OnlineBeaconClient { return Err(e); } }; - let raw_response = match raw_response.json::().await { + let raw_response = match raw_response.json::().await { Ok(response) => response, Err(e) => { crate::timer!(DISCARD, timer); @@ -245,7 +186,7 @@ impl BeaconClient for OnlineBeaconClient { // Filter the sidecars by the hashes, in-order. hashes.iter().for_each(|hash| { if let Some(sidecar) = - raw_response.data.iter().find(|sidecar| sidecar.inner.index == hash.index as u64) + raw_response.data.iter().find(|sidecar| sidecar.index == hash.index as u64) { sidecars.push(sidecar.clone()); } diff --git a/crates/providers-alloy/src/blob_provider.rs b/crates/providers-alloy/src/blob_provider.rs index 99e58413..37fab8bc 100644 --- a/crates/providers-alloy/src/blob_provider.rs +++ b/crates/providers-alloy/src/blob_provider.rs @@ -1,12 +1,13 @@ //! Contains an online implementation of the `BlobProvider` trait. 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::{APIBlobSidecar, BeaconClient, OnlineBeaconClient}; +use crate::{BeaconClient, OnlineBeaconClient}; /// An online implementation of the [BlobProvider] trait. #[derive(Debug, Clone)] @@ -63,7 +64,7 @@ impl OnlineBlobProvider { &self, slot: u64, hashes: &[IndexedBlobHash], - ) -> Result, BlobProviderError> { + ) -> Result, BlobProviderError> { self.beacon_client .beacon_blob_side_cars(slot, hashes) .await @@ -100,7 +101,7 @@ impl OnlineBlobProvider { let blob_hash_indicies = blob_hashes.iter().map(|b| b.index as u64).collect::>(); let filtered = sidecars .into_iter() - .filter(|s| blob_hash_indicies.contains(&s.inner.index)) + .filter(|s| blob_hash_indicies.contains(&s.index)) .collect::>(); // Validate the correct number of blob sidecars were retrieved. @@ -108,7 +109,15 @@ impl OnlineBlobProvider { return Err(BlobProviderError::SidecarLengthMismatch(blob_hashes.len(), filtered.len())); } - Ok(filtered.into_iter().map(|s| s.inner).collect::>()) + Ok(filtered + .into_iter() + .map(|s| BlobTransactionSidecarItem { + index: s.index, + blob: s.blob, + kzg_commitment: s.kzg_commitment, + kzg_proof: s.kzg_proof, + }) + .collect::>()) } } @@ -192,7 +201,7 @@ pub trait BlobSidecarProvider { &self, slot: u64, hashes: &[IndexedBlobHash], - ) -> Result, BlobProviderError>; + ) -> Result, BlobProviderError>; } /// Blanket implementation of the [BlobSidecarProvider] trait for all types that @@ -203,7 +212,7 @@ impl BlobSidecarProvider for B { &self, slot: u64, hashes: &[IndexedBlobHash], - ) -> Result, BlobProviderError> { + ) -> Result, BlobProviderError> { self.beacon_blob_side_cars(slot, hashes) .await .map_err(|e| BlobProviderError::Backend(e.to_string())) @@ -263,7 +272,7 @@ impl OnlineBlobProviderWithFallback>(); let filtered = sidecars .into_iter() - .filter(|s| blob_hash_indicies.contains(&s.inner.index)) + .filter(|s| blob_hash_indicies.contains(&s.index)) .collect::>(); // Validate the correct number of blob sidecars were retrieved. @@ -271,7 +280,15 @@ impl OnlineBlobProviderWithFallback>()) + Ok(filtered + .into_iter() + .map(|s| BlobTransactionSidecarItem { + index: s.index, + blob: s.blob, + kzg_commitment: s.kzg_commitment, + kzg_proof: s.kzg_proof, + }) + .collect::>()) } } @@ -440,11 +457,12 @@ impl From>(), }; diff --git a/crates/providers-alloy/src/lib.rs b/crates/providers-alloy/src/lib.rs index 329d0650..1076f62f 100644 --- a/crates/providers-alloy/src/lib.rs +++ b/crates/providers-alloy/src/lib.rs @@ -39,10 +39,7 @@ pub mod alloy_providers; pub use alloy_providers::{AlloyChainProvider, AlloyL2ChainProvider}; pub mod beacon_client; -pub use beacon_client::{ - APIBlobSidecar, APIConfigResponse, APIGenesisResponse, APIGetBlobSidecarsResponse, - BeaconClient, OnlineBeaconClient, -}; +pub use beacon_client::{APIConfigResponse, APIGenesisResponse, BeaconClient, OnlineBeaconClient}; pub mod blob_provider; pub use blob_provider::{ diff --git a/crates/providers-alloy/src/test_utils.rs b/crates/providers-alloy/src/test_utils.rs index 1bc23b22..17d94fa8 100644 --- a/crates/providers-alloy/src/test_utils.rs +++ b/crates/providers-alloy/src/test_utils.rs @@ -1,9 +1,10 @@ //! Test Utilities for Online Providers -use crate::{APIBlobSidecar, APIConfigResponse, APIGenesisResponse, APIGetBlobSidecarsResponse}; +use crate::{APIConfigResponse, APIGenesisResponse}; use alloy_node_bindings::{Anvil, AnvilInstance}; use alloy_provider::{network::Ethereum, ReqwestProvider}; use alloy_rpc_client::RpcClient; +use alloy_rpc_types_beacon::sidecar::{BeaconBlobBundle, BlobData}; use alloy_transport_http::Http; use async_trait::async_trait; use kona_derive::sources::IndexedBlobHash; @@ -37,7 +38,7 @@ pub struct MockBeaconClient { /// The beacon genesis. pub beacon_genesis: Option, /// The blob sidecars. - pub blob_sidecars: Option, + pub blob_sidecars: Option, } /// A mock beacon client error @@ -70,7 +71,7 @@ impl crate::BeaconClient for MockBeaconClient { &self, _: u64, _: &[IndexedBlobHash], - ) -> Result, Self::Error> { + ) -> Result, Self::Error> { self.blob_sidecars .clone() .ok_or_else(|| MockBeaconClientError::BlobSidecarsNotSet)