Skip to content

Commit 56d1c8c

Browse files
Avoid redundant allocations in blob verification (#6282)
* Avoid redundant allocations in blob verification
1 parent 1f0d129 commit 56d1c8c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

beacon_node/beacon_chain/src/blob_verification.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,16 +339,16 @@ impl<E: EthSpec> KzgVerifiedBlobList<E> {
339339
kzg: &Kzg,
340340
seen_timestamp: Duration,
341341
) -> Result<Self, KzgError> {
342-
let blobs = blob_list.into_iter().collect::<Vec<_>>();
343-
verify_kzg_for_blob_list(blobs.iter(), kzg)?;
342+
let blobs = blob_list
343+
.into_iter()
344+
.map(|blob| KzgVerifiedBlob {
345+
blob,
346+
seen_timestamp,
347+
})
348+
.collect::<Vec<_>>();
349+
verify_kzg_for_blob_list(blobs.iter().map(|b| &b.blob), kzg)?;
344350
Ok(Self {
345-
verified_blobs: blobs
346-
.into_iter()
347-
.map(|blob| KzgVerifiedBlob {
348-
blob,
349-
seen_timestamp,
350-
})
351-
.collect(),
351+
verified_blobs: blobs,
352352
})
353353
}
354354
}
@@ -570,8 +570,9 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(
570570
.kzg
571571
.as_ref()
572572
.ok_or(GossipBlobError::KzgNotInitialized)?;
573-
let kzg_verified_blob = KzgVerifiedBlob::new(blob_sidecar.clone(), kzg, seen_timestamp)
573+
let kzg_verified_blob = KzgVerifiedBlob::new(blob_sidecar, kzg, seen_timestamp)
574574
.map_err(GossipBlobError::KzgError)?;
575+
let blob_sidecar = &kzg_verified_blob.blob;
575576

576577
chain
577578
.observed_slashable
@@ -597,7 +598,7 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(
597598
if chain
598599
.observed_blob_sidecars
599600
.write()
600-
.observe_sidecar(&blob_sidecar)
601+
.observe_sidecar(blob_sidecar)
601602
.map_err(|e| GossipBlobError::BeaconChainError(e.into()))?
602603
{
603604
return Err(GossipBlobError::RepeatBlob {

0 commit comments

Comments
 (0)