Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blob count label to DATA_COLUMN_SIDECAR_COMPUTATION metric #6340

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,7 @@ fn build_gossip_verified_data_columns<T: BeaconChainTypes>(
GossipDataColumnError::KzgNotInitialized,
))?;

let timer = metrics::start_timer(&metrics::DATA_COLUMN_SIDECAR_COMPUTATION);
let sidecars = blobs_to_data_column_sidecars(&blobs, block, kzg, &chain.spec)?;
jimmygchen marked this conversation as resolved.
Show resolved Hide resolved
drop(timer);
let mut gossip_verified_data_columns = vec![];
for sidecar in sidecars {
let subnet = DataColumnSubnetId::from_column_index::<T::EthSpec>(
Expand Down
18 changes: 16 additions & 2 deletions beacon_node/beacon_chain/src/kzg_utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::metrics;
use kzg::{
Blob as KzgBlob, Bytes48, CellRef as KzgCellRef, CellsAndKzgProofs, Error as KzgError, Kzg,
};
use lighthouse_metrics::TryExt;
use rayon::prelude::*;
use ssz_types::FixedVector;
use std::sync::Arc;
Expand Down Expand Up @@ -150,12 +152,22 @@ pub fn blobs_to_data_column_sidecars<E: EthSpec>(
if blobs.is_empty() {
return Ok(vec![]);
}

let mut timer = metrics::start_timer_vec(
&metrics::DATA_COLUMN_SIDECAR_COMPUTATION,
&[&blobs.len().to_string()],
);

let kzg_commitments = block
.message()
.body()
.blob_kzg_commitments()
.map_err(|_err| DataColumnSidecarError::PreDeneb)?;
let kzg_commitments_inclusion_proof = block.message().body().kzg_commitments_merkle_proof()?;
let kzg_commitments_inclusion_proof = block
.message()
.body()
.kzg_commitments_merkle_proof()
.discard_timer_on_break(&mut timer)?;
let signed_block_header = block.signed_block_header();

// NOTE: assumes blob sidecars are ordered by index
Expand All @@ -168,7 +180,8 @@ pub fn blobs_to_data_column_sidecars<E: EthSpec>(
.expect("blob should have a guaranteed size due to FixedVector");
kzg.compute_cells_and_proofs(blob)
})
.collect::<Result<Vec<_>, KzgError>>()?;
.collect::<Result<Vec<_>, KzgError>>()
.discard_timer_on_break(&mut timer)?;

build_data_column_sidecars(
kzg_commitments.clone(),
Expand All @@ -177,6 +190,7 @@ pub fn blobs_to_data_column_sidecars<E: EthSpec>(
blob_cells_and_proofs_vec,
spec,
)
.discard_timer_on_break(&mut timer)
.map_err(DataColumnSidecarError::BuildSidecarFailed)
}

Expand Down
7 changes: 4 additions & 3 deletions beacon_node/beacon_chain/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,11 +1646,12 @@ pub static BLOB_SIDECAR_INCLUSION_PROOF_COMPUTATION: LazyLock<Result<Histogram>>
"Time taken to compute blob sidecar inclusion proof",
)
});
pub static DATA_COLUMN_SIDECAR_COMPUTATION: LazyLock<Result<Histogram>> = LazyLock::new(|| {
try_create_histogram_with_buckets(
pub static DATA_COLUMN_SIDECAR_COMPUTATION: LazyLock<Result<HistogramVec>> = LazyLock::new(|| {
try_create_histogram_vec_with_buckets(
"data_column_sidecar_computation_seconds",
"Time taken to compute data column sidecar, including cells, proofs and inclusion proof",
Ok(vec![0.04, 0.05, 0.1, 0.2, 0.3, 0.5, 0.7, 1.0]),
Ok(vec![0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0]),
&["blob_count"],
)
});
pub static DATA_COLUMN_SIDECAR_INCLUSION_PROOF_VERIFICATION: LazyLock<Result<Histogram>> =
Expand Down
28 changes: 28 additions & 0 deletions common/lighthouse_metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,31 @@ pub fn decimal_buckets(min_power: i32, max_power: i32) -> Result<Vec<f64>> {
}
Ok(buckets)
}

/// Would be nice to use the `Try` trait bound and have a single implementation, but try_trait_v2
/// is not a stable feature yet.
pub trait TryExt {
fn discard_timer_on_break(self, timer: &mut Option<HistogramTimer>) -> Self;
}

impl<T, E> TryExt for std::result::Result<T, E> {
fn discard_timer_on_break(self, timer_opt: &mut Option<HistogramTimer>) -> Self {
if self.is_err() {
if let Some(timer) = timer_opt.take() {
timer.stop_and_discard();
}
}
self
}
}

impl<T> TryExt for Option<T> {
fn discard_timer_on_break(self, timer_opt: &mut Option<HistogramTimer>) -> Self {
if self.is_none() {
if let Some(timer) = timer_opt.take() {
timer.stop_and_discard();
}
}
self
}
}
Loading