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

feat: use semver for metrics, move constants to prover workspace #2098

Merged
merged 8 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions core/lib/basic_types/src/basic_fri_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::{convert::TryFrom, str::FromStr};

use serde::{Deserialize, Serialize};

use crate::protocol_version::{ProtocolSemanticVersion, ProtocolVersionId, VersionPatch};

const BLOB_CHUNK_SIZE: usize = 31;
const ELEMENTS_PER_4844_BLOCK: usize = 4096;
pub const MAX_4844_BLOBS_PER_BLOCK: usize = 16;
Expand Down Expand Up @@ -189,6 +191,16 @@ pub struct JobIdentifiers {
pub circuit_id: u8,
pub aggregation_round: u8,
pub protocol_version: u16,
pub protocol_version_patch: u32,
}

impl JobIdentifiers {
pub fn get_semantic_protocol_version(&self) -> ProtocolSemanticVersion {
ProtocolSemanticVersion::new(
ProtocolVersionId::try_from(self.protocol_version).unwrap(),
VersionPatch(self.protocol_version_patch),
)
}
}

#[cfg(test)]
Expand Down
18 changes: 0 additions & 18 deletions core/lib/basic_types/src/protocol_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ use crate::{
pub const PACKED_SEMVER_MINOR_OFFSET: u32 = 32;
pub const PACKED_SEMVER_MINOR_MASK: u32 = 0xFFFF;

// These values should be manually updated for every protocol upgrade
// Otherwise, the prover will not be able to work with new versions.
// TODO(PLA-954): Move to prover workspace
pub const PROVER_PROTOCOL_VERSION: ProtocolVersionId = ProtocolVersionId::Version24;
pub const PROVER_PROTOCOL_PATCH: VersionPatch = VersionPatch(0);
pub const PROVER_PROTOCOL_SEMANTIC_VERSION: ProtocolSemanticVersion = ProtocolSemanticVersion {
minor: PROVER_PROTOCOL_VERSION,
patch: PROVER_PROTOCOL_PATCH,
};

/// `ProtocolVersionId` is a unique identifier of the protocol version.
/// Note, that it is an identifier of the `minor` semver version of the protocol, with
/// the `major` version being `0`. Also, the protocol version on the contracts may contain
Expand Down Expand Up @@ -85,10 +75,6 @@ impl ProtocolVersionId {
Self::Version24
}

pub fn current_prover_version() -> Self {
PROVER_PROTOCOL_VERSION
}

pub fn next() -> Self {
Self::Version25
}
Expand Down Expand Up @@ -311,10 +297,6 @@ impl ProtocolSemanticVersion {
Self { minor, patch }
}

pub fn current_prover_version() -> Self {
PROVER_PROTOCOL_SEMANTIC_VERSION
}

pub fn try_from_packed(packed: U256) -> Result<Self, String> {
let minor = ((packed >> U256::from(PACKED_SEMVER_MINOR_OFFSET))
& U256::from(PACKED_SEMVER_MINOR_MASK))
Expand Down
5 changes: 2 additions & 3 deletions core/node/house_keeper/src/prover/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use vise::{Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, LabeledFamily, Metrics};
use zksync_types::ProtocolVersionId;

use zksync_types::protocol_version::ProtocolSemanticVersion;
#[derive(Debug, Metrics)]
#[metrics(prefix = "house_keeper")]
pub(crate) struct HouseKeeperMetrics {
Expand Down Expand Up @@ -63,7 +62,7 @@ impl FriProverMetrics {
circuit_id: u8,
aggregation_round: u8,
prover_group_id: u8,
protocol_version: ProtocolVersionId,
protocol_version: ProtocolSemanticVersion,
amount: u64,
) {
self.prover_jobs[&ProverJobsLabels {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use async_trait::async_trait;
use prover_dal::{Prover, ProverDal};
use zksync_dal::ConnectionPool;
use zksync_types::{prover_dal::JobCountStatistics, ProtocolVersionId};
use zksync_types::{protocol_version::ProtocolSemanticVersion, prover_dal::JobCountStatistics};

use crate::{
periodic_job::PeriodicJob,
Expand All @@ -28,7 +28,7 @@ impl FriProofCompressorQueueReporter {

async fn get_job_statistics(
pool: &ConnectionPool<Prover>,
) -> HashMap<ProtocolVersionId, JobCountStatistics> {
) -> HashMap<ProtocolSemanticVersion, JobCountStatistics> {
pool.connection()
.await
.unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use async_trait::async_trait;
use prover_dal::{Prover, ProverDal};
use zksync_config::configs::fri_prover_group::FriProverGroupConfig;
use zksync_dal::{ConnectionPool, Core, CoreDal};
use zksync_types::ProtocolVersionId;

use crate::{periodic_job::PeriodicJob, prover::metrics::FRI_PROVER_METRICS};

Expand Down Expand Up @@ -67,7 +66,7 @@ impl PeriodicJob for FriProverQueueReporter {
circuit_id,
job_identifiers.aggregation_round,
group_id,
ProtocolVersionId::try_from(job_identifiers.protocol_version).unwrap(),
job_identifiers.get_semantic_protocol_version(),
stats.queued as u64,
);

Expand All @@ -76,7 +75,7 @@ impl PeriodicJob for FriProverQueueReporter {
circuit_id,
job_identifiers.aggregation_round,
group_id,
ProtocolVersionId::try_from(job_identifiers.protocol_version).unwrap(),
job_identifiers.get_semantic_protocol_version(),
stats.in_progress as u64,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use async_trait::async_trait;
use prover_dal::{Prover, ProverDal};
use zksync_dal::ConnectionPool;
use zksync_types::{
basic_fri_types::AggregationRound, prover_dal::JobCountStatistics, ProtocolVersionId,
basic_fri_types::AggregationRound, protocol_version::ProtocolSemanticVersion,
prover_dal::JobCountStatistics,
};

use crate::{periodic_job::PeriodicJob, prover::metrics::SERVER_METRICS};
Expand All @@ -27,7 +28,7 @@ impl FriWitnessGeneratorQueueReporter {

async fn get_job_statistics(
&self,
) -> HashMap<(AggregationRound, ProtocolVersionId), JobCountStatistics> {
) -> HashMap<(AggregationRound, ProtocolSemanticVersion), JobCountStatistics> {
let mut conn = self.pool.connection().await.unwrap();
let mut result = HashMap::new();
result.extend(
Expand Down Expand Up @@ -62,7 +63,7 @@ impl FriWitnessGeneratorQueueReporter {

fn emit_metrics_for_round(
round: AggregationRound,
protocol_version: ProtocolVersionId,
protocol_version: ProtocolSemanticVersion,
stats: &JobCountStatistics,
) {
if stats.queued > 0 || stats.in_progress > 0 {
Expand Down Expand Up @@ -95,7 +96,7 @@ impl PeriodicJob for FriWitnessGeneratorQueueReporter {

async fn run_routine_task(&mut self) -> anyhow::Result<()> {
let stats_for_all_rounds = self.get_job_statistics().await;
let mut aggregated = HashMap::<ProtocolVersionId, JobCountStatistics>::new();
let mut aggregated = HashMap::<ProtocolSemanticVersion, JobCountStatistics>::new();
for ((round, protocol_version), stats) in stats_for_all_rounds {
emit_metrics_for_round(round, protocol_version, &stats);

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/protocol-upgrade/src/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumberish } from '@ethersproject/bignumber';
import { Bytes, BytesLike, ethers } from 'ethers';
import { BytesLike, ethers } from 'ethers';
import { ForceDeployUpgraderFactory as ForceDeployUpgraderFactoryL2 } from 'l2-contracts/typechain';
import {
DefaultUpgradeFactory as DefaultUpgradeFactoryL1,
Expand Down
2 changes: 1 addition & 1 deletion prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions prover/proof_fri_compressor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use tokio::sync::{oneshot, watch};
use zksync_config::configs::{DatabaseSecrets, FriProofCompressorConfig, ObservabilityConfig};
use zksync_env_config::{object_store::ProverObjectStoreConfig, FromEnv};
use zksync_object_store::ObjectStoreFactory;
use zksync_prover_fri_types::PROVER_PROTOCOL_SEMANTIC_VERSION;
use zksync_queued_job_processor::JobProcessor;
use zksync_types::protocol_version::ProtocolSemanticVersion;
use zksync_utils::wait_for_tasks::ManagedTasks;

use crate::{
Expand Down Expand Up @@ -73,7 +73,7 @@ async fn main() -> anyhow::Result<()> {
.create_store()
.await;

let protocol_version = ProtocolSemanticVersion::current_prover_version();
let protocol_version = PROVER_PROTOCOL_SEMANTIC_VERSION;

let proof_compressor = ProofCompressor::new(
blob_store,
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions prover/prover_dal/src/fri_proof_compressor_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,12 @@ impl FriProofCompressorDal<'_, '_> {
.unwrap();
}

pub async fn get_jobs_stats(&mut self) -> HashMap<ProtocolVersionId, JobCountStatistics> {
pub async fn get_jobs_stats(&mut self) -> HashMap<ProtocolSemanticVersion, JobCountStatistics> {
sqlx::query!(
r#"
SELECT
protocol_version,
protocol_version_patch,
COUNT(*) FILTER (
WHERE
status = 'queued'
Expand All @@ -269,15 +270,19 @@ impl FriProofCompressorDal<'_, '_> {
WHERE
protocol_version IS NOT NULL
GROUP BY
protocol_version
protocol_version,
protocol_version_patch
"#,
)
.fetch_all(self.storage.conn())
.await
.unwrap()
.into_iter()
.map(|row| {
let key = ProtocolVersionId::try_from(row.protocol_version.unwrap() as u16).unwrap();
let key = ProtocolSemanticVersion::new(
ProtocolVersionId::try_from(row.protocol_version.unwrap() as u16).unwrap(),
VersionPatch(row.protocol_version_patch as u32),
);
let value = JobCountStatistics {
queued: row.queued.unwrap() as usize,
in_progress: row.in_progress.unwrap() as usize,
Expand Down
7 changes: 5 additions & 2 deletions prover/prover_dal/src/fri_prover_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ impl FriProverDal<'_, '_> {
circuit_id AS "circuit_id!",
aggregation_round AS "aggregation_round!",
status AS "status!",
protocol_version AS "protocol_version!"
protocol_version AS "protocol_version!",
protocol_version_patch AS "protocol_version_patch!"
FROM
prover_jobs_fri
WHERE
Expand All @@ -422,7 +423,8 @@ impl FriProverDal<'_, '_> {
circuit_id,
aggregation_round,
status,
protocol_version
protocol_version,
protocol_version_patch
"#
)
.fetch_all(self.storage.conn())
Expand All @@ -437,6 +439,7 @@ impl FriProverDal<'_, '_> {
circuit_id: row.circuit_id as u8,
aggregation_round: row.aggregation_round as u8,
protocol_version: row.protocol_version as u16,
protocol_version_patch: row.protocol_version_patch as u32,
})
.or_default();
match row.status.as_ref() {
Expand Down
Loading
Loading