From abe113589d8bcb1e13c7c18e2f125de8cdf2fc44 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 20 Aug 2024 15:20:15 +1000 Subject: [PATCH] Avoid redundant allocations in blob verification --- .../beacon_chain/src/blob_verification.rs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/beacon_node/beacon_chain/src/blob_verification.rs b/beacon_node/beacon_chain/src/blob_verification.rs index bba58675933..228b3f7092c 100644 --- a/beacon_node/beacon_chain/src/blob_verification.rs +++ b/beacon_node/beacon_chain/src/blob_verification.rs @@ -339,16 +339,16 @@ impl KzgVerifiedBlobList { kzg: &Kzg, seen_timestamp: Duration, ) -> Result { - let blobs = blob_list.into_iter().collect::>(); - verify_kzg_for_blob_list(blobs.iter(), kzg)?; + let blobs = blob_list + .into_iter() + .map(|blob| KzgVerifiedBlob { + blob, + seen_timestamp, + }) + .collect::>(); + verify_kzg_for_blob_list(blobs.iter().map(|b| &b.blob), kzg)?; Ok(Self { - verified_blobs: blobs - .into_iter() - .map(|blob| KzgVerifiedBlob { - blob, - seen_timestamp, - }) - .collect(), + verified_blobs: blobs, }) } } @@ -570,8 +570,9 @@ pub fn validate_blob_sidecar_for_gossip( .kzg .as_ref() .ok_or(GossipBlobError::KzgNotInitialized)?; - let kzg_verified_blob = KzgVerifiedBlob::new(blob_sidecar.clone(), kzg, seen_timestamp) + let kzg_verified_blob = KzgVerifiedBlob::new(blob_sidecar, kzg, seen_timestamp) .map_err(GossipBlobError::KzgError)?; + let blob_sidecar = &kzg_verified_blob.blob; chain .observed_slashable @@ -597,7 +598,7 @@ pub fn validate_blob_sidecar_for_gossip( if chain .observed_blob_sidecars .write() - .observe_sidecar(&blob_sidecar) + .observe_sidecar(blob_sidecar) .map_err(|e| GossipBlobError::BeaconChainError(e.into()))? { return Err(GossipBlobError::RepeatBlob {