Skip to content

Commit 8b62434

Browse files
authored
feat: add more metrics for the tee_prover (#3276)
## What ❔ Add a `sealed_at` column to the `l1_batches` table and extend the tee_prover metrics. ## Why ❔ The duration metric of sealed -> TEE proven is of special interest for Interop. It should not regress and should be optimized in future development. ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [x] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`. --------- Signed-off-by: Harald Hoyer <harald@matterlabs.dev>
1 parent 3404e2a commit 8b62434

10 files changed

+106
-11
lines changed

core/bin/zksync_tee_prover/src/tee_prover.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ impl TeeProver {
8080
let msg_to_sign = Message::from_slice(root_hash_bytes)
8181
.map_err(|e| TeeProverError::Verification(e.into()))?;
8282
let signature = self.config.signing_key.sign_ecdsa(msg_to_sign);
83-
observer.observe();
83+
let duration = observer.observe();
84+
tracing::info!(
85+
proof_generation_time = duration.as_secs_f64(),
86+
l1_batch_number = %batch_number,
87+
l1_root_hash = ?verification_result.value_hash,
88+
"L1 batch verified",
89+
);
8490
Ok((signature, batch_number, verification_result.value_hash))
8591
}
8692
_ => Err(TeeProverError::Verification(anyhow::anyhow!(

core/lib/basic_types/src/tee_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22

33
use serde::{Deserialize, Serialize};
44

5-
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
5+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
66
#[serde(rename_all = "lowercase")]
77
#[non_exhaustive]
88
pub enum TeeType {

core/lib/dal/.sqlx/query-746d8b62d576b4b9596458aa865e0294e53eb37c1a2dbcc3044b8311200d549a.json renamed to core/lib/dal/.sqlx/query-6069d168d5c4b5131b50500302cdde79388b62926ff83d954b4d93dedfe2503a.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-6ec93ebdd58bdc0259d98ef5ae0d087ed816920e8e75a163b87a19e39db86227.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Add down migration script here
2+
ALTER TABLE l1_batches DROP COLUMN IF EXISTS sealed_at;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- add a sealed_at column for metrics
2+
ALTER TABLE l1_batches ADD COLUMN sealed_at TIMESTAMP;

core/lib/dal/src/blocks_dal.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77

88
use anyhow::Context as _;
99
use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive};
10+
use sqlx::types::chrono::{DateTime, Utc};
1011
use zksync_db_connection::{
1112
connection::Connection,
1213
error::{DalResult, SqlxContext},
@@ -742,6 +743,7 @@ impl BlocksDal<'_, '_> {
742743
pubdata_input = $19,
743744
predicted_circuits_by_type = $20,
744745
updated_at = NOW(),
746+
sealed_at = NOW(),
745747
is_sealed = TRUE
746748
WHERE
747749
number = $1
@@ -2394,6 +2396,28 @@ impl BlocksDal<'_, '_> {
23942396
.flatten())
23952397
}
23962398

2399+
pub async fn get_batch_sealed_at(
2400+
&mut self,
2401+
l1_batch_number: L1BatchNumber,
2402+
) -> DalResult<Option<DateTime<Utc>>> {
2403+
Ok(sqlx::query!(
2404+
r#"
2405+
SELECT
2406+
sealed_at
2407+
FROM
2408+
l1_batches
2409+
WHERE
2410+
number = $1
2411+
"#,
2412+
i64::from(l1_batch_number.0)
2413+
)
2414+
.instrument("get_batch_sealed_at")
2415+
.with_arg("l1_batch_number", &l1_batch_number)
2416+
.fetch_optional(self.storage)
2417+
.await?
2418+
.and_then(|row| row.sealed_at.map(|d| d.and_utc())))
2419+
}
2420+
23972421
pub async fn set_protocol_version_for_pending_l2_blocks(
23982422
&mut self,
23992423
id: ProtocolVersionId,

core/node/proof_data_handler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ keywords.workspace = true
1111
categories.workspace = true
1212

1313
[dependencies]
14+
chrono.workspace = true
1415
vise.workspace = true
1516
zksync_config.workspace = true
1617
zksync_dal.workspace = true

core/node/proof_data_handler/src/metrics.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
use vise::{Histogram, Metrics};
1+
use std::{fmt, time::Duration};
2+
3+
use vise::{EncodeLabelSet, EncodeLabelValue, Family, Histogram, Metrics, Unit};
24
use zksync_object_store::bincode;
35
use zksync_prover_interface::inputs::WitnessInputData;
6+
use zksync_types::tee_types::TeeType;
47

58
const BYTES_IN_MEGABYTE: u64 = 1024 * 1024;
69

@@ -14,6 +17,24 @@ pub(super) struct ProofDataHandlerMetrics {
1417
pub eip_4844_blob_size_in_mb: Histogram<u64>,
1518
#[metrics(buckets = vise::Buckets::exponential(1.0..=2_048.0, 2.0))]
1619
pub total_blob_size_in_mb: Histogram<u64>,
20+
#[metrics(buckets = vise::Buckets::LATENCIES, unit = Unit::Seconds)]
21+
pub tee_proof_roundtrip_time: Family<MetricsTeeType, Histogram<Duration>>,
22+
}
23+
24+
#[derive(Debug, Clone, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)]
25+
#[metrics(label = "tee_type")]
26+
pub(crate) struct MetricsTeeType(pub TeeType);
27+
28+
impl fmt::Display for MetricsTeeType {
29+
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
30+
self.0.fmt(formatter)
31+
}
32+
}
33+
34+
impl From<TeeType> for MetricsTeeType {
35+
fn from(value: TeeType) -> Self {
36+
Self(value)
37+
}
1738
}
1839

1940
impl ProofDataHandlerMetrics {

core/node/proof_data_handler/src/tee_request_processor.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::sync::Arc;
22

33
use axum::{extract::Path, Json};
4+
use chrono::Utc;
45
use zksync_config::configs::ProofDataHandlerConfig;
56
use zksync_dal::{ConnectionPool, Core, CoreDal};
67
use zksync_object_store::{ObjectStore, ObjectStoreError};
@@ -16,7 +17,7 @@ use zksync_prover_interface::{
1617
use zksync_types::{tee_types::TeeType, L1BatchNumber, L2ChainId};
1718
use zksync_vm_executor::storage::L1BatchParamsProvider;
1819

19-
use crate::errors::RequestProcessorError;
20+
use crate::{errors::RequestProcessorError, metrics::METRICS};
2021

2122
#[derive(Clone)]
2223
pub(crate) struct TeeRequestProcessor {
@@ -194,11 +195,6 @@ impl TeeRequestProcessor {
194195
let mut connection = self.pool.connection_tagged("tee_request_processor").await?;
195196
let mut dal = connection.tee_proof_generation_dal();
196197

197-
tracing::info!(
198-
"Received proof {:?} for batch number: {:?}",
199-
proof,
200-
l1_batch_number
201-
);
202198
dal.save_proof_artifacts_metadata(
203199
l1_batch_number,
204200
proof.0.tee_type,
@@ -208,6 +204,27 @@ impl TeeRequestProcessor {
208204
)
209205
.await?;
210206

207+
let sealed_at = connection
208+
.blocks_dal()
209+
.get_batch_sealed_at(l1_batch_number)
210+
.await?;
211+
212+
let duration = sealed_at.and_then(|sealed_at| (Utc::now() - sealed_at).to_std().ok());
213+
214+
let duration_secs_f64 = if let Some(duration) = duration {
215+
METRICS.tee_proof_roundtrip_time[&proof.0.tee_type.into()].observe(duration);
216+
duration.as_secs_f64()
217+
} else {
218+
f64::NAN
219+
};
220+
221+
tracing::info!(
222+
l1_batch_number = %l1_batch_number,
223+
sealed_to_proven_in_secs = duration_secs_f64,
224+
"Received proof {:?}",
225+
proof
226+
);
227+
211228
Ok(Json(SubmitProofResponse::Success))
212229
}
213230

0 commit comments

Comments
 (0)