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: External prover API #2538

Merged
merged 25 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
24 changes: 12 additions & 12 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
unit-tests:
runs-on: [matterlabs-ci-runner]
runs-on: [ matterlabs-ci-runner ]
Artemka374 marked this conversation as resolved.
Show resolved Hide resolved

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
run: ci_run zk test rust

loadtest:
runs-on: [matterlabs-ci-runner]
runs-on: [ matterlabs-ci-runner ]

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
Expand Down Expand Up @@ -143,13 +143,13 @@ jobs:
# To be consistent with the rest of the workflow we disable it explicitly.
fail-fast: false
matrix:
consensus: [false, true]
base_token: ["Eth", "Custom"]
deployment_mode: ["Rollup", "Validium"]
consensus: [ false, true ]
base_token: [ "Eth", "Custom" ]
deployment_mode: [ "Rollup", "Validium" ]
env:
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,vm_runner_bwip,da_dispatcher${{ matrix.consensus && ',consensus' || '' }}${{ matrix.base_token == 'Custom' && ',base_token_ratio_persister' || '' }}"
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,vm_runner_bwip,da_dispatcher,prover_api${{ matrix.consensus && ',consensus' || '' }}${{ matrix.base_token == 'Custom' && ',base_token_ratio_persister' || '' }}"

runs-on: [matterlabs-ci-runner]
runs-on: [ matterlabs-ci-runner ]
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
with:
Expand Down Expand Up @@ -316,13 +316,13 @@ jobs:
strategy:
fail-fast: false
matrix:
consensus: [false, true]
base_token: ["Eth", "Custom"]
deployment_mode: ["Rollup", "Validium"]
runs-on: [matterlabs-ci-runner]
consensus: [ false, true ]
base_token: [ "Eth", "Custom" ]
deployment_mode: [ "Rollup", "Validium" ]
runs-on: [ matterlabs-ci-runner ]

env:
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,vm_runner_bwip,da_dispatcher${{ matrix.consensus && ',consensus' || '' }}${{ matrix.base_token == 'Custom' && ',base_token_ratio_persister' || '' }}"
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,vm_runner_bwip,da_dispatcher,prover_api${{ matrix.consensus && ',consensus' || '' }}${{ matrix.base_token == 'Custom' && ',base_token_ratio_persister' || '' }}"
EXT_NODE_FLAGS: "${{ matrix.consensus && '-- --enable-consensus' || '' }}"

steps:
Expand Down
17 changes: 17 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ members = [
"core/node/api_server",
"core/node/tee_verifier_input_producer",
"core/node/base_token_adjuster",
"core/node/prover_api",
Artemka374 marked this conversation as resolved.
Show resolved Hide resolved
# Libraries
"core/lib/db_connection",
"core/lib/zksync_core_leftovers",
Expand Down Expand Up @@ -77,7 +78,6 @@ members = [
"core/tests/loadnext",
"core/tests/vm-benchmark",
"core/tests/vm-benchmark/harness",

# Parts of prover workspace that are needed for Core workspace
"prover/crates/lib/prover_dal",
]
Expand Down Expand Up @@ -277,6 +277,7 @@ zksync_eth_sender = { version = "0.1.0", path = "core/node/eth_sender" }
zksync_node_db_pruner = { version = "0.1.0", path = "core/node/db_pruner" }
zksync_node_fee_model = { version = "0.1.0", path = "core/node/fee_model" }
zksync_vm_runner = { version = "0.1.0", path = "core/node/vm_runner" }
zksync_prover_api = { version = "0.1.0", path = "core/node/prover_api" }
zksync_node_test_utils = { version = "0.1.0", path = "core/node/test_utils" }
zksync_state_keeper = { version = "0.1.0", path = "core/node/state_keeper" }
zksync_reorg_detector = { version = "0.1.0", path = "core/node/reorg_detector" }
Expand Down
3 changes: 2 additions & 1 deletion core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use zksync_config::{
},
ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, DADispatcherConfig, DBConfig,
EthConfig, EthWatchConfig, GasAdjusterConfig, GenesisConfig, ObjectStoreConfig, PostgresConfig,
SnapshotsCreatorConfig,
ProverApiConfig, SnapshotsCreatorConfig,
};
use zksync_core_leftovers::{
temp_config_store::{decode_yaml_repr, TempConfigStore},
Expand Down Expand Up @@ -208,5 +208,6 @@ fn load_env_config() -> anyhow::Result<TempConfigStore> {
pruning: None,
snapshot_recovery: None,
external_price_api_client_config: ExternalPriceApiClientConfig::from_env().ok(),
prover_api_config: ProverApiConfig::from_env().ok(),
})
}
14 changes: 14 additions & 0 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use zksync_node_framework::{
postgres_metrics::PostgresMetricsLayer,
prometheus_exporter::PrometheusExporterLayer,
proof_data_handler::ProofDataHandlerLayer,
prover_api::ProverApiLayer,
query_eth_client::QueryEthClientLayer,
sigint::SigintHandlerLayer,
state_keeper::{
Expand Down Expand Up @@ -562,6 +563,16 @@ impl MainNodeBuilder {
Ok(self)
}

fn add_prover_api_layer(mut self) -> anyhow::Result<Self> {
let config = try_load_config!(self.configs.prover_api_config);
self.node.add_layer(ProverApiLayer::new(
config,
self.genesis_config.l1_batch_commit_data_generator_mode,
Artemka374 marked this conversation as resolved.
Show resolved Hide resolved
));

Ok(self)
}

/// This layer will make sure that the database is initialized correctly,
/// e.g. genesis will be performed if it's required.
///
Expand Down Expand Up @@ -703,6 +714,9 @@ impl MainNodeBuilder {
Component::VmRunnerBwip => {
self = self.add_vm_runner_bwip_layer()?;
}
Component::ProverApi => {
self = self.add_prover_api_layer()?;
}
}
}
Ok(self.node.build())
Expand Down
3 changes: 2 additions & 1 deletion core/lib/config/src/configs/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
ProofDataHandlerConfig,
},
ApiConfig, ContractVerifierConfig, DBConfig, EthConfig, ObjectStoreConfig, PostgresConfig,
SnapshotsCreatorConfig,
ProverApiConfig, SnapshotsCreatorConfig,
};

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -50,4 +50,5 @@ pub struct GeneralConfig {
pub base_token_adjuster: Option<BaseTokenAdjusterConfig>,
pub external_price_api_client_config: Option<ExternalPriceApiClientConfig>,
pub consensus_config: Option<ConsensusConfig>,
pub prover_api_config: Option<ProverApiConfig>,
}
2 changes: 2 additions & 0 deletions core/lib/config/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub use self::{
object_store::ObjectStoreConfig,
observability::{ObservabilityConfig, OpentelemetryConfig},
proof_data_handler::ProofDataHandlerConfig,
prover_api::ProverApiConfig,
pruning::PruningConfig,
secrets::{DatabaseSecrets, L1Secrets, Secrets},
snapshot_recovery::SnapshotRecoveryConfig,
Expand Down Expand Up @@ -55,6 +56,7 @@ pub mod house_keeper;
pub mod object_store;
pub mod observability;
pub mod proof_data_handler;
pub mod prover_api;
pub mod pruning;
pub mod secrets;
pub mod snapshot_recovery;
Expand Down
6 changes: 6 additions & 0 deletions core/lib/config/src/configs/prover_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use serde::Deserialize;

#[derive(Debug, Deserialize, Clone, PartialEq)]
pub struct ProverApiConfig {
pub http_port: u16,
}
2 changes: 1 addition & 1 deletion core/lib/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pub use crate::configs::{
ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, ContractsConfig,
DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig, GasAdjusterConfig, GenesisConfig,
ObjectStoreConfig, PostgresConfig, SnapshotsCreatorConfig,
ObjectStoreConfig, PostgresConfig, ProverApiConfig, SnapshotsCreatorConfig,
};

pub mod configs;
Expand Down
9 changes: 9 additions & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,14 @@ impl Distribution<configs::base_token_adjuster::BaseTokenAdjusterConfig> for Enc
}
}

impl Distribution<configs::prover_api::ProverApiConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::prover_api::ProverApiConfig {
configs::prover_api::ProverApiConfig {
http_port: self.sample(rng),
}
}
}

impl Distribution<configs::external_price_api_client::ExternalPriceApiClientConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(
&self,
Expand Down Expand Up @@ -1041,6 +1049,7 @@ impl Distribution<configs::GeneralConfig> for EncodeDist {
base_token_adjuster: self.sample(rng),
external_price_api_client_config: self.sample(rng),
consensus_config: self.sample(rng),
prover_api_config: self.sample(rng),
}
}
}

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.

51 changes: 51 additions & 0 deletions core/lib/dal/src/proof_generation_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,57 @@ impl ProofGenerationDal<'_, '_> {
Ok(result)
}

pub async fn get_available_batch(&mut self) -> DalResult<L1BatchNumber> {
Artemka374 marked this conversation as resolved.
Show resolved Hide resolved
let result = sqlx::query!(
Artemka374 marked this conversation as resolved.
Show resolved Hide resolved
r#"
SELECT
l1_batch_number
FROM
proof_generation_details
LEFT JOIN l1_batches ON l1_batch_number = l1_batches.number
WHERE
vm_run_data_blob_url IS NOT NULL
AND proof_gen_data_blob_url IS NOT NULL
AND l1_batches.hash IS NOT NULL
AND l1_batches.aux_data_hash IS NOT NULL
AND l1_batches.meta_parameters_hash IS NOT NULL
ORDER BY
l1_batch_number ASC
LIMIT
1
"#,
)
.instrument("get_available batch")
.fetch_one(self.storage)
.await?
.l1_batch_number as u32;

Ok(L1BatchNumber(result))
}

pub async fn check_proof_presence(
Artemka374 marked this conversation as resolved.
Show resolved Hide resolved
&mut self,
l1_batch_number: L1BatchNumber,
) -> DalResult<bool> {
let result = sqlx::query!(
r#"
SELECT
proof_blob_url
FROM
proof_generation_details
WHERE
l1_batch_number = $1
"#,
i64::from(l1_batch_number.0),
)
.instrument("is_proof_present")
.with_arg("l1_batch_number", &l1_batch_number)
.fetch_optional(self.storage)
.await?;

Ok(result.is_some())
}

/// Marks a previously locked batch as 'unpicked', allowing it to be picked without having
/// to wait for the processing timeout.
pub async fn unlock_batch(&mut self, l1_batch_number: L1BatchNumber) -> DalResult<()> {
Expand Down
1 change: 1 addition & 0 deletions core/lib/env_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod base_token_adjuster;
mod da_dispatcher;
mod external_price_api_client;
mod genesis;
mod prover_api;
#[cfg(test)]
mod test_utils;
mod vm_runner;
Expand Down
32 changes: 32 additions & 0 deletions core/lib/env_config/src/prover_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use zksync_config::configs::ProverApiConfig;

use crate::{envy_load, FromEnv};

impl FromEnv for ProverApiConfig {
fn from_env() -> anyhow::Result<Self> {
envy_load("prover_api", "PROVER_API_")
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::test_utils::EnvMutex;

static MUTEX: EnvMutex = EnvMutex::new();

fn expected_config() -> ProverApiConfig {
ProverApiConfig { http_port: 3320 }
}

#[test]
fn from_env() {
let config = r#"
PROVER_API_HTTP_PORT="3320"
"#;
let mut lock = MUTEX.lock();
lock.set_env(config);
let actual = ProverApiConfig::from_env().unwrap();
assert_eq!(actual, expected_config());
}
}
2 changes: 2 additions & 0 deletions core/lib/protobuf_config/src/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl ProtoRepr for proto::GeneralConfig {
snapshot_recovery: read_optional_repr(&self.snapshot_recovery),
external_price_api_client_config: read_optional_repr(&self.external_price_api_client),
consensus_config: read_optional_repr(&self.consensus),
prover_api_config: read_optional_repr(&self.prover_api),
})
}

Expand Down Expand Up @@ -90,6 +91,7 @@ impl ProtoRepr for proto::GeneralConfig {
.as_ref()
.map(ProtoRepr::build),
consensus: this.consensus_config.as_ref().map(ProtoRepr::build),
prover_api: this.prover_api_config.as_ref().map(ProtoRepr::build),
}
}
}
1 change: 1 addition & 0 deletions core/lib/protobuf_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod secrets;
mod snapshots_creator;

mod external_price_api_client;
mod prover_api;
mod snapshot_recovery;
#[cfg(test)]
mod tests;
Expand Down
Loading
Loading