Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit 75bdfcc

Browse files
feat: BWIP (#2258)
## What ❔ Remove Core db connection from prover subsystems Create new component - BasicWitnessInputProducer, that will run VM in the background and produce necessary inputs for basic witness generation ## Why ❔ We want to separate accesses to DB in core/prover subsystems ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. - [x] Spellcheck has been run via `zk spellcheck`. --------- Co-authored-by: perekopskiy <[email protected]>
1 parent 2c8cf35 commit 75bdfcc

File tree

79 files changed

+1307
-513
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1307
-513
lines changed

.github/workflows/ci-core-reusable.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ jobs:
135135
base_token: ["Eth", "Custom"]
136136
deployment_mode: ["Rollup", "Validium"]
137137
env:
138-
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,da_dispatcher,base_token_ratio_persister${{ matrix.consensus && ',consensus' || '' }}"
138+
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,vm_runner_bwip,da_dispatcher,base_token_ratio_persister${{ matrix.consensus && ',consensus' || '' }}"
139139

140140
runs-on: [matterlabs-ci-runner]
141141
steps:
@@ -309,7 +309,7 @@ jobs:
309309
runs-on: [matterlabs-ci-runner]
310310

311311
env:
312-
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,da_dispatcher,base_token_ratio_persister${{ matrix.consensus && ',consensus' || '' }}"
312+
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,vm_runner_bwip,da_dispatcher,base_token_ratio_persister${{ matrix.consensus && ',consensus' || '' }}"
313313
EXT_NODE_FLAGS: "${{ matrix.consensus && '-- --enable-consensus' || '' }}"
314314

315315
steps:

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/bin/zksync_server/src/main.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use zksync_config::{
1111
},
1212
fri_prover_group::FriProverGroupConfig,
1313
house_keeper::HouseKeeperConfig,
14-
ContractsConfig, DatabaseSecrets, FriProofCompressorConfig, FriProverConfig,
15-
FriProverGatewayConfig, FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig,
16-
L1Secrets, ObservabilityConfig, PrometheusConfig, ProofDataHandlerConfig,
17-
ProtectiveReadsWriterConfig, Secrets,
14+
BasicWitnessInputProducerConfig, ContractsConfig, DatabaseSecrets,
15+
FriProofCompressorConfig, FriProverConfig, FriProverGatewayConfig,
16+
FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, L1Secrets, ObservabilityConfig,
17+
PrometheusConfig, ProofDataHandlerConfig, ProtectiveReadsWriterConfig, Secrets,
1818
},
1919
ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, DADispatcherConfig, DBConfig,
2020
EthConfig, EthWatchConfig, GasAdjusterConfig, GenesisConfig, ObjectStoreConfig, PostgresConfig,
@@ -271,6 +271,7 @@ fn load_env_config() -> anyhow::Result<TempConfigStore> {
271271
snapshot_creator: SnapshotsCreatorConfig::from_env().ok(),
272272
da_dispatcher_config: DADispatcherConfig::from_env().ok(),
273273
protective_reads_writer_config: ProtectiveReadsWriterConfig::from_env().ok(),
274+
basic_witness_input_producer_config: BasicWitnessInputProducerConfig::from_env().ok(),
274275
core_object_store: ObjectStoreConfig::from_env().ok(),
275276
base_token_adjuster_config: BaseTokenAdjusterConfig::from_env().ok(),
276277
commitment_generator: None,

core/bin/zksync_server/src/node_builder.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ use zksync_node_framework::{
4848
output_handler::OutputHandlerLayer, RocksdbStorageOptions, StateKeeperLayer,
4949
},
5050
tee_verifier_input_producer::TeeVerifierInputProducerLayer,
51-
vm_runner::protective_reads::ProtectiveReadsWriterLayer,
51+
vm_runner::{
52+
bwip::BasicWitnessInputProducerLayer, protective_reads::ProtectiveReadsWriterLayer,
53+
},
5254
web3_api::{
5355
caches::MempoolCacheLayer,
5456
server::{Web3ServerLayer, Web3ServerOptionalConfig},
@@ -503,6 +505,17 @@ impl MainNodeBuilder {
503505
Ok(self)
504506
}
505507

508+
fn add_vm_runner_bwip_layer(mut self) -> anyhow::Result<Self> {
509+
let basic_witness_input_producer_config =
510+
try_load_config!(self.configs.basic_witness_input_producer_config);
511+
self.node.add_layer(BasicWitnessInputProducerLayer::new(
512+
basic_witness_input_producer_config,
513+
self.genesis_config.l2_chain_id,
514+
));
515+
516+
Ok(self)
517+
}
518+
506519
fn add_base_token_ratio_persister_layer(mut self) -> anyhow::Result<Self> {
507520
let config = try_load_config!(self.configs.base_token_adjuster);
508521
self.node
@@ -604,6 +617,9 @@ impl MainNodeBuilder {
604617
Component::BaseTokenRatioPersister => {
605618
self = self.add_base_token_ratio_persister_layer()?;
606619
}
620+
Component::VmRunnerBwip => {
621+
self = self.add_vm_runner_bwip_layer()?;
622+
}
607623
}
608624
}
609625
Ok(self.node.build()?)

core/lib/basic_types/src/prover_dal.rs

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ pub struct ProverJobFriInfo {
267267
pub struct BasicWitnessGeneratorJobInfo {
268268
pub l1_batch_number: L1BatchNumber,
269269
pub merkle_tree_paths_blob_url: Option<String>,
270+
pub witness_inputs_blob_url: Option<String>,
270271
pub attempts: u32,
271272
pub status: WitnessJobStatus,
272273
pub error: Option<String>,

core/lib/config/src/configs/general.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
house_keeper::HouseKeeperConfig,
88
pruning::PruningConfig,
99
snapshot_recovery::SnapshotRecoveryConfig,
10-
vm_runner::ProtectiveReadsWriterConfig,
10+
vm_runner::{BasicWitnessInputProducerConfig, ProtectiveReadsWriterConfig},
1111
CommitmentGeneratorConfig, FriProofCompressorConfig, FriProverConfig,
1212
FriProverGatewayConfig, FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig,
1313
ObservabilityConfig, PrometheusConfig, ProofDataHandlerConfig,
@@ -40,6 +40,7 @@ pub struct GeneralConfig {
4040
pub observability: Option<ObservabilityConfig>,
4141
pub da_dispatcher_config: Option<DADispatcherConfig>,
4242
pub protective_reads_writer_config: Option<ProtectiveReadsWriterConfig>,
43+
pub basic_witness_input_producer_config: Option<BasicWitnessInputProducerConfig>,
4344
pub commitment_generator: Option<CommitmentGeneratorConfig>,
4445
pub snapshot_recovery: Option<SnapshotRecoveryConfig>,
4546
pub pruning: Option<PruningConfig>,

core/lib/config/src/configs/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub use self::{
2525
snapshot_recovery::SnapshotRecoveryConfig,
2626
snapshots_creator::SnapshotsCreatorConfig,
2727
utils::PrometheusConfig,
28-
vm_runner::ProtectiveReadsWriterConfig,
28+
vm_runner::{BasicWitnessInputProducerConfig, ProtectiveReadsWriterConfig},
2929
};
3030

3131
pub mod api;

core/lib/config/src/configs/vm_runner.rs

+17
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,20 @@ impl ProtectiveReadsWriterConfig {
1717
"./db/protective_reads_writer".to_owned()
1818
}
1919
}
20+
21+
#[derive(Debug, Deserialize, Clone, PartialEq, Default)]
22+
pub struct BasicWitnessInputProducerConfig {
23+
/// Path to the RocksDB data directory that serves state cache.
24+
#[serde(default = "BasicWitnessInputProducerConfig::default_db_path")]
25+
pub db_path: String,
26+
/// How many max batches should be processed at the same time.
27+
pub window_size: u32,
28+
/// All batches before this one (inclusive) are always considered to be processed.
29+
pub first_processed_batch: L1BatchNumber,
30+
}
31+
32+
impl BasicWitnessInputProducerConfig {
33+
fn default_db_path() -> String {
34+
"./db/basic_witness_input_producer".to_owned()
35+
}
36+
}

core/lib/dal/.sqlx/query-05c2a77d9f65d435e2df63a300850e42abbaf365a1b041d0e7a809796ef0fe63.json

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-11af69fc254e54449b64c086667700a95e4c37a7a18531b3cdf120394cb055b9.json

-22
This file was deleted.

core/lib/dal/.sqlx/query-2482716de397893c52840eb39391ad3349e4d932d3de64b6dade97481cd171a4.json

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-08e59ed8e2fd1a74e19d8bf0d131e4ee6682a89fb86f3b715a240805d44e6d87.json core/lib/dal/.sqlx/query-41a2731a3fe6ae441902632dcce15601ff39acd03e3c8a2265c9036b3dc54383.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-703836a3f065b0aedf71ad0474cac5e5fccb3ec55aa1227f5f1ea5a11f9b36a9.json

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-58aed39245c72d231b268ce83105bb2036d21f60d4c6934f9145730ac35c04de.json core/lib/dal/.sqlx/query-815a7037a11dfc32e9d084d57178a9777126abebaf648c00fdcc24beb9967010.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-a3f24c7f2298398517db009f7e5373c57d2dc6ec03d84f91a221ab8097e587cc.json

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-a85a15aa2e0be1c1f50d15a8354afcf939e8352e21689baf861b61a666bdc1fd.json

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE proof_generation_details DROP COLUMN IF EXISTS vm_run_data_blob_url;
2+
DROP TABLE IF EXISTS vm_runner_bwip;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ALTER TABLE proof_generation_details
2+
ADD COLUMN IF NOT EXISTS vm_run_data_blob_url TEXT DEFAULT NULL;
3+
4+
CREATE TABLE IF NOT EXISTS vm_runner_bwip
5+
(
6+
l1_batch_number BIGINT NOT NULL PRIMARY KEY,
7+
created_at TIMESTAMP NOT NULL,
8+
updated_at TIMESTAMP NOT NULL,
9+
time_taken TIME
10+
);

0 commit comments

Comments
 (0)