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

Revert "chore: Bump Alloy Deps" #791

Merged
merged 1 commit into from
Nov 7, 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
537 changes: 146 additions & 391 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,24 @@ kona-derive-alloy = { path = "crates/derive-alloy", version = "0.0.3", default-f
# Alloy
alloy-rlp = { version = "0.3.9", default-features = false }
alloy-trie = { version = "0.7.2", default-features = false }
alloy-eips = { version = "0.6.1", default-features = false }
alloy-serde = { version = "0.6.1", default-features = false }
alloy-provider = { version = "0.6.1", default-features = false }
alloy-eips = { version = "0.5.4", default-features = false }
alloy-serde = { version = "0.5.4", default-features = false }
alloy-provider = { version = "0.5.4", default-features = false }
alloy-primitives = { version = "0.8", default-features = false }
alloy-consensus = { version = "0.6.1", default-features = false }
alloy-transport = { version = "0.6.1", default-features = false }
alloy-rpc-types = { version = "0.6.1", default-features = false }
alloy-rpc-client = { version = "0.6.1", default-features = false }
alloy-node-bindings = { version = "0.6.1", default-features = false }
alloy-transport-http = { version = "0.6.1", default-features = false }
alloy-rpc-types-engine = { version = "0.6.1", default-features = false }
alloy-rpc-types-beacon = { version = "0.6.1", default-features = false }
alloy-consensus = { version = "0.5.4", default-features = false }
alloy-transport = { version = "0.5.4", default-features = false }
alloy-rpc-types = { version = "0.5.4", default-features = false }
alloy-rpc-client = { version = "0.5.4", default-features = false }
alloy-node-bindings = { version = "0.5.4", default-features = false }
alloy-transport-http = { version = "0.5.4", default-features = false }
alloy-rpc-types-engine = { version = "0.5.4", default-features = false }
alloy-rpc-types-beacon = { version = "0.5.4", default-features = false }

# OP Alloy
op-alloy-genesis = { version = "0.6.1", default-features = false }
op-alloy-protocol = { version = "0.6.1", default-features = false }
op-alloy-consensus = { version = "0.6.1", default-features = false }
op-alloy-rpc-types-engine = { version = "0.6.1", default-features = false }
op-alloy-genesis = { version = "0.5.2", default-features = false }
op-alloy-protocol = { version = "0.5.2", default-features = false }
op-alloy-consensus = { version = "0.5.2", default-features = false }
op-alloy-rpc-types-engine = { version = "0.5.2", default-features = false }

# General
lru = "0.12.4"
Expand Down
4 changes: 2 additions & 2 deletions bin/client/src/l1/blob_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use crate::{errors::OracleProviderError, HintType};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use alloy_consensus::Blob;
use alloy_eips::eip4844::{IndexedBlobHash, FIELD_ELEMENTS_PER_BLOB};
use alloy_eips::eip4844::FIELD_ELEMENTS_PER_BLOB;
use alloy_primitives::keccak256;
use async_trait::async_trait;
use kona_derive::traits::BlobProvider;
use kona_derive::{sources::IndexedBlobHash, traits::BlobProvider};
use kona_preimage::{CommsClient, PreimageKey, PreimageKeyType};
use op_alloy_protocol::BlockInfo;

Expand Down
1 change: 1 addition & 0 deletions bin/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ workspace = true
# Workspace
kona-mpt.workspace = true
kona-client.workspace = true
kona-derive.workspace = true
kona-common.workspace = true
kona-preimage.workspace = true
kona-derive-alloy.workspace = true
Expand Down
15 changes: 8 additions & 7 deletions bin/host/src/fetcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

use crate::{kv::KeyValueStore, util};
use alloy_consensus::{Header, TxEnvelope, EMPTY_ROOT_HASH};
use alloy_eips::{
eip2718::Encodable2718,
eip4844::{IndexedBlobHash, FIELD_ELEMENTS_PER_BLOB},
BlockId,
};
use alloy_eips::{eip2718::Encodable2718, eip4844::FIELD_ELEMENTS_PER_BLOB, BlockId};
use alloy_primitives::{address, keccak256, Address, Bytes, B256};
use alloy_provider::{Provider, ReqwestProvider};
use alloy_rlp::{Decodable, EMPTY_STRING_CODE};
Expand All @@ -16,6 +12,7 @@ use alloy_rpc_types::{
};
use anyhow::{anyhow, Result};
use kona_client::HintType;
use kona_derive::sources::IndexedBlobHash;
use kona_derive_alloy::{OnlineBeaconClient, OnlineBlobProvider};
use kona_preimage::{PreimageKey, PreimageKeyType};
use op_alloy_protocol::BlockInfo;
Expand Down Expand Up @@ -185,7 +182,7 @@ where
let timestamp = u64::from_be_bytes(timestamp_data_bytes);

let partial_block_ref = BlockInfo { timestamp, ..Default::default() };
let indexed_hash = IndexedBlobHash { index, hash };
let indexed_hash = IndexedBlobHash { index: index as usize, hash };

// Fetch the blob sidecar from the blob provider.
let mut sidecars = self
Expand Down Expand Up @@ -519,7 +516,11 @@ where
let encoded_transactions = transactions
.into_iter()
.map(|tx| {
let envelope = TxEnvelope::from(tx);
let envelope: TxEnvelope = tx.try_into().map_err(|e| {
anyhow!(
"Failed to convert RPC transaction into consensus envelope: {e}"
)
})?;

Ok::<_, anyhow::Error>(envelope.encoded_2718())
})
Expand Down
3 changes: 1 addition & 2 deletions crates/derive-alloy/src/alloy_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ impl ChainProvider for AlloyChainProvider {
.raw_request("debug_getRawBlock".into(), [hash])
.await
.map_err(AlloyProviderError::Rpc)?;
let block: Block<TxEnvelope> =
Block::decode(&mut raw_block.as_ref()).map_err(AlloyProviderError::Rlp)?;
let block = Block::decode(&mut raw_block.as_ref()).map_err(AlloyProviderError::Rlp)?;

let block_info = BlockInfo {
hash: block.header.hash_slow(),
Expand Down
4 changes: 2 additions & 2 deletions crates/derive-alloy/src/beacon_client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Contains an online implementation of the `BeaconClient` trait.

use alloy_eips::eip4844::IndexedBlobHash;
use alloy_rpc_types_beacon::sidecar::{BeaconBlobBundle, BlobData};
use async_trait::async_trait;
use kona_derive::sources::IndexedBlobHash;
use reqwest::Client;

/// The config spec engine api method.
Expand Down Expand Up @@ -128,7 +128,7 @@ impl BeaconClient for OnlineBeaconClient {
let mut sidecars = Vec::with_capacity(hashes.len());
hashes.iter().for_each(|hash| {
if let Some(sidecar) =
raw_response.data.iter().find(|sidecar| sidecar.index == hash.index)
raw_response.data.iter().find(|sidecar| sidecar.index == hash.index as u64)
{
sidecars.push(sidecar.clone());
}
Expand Down
20 changes: 12 additions & 8 deletions crates/derive-alloy/src/blob_provider.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Contains an online implementation of the `BlobProvider` trait.

use crate::{BeaconClient, OnlineBeaconClient};
use alloy_eips::eip4844::{Blob, BlobTransactionSidecarItem, IndexedBlobHash};
use alloy_eips::eip4844::{Blob, BlobTransactionSidecarItem};
use alloy_rpc_types_beacon::sidecar::BlobData;
use async_trait::async_trait;
use kona_derive::{errors::BlobProviderError, traits::BlobProvider};
use kona_derive::{errors::BlobProviderError, sources::IndexedBlobHash, traits::BlobProvider};
use op_alloy_protocol::BlockInfo;
use tracing::warn;

Expand Down Expand Up @@ -103,7 +103,7 @@ impl<B: BeaconClient> OnlineBlobProvider<B> {
let sidecars = self.fetch_sidecars(slot, blob_hashes).await?;

// Filter blob sidecars that match the indicies in the specified list.
let blob_hash_indicies = blob_hashes.iter().map(|b| b.index).collect::<Vec<u64>>();
let blob_hash_indicies = blob_hashes.iter().map(|b| b.index as u64).collect::<Vec<u64>>();
let filtered = sidecars
.into_iter()
.filter(|s| blob_hash_indicies.contains(&s.index))
Expand Down Expand Up @@ -156,7 +156,10 @@ where
let hash = blob_hashes
.get(i)
.ok_or(BlobProviderError::Backend("Missing blob hash".to_string()))?;
match sidecar.verify_blob(&IndexedBlobHash { hash: hash.hash, index: hash.index }) {
match sidecar.verify_blob(&alloy_eips::eip1898::NumHash {
hash: hash.hash,
number: hash.index as u64,
}) {
Ok(_) => Ok(sidecar.blob),
Err(e) => Err(BlobProviderError::Backend(e.to_string())),
}
Expand Down Expand Up @@ -247,7 +250,7 @@ impl<B: BeaconClient, F: BlobSidecarProvider> OnlineBlobProviderWithFallback<B,
let sidecars = fallback.beacon_blob_side_cars(slot, blob_hashes).await?;

// Filter blob sidecars that match the indicies in the specified list.
let blob_hash_indicies = blob_hashes.iter().map(|b| b.index).collect::<Vec<_>>();
let blob_hash_indicies = blob_hashes.iter().map(|b| b.index as u64).collect::<Vec<_>>();
let filtered = sidecars
.into_iter()
.filter(|s| blob_hash_indicies.contains(&s.index))
Expand Down Expand Up @@ -309,9 +312,10 @@ where
let hash = blob_hashes.get(i).ok_or(BlobProviderError::Backend(
"fallback: failed to get blob hash".to_string(),
))?;
match sidecar
.verify_blob(&IndexedBlobHash { hash: hash.hash, index: hash.index })
{
match sidecar.verify_blob(&alloy_eips::eip1898::NumHash {
hash: hash.hash,
number: hash.index as u64,
}) {
Ok(_) => Ok(sidecar.blob),
Err(e) => Err(BlobProviderError::Backend(e.to_string())),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/derive-alloy/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Test Utilities for Online Providers

use crate::{APIConfigResponse, APIGenesisResponse};
use alloy_eips::eip4844::IndexedBlobHash;
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;
use reqwest::Client;

/// Spawns an Anvil instance and returns a provider and the instance.
Expand Down
4 changes: 4 additions & 0 deletions crates/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ async-trait.workspace = true
alloc-no-stdlib.workspace = true
derive_more = { workspace = true, features = ["full"] }

# `serde` feature dependencies
serde = { workspace = true, optional = true, features = ["derive"] }

# `test-utils` feature dependencies
spin = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, optional = true, features = ["fmt"] }
Expand All @@ -48,6 +51,7 @@ alloy-primitives = { workspace = true, features = ["rlp", "k256", "map", "arbitr
[features]
default = ["serde"]
serde = [
"dep:serde",
"alloy-primitives/serde",
"alloy-consensus/serde",
"op-alloy-consensus/serde",
Expand Down
45 changes: 45 additions & 0 deletions crates/derive/src/sources/blob_hash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//! Contains the `BlobHash` type and related types.

use alloy_primitives::B256;

/// A Blob hash
#[derive(Default, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IndexedBlobHash {
/// The index of the blob
pub index: usize,
/// The hash of the blob
pub hash: B256,
}

impl PartialEq for IndexedBlobHash {
fn eq(&self, other: &Self) -> bool {
self.index == other.index && self.hash == other.hash
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_indexed_blob_hash() {
let hash = B256::from([1; 32]);
let indexed_blob_hash = IndexedBlobHash { index: 1, hash };

assert_eq!(indexed_blob_hash.index, 1);
assert_eq!(indexed_blob_hash.hash, hash);
}

#[test]
#[cfg(feature = "serde")]
fn test_indexed_blob_hash_serde_roundtrip() {
let hash = B256::from([1; 32]);
let indexed_blob_hash = IndexedBlobHash { index: 1, hash };

let serialized = serde_json::to_string(&indexed_blob_hash).unwrap();
let deserialized: IndexedBlobHash = serde_json::from_str(&serialized).unwrap();

assert_eq!(indexed_blob_hash, deserialized);
}
}
15 changes: 7 additions & 8 deletions crates/derive/src/sources/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

use crate::{
errors::{BlobProviderError, PipelineError},
sources::BlobData,
sources::{BlobData, IndexedBlobHash},
traits::{BlobProvider, ChainProvider, DataAvailabilityProvider},
types::PipelineResult,
};
use alloc::{boxed::Box, string::ToString, vec::Vec};
use alloy_consensus::{Transaction, TxEip4844Variant, TxEnvelope, TxType};
use alloy_eips::eip4844::IndexedBlobHash;
use alloy_primitives::{Address, Bytes};
use async_trait::async_trait;
use op_alloy_protocol::BlockInfo;
Expand Down Expand Up @@ -58,7 +57,7 @@ where
}

fn extract_blob_data(&self, txs: Vec<TxEnvelope>) -> (Vec<BlobData>, Vec<IndexedBlobHash>) {
let mut index: u64 = 0;
let mut number: u64 = 0;
let mut data = Vec::new();
let mut hashes = Vec::new();
for tx in txs {
Expand All @@ -80,11 +79,11 @@ where
let Some(to) = tx_kind else { continue };

if to != self.batcher_address {
index += blob_hashes.map_or(0, |h| h.len() as u64);
number += blob_hashes.map_or(0, |h| h.len() as u64);
continue;
}
if tx.recover_signer().unwrap_or_default() != self.signer {
index += blob_hashes.map_or(0, |h| h.len() as u64);
number += blob_hashes.map_or(0, |h| h.len() as u64);
continue;
}
if tx.tx_type() != TxType::Eip4844 {
Expand All @@ -107,11 +106,11 @@ where
} else {
continue;
};
for hash in blob_hashes {
let indexed = IndexedBlobHash { hash, index };
for blob in blob_hashes {
let indexed = IndexedBlobHash { hash: blob, index: number as usize };
hashes.push(indexed);
data.push(BlobData::default());
index += 1;
number += 1;
}
}
(data, hashes)
Expand Down
2 changes: 1 addition & 1 deletion crates/derive/src/sources/calldata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ mod tests {
use crate::{errors::PipelineErrorKind, test_utils::TestChainProvider};
use alloc::{vec, vec::Vec};
use alloy_consensus::{Signed, TxEip2930, TxEip4844, TxEip4844Variant, TxLegacy};
use alloy_primitives::{address, Address, PrimitiveSignature as Signature, TxKind};
use alloy_primitives::{address, Address, Signature, TxKind};

pub(crate) fn test_legacy_tx(to: Address) -> TxEnvelope {
let sig = Signature::test_signature();
Expand Down
3 changes: 3 additions & 0 deletions crates/derive/src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//! [DataAvailabilityProvider]: crate::traits::DataAvailabilityProvider
//! [BlockInfo]: op_alloy_protocol::BlockInfo

mod blob_hash;
pub use blob_hash::IndexedBlobHash;

mod blob_data;
pub use blob_data::BlobData;

Expand Down
4 changes: 2 additions & 2 deletions crates/derive/src/test_utils/blob_provider.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! An implementation of the [BlobProvider] trait for tests.

use crate::{errors::BlobProviderError, traits::BlobProvider};
use crate::{errors::BlobProviderError, sources::IndexedBlobHash, traits::BlobProvider};
use alloc::{boxed::Box, vec::Vec};
use alloy_eips::eip4844::{Blob, IndexedBlobHash};
use alloy_eips::eip4844::Blob;
use alloy_primitives::{map::HashMap, B256};
use async_trait::async_trait;
use op_alloy_protocol::BlockInfo;
Expand Down
4 changes: 2 additions & 2 deletions crates/derive/src/traits/data_sources.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Contains traits that describe the functionality of various data sources used in the derivation
//! pipeline's stages.

use crate::{errors::PipelineErrorKind, types::PipelineResult};
use crate::{errors::PipelineErrorKind, sources::IndexedBlobHash, types::PipelineResult};
use alloc::{boxed::Box, fmt::Debug, string::ToString, vec::Vec};
use alloy_eips::eip4844::{Blob, IndexedBlobHash};
use alloy_eips::eip4844::Blob;
use alloy_primitives::Bytes;
use async_trait::async_trait;
use core::fmt::Display;
Expand Down
5 changes: 4 additions & 1 deletion crates/mpt/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ pub(crate) async fn get_live_derivable_transactions_list(
let BlockTransactions::Full(txs) = block.transactions else {
anyhow::bail!("Did not fetch full block");
};
let consensus_txs = txs.into_iter().map(TxEnvelope::from).collect::<Vec<_>>();
let consensus_txs = txs
.into_iter()
.map(|tx| TxEnvelope::try_from(tx).map_err(anyhow::Error::from))
.collect::<Result<Vec<_>>>()?;

// Compute the derivable list
let mut list = ordered_trie_with_encoder(consensus_txs.as_ref(), |rlp: &TxEnvelope, buf| {
Expand Down
Loading