Skip to content

Commit

Permalink
feat: Prover interface and L1 interface crates (matter-labs#959)
Browse files Browse the repository at this point in the history
tl;dr:
- Removes crypto stuff from `zksync_types` (this was a primary goal for
this PR)
- Reduces public API surface for general-purpose crates
- Introduces `l1_contract_interface` crate for stuff related to
interacting with our main L1 contract.
- Introduces `prover_interface` crate as a point of interaction between
prover and core subsystems.

❕Note: this is not a complete refactoring, there is still a lot of stuff
that can be moved to either of these two crates, this will be worked on
iteratively. This PR is meant to be just an improvement over what we
currently have.

Rationale: `l1_contract_interface` and `prover_interface` are currently
scattered across several crates (`zksync_types`, most notably) while
actually being used only by few. Encapsulating them both reduces the
public API surface plus reduces the number of (transitive) dependencies,
including getting rid of some heavyweight stuff.
  • Loading branch information
popzxc authored Jan 31, 2024
1 parent 32c1637 commit 4f7e107
Show file tree
Hide file tree
Showing 90 changed files with 1,311 additions and 1,144 deletions.
51 changes: 39 additions & 12 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ members = [
"core/lib/env_config",
"core/lib/eth_client",
"core/lib/eth_signer",
"core/lib/l1_contract_interface",
"core/lib/mempool",
"core/lib/merkle_tree",
"core/lib/mini_merkle_tree",
"core/lib/node",
"core/lib/object_store",
"core/lib/prometheus_exporter",
"core/lib/prover_interface",
"core/lib/queued_job_processor",
"core/lib/state",
"core/lib/storage",
Expand Down
83 changes: 83 additions & 0 deletions core/lib/basic_types/src/basic_fri_types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//! Basic types for FRI prover.
// TODO (PLA-773): Should be moved to the prover workspace.

use std::{convert::TryFrom, str::FromStr};

use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
Expand All @@ -16,3 +20,82 @@ impl CircuitIdRoundTuple {
}
}
}

/// Represents the sequential number of the proof aggregation round.
/// Mostly used to be stored in `aggregation_round` column in `prover_jobs` table
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum AggregationRound {
BasicCircuits = 0,
LeafAggregation = 1,
NodeAggregation = 2,
Scheduler = 3,
}

impl From<u8> for AggregationRound {
fn from(item: u8) -> Self {
match item {
0 => AggregationRound::BasicCircuits,
1 => AggregationRound::LeafAggregation,
2 => AggregationRound::NodeAggregation,
3 => AggregationRound::Scheduler,
_ => panic!("Invalid round"),
}
}
}

impl AggregationRound {
pub fn next(&self) -> Option<AggregationRound> {
match self {
AggregationRound::BasicCircuits => Some(AggregationRound::LeafAggregation),
AggregationRound::LeafAggregation => Some(AggregationRound::NodeAggregation),
AggregationRound::NodeAggregation => Some(AggregationRound::Scheduler),
AggregationRound::Scheduler => None,
}
}
}

impl std::fmt::Display for AggregationRound {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(match self {
Self::BasicCircuits => "basic_circuits",
Self::LeafAggregation => "leaf_aggregation",
Self::NodeAggregation => "node_aggregation",
Self::Scheduler => "scheduler",
})
}
}

impl FromStr for AggregationRound {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"basic_circuits" => Ok(AggregationRound::BasicCircuits),
"leaf_aggregation" => Ok(AggregationRound::LeafAggregation),
"node_aggregation" => Ok(AggregationRound::NodeAggregation),
"scheduler" => Ok(AggregationRound::Scheduler),
other => Err(format!(
"{} is not a valid round name for witness generation",
other
)),
}
}
}

impl TryFrom<i32> for AggregationRound {
type Error = ();

fn try_from(v: i32) -> Result<Self, Self::Error> {
match v {
x if x == AggregationRound::BasicCircuits as i32 => Ok(AggregationRound::BasicCircuits),
x if x == AggregationRound::LeafAggregation as i32 => {
Ok(AggregationRound::LeafAggregation)
}
x if x == AggregationRound::NodeAggregation as i32 => {
Ok(AggregationRound::NodeAggregation)
}
x if x == AggregationRound::Scheduler as i32 => Ok(AggregationRound::Scheduler),
_ => Err(()),
}
}
}
1 change: 1 addition & 0 deletions core/lib/dal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ hex = "0.4"
once_cell = "1.7"
strum = { version = "0.24", features = ["derive"] }
tracing = "0.1"
chrono = { version = "0.4", features = ["serde"] }

[dev-dependencies]
assert_matches = "1.5.0"
Expand Down
8 changes: 5 additions & 3 deletions core/lib/dal/src/fri_gpu_prover_queue_dal.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::time::Duration;

use zksync_types::proofs::{GpuProverInstanceStatus, SocketAddress};

use crate::{time_utils::pg_interval_from_duration, StorageProcessor};
use crate::{
fri_prover_dal::types::{GpuProverInstanceStatus, SocketAddress},
time_utils::pg_interval_from_duration,
StorageProcessor,
};

#[derive(Debug)]
pub struct FriGpuProverQueueDal<'a, 'c> {
Expand Down
6 changes: 2 additions & 4 deletions core/lib/dal/src/fri_proof_compressor_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use std::{collections::HashMap, str::FromStr, time::Duration};

use sqlx::Row;
use strum::{Display, EnumString};
use zksync_types::{
proofs::{JobCountStatistics, StuckJobs},
L1BatchNumber,
};
use zksync_types::L1BatchNumber;

use crate::{
fri_prover_dal::types::{JobCountStatistics, StuckJobs},
time_utils::{duration_to_naive_time, pg_interval_from_duration},
StorageProcessor,
};
Expand Down
Loading

0 comments on commit 4f7e107

Please sign in to comment.