Skip to content

Commit

Permalink
Batch verify rpc blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Oct 17, 2023
1 parent 81dc30e commit 15d73b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
9 changes: 7 additions & 2 deletions beacon_node/beacon_chain/src/blob_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ pub fn verify_kzg_for_blob<T: EthSpec>(
pub fn verify_kzg_for_blob_list<T: EthSpec>(
blob_list: &BlobSidecarList<T>,
kzg: &Kzg<T::Kzg>,
) -> Result<(), AvailabilityCheckError> {
) -> Result<Vec<KzgVerifiedBlob<T>>, AvailabilityCheckError> {
let _timer = crate::metrics::start_timer(&crate::metrics::KZG_VERIFICATION_BATCH_TIMES);
let (blobs, (commitments, proofs)): (Vec<_>, (Vec<_>, Vec<_>)) = blob_list
.iter()
Expand All @@ -534,7 +534,12 @@ pub fn verify_kzg_for_blob_list<T: EthSpec>(
)
.map_err(AvailabilityCheckError::Kzg)?
{
Ok(())
Ok(blob_list
.into_iter()
.map(|blob_sidecar| KzgVerifiedBlob {
blob: blob_sidecar.clone(),
})
.collect())
} else {
Err(AvailabilityCheckError::KzgVerificationFailed)
}
Expand Down
16 changes: 9 additions & 7 deletions beacon_node/beacon_chain/src/data_availability_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,18 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
block_root: Hash256,
blobs: FixedBlobSidecarList<T::EthSpec>,
) -> Result<Availability<T::EthSpec>, AvailabilityCheckError> {
let mut verified_blobs = vec![];
if let Some(kzg) = self.kzg.as_ref() {
for blob in blobs.iter().flatten() {
verified_blobs.push(verify_kzg_for_blob(blob.clone(), kzg)?)
}
let blob_list: BlobSidecarList<T::EthSpec> = blobs
.into_iter()
.flat_map(|blob| blob.clone())
.collect::<Vec<_>>()
.into();
let verified_blob_list = verify_kzg_for_blob_list(&blob_list, kzg)?;
self.availability_cache
.put_kzg_verified_blobs(block_root, verified_blob_list)
} else {
return Err(AvailabilityCheckError::KzgNotInitialized);
};
self.availability_cache
.put_kzg_verified_blobs(block_root, verified_blobs)
}
}

/// This first validates the KZG commitments included in the blob sidecar.
Expand Down

0 comments on commit 15d73b2

Please sign in to comment.