From d5333c4996e5cdf87e28f6ede3f347b0e7feb986 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Tue, 26 Nov 2024 12:39:49 -0800 Subject: [PATCH 1/2] fix: make index in indexedblobhash a u64 --- bin/host/src/fetcher/mod.rs | 2 +- bin/host/src/providers/blob.rs | 8 ++++---- crates/derive/src/sources/blob_hash.rs | 2 +- crates/derive/src/sources/blobs.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/host/src/fetcher/mod.rs b/bin/host/src/fetcher/mod.rs index 07557348e..2a11cea39 100644 --- a/bin/host/src/fetcher/mod.rs +++ b/bin/host/src/fetcher/mod.rs @@ -187,7 +187,7 @@ where let timestamp = u64::from_be_bytes(timestamp_data_bytes); let partial_block_ref = BlockInfo { timestamp, ..Default::default() }; - let indexed_hash = IndexedBlobHash { index: index as usize, hash }; + let indexed_hash = IndexedBlobHash { index, hash }; // Fetch the blob sidecar from the blob provider. let mut sidecars = self diff --git a/bin/host/src/providers/blob.rs b/bin/host/src/providers/blob.rs index a8a96d7cb..2d91d2465 100644 --- a/bin/host/src/providers/blob.rs +++ b/bin/host/src/providers/blob.rs @@ -103,10 +103,10 @@ impl OnlineBlobProvider { 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::>(); + let blob_hash_indicies = blob_hashes.iter().map(|b| b.index).collect::>(); let filtered = sidecars .into_iter() - .filter(|s| blob_hash_indicies.contains(&(s.index as usize))) + .filter(|s| blob_hash_indicies.contains(&s.index)) .collect::>(); // Validate the correct number of blob sidecars were retrieved. @@ -158,7 +158,7 @@ where .ok_or(BlobProviderError::Backend("Missing blob hash".to_string()))?; match sidecar.verify_blob(&alloy_eips::eip4844::IndexedBlobHash { hash: hash.hash, - index: hash.index as u64, + index: hash.index, }) { Ok(_) => Ok(sidecar.blob), Err(e) => Err(BlobProviderError::Backend(e.to_string())), @@ -253,7 +253,7 @@ impl OnlineBlobProviderWithFallback>(); let filtered = sidecars .into_iter() - .filter(|s| blob_hash_indicies.contains(&(s.index as usize))) + .filter(|s| blob_hash_indicies.contains(&s.index)) .collect::>(); // Validate the correct number of blob sidecars were retrieved. diff --git a/crates/derive/src/sources/blob_hash.rs b/crates/derive/src/sources/blob_hash.rs index 18008936b..03caa82dd 100644 --- a/crates/derive/src/sources/blob_hash.rs +++ b/crates/derive/src/sources/blob_hash.rs @@ -7,7 +7,7 @@ use alloy_primitives::B256; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct IndexedBlobHash { /// The index of the blob - pub index: usize, + pub index: u64, /// The hash of the blob pub hash: B256, } diff --git a/crates/derive/src/sources/blobs.rs b/crates/derive/src/sources/blobs.rs index 87bb97b56..2bc00c901 100644 --- a/crates/derive/src/sources/blobs.rs +++ b/crates/derive/src/sources/blobs.rs @@ -106,7 +106,7 @@ where continue; }; for blob in blob_hashes { - let indexed = IndexedBlobHash { hash: blob, index: number as usize }; + let indexed = IndexedBlobHash { hash: blob, index: number }; hashes.push(indexed); data.push(BlobData::default()); number += 1; From 35febd8a776fe58deacc54c04a272422d43c3406 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Tue, 26 Nov 2024 13:19:53 -0800 Subject: [PATCH 2/2] clippy --- bin/host/src/providers/beacon.rs | 2 +- bin/host/src/providers/blob.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/host/src/providers/beacon.rs b/bin/host/src/providers/beacon.rs index 0447b9290..da608f4ae 100644 --- a/bin/host/src/providers/beacon.rs +++ b/bin/host/src/providers/beacon.rs @@ -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 as u64) + raw_response.data.iter().find(|sidecar| sidecar.index == hash.index) { sidecars.push(sidecar.clone()); } diff --git a/bin/host/src/providers/blob.rs b/bin/host/src/providers/blob.rs index 2d91d2465..6ce8f2bf5 100644 --- a/bin/host/src/providers/blob.rs +++ b/bin/host/src/providers/blob.rs @@ -314,7 +314,7 @@ where ))?; match sidecar.verify_blob(&alloy_eips::eip4844::IndexedBlobHash { hash: hash.hash, - index: hash.index as u64, + index: hash.index, }) { Ok(_) => Ok(sidecar.blob), Err(e) => Err(BlobProviderError::Backend(e.to_string())),