Skip to content

Commit

Permalink
Avoid redundant allocations in blob verification (#6282)
Browse files Browse the repository at this point in the history
* Avoid redundant allocations in blob verification
  • Loading branch information
michaelsproul authored Aug 20, 2024
1 parent 1f0d129 commit 56d1c8c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions beacon_node/beacon_chain/src/blob_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,16 @@ impl<E: EthSpec> KzgVerifiedBlobList<E> {
kzg: &Kzg,
seen_timestamp: Duration,
) -> Result<Self, KzgError> {
let blobs = blob_list.into_iter().collect::<Vec<_>>();
verify_kzg_for_blob_list(blobs.iter(), kzg)?;
let blobs = blob_list
.into_iter()
.map(|blob| KzgVerifiedBlob {
blob,
seen_timestamp,
})
.collect::<Vec<_>>();
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,
})
}
}
Expand Down Expand Up @@ -570,8 +570,9 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(
.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
Expand All @@ -597,7 +598,7 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(
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 {
Expand Down

0 comments on commit 56d1c8c

Please sign in to comment.