Deneb review suggestions (3) (#4694)
* Fix typos * Avoid consuming/cloning blob * Tidy comments
This commit is contained in:
parent
0bfc933c50
commit
2550170337
@ -475,7 +475,10 @@ pub struct BeaconChain<T: BeaconChainTypes> {
|
||||
pub validator_monitor: RwLock<ValidatorMonitor<T::EthSpec>>,
|
||||
/// The slot at which blocks are downloaded back to.
|
||||
pub genesis_backfill_slot: Slot,
|
||||
// Provides a KZG verification and temporary storage for blocks and blobs as
|
||||
// they are collected and combined.
|
||||
pub data_availability_checker: Arc<DataAvailabilityChecker<T>>,
|
||||
/// The KZG trusted setup used by this chain.
|
||||
pub kzg: Option<Arc<Kzg<<T::EthSpec as EthSpec>::Kzg>>>,
|
||||
}
|
||||
|
||||
|
@ -35,12 +35,13 @@ pub enum GossipBlobError<T: EthSpec> {
|
||||
latest_permissible_slot: Slot,
|
||||
},
|
||||
|
||||
/// There was an error whilst processing the sync contribution. It is not known if it is valid or invalid.
|
||||
/// There was an error whilst processing the blob. It is not known if it is
|
||||
/// valid or invalid.
|
||||
///
|
||||
/// ## Peer scoring
|
||||
///
|
||||
/// We were unable to process this sync committee message due to an internal error. It's unclear if the
|
||||
/// sync committee message is valid.
|
||||
/// We were unable to process this blob due to an internal error. It's
|
||||
/// unclear if the blob is valid.
|
||||
BeaconChainError(BeaconChainError),
|
||||
|
||||
/// The `BlobSidecar` was gossiped over an incorrect subnet.
|
||||
@ -80,7 +81,7 @@ pub enum GossipBlobError<T: EthSpec> {
|
||||
///
|
||||
/// ## Peer scoring
|
||||
///
|
||||
/// The block is invalid and the peer is faulty.
|
||||
/// The blob is invalid and the peer is faulty.
|
||||
UnknownValidator(u64),
|
||||
|
||||
/// The provided blob is not from a later slot than its parent.
|
||||
|
@ -758,7 +758,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
|
||||
/// Instantiates `Self`, a wrapper that indicates the given `block` is safe to be re-gossiped
|
||||
/// on the p2p network.
|
||||
///
|
||||
/// Returns an error if the block is invalid, or i8f the block was unable to be verified.
|
||||
/// Returns an error if the block is invalid, or if the block was unable to be verified.
|
||||
pub fn new(
|
||||
block: Arc<SignedBeaconBlock<T::EthSpec>>,
|
||||
chain: &BeaconChain<T>,
|
||||
|
@ -24,7 +24,7 @@ use types::{
|
||||
/// 1. `BlockAndBlobs`: A fully available post deneb block with all the blobs available. This variant
|
||||
/// is only constructed after making consistency checks between blocks and blobs.
|
||||
/// Hence, it is fully self contained w.r.t verification. i.e. this block has all the required
|
||||
/// data to get verfied and imported into fork choice.
|
||||
/// data to get verified and imported into fork choice.
|
||||
///
|
||||
/// 2. `Block`: This can be a fully available pre-deneb block **or** a post-deneb block that may or may
|
||||
/// not require blobs to be considered fully available.
|
||||
@ -118,7 +118,7 @@ impl<E: EthSpec> From<SignedBeaconBlock<E>> for RpcBlock<E> {
|
||||
}
|
||||
|
||||
/// A block that has gone through all pre-deneb block processing checks including block processing
|
||||
/// and execution by an EL client. This block hasn't completed data availability checks.
|
||||
/// and execution by an EL client. This block hasn't necessarily completed data availability checks.
|
||||
///
|
||||
///
|
||||
/// It contains 2 variants:
|
||||
|
@ -4,9 +4,9 @@ use types::{Blob, EthSpec, Hash256, KzgCommitment, KzgProof};
|
||||
/// Converts a blob ssz List object to an array to be used with the kzg
|
||||
/// crypto library.
|
||||
fn ssz_blob_to_crypto_blob<T: EthSpec>(
|
||||
blob: Blob<T>,
|
||||
blob: &Blob<T>,
|
||||
) -> Result<<<T as EthSpec>::Kzg as KzgPreset>::Blob, KzgError> {
|
||||
T::blob_from_bytes(blob.to_vec().as_slice())
|
||||
T::blob_from_bytes(blob.as_ref())
|
||||
}
|
||||
|
||||
/// Validate a single blob-commitment-proof triplet from a `BlobSidecar`.
|
||||
@ -17,7 +17,7 @@ pub fn validate_blob<T: EthSpec>(
|
||||
kzg_proof: KzgProof,
|
||||
) -> Result<bool, KzgError> {
|
||||
kzg.verify_blob_kzg_proof(
|
||||
ssz_blob_to_crypto_blob::<T>(blob)?,
|
||||
ssz_blob_to_crypto_blob::<T>(&blob)?,
|
||||
kzg_commitment,
|
||||
kzg_proof,
|
||||
)
|
||||
@ -32,7 +32,7 @@ pub fn validate_blobs<T: EthSpec>(
|
||||
) -> Result<bool, KzgError> {
|
||||
let blobs = blobs
|
||||
.iter()
|
||||
.map(|blob| ssz_blob_to_crypto_blob::<T>(blob.clone())) // Avoid this clone
|
||||
.map(|blob| ssz_blob_to_crypto_blob::<T>(blob)) // Avoid this clone
|
||||
.collect::<Result<Vec<_>, KzgError>>()?;
|
||||
|
||||
kzg.verify_blob_kzg_proof_batch(&blobs, expected_kzg_commitments, kzg_proofs)
|
||||
@ -45,13 +45,13 @@ pub fn compute_blob_kzg_proof<T: EthSpec>(
|
||||
kzg_commitment: KzgCommitment,
|
||||
) -> Result<KzgProof, KzgError> {
|
||||
// Avoid this blob clone
|
||||
kzg.compute_blob_kzg_proof(ssz_blob_to_crypto_blob::<T>(blob.clone())?, kzg_commitment)
|
||||
kzg.compute_blob_kzg_proof(ssz_blob_to_crypto_blob::<T>(blob)?, kzg_commitment)
|
||||
}
|
||||
|
||||
/// Compute the kzg commitment for a given blob.
|
||||
pub fn blob_to_kzg_commitment<T: EthSpec>(
|
||||
kzg: &Kzg<T::Kzg>,
|
||||
blob: Blob<T>,
|
||||
blob: &Blob<T>,
|
||||
) -> Result<KzgCommitment, KzgError> {
|
||||
kzg.blob_to_kzg_commitment(ssz_blob_to_crypto_blob::<T>(blob)?)
|
||||
}
|
||||
@ -59,7 +59,7 @@ pub fn blob_to_kzg_commitment<T: EthSpec>(
|
||||
/// Compute the kzg proof for a given blob and an evaluation point z.
|
||||
pub fn compute_kzg_proof<T: EthSpec>(
|
||||
kzg: &Kzg<T::Kzg>,
|
||||
blob: Blob<T>,
|
||||
blob: &Blob<T>,
|
||||
z: Hash256,
|
||||
) -> Result<(KzgProof, Hash256), KzgError> {
|
||||
let z = z.0.into();
|
||||
|
@ -35,7 +35,7 @@ impl<E: EthSpec> Case for KZGBlobToKZGCommitment<E> {
|
||||
let kzg = get_kzg::<E::Kzg>()?;
|
||||
|
||||
let commitment = parse_blob::<E>(&self.input.blob).and_then(|blob| {
|
||||
blob_to_kzg_commitment::<E>(&kzg, blob).map_err(|e| {
|
||||
blob_to_kzg_commitment::<E>(&kzg, &blob).map_err(|e| {
|
||||
Error::InternalError(format!("Failed to compute kzg commitment: {:?}", e))
|
||||
})
|
||||
});
|
||||
|
@ -48,7 +48,7 @@ impl<E: EthSpec> Case for KZGComputeKZGProof<E> {
|
||||
|
||||
let kzg = get_kzg::<E::Kzg>()?;
|
||||
let proof = parse_input(&self.input).and_then(|(blob, z)| {
|
||||
compute_kzg_proof::<E>(&kzg, blob, z)
|
||||
compute_kzg_proof::<E>(&kzg, &blob, z)
|
||||
.map_err(|e| Error::InternalError(format!("Failed to compute kzg proof: {:?}", e)))
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user