mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Add more gossip verification functions for blobs
This commit is contained in:
@@ -6,6 +6,7 @@ use crate::attestation_verification::{
|
||||
use crate::attester_cache::{AttesterCache, AttesterCacheKey};
|
||||
use crate::beacon_proposer_cache::compute_proposer_duties_from_head;
|
||||
use crate::beacon_proposer_cache::BeaconProposerCache;
|
||||
use crate::blob_verification::{BlobError, VerifiedBlobsSidecar};
|
||||
use crate::block_times_cache::BlockTimesCache;
|
||||
use crate::block_verification::{
|
||||
check_block_is_finalized_descendant, check_block_relevancy, get_block_root,
|
||||
@@ -1773,6 +1774,23 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Accepts some `SignedBlobsSidecar` from the network and attempts to verify it,
|
||||
/// returning `Ok(_)` if it is valid to be (re)broadcast on the gossip network.
|
||||
pub fn verify_blobs_sidecar_for_gossip<'a>(
|
||||
&self,
|
||||
blobs_sidecar: &'a SignedBlobsSidecar<T::EthSpec>,
|
||||
) -> Result<VerifiedBlobsSidecar<'a, T>, BlobError> {
|
||||
metrics::inc_counter(&metrics::BLOBS_SIDECAR_PROCESSING_REQUESTS);
|
||||
let _timer = metrics::start_timer(&metrics::BLOBS_SIDECAR_GOSSIP_VERIFICATION_TIMES);
|
||||
VerifiedBlobsSidecar::verify(blobs_sidecar, self).map(|v| {
|
||||
if let Some(_event_handler) = self.event_handler.as_ref() {
|
||||
// TODO: Handle sse events
|
||||
}
|
||||
metrics::inc_counter(&metrics::BLOBS_SIDECAR_PROCESSING_SUCCESSES);
|
||||
v
|
||||
})
|
||||
}
|
||||
|
||||
/// Accepts some attestation-type object and attempts to verify it in the context of fork
|
||||
/// choice. If it is valid it is applied to `self.fork_choice`.
|
||||
///
|
||||
|
||||
@@ -87,13 +87,13 @@ impl From<BeaconStateError> for BlobError {
|
||||
/// the p2p network.
|
||||
#[derive(Derivative)]
|
||||
#[derivative(Debug(bound = "T: BeaconChainTypes"))]
|
||||
pub struct GossipVerifiedBlobsSidecar<T: BeaconChainTypes> {
|
||||
pub blob_sidecar: Arc<SignedBlobsSidecar<T::EthSpec>>,
|
||||
pub struct VerifiedBlobsSidecar<'a, T: BeaconChainTypes> {
|
||||
pub blob_sidecar: &'a SignedBlobsSidecar<T::EthSpec>,
|
||||
}
|
||||
|
||||
impl<T: BeaconChainTypes> GossipVerifiedBlobsSidecar<T> {
|
||||
pub fn new(
|
||||
blob_sidecar: Arc<SignedBlobsSidecar<T::EthSpec>>,
|
||||
impl<'a, T: BeaconChainTypes> VerifiedBlobsSidecar<'a, T> {
|
||||
pub fn verify(
|
||||
blob_sidecar: &'a SignedBlobsSidecar<T::EthSpec>,
|
||||
chain: &BeaconChain<T>,
|
||||
) -> Result<Self, BlobError> {
|
||||
let blob_slot = blob_sidecar.message.beacon_block_slot;
|
||||
@@ -121,7 +121,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlobsSidecar<T> {
|
||||
}
|
||||
|
||||
// Verify that blobs are properly formatted
|
||||
//TODO: add the check while constructing a Blob type from bytes
|
||||
//TODO: add the check while constructing a Blob type from bytes instead of after
|
||||
for (i, blob) in blob_sidecar.message.blobs.iter().enumerate() {
|
||||
if blob.iter().any(|b| *b >= *BLS_MODULUS) {
|
||||
return Err(BlobError::BlobOutOfRange { blob_index: i });
|
||||
|
||||
@@ -5,7 +5,7 @@ mod beacon_chain;
|
||||
mod beacon_fork_choice_store;
|
||||
pub mod beacon_proposer_cache;
|
||||
mod beacon_snapshot;
|
||||
mod blob_verification;
|
||||
pub mod blob_verification;
|
||||
pub mod block_reward;
|
||||
mod block_times_cache;
|
||||
mod block_verification;
|
||||
|
||||
@@ -941,6 +941,22 @@ lazy_static! {
|
||||
"beacon_pre_finalization_block_lookup_count",
|
||||
"Number of block roots subject to single block lookups"
|
||||
);
|
||||
|
||||
/*
|
||||
* Blob sidecar Verification
|
||||
*/
|
||||
pub static ref BLOBS_SIDECAR_PROCESSING_REQUESTS: Result<IntCounter> = try_create_int_counter(
|
||||
"beacon_blobs_sidecar_processing_requests_total",
|
||||
"Count of all blob sidecars submitted for processing"
|
||||
);
|
||||
pub static ref BLOBS_SIDECAR_PROCESSING_SUCCESSES: Result<IntCounter> = try_create_int_counter(
|
||||
"beacon_blobs_sidecar_processing_successes_total",
|
||||
"Number of blob sidecars verified for gossip"
|
||||
);
|
||||
pub static ref BLOBS_SIDECAR_GOSSIP_VERIFICATION_TIMES: Result<Histogram> = try_create_histogram(
|
||||
"beacon_blobs_sidecar_gossip_verification_seconds",
|
||||
"Full runtime of blob sidecars gossip verification"
|
||||
);
|
||||
}
|
||||
|
||||
/// Scrape the `beacon_chain` for metrics that are not constantly updated (e.g., the present slot,
|
||||
|
||||
Reference in New Issue
Block a user