From c6cf36646e86455557c0b31cd0c5305a3bfd4893 Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Wed, 7 Aug 2024 15:36:45 +0300 Subject: [PATCH 1/6] Sketch experimental VM config --- core/bin/zksync_server/src/main.rs | 3 ++- core/bin/zksync_server/src/node_builder.rs | 4 +++- core/lib/config/src/configs/experimental.rs | 13 ++++++++++- core/lib/config/src/configs/general.rs | 9 ++++---- core/lib/config/src/configs/mod.rs | 2 +- core/lib/config/src/testonly.rs | 23 +++++++++++++++---- core/lib/env_config/src/vm_runner.rs | 9 +++++++- core/lib/protobuf_config/src/experimental.rs | 23 +++++++++++++++++++ core/lib/protobuf_config/src/general.rs | 2 ++ .../src/proto/config/experimental.proto | 4 ++++ .../src/proto/config/general.proto | 1 + .../src/temp_config_store/mod.rs | 13 +++++++---- .../state_keeper/main_batch_executor.rs | 11 ++++++++- 13 files changed, 97 insertions(+), 20 deletions(-) diff --git a/core/bin/zksync_server/src/main.rs b/core/bin/zksync_server/src/main.rs index c0ecef5044c3..e66b93fc942c 100644 --- a/core/bin/zksync_server/src/main.rs +++ b/core/bin/zksync_server/src/main.rs @@ -11,7 +11,7 @@ use zksync_config::{ }, fri_prover_group::FriProverGroupConfig, house_keeper::HouseKeeperConfig, - BasicWitnessInputProducerConfig, ContractsConfig, DatabaseSecrets, + BasicWitnessInputProducerConfig, ContractsConfig, DatabaseSecrets, ExperimentalVmConfig, ExperimentalVmPlaygroundConfig, ExternalPriceApiClientConfig, FriProofCompressorConfig, FriProverConfig, FriProverGatewayConfig, FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, L1Secrets, ObservabilityConfig, PrometheusConfig, @@ -209,5 +209,6 @@ fn load_env_config() -> anyhow::Result { pruning: None, snapshot_recovery: None, external_price_api_client_config: ExternalPriceApiClientConfig::from_env().ok(), + experimental_vm_config: ExperimentalVmConfig::from_env().ok(), }) } diff --git a/core/bin/zksync_server/src/node_builder.rs b/core/bin/zksync_server/src/node_builder.rs index d74e6258e32a..d12adba36ba9 100644 --- a/core/bin/zksync_server/src/node_builder.rs +++ b/core/bin/zksync_server/src/node_builder.rs @@ -236,8 +236,10 @@ impl MainNodeBuilder { try_load_config!(wallets.state_keeper), ); let db_config = try_load_config!(self.configs.db_config); + let experimental_vm_config = try_load_config!(self.configs.experimental_vm_config); let main_node_batch_executor_builder_layer = - MainBatchExecutorLayer::new(sk_config.save_call_traces, OPTIONAL_BYTECODE_COMPRESSION); + MainBatchExecutorLayer::new(sk_config.save_call_traces, OPTIONAL_BYTECODE_COMPRESSION) + .with_fast_vm_mode(experimental_vm_config.state_keeper_fast_vm_mode); let rocksdb_options = RocksdbStorageOptions { block_cache_capacity: db_config diff --git a/core/lib/config/src/configs/experimental.rs b/core/lib/config/src/configs/experimental.rs index 0b9505d4e19b..1de3262b2b39 100644 --- a/core/lib/config/src/configs/experimental.rs +++ b/core/lib/config/src/configs/experimental.rs @@ -62,7 +62,8 @@ impl ExperimentalDBConfig { } } -#[derive(Debug, Deserialize, Clone, PartialEq)] +/// Configuration for the VM playground (an experimental component that's unlikely to ever be stabilized). +#[derive(Debug, Clone, PartialEq, Deserialize)] pub struct ExperimentalVmPlaygroundConfig { /// Mode in which to run the fast VM implementation. Note that for it to actually be used, L1 batches should have a recent version. #[serde(default)] @@ -95,3 +96,13 @@ impl ExperimentalVmPlaygroundConfig { "./db/vm_playground".to_owned() } } + +/// Experimental VM configuration options. +#[derive(Debug, Clone, Default, PartialEq, Deserialize)] +pub struct ExperimentalVmConfig { + // FIXME: embed `ExperimentalVmPlaygroundConfig`? + /// Mode in which to run the fast VM implementation in the state keeper. Should not be set in production; + /// the new VM doesn't produce call traces and can diverge from the old VM! + #[serde(default)] + pub state_keeper_fast_vm_mode: FastVmMode, +} diff --git a/core/lib/config/src/configs/general.rs b/core/lib/config/src/configs/general.rs index 557bfbf0b77a..9645fed659e3 100644 --- a/core/lib/config/src/configs/general.rs +++ b/core/lib/config/src/configs/general.rs @@ -9,10 +9,10 @@ use crate::{ pruning::PruningConfig, snapshot_recovery::SnapshotRecoveryConfig, vm_runner::{BasicWitnessInputProducerConfig, ProtectiveReadsWriterConfig}, - CommitmentGeneratorConfig, ExperimentalVmPlaygroundConfig, ExternalPriceApiClientConfig, - FriProofCompressorConfig, FriProverConfig, FriProverGatewayConfig, - FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, ObservabilityConfig, - PrometheusConfig, ProofDataHandlerConfig, + CommitmentGeneratorConfig, ExperimentalVmConfig, ExperimentalVmPlaygroundConfig, + ExternalPriceApiClientConfig, FriProofCompressorConfig, FriProverConfig, + FriProverGatewayConfig, FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, + ObservabilityConfig, PrometheusConfig, ProofDataHandlerConfig, }, ApiConfig, ContractVerifierConfig, DBConfig, EthConfig, ObjectStoreConfig, PostgresConfig, SnapshotsCreatorConfig, @@ -51,4 +51,5 @@ pub struct GeneralConfig { pub base_token_adjuster: Option, pub external_price_api_client_config: Option, pub consensus_config: Option, + pub experimental_vm_config: Option, } diff --git a/core/lib/config/src/configs/mod.rs b/core/lib/config/src/configs/mod.rs index 06c5a8af97f0..ec195a0f6600 100644 --- a/core/lib/config/src/configs/mod.rs +++ b/core/lib/config/src/configs/mod.rs @@ -9,7 +9,7 @@ pub use self::{ database::{DBConfig, PostgresConfig}, eth_sender::{EthConfig, GasAdjusterConfig}, eth_watch::EthWatchConfig, - experimental::{ExperimentalDBConfig, ExperimentalVmPlaygroundConfig}, + experimental::{ExperimentalDBConfig, ExperimentalVmConfig, ExperimentalVmPlaygroundConfig}, external_price_api_client::ExternalPriceApiClientConfig, fri_proof_compressor::FriProofCompressorConfig, fri_prover::FriProverConfig, diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index 3b7d9ebabb4c..56c9e6051b90 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -295,11 +295,7 @@ impl Distribution for EncodeDist { impl Distribution for EncodeDist { fn sample(&self, rng: &mut R) -> configs::ExperimentalVmPlaygroundConfig { configs::ExperimentalVmPlaygroundConfig { - fast_vm_mode: match rng.gen_range(0..3) { - 0 => FastVmMode::Old, - 1 => FastVmMode::New, - _ => FastVmMode::Shadow, - }, + fast_vm_mode: gen_fast_vm_mode(rng), db_path: self.sample(rng), first_processed_batch: L1BatchNumber(rng.gen()), reset: self.sample(rng), @@ -307,6 +303,22 @@ impl Distribution for EncodeDist { } } +fn gen_fast_vm_mode(rng: &mut R) -> FastVmMode { + match rng.gen_range(0..3) { + 0 => FastVmMode::Old, + 1 => FastVmMode::New, + _ => FastVmMode::Shadow, + } +} + +impl Distribution for EncodeDist { + fn sample(&self, rng: &mut R) -> configs::ExperimentalVmConfig { + configs::ExperimentalVmConfig { + state_keeper_fast_vm_mode: gen_fast_vm_mode(rng), + } + } +} + impl Distribution for EncodeDist { fn sample(&self, rng: &mut R) -> configs::database::DBConfig { configs::database::DBConfig { @@ -1061,6 +1073,7 @@ impl Distribution for EncodeDist { base_token_adjuster: self.sample(rng), external_price_api_client_config: self.sample(rng), consensus_config: self.sample(rng), + experimental_vm_config: self.sample(rng), } } } diff --git a/core/lib/env_config/src/vm_runner.rs b/core/lib/env_config/src/vm_runner.rs index 49ed5d8b9289..b433d1a896c9 100644 --- a/core/lib/env_config/src/vm_runner.rs +++ b/core/lib/env_config/src/vm_runner.rs @@ -1,5 +1,6 @@ use zksync_config::configs::{ - BasicWitnessInputProducerConfig, ExperimentalVmPlaygroundConfig, ProtectiveReadsWriterConfig, + BasicWitnessInputProducerConfig, ExperimentalVmConfig, ExperimentalVmPlaygroundConfig, + ProtectiveReadsWriterConfig, }; use crate::{envy_load, FromEnv}; @@ -22,6 +23,12 @@ impl FromEnv for ExperimentalVmPlaygroundConfig { } } +impl FromEnv for ExperimentalVmConfig { + fn from_env() -> anyhow::Result { + envy_load("experimental_vm", "EXPERIMENTAL_VM_") + } +} + #[cfg(test)] mod tests { use zksync_basic_types::{vm::FastVmMode, L1BatchNumber}; diff --git a/core/lib/protobuf_config/src/experimental.rs b/core/lib/protobuf_config/src/experimental.rs index fa49e4836456..fc4693dabbc1 100644 --- a/core/lib/protobuf_config/src/experimental.rs +++ b/core/lib/protobuf_config/src/experimental.rs @@ -98,3 +98,26 @@ impl ProtoRepr for proto::VmPlayground { } } } + +impl ProtoRepr for proto::Vm { + type Type = configs::ExperimentalVmConfig; + + fn read(&self) -> anyhow::Result { + Ok(Self::Type { + state_keeper_fast_vm_mode: self + .state_keeper_fast_vm_mode + .map(proto::FastVmMode::try_from) + .transpose() + .context("fast_vm_mode")? + .map_or_else(FastVmMode::default, |mode| mode.parse()), + }) + } + + fn build(this: &Self::Type) -> Self { + Self { + state_keeper_fast_vm_mode: Some( + proto::FastVmMode::new(this.state_keeper_fast_vm_mode).into(), + ), + } + } +} diff --git a/core/lib/protobuf_config/src/general.rs b/core/lib/protobuf_config/src/general.rs index ed0e076cb711..b4db75daab9c 100644 --- a/core/lib/protobuf_config/src/general.rs +++ b/core/lib/protobuf_config/src/general.rs @@ -41,6 +41,7 @@ impl ProtoRepr for proto::GeneralConfig { external_price_api_client_config: read_optional_repr(&self.external_price_api_client), consensus_config: read_optional_repr(&self.consensus), vm_playground_config: read_optional_repr(&self.vm_playground), + experimental_vm_config: read_optional_repr(&self.experimental_vm), }) } @@ -92,6 +93,7 @@ impl ProtoRepr for proto::GeneralConfig { .map(ProtoRepr::build), consensus: this.consensus_config.as_ref().map(ProtoRepr::build), vm_playground: this.vm_playground_config.as_ref().map(ProtoRepr::build), + experimental_vm: this.experimental_vm_config.as_ref().map(ProtoRepr::build), } } } diff --git a/core/lib/protobuf_config/src/proto/config/experimental.proto b/core/lib/protobuf_config/src/proto/config/experimental.proto index fb9342a166ad..fdc706ae609c 100644 --- a/core/lib/protobuf_config/src/proto/config/experimental.proto +++ b/core/lib/protobuf_config/src/proto/config/experimental.proto @@ -32,3 +32,7 @@ message VmPlayground { optional uint32 first_processed_batch = 3; // optional; defaults to 0 optional bool reset = 4; // optional; defaults to false } + +message Vm { + optional FastVmMode state_keeper_fast_vm_mode = 1; // optional; if not set, fast VM is not used +} diff --git a/core/lib/protobuf_config/src/proto/config/general.proto b/core/lib/protobuf_config/src/proto/config/general.proto index 80590c3df0a8..158cad5dbfea 100644 --- a/core/lib/protobuf_config/src/proto/config/general.proto +++ b/core/lib/protobuf_config/src/proto/config/general.proto @@ -56,4 +56,5 @@ message GeneralConfig { optional external_price_api_client.ExternalPriceApiClient external_price_api_client = 41; optional core.consensus.Config consensus = 42; optional experimental.VmPlayground vm_playground = 43; + optional experimental.Vm experimental_vm = 44; } diff --git a/core/lib/zksync_core_leftovers/src/temp_config_store/mod.rs b/core/lib/zksync_core_leftovers/src/temp_config_store/mod.rs index 75aad29903b5..ad5d5c57a269 100644 --- a/core/lib/zksync_core_leftovers/src/temp_config_store/mod.rs +++ b/core/lib/zksync_core_leftovers/src/temp_config_store/mod.rs @@ -12,11 +12,11 @@ use zksync_config::{ house_keeper::HouseKeeperConfig, vm_runner::BasicWitnessInputProducerConfig, wallets::{AddressWallet, EthSender, StateKeeper, Wallet, Wallets}, - CommitmentGeneratorConfig, DatabaseSecrets, ExperimentalVmPlaygroundConfig, - ExternalPriceApiClientConfig, FriProofCompressorConfig, FriProverConfig, - FriProverGatewayConfig, FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, - GeneralConfig, ObservabilityConfig, PrometheusConfig, ProofDataHandlerConfig, - ProtectiveReadsWriterConfig, PruningConfig, SnapshotRecoveryConfig, + CommitmentGeneratorConfig, DatabaseSecrets, ExperimentalVmConfig, + ExperimentalVmPlaygroundConfig, ExternalPriceApiClientConfig, FriProofCompressorConfig, + FriProverConfig, FriProverGatewayConfig, FriWitnessGeneratorConfig, + FriWitnessVectorGeneratorConfig, GeneralConfig, ObservabilityConfig, PrometheusConfig, + ProofDataHandlerConfig, ProtectiveReadsWriterConfig, PruningConfig, SnapshotRecoveryConfig, }, ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig, GasAdjusterConfig, ObjectStoreConfig, PostgresConfig, @@ -78,6 +78,7 @@ pub struct TempConfigStore { pub pruning: Option, pub snapshot_recovery: Option, pub external_price_api_client_config: Option, + pub experimental_vm_config: Option, } impl TempConfigStore { @@ -114,6 +115,7 @@ impl TempConfigStore { pruning: self.pruning.clone(), external_price_api_client_config: self.external_price_api_client_config.clone(), consensus_config: None, + experimental_vm_config: self.experimental_vm_config.clone(), } } @@ -186,6 +188,7 @@ fn load_env_config() -> anyhow::Result { pruning: None, snapshot_recovery: None, external_price_api_client_config: ExternalPriceApiClientConfig::from_env().ok(), + experimental_vm_config: ExperimentalVmConfig::from_env().ok(), }) } diff --git a/core/node/node_framework/src/implementations/layers/state_keeper/main_batch_executor.rs b/core/node/node_framework/src/implementations/layers/state_keeper/main_batch_executor.rs index 91b89adc20af..3288b68bdebb 100644 --- a/core/node/node_framework/src/implementations/layers/state_keeper/main_batch_executor.rs +++ b/core/node/node_framework/src/implementations/layers/state_keeper/main_batch_executor.rs @@ -1,4 +1,5 @@ use zksync_state_keeper::MainBatchExecutor; +use zksync_types::vm::FastVmMode; use crate::{ implementations::resources::state_keeper::BatchExecutorResource, @@ -10,6 +11,7 @@ use crate::{ pub struct MainBatchExecutorLayer { save_call_traces: bool, optional_bytecode_compression: bool, + fast_vm_mode: FastVmMode, } impl MainBatchExecutorLayer { @@ -17,8 +19,14 @@ impl MainBatchExecutorLayer { Self { save_call_traces, optional_bytecode_compression, + fast_vm_mode: FastVmMode::default(), } } + + pub fn with_fast_vm_mode(mut self, mode: FastVmMode) -> Self { + self.fast_vm_mode = mode; + self + } } #[async_trait::async_trait] @@ -31,8 +39,9 @@ impl WiringLayer for MainBatchExecutorLayer { } async fn wire(self, (): Self::Input) -> Result { - let executor = + let mut executor = MainBatchExecutor::new(self.save_call_traces, self.optional_bytecode_compression); + executor.set_fast_vm_mode(self.fast_vm_mode); Ok(executor.into()) } } From 102cc609f68c317dbd6b7db461044cc0155e4f48 Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Wed, 7 Aug 2024 15:46:54 +0300 Subject: [PATCH 2/6] Embed playground config into `ExperimentalVm` --- core/bin/zksync_server/src/main.rs | 9 ++- core/bin/zksync_server/src/node_builder.rs | 4 +- core/lib/config/src/configs/experimental.rs | 4 +- core/lib/config/src/configs/general.rs | 9 ++- core/lib/config/src/testonly.rs | 2 +- core/lib/env_config/src/vm_runner.rs | 60 +++++++++---------- core/lib/protobuf_config/src/experimental.rs | 4 +- core/lib/protobuf_config/src/general.rs | 2 - .../src/proto/config/experimental.proto | 3 +- .../src/proto/config/general.proto | 3 +- .../src/temp_config_store/mod.rs | 11 ++-- 11 files changed, 53 insertions(+), 58 deletions(-) diff --git a/core/bin/zksync_server/src/main.rs b/core/bin/zksync_server/src/main.rs index e66b93fc942c..7c1a7f9a09a4 100644 --- a/core/bin/zksync_server/src/main.rs +++ b/core/bin/zksync_server/src/main.rs @@ -12,10 +12,10 @@ use zksync_config::{ fri_prover_group::FriProverGroupConfig, house_keeper::HouseKeeperConfig, BasicWitnessInputProducerConfig, ContractsConfig, DatabaseSecrets, ExperimentalVmConfig, - ExperimentalVmPlaygroundConfig, ExternalPriceApiClientConfig, FriProofCompressorConfig, - FriProverConfig, FriProverGatewayConfig, FriWitnessGeneratorConfig, - FriWitnessVectorGeneratorConfig, L1Secrets, ObservabilityConfig, PrometheusConfig, - ProofDataHandlerConfig, ProtectiveReadsWriterConfig, Secrets, + ExternalPriceApiClientConfig, FriProofCompressorConfig, FriProverConfig, + FriProverGatewayConfig, FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, + L1Secrets, ObservabilityConfig, PrometheusConfig, ProofDataHandlerConfig, + ProtectiveReadsWriterConfig, Secrets, }, ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig, GasAdjusterConfig, GenesisConfig, ObjectStoreConfig, PostgresConfig, @@ -202,7 +202,6 @@ fn load_env_config() -> anyhow::Result { da_dispatcher_config: DADispatcherConfig::from_env().ok(), protective_reads_writer_config: ProtectiveReadsWriterConfig::from_env().ok(), basic_witness_input_producer_config: BasicWitnessInputProducerConfig::from_env().ok(), - vm_playground_config: ExperimentalVmPlaygroundConfig::from_env().ok(), core_object_store: ObjectStoreConfig::from_env().ok(), base_token_adjuster_config: BaseTokenAdjusterConfig::from_env().ok(), commitment_generator: None, diff --git a/core/bin/zksync_server/src/node_builder.rs b/core/bin/zksync_server/src/node_builder.rs index d12adba36ba9..7f9e20bd5754 100644 --- a/core/bin/zksync_server/src/node_builder.rs +++ b/core/bin/zksync_server/src/node_builder.rs @@ -565,9 +565,9 @@ impl MainNodeBuilder { } fn add_vm_playground_layer(mut self) -> anyhow::Result { - let vm_playground_config = try_load_config!(self.configs.vm_playground_config); + let vm_config = try_load_config!(self.configs.experimental_vm_config); self.node.add_layer(VmPlaygroundLayer::new( - vm_playground_config, + vm_config.playground, self.genesis_config.l2_chain_id, )); diff --git a/core/lib/config/src/configs/experimental.rs b/core/lib/config/src/configs/experimental.rs index 1de3262b2b39..bb00554ead1c 100644 --- a/core/lib/config/src/configs/experimental.rs +++ b/core/lib/config/src/configs/experimental.rs @@ -100,7 +100,9 @@ impl ExperimentalVmPlaygroundConfig { /// Experimental VM configuration options. #[derive(Debug, Clone, Default, PartialEq, Deserialize)] pub struct ExperimentalVmConfig { - // FIXME: embed `ExperimentalVmPlaygroundConfig`? + #[serde(skip)] // Isn't properly deserialized by `envy` + pub playground: ExperimentalVmPlaygroundConfig, + /// Mode in which to run the fast VM implementation in the state keeper. Should not be set in production; /// the new VM doesn't produce call traces and can diverge from the old VM! #[serde(default)] diff --git a/core/lib/config/src/configs/general.rs b/core/lib/config/src/configs/general.rs index 9645fed659e3..0c7b5510d5fc 100644 --- a/core/lib/config/src/configs/general.rs +++ b/core/lib/config/src/configs/general.rs @@ -9,10 +9,10 @@ use crate::{ pruning::PruningConfig, snapshot_recovery::SnapshotRecoveryConfig, vm_runner::{BasicWitnessInputProducerConfig, ProtectiveReadsWriterConfig}, - CommitmentGeneratorConfig, ExperimentalVmConfig, ExperimentalVmPlaygroundConfig, - ExternalPriceApiClientConfig, FriProofCompressorConfig, FriProverConfig, - FriProverGatewayConfig, FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, - ObservabilityConfig, PrometheusConfig, ProofDataHandlerConfig, + CommitmentGeneratorConfig, ExperimentalVmConfig, ExternalPriceApiClientConfig, + FriProofCompressorConfig, FriProverConfig, FriProverGatewayConfig, + FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, ObservabilityConfig, + PrometheusConfig, ProofDataHandlerConfig, }, ApiConfig, ContractVerifierConfig, DBConfig, EthConfig, ObjectStoreConfig, PostgresConfig, SnapshotsCreatorConfig, @@ -43,7 +43,6 @@ pub struct GeneralConfig { pub da_dispatcher_config: Option, pub protective_reads_writer_config: Option, pub basic_witness_input_producer_config: Option, - pub vm_playground_config: Option, pub commitment_generator: Option, pub snapshot_recovery: Option, pub pruning: Option, diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index 56c9e6051b90..054617e7916a 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -314,6 +314,7 @@ fn gen_fast_vm_mode(rng: &mut R) -> FastVmMode { impl Distribution for EncodeDist { fn sample(&self, rng: &mut R) -> configs::ExperimentalVmConfig { configs::ExperimentalVmConfig { + playground: self.sample(rng), state_keeper_fast_vm_mode: gen_fast_vm_mode(rng), } } @@ -1065,7 +1066,6 @@ impl Distribution for EncodeDist { da_dispatcher_config: self.sample(rng), protective_reads_writer_config: self.sample(rng), basic_witness_input_producer_config: self.sample(rng), - vm_playground_config: self.sample(rng), commitment_generator: self.sample(rng), snapshot_recovery: self.sample(rng), pruning: self.sample(rng), diff --git a/core/lib/env_config/src/vm_runner.rs b/core/lib/env_config/src/vm_runner.rs index b433d1a896c9..efaf5d1666c3 100644 --- a/core/lib/env_config/src/vm_runner.rs +++ b/core/lib/env_config/src/vm_runner.rs @@ -1,6 +1,5 @@ use zksync_config::configs::{ - BasicWitnessInputProducerConfig, ExperimentalVmConfig, ExperimentalVmPlaygroundConfig, - ProtectiveReadsWriterConfig, + BasicWitnessInputProducerConfig, ExperimentalVmConfig, ProtectiveReadsWriterConfig, }; use crate::{envy_load, FromEnv}; @@ -17,15 +16,12 @@ impl FromEnv for BasicWitnessInputProducerConfig { } } -impl FromEnv for ExperimentalVmPlaygroundConfig { - fn from_env() -> anyhow::Result { - envy_load("vm_runner.playground", "VM_RUNNER_PLAYGROUND_") - } -} - impl FromEnv for ExperimentalVmConfig { fn from_env() -> anyhow::Result { - envy_load("experimental_vm", "EXPERIMENTAL_VM_") + Ok(Self { + playground: envy_load("experimental_vm.playground", "EXPERIMENTAL_VM_PLAYGROUND_")?, + ..envy_load("experimental_vm", "EXPERIMENTAL_VM_")? + }) } } @@ -55,36 +51,38 @@ mod tests { } #[test] - fn playground_config_from_env() { + fn experimental_vm_config_from_env() { let mut lock = MUTEX.lock(); let config = r#" - VM_RUNNER_PLAYGROUND_FAST_VM_MODE=shadow - VM_RUNNER_PLAYGROUND_DB_PATH=/db/vm_playground - VM_RUNNER_PLAYGROUND_FIRST_PROCESSED_BATCH=123 - VM_RUNNER_PLAYGROUND_RESET=true + EXPERIMENTAL_VM_STATE_KEEPER_FAST_VM_MODE=new + EXPERIMENTAL_VM_PLAYGROUND_FAST_VM_MODE=shadow + EXPERIMENTAL_VM_PLAYGROUND_DB_PATH=/db/vm_playground + EXPERIMENTAL_VM_PLAYGROUND_FIRST_PROCESSED_BATCH=123 + EXPERIMENTAL_VM_PLAYGROUND_RESET=true "#; lock.set_env(config); - let config = ExperimentalVmPlaygroundConfig::from_env().unwrap(); - assert_eq!(config.fast_vm_mode, FastVmMode::Shadow); - assert_eq!(config.db_path, "/db/vm_playground"); - assert_eq!(config.first_processed_batch, L1BatchNumber(123)); - assert!(config.reset); + let config = ExperimentalVmConfig::from_env().unwrap(); + assert_eq!(config.state_keeper_fast_vm_mode, FastVmMode::New); + assert_eq!(config.playground.fast_vm_mode, FastVmMode::Shadow); + assert_eq!(config.playground.db_path, "/db/vm_playground"); + assert_eq!(config.playground.first_processed_batch, L1BatchNumber(123)); + assert!(config.playground.reset); - lock.remove_env(&["VM_RUNNER_PLAYGROUND_RESET"]); - let config = ExperimentalVmPlaygroundConfig::from_env().unwrap(); - assert!(!config.reset); + lock.remove_env(&["EXPERIMENTAL_VM_PLAYGROUND_RESET"]); + let config = ExperimentalVmConfig::from_env().unwrap(); + assert!(!config.playground.reset); - lock.remove_env(&["VM_RUNNER_PLAYGROUND_FIRST_PROCESSED_BATCH"]); - let config = ExperimentalVmPlaygroundConfig::from_env().unwrap(); - assert_eq!(config.first_processed_batch, L1BatchNumber(0)); + lock.remove_env(&["EXPERIMENTAL_VM_PLAYGROUND_FIRST_PROCESSED_BATCH"]); + let config = ExperimentalVmConfig::from_env().unwrap(); + assert_eq!(config.playground.first_processed_batch, L1BatchNumber(0)); - lock.remove_env(&["VM_RUNNER_PLAYGROUND_FAST_VM_MODE"]); - let config = ExperimentalVmPlaygroundConfig::from_env().unwrap(); - assert_eq!(config.fast_vm_mode, FastVmMode::Old); + lock.remove_env(&["EXPERIMENTAL_VM_PLAYGROUND_FAST_VM_MODE"]); + let config = ExperimentalVmConfig::from_env().unwrap(); + assert_eq!(config.playground.fast_vm_mode, FastVmMode::Old); - lock.remove_env(&["VM_RUNNER_PLAYGROUND_DB_PATH"]); - let config = ExperimentalVmPlaygroundConfig::from_env().unwrap(); - assert!(!config.db_path.is_empty()); + lock.remove_env(&["EXPERIMENTAL_VM_PLAYGROUND_DB_PATH"]); + let config = ExperimentalVmConfig::from_env().unwrap(); + assert!(!config.playground.db_path.is_empty()); } } diff --git a/core/lib/protobuf_config/src/experimental.rs b/core/lib/protobuf_config/src/experimental.rs index fc4693dabbc1..cb959e229047 100644 --- a/core/lib/protobuf_config/src/experimental.rs +++ b/core/lib/protobuf_config/src/experimental.rs @@ -5,7 +5,7 @@ use zksync_basic_types::{vm::FastVmMode, L1BatchNumber}; use zksync_config::configs; use zksync_protobuf::{repr::ProtoRepr, required}; -use crate::proto::experimental as proto; +use crate::{proto::experimental as proto, read_optional_repr}; impl ProtoRepr for proto::Db { type Type = configs::ExperimentalDBConfig; @@ -104,6 +104,7 @@ impl ProtoRepr for proto::Vm { fn read(&self) -> anyhow::Result { Ok(Self::Type { + playground: read_optional_repr(&self.playground).unwrap_or_default(), state_keeper_fast_vm_mode: self .state_keeper_fast_vm_mode .map(proto::FastVmMode::try_from) @@ -115,6 +116,7 @@ impl ProtoRepr for proto::Vm { fn build(this: &Self::Type) -> Self { Self { + playground: Some(ProtoRepr::build(&this.playground)), state_keeper_fast_vm_mode: Some( proto::FastVmMode::new(this.state_keeper_fast_vm_mode).into(), ), diff --git a/core/lib/protobuf_config/src/general.rs b/core/lib/protobuf_config/src/general.rs index b4db75daab9c..4ee06845f497 100644 --- a/core/lib/protobuf_config/src/general.rs +++ b/core/lib/protobuf_config/src/general.rs @@ -40,7 +40,6 @@ 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), - vm_playground_config: read_optional_repr(&self.vm_playground), experimental_vm_config: read_optional_repr(&self.experimental_vm), }) } @@ -92,7 +91,6 @@ impl ProtoRepr for proto::GeneralConfig { .as_ref() .map(ProtoRepr::build), consensus: this.consensus_config.as_ref().map(ProtoRepr::build), - vm_playground: this.vm_playground_config.as_ref().map(ProtoRepr::build), experimental_vm: this.experimental_vm_config.as_ref().map(ProtoRepr::build), } } diff --git a/core/lib/protobuf_config/src/proto/config/experimental.proto b/core/lib/protobuf_config/src/proto/config/experimental.proto index fdc706ae609c..1682b2c9a834 100644 --- a/core/lib/protobuf_config/src/proto/config/experimental.proto +++ b/core/lib/protobuf_config/src/proto/config/experimental.proto @@ -34,5 +34,6 @@ message VmPlayground { } message Vm { - optional FastVmMode state_keeper_fast_vm_mode = 1; // optional; if not set, fast VM is not used + optional VmPlayground playground = 1; // optional + optional FastVmMode state_keeper_fast_vm_mode = 2; // optional; if not set, fast VM is not used } diff --git a/core/lib/protobuf_config/src/proto/config/general.proto b/core/lib/protobuf_config/src/proto/config/general.proto index 158cad5dbfea..9d717676479d 100644 --- a/core/lib/protobuf_config/src/proto/config/general.proto +++ b/core/lib/protobuf_config/src/proto/config/general.proto @@ -55,6 +55,5 @@ message GeneralConfig { optional vm_runner.BasicWitnessInputProducer basic_witness_input_producer = 40; optional external_price_api_client.ExternalPriceApiClient external_price_api_client = 41; optional core.consensus.Config consensus = 42; - optional experimental.VmPlayground vm_playground = 43; - optional experimental.Vm experimental_vm = 44; + optional experimental.Vm experimental_vm = 43; } diff --git a/core/lib/zksync_core_leftovers/src/temp_config_store/mod.rs b/core/lib/zksync_core_leftovers/src/temp_config_store/mod.rs index ad5d5c57a269..c6d8d0eafb28 100644 --- a/core/lib/zksync_core_leftovers/src/temp_config_store/mod.rs +++ b/core/lib/zksync_core_leftovers/src/temp_config_store/mod.rs @@ -13,10 +13,10 @@ use zksync_config::{ vm_runner::BasicWitnessInputProducerConfig, wallets::{AddressWallet, EthSender, StateKeeper, Wallet, Wallets}, CommitmentGeneratorConfig, DatabaseSecrets, ExperimentalVmConfig, - ExperimentalVmPlaygroundConfig, ExternalPriceApiClientConfig, FriProofCompressorConfig, - FriProverConfig, FriProverGatewayConfig, FriWitnessGeneratorConfig, - FriWitnessVectorGeneratorConfig, GeneralConfig, ObservabilityConfig, PrometheusConfig, - ProofDataHandlerConfig, ProtectiveReadsWriterConfig, PruningConfig, SnapshotRecoveryConfig, + ExternalPriceApiClientConfig, FriProofCompressorConfig, FriProverConfig, + FriProverGatewayConfig, FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, + GeneralConfig, ObservabilityConfig, PrometheusConfig, ProofDataHandlerConfig, + ProtectiveReadsWriterConfig, PruningConfig, SnapshotRecoveryConfig, }, ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig, GasAdjusterConfig, ObjectStoreConfig, PostgresConfig, @@ -71,7 +71,6 @@ pub struct TempConfigStore { pub da_dispatcher_config: Option, pub protective_reads_writer_config: Option, pub basic_witness_input_producer_config: Option, - pub vm_playground_config: Option, pub core_object_store: Option, pub base_token_adjuster_config: Option, pub commitment_generator: Option, @@ -107,7 +106,6 @@ impl TempConfigStore { da_dispatcher_config: self.da_dispatcher_config.clone(), protective_reads_writer_config: self.protective_reads_writer_config.clone(), basic_witness_input_producer_config: self.basic_witness_input_producer_config.clone(), - vm_playground_config: self.vm_playground_config.clone(), core_object_store: self.core_object_store.clone(), base_token_adjuster: self.base_token_adjuster_config.clone(), commitment_generator: self.commitment_generator.clone(), @@ -181,7 +179,6 @@ fn load_env_config() -> anyhow::Result { da_dispatcher_config: DADispatcherConfig::from_env().ok(), protective_reads_writer_config: ProtectiveReadsWriterConfig::from_env().ok(), basic_witness_input_producer_config: BasicWitnessInputProducerConfig::from_env().ok(), - vm_playground_config: ExperimentalVmPlaygroundConfig::from_env().ok(), core_object_store: ObjectStoreConfig::from_env().ok(), base_token_adjuster_config: BaseTokenAdjusterConfig::from_env().ok(), commitment_generator: None, From 19936f13ac84197170d41db11861c7cf789605b8 Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Wed, 7 Aug 2024 15:56:22 +0300 Subject: [PATCH 3/6] Update configs in `etc` --- etc/env/base/vm_runner.toml | 10 ++++++---- etc/env/file_based/general.yaml | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/etc/env/base/vm_runner.toml b/etc/env/base/vm_runner.toml index 4835706b74d8..8e6171d79366 100644 --- a/etc/env/base/vm_runner.toml +++ b/etc/env/base/vm_runner.toml @@ -1,6 +1,4 @@ -# Configuration for the VM runner crate - -[vm_runner] +# Configuration for the VM runner instances and experimental VM [vm_runner.protective_reads] # Path to the directory that contains RocksDB with protective reads writer cache. @@ -18,7 +16,11 @@ window_size = 3 # All batches before this one (inclusive) are always considered to be processed. first_processed_batch = 0 -[vm_runner.playground] +[experimental_vm] +# Mode in which to run the new fast VM in the state keeper. Don't set to "new" / "shadow" in production yet! +state_keeper_fast_vm_mode = "old" # default value + +[experimental_vm.playground] # Path to the directory that contains RocksDB with protective reads writer cache. db_path = "./db/main/vm_playground" # Mode in which to run the new fast VM diff --git a/etc/env/file_based/general.yaml b/etc/env/file_based/general.yaml index c9cd78b736e4..09c9ce71ae51 100644 --- a/etc/env/file_based/general.yaml +++ b/etc/env/file_based/general.yaml @@ -323,9 +323,11 @@ basic_witness_input_producer: window_size: 3 first_processed_batch: 0 -vm_playground: - db_path: "./db/main/vm_playground" - fast_vm_mode: SHADOW +experimental_vm: + state_keeper_fast_vm_mode: OLD + playground: + db_path: "./db/main/vm_playground" + fast_vm_mode: SHADOW snapshot_recovery: enabled: false From 5375c5e61d309c6dd922aa9cb6c5c03fcce01027 Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Wed, 7 Aug 2024 16:15:06 +0300 Subject: [PATCH 4/6] Add load test with new VM to CI --- .github/workflows/ci-core-reusable.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 6eae8501dcdc..a33392609e3f 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -78,6 +78,10 @@ jobs: loadtest: runs-on: [matterlabs-ci-runner] + strategy: + fail-fast: false + matrix: + vm_mode: ["old", "new"] steps: - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 @@ -117,7 +121,9 @@ jobs: # `sleep 60` because we need to wait until server added all the tokens - name: Run server run: | - ci_run zk server --uring --components api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads &>server.log & + EXPERIMENTAL_VM_STATE_KEEPER_FAST_VM_MODE=${{ matrix.vm_mode }} \ + PASSED_ENV_VARS="EXPERIMENTAL_VM_STATE_KEEPER_FAST_VM_MODE" \ + ci_run zk server --uring --components api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads &>server.log & ci_run sleep 60 - name: Deploy legacy era contracts From 4b773c465677fd8d0bb927510a628356bb306608 Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Wed, 7 Aug 2024 16:53:02 +0300 Subject: [PATCH 5/6] Increase number of accounts for load test --- .github/workflows/ci-core-reusable.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index a33392609e3f..8006df33d4ba 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -99,6 +99,7 @@ jobs: - name: Loadtest configuration run: | echo EXPECTED_TX_COUNT="16000" >> .env + echo ACCOUNTS_AMOUNT="150" >> .env echo FAIL_FAST=true >> .env echo IN_DOCKER=1 >> .env echo DATABASE_MERKLE_TREE_MODE=lightweight >> .env From f04f2b7c180b63f8d2b777dbcefd3f74974776ea Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Wed, 7 Aug 2024 17:40:39 +0300 Subject: [PATCH 6/6] Increase expected tx count --- .github/workflows/ci-core-reusable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 8006df33d4ba..8f8e3bae28f3 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -98,7 +98,7 @@ jobs: - name: Loadtest configuration run: | - echo EXPECTED_TX_COUNT="16000" >> .env + echo EXPECTED_TX_COUNT=${{ matrix.vm_mode == 'new' && 24000 || 18000 }} >> .env echo ACCOUNTS_AMOUNT="150" >> .env echo FAIL_FAST=true >> .env echo IN_DOCKER=1 >> .env