Merge remote-tracking branch 'origin/deneb-free-blobs' into tree-states-deneb

This commit is contained in:
Michael Sproul
2023-10-06 11:11:36 +11:00
85 changed files with 3731 additions and 2675 deletions

View File

@@ -6,11 +6,12 @@ use crate::beacon_chain::{BeaconChain, BeaconChainTypes};
use crate::block_verification::cheap_state_advance_to_obtain_committees;
use crate::data_availability_checker::AvailabilityCheckError;
use crate::kzg_utils::{validate_blob, validate_blobs};
use crate::BeaconChainError;
use crate::{metrics, BeaconChainError};
use kzg::Kzg;
use slog::debug;
use ssz_derive::{Decode, Encode};
use ssz_types::VariableList;
use tree_hash::TreeHash;
use types::blob_sidecar::BlobIdentifier;
use types::{
BeaconStateError, BlobSidecar, BlobSidecarList, EthSpec, Hash256, SignedBlobSidecar, Slot,
@@ -168,6 +169,9 @@ impl<T: BeaconChainTypes> GossipVerifiedBlob<T> {
pub fn to_blob(self) -> Arc<BlobSidecar<T::EthSpec>> {
self.blob.message
}
pub fn as_blob(&self) -> &BlobSidecar<T::EthSpec> {
&self.blob.message
}
pub fn signed_blob(&self) -> SignedBlobSidecar<T::EthSpec> {
self.blob.clone()
}
@@ -199,6 +203,8 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(
});
}
let blob_root = get_blob_root(&signed_blob_sidecar);
// Verify that the sidecar is not from a future slot.
let latest_permissible_slot = chain
.slot_clock
@@ -330,7 +336,7 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(
.ok_or_else(|| GossipBlobError::UnknownValidator(proposer_index as u64))?;
signed_blob_sidecar.verify_signature(
None,
Some(blob_root),
pubkey,
&fork,
chain.genesis_validators_root,
@@ -410,6 +416,15 @@ impl<T: EthSpec> KzgVerifiedBlob<T> {
}
}
#[cfg(test)]
impl<T: EthSpec> KzgVerifiedBlob<T> {
pub fn new(blob: BlobSidecar<T>) -> Self {
Self {
blob: Arc::new(blob),
}
}
}
/// Complete kzg verification for a `GossipVerifiedBlob`.
///
/// Returns an error if the kzg verification check fails.
@@ -455,3 +470,16 @@ pub fn verify_kzg_for_blob_list<T: EthSpec>(
Err(AvailabilityCheckError::KzgVerificationFailed)
}
}
/// Returns the canonical root of the given `blob`.
///
/// Use this function to ensure that we report the blob hashing time Prometheus metric.
pub fn get_blob_root<E: EthSpec>(blob: &SignedBlobSidecar<E>) -> Hash256 {
let blob_root_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_BLOB_ROOT);
let blob_root = blob.message.tree_hash_root();
metrics::stop_timer(blob_root_timer);
blob_root
}