diff --git a/core/bin/zksync_server/src/main.rs b/core/bin/zksync_server/src/main.rs index b589d04aed66..a59705b8e587 100644 --- a/core/bin/zksync_server/src/main.rs +++ b/core/bin/zksync_server/src/main.rs @@ -91,12 +91,25 @@ fn main() -> anyhow::Result<()> { let tmp_config = load_env_config()?; let configs = match opt.config_path { - None => tmp_config.general(), + None => { + let mut configs = tmp_config.general(); + configs.consensus_config = + config::read_consensus_config().context("read_consensus_config()")?; + configs + } Some(path) => { let yaml = std::fs::read_to_string(&path).with_context(|| path.display().to_string())?; - decode_yaml_repr::(&yaml) - .context("failed decoding general YAML config")? + let mut configs = + decode_yaml_repr::(&yaml) + .context("failed decoding general YAML config")?; + // Fallback to the consensus_config.yaml file. + // TODO: remove once we move the consensus config to general config on stage + if configs.consensus_config.is_none() { + configs.consensus_config = + config::read_consensus_config().context("read_consensus_config()")?; + } + configs } }; @@ -154,8 +167,6 @@ fn main() -> anyhow::Result<()> { }, }; - let consensus = config::read_consensus_config().context("read_consensus_config()")?; - let contracts_config = match opt.contracts_config_path { None => ContractsConfig::from_env().context("contracts_config")?, Some(path) => { @@ -176,14 +187,7 @@ fn main() -> anyhow::Result<()> { } }; - let node = MainNodeBuilder::new( - configs, - wallets, - genesis, - contracts_config, - secrets, - consensus, - ); + let node = MainNodeBuilder::new(configs, wallets, genesis, contracts_config, secrets); if opt.genesis { // If genesis is requested, we don't need to run the node. diff --git a/core/bin/zksync_server/src/node_builder.rs b/core/bin/zksync_server/src/node_builder.rs index f8173579b57e..0eaa9b651f64 100644 --- a/core/bin/zksync_server/src/node_builder.rs +++ b/core/bin/zksync_server/src/node_builder.rs @@ -3,10 +3,7 @@ use anyhow::Context; use zksync_config::{ - configs::{ - consensus::ConsensusConfig, eth_sender::PubdataSendingMode, wallets::Wallets, - GeneralConfig, Secrets, - }, + configs::{eth_sender::PubdataSendingMode, wallets::Wallets, GeneralConfig, Secrets}, ContractsConfig, GenesisConfig, }; use zksync_core_leftovers::Component; @@ -86,7 +83,6 @@ pub struct MainNodeBuilder { genesis_config: GenesisConfig, contracts_config: ContractsConfig, secrets: Secrets, - consensus_config: Option, } impl MainNodeBuilder { @@ -96,7 +92,6 @@ impl MainNodeBuilder { genesis_config: GenesisConfig, contracts_config: ContractsConfig, secrets: Secrets, - consensus_config: Option, ) -> Self { Self { node: ZkStackServiceBuilder::new(), @@ -105,7 +100,6 @@ impl MainNodeBuilder { genesis_config, contracts_config, secrets, - consensus_config, } } @@ -456,6 +450,7 @@ impl MainNodeBuilder { fn add_consensus_layer(mut self) -> anyhow::Result { self.node.add_layer(MainNodeConsensusLayer { config: self + .configs .consensus_config .clone() .context("Consensus config has to be provided")?, diff --git a/core/lib/config/src/configs/general.rs b/core/lib/config/src/configs/general.rs index e80538b2a4b9..122d1e278553 100644 --- a/core/lib/config/src/configs/general.rs +++ b/core/lib/config/src/configs/general.rs @@ -2,6 +2,7 @@ use crate::{ configs::{ base_token_adjuster::BaseTokenAdjusterConfig, chain::{CircuitBreakerConfig, MempoolConfig, OperationsManagerConfig, StateKeeperConfig}, + consensus::ConsensusConfig, da_dispatcher::DADispatcherConfig, fri_prover_group::FriProverGroupConfig, house_keeper::HouseKeeperConfig, @@ -17,7 +18,7 @@ use crate::{ SnapshotsCreatorConfig, }; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct GeneralConfig { pub postgres_config: Option, pub api_config: Option, @@ -48,4 +49,5 @@ pub struct GeneralConfig { pub core_object_store: Option, pub base_token_adjuster: Option, pub external_price_api_client_config: Option, + pub consensus_config: Option, } diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index e105c3282639..f3d6b98491be 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -235,24 +235,24 @@ impl Distribution for EncodeDist { } impl Distribution for EncodeDist { - fn sample(&self, g: &mut R) -> configs::ContractsConfig { + fn sample(&self, rng: &mut R) -> configs::ContractsConfig { configs::ContractsConfig { - governance_addr: g.gen(), - verifier_addr: g.gen(), - default_upgrade_addr: g.gen(), - diamond_proxy_addr: g.gen(), - validator_timelock_addr: g.gen(), - l1_erc20_bridge_proxy_addr: g.gen(), - l2_erc20_bridge_addr: g.gen(), - l1_shared_bridge_proxy_addr: g.gen(), - l2_shared_bridge_addr: g.gen(), - l1_weth_bridge_proxy_addr: g.gen(), - l2_weth_bridge_addr: g.gen(), - l2_testnet_paymaster_addr: g.gen(), - l1_multicall3_addr: g.gen(), - base_token_addr: g.gen(), - chain_admin_addr: g.gen(), - ecosystem_contracts: self.sample(g), + governance_addr: rng.gen(), + verifier_addr: rng.gen(), + default_upgrade_addr: rng.gen(), + diamond_proxy_addr: rng.gen(), + validator_timelock_addr: rng.gen(), + l1_erc20_bridge_proxy_addr: rng.gen(), + l2_erc20_bridge_addr: rng.gen(), + l1_shared_bridge_proxy_addr: rng.gen(), + l2_shared_bridge_addr: rng.gen(), + l1_weth_bridge_proxy_addr: rng.gen(), + l2_weth_bridge_addr: rng.gen(), + l2_testnet_paymaster_addr: rng.gen(), + l1_multicall3_addr: rng.gen(), + base_token_addr: rng.gen(), + chain_admin_addr: rng.gen(), + ecosystem_contracts: self.sample(rng), } } } @@ -887,3 +887,164 @@ impl Distribution for EncodeDist { } } } + +impl Distribution for EncodeDist { + fn sample(&self, rng: &mut R) -> configs::da_dispatcher::DADispatcherConfig { + configs::da_dispatcher::DADispatcherConfig { + polling_interval_ms: self.sample(rng), + max_rows_to_dispatch: self.sample(rng), + max_retries: self.sample(rng), + } + } +} + +impl Distribution for EncodeDist { + fn sample( + &self, + rng: &mut R, + ) -> configs::vm_runner::ProtectiveReadsWriterConfig { + configs::vm_runner::ProtectiveReadsWriterConfig { + db_path: self.sample(rng), + window_size: self.sample(rng), + first_processed_batch: L1BatchNumber(rng.gen()), + } + } +} + +impl Distribution for EncodeDist { + fn sample( + &self, + rng: &mut R, + ) -> configs::vm_runner::BasicWitnessInputProducerConfig { + configs::vm_runner::BasicWitnessInputProducerConfig { + db_path: self.sample(rng), + window_size: self.sample(rng), + first_processed_batch: L1BatchNumber(rng.gen()), + } + } +} + +impl Distribution for EncodeDist { + fn sample(&self, rng: &mut R) -> configs::CommitmentGeneratorConfig { + configs::CommitmentGeneratorConfig { + max_parallelism: self.sample(rng), + } + } +} + +impl Distribution for EncodeDist { + fn sample( + &self, + rng: &mut R, + ) -> configs::snapshot_recovery::TreeRecoveryConfig { + configs::snapshot_recovery::TreeRecoveryConfig { + chunk_size: self.sample(rng), + parallel_persistence_buffer: self.sample_opt(|| rng.gen()), + } + } +} + +impl Distribution for EncodeDist { + fn sample( + &self, + rng: &mut R, + ) -> configs::snapshot_recovery::PostgresRecoveryConfig { + configs::snapshot_recovery::PostgresRecoveryConfig { + max_concurrency: self.sample_opt(|| rng.gen()), + } + } +} + +impl Distribution for EncodeDist { + fn sample( + &self, + rng: &mut R, + ) -> configs::snapshot_recovery::SnapshotRecoveryConfig { + use configs::snapshot_recovery::{SnapshotRecoveryConfig, TreeRecoveryConfig}; + let tree: TreeRecoveryConfig = self.sample(rng); + SnapshotRecoveryConfig { + enabled: self.sample(rng), + l1_batch: self.sample_opt(|| L1BatchNumber(rng.gen())), + drop_storage_key_preimages: (tree != TreeRecoveryConfig::default()) && self.sample(rng), + tree, + postgres: self.sample(rng), + object_store: self.sample(rng), + } + } +} + +impl Distribution for EncodeDist { + fn sample(&self, rng: &mut R) -> configs::pruning::PruningConfig { + configs::pruning::PruningConfig { + enabled: self.sample(rng), + chunk_size: self.sample(rng), + removal_delay_sec: self.sample_opt(|| rng.gen()), + data_retention_sec: self.sample(rng), + } + } +} + +impl Distribution for EncodeDist { + fn sample( + &self, + rng: &mut R, + ) -> configs::base_token_adjuster::BaseTokenAdjusterConfig { + configs::base_token_adjuster::BaseTokenAdjusterConfig { + price_polling_interval_ms: self.sample(rng), + price_cache_update_interval_ms: self.sample(rng), + } + } +} + +impl Distribution for EncodeDist { + fn sample( + &self, + rng: &mut R, + ) -> configs::external_price_api_client::ExternalPriceApiClientConfig { + configs::external_price_api_client::ExternalPriceApiClientConfig { + source: self.sample(rng), + base_url: self.sample(rng), + api_key: self.sample(rng), + client_timeout_ms: self.sample(rng), + forced_numerator: self.sample(rng), + forced_denominator: self.sample(rng), + } + } +} + +impl Distribution for EncodeDist { + fn sample(&self, rng: &mut R) -> configs::GeneralConfig { + configs::GeneralConfig { + postgres_config: self.sample(rng), + api_config: self.sample(rng), + contract_verifier: self.sample(rng), + circuit_breaker_config: self.sample(rng), + mempool_config: self.sample(rng), + operations_manager_config: self.sample(rng), + state_keeper_config: self.sample(rng), + house_keeper_config: self.sample(rng), + proof_compressor_config: self.sample(rng), + prover_config: self.sample(rng), + prover_gateway: self.sample(rng), + witness_vector_generator: self.sample(rng), + prover_group_config: self.sample(rng), + witness_generator: self.sample(rng), + prometheus_config: self.sample(rng), + proof_data_handler_config: self.sample(rng), + db_config: self.sample(rng), + eth: self.sample(rng), + snapshot_creator: self.sample(rng), + observability: self.sample(rng), + da_dispatcher_config: self.sample(rng), + protective_reads_writer_config: self.sample(rng), + basic_witness_input_producer_config: self.sample(rng), + commitment_generator: self.sample(rng), + snapshot_recovery: self.sample(rng), + pruning: self.sample(rng), + core_object_store: self.sample(rng), + base_token_adjuster: self.sample(rng), + external_price_api_client_config: self.sample(rng), + consensus_config: self.sample(rng), + } + } +} diff --git a/core/lib/protobuf_config/src/general.rs b/core/lib/protobuf_config/src/general.rs index 44ce9d8d1eba..31d1ea6bc1b7 100644 --- a/core/lib/protobuf_config/src/general.rs +++ b/core/lib/protobuf_config/src/general.rs @@ -56,6 +56,7 @@ impl ProtoRepr for proto::GeneralConfig { .context("snapshot_recovery")?, external_price_api_client_config: read_optional_repr(&self.external_price_api_client) .context("external_price_api_client")?, + consensus_config: read_optional_repr(&self.consensus).context("consensus")?, }) } @@ -105,6 +106,7 @@ impl ProtoRepr for proto::GeneralConfig { .external_price_api_client_config .as_ref() .map(ProtoRepr::build), + consensus: this.consensus_config.as_ref().map(ProtoRepr::build), } } } diff --git a/core/lib/protobuf_config/src/proto/config/general.proto b/core/lib/protobuf_config/src/proto/config/general.proto index be64f7bb97ee..37d507b9ab62 100644 --- a/core/lib/protobuf_config/src/proto/config/general.proto +++ b/core/lib/protobuf_config/src/proto/config/general.proto @@ -21,35 +21,37 @@ import "zksync/config/pruning.proto"; import "zksync/config/object_store.proto"; import "zksync/config/base_token_adjuster.proto"; import "zksync/config/external_price_api_client.proto"; +import "zksync/core/consensus.proto"; message GeneralConfig { - optional config.database.Postgres postgres = 1; - optional config.api.Api api = 2; - optional config.contract_verifier.ContractVerifier contract_verifier = 3; - optional config.circuit_breaker.CircuitBreaker circuit_breaker = 5; - optional config.chain.Mempool mempool = 6; - optional config.chain.OperationsManager operations_manager = 8; - optional config.chain.StateKeeper state_keeper = 9; - optional config.house_keeper.HouseKeeper house_keeper = 10; - optional config.prover.Prover prover = 12; - optional config.utils.Prometheus prometheus = 15; - optional config.database.DB db = 20; - optional config.eth.ETH eth = 22; - optional config.prover.WitnessGenerator witness_generator = 24; - optional config.prover.WitnessVectorGenerator witness_vector_generator = 25; - optional config.prover.ProofCompressor proof_compressor = 27; - optional config.prover.ProofDataHandler data_handler = 28; - optional config.prover.ProverGroup prover_group = 29; - optional config.prover.ProverGateway prover_gateway = 30; - optional config.snapshot_creator.SnapshotsCreator snapshot_creator = 31; - optional config.observability.Observability observability = 32; - optional config.vm_runner.ProtectiveReadsWriter protective_reads_writer = 33; - optional config.object_store.ObjectStore core_object_store = 34; - optional config.snapshot_recovery.SnapshotRecovery snapshot_recovery = 35; - optional config.pruning.Pruning pruning = 36; - optional config.commitment_generator.CommitmentGenerator commitment_generator = 37; - optional config.da_dispatcher.DataAvailabilityDispatcher da_dispatcher = 38; - optional config.base_token_adjuster.BaseTokenAdjuster base_token_adjuster = 39; - optional config.vm_runner.BasicWitnessInputProducer basic_witness_input_producer = 40; - optional config.external_price_api_client.ExternalPriceApiClient external_price_api_client = 41; + optional database.Postgres postgres = 1; + optional api.Api api = 2; + optional contract_verifier.ContractVerifier contract_verifier = 3; + optional circuit_breaker.CircuitBreaker circuit_breaker = 5; + optional chain.Mempool mempool = 6; + optional chain.OperationsManager operations_manager = 8; + optional chain.StateKeeper state_keeper = 9; + optional house_keeper.HouseKeeper house_keeper = 10; + optional prover.Prover prover = 12; + optional utils.Prometheus prometheus = 15; + optional database.DB db = 20; + optional eth.ETH eth = 22; + optional prover.WitnessGenerator witness_generator = 24; + optional prover.WitnessVectorGenerator witness_vector_generator = 25; + optional prover.ProofCompressor proof_compressor = 27; + optional prover.ProofDataHandler data_handler = 28; + optional prover.ProverGroup prover_group = 29; + optional prover.ProverGateway prover_gateway = 30; + optional snapshot_creator.SnapshotsCreator snapshot_creator = 31; + optional observability.Observability observability = 32; + optional vm_runner.ProtectiveReadsWriter protective_reads_writer = 33; + optional object_store.ObjectStore core_object_store = 34; + optional snapshot_recovery.SnapshotRecovery snapshot_recovery = 35; + optional pruning.Pruning pruning = 36; + optional commitment_generator.CommitmentGenerator commitment_generator = 37; + optional da_dispatcher.DataAvailabilityDispatcher da_dispatcher = 38; + optional base_token_adjuster.BaseTokenAdjuster base_token_adjuster = 39; + 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; } diff --git a/core/lib/protobuf_config/src/tests.rs b/core/lib/protobuf_config/src/tests.rs index 3cb18c5bbf6d..695f404f64d1 100644 --- a/core/lib/protobuf_config/src/tests.rs +++ b/core/lib/protobuf_config/src/tests.rs @@ -42,6 +42,18 @@ fn test_encoding() { test_encode_all_formats::>(rng); test_encode_all_formats::>(rng); test_encode_all_formats::>(rng); + test_encode_all_formats::>(rng); + test_encode_all_formats::>(rng); + test_encode_all_formats::>(rng); + test_encode_all_formats::>(rng); + test_encode_all_formats::>(rng); + test_encode_all_formats::>(rng); + test_encode_all_formats::>(rng); + test_encode_all_formats::>(rng); + test_encode_all_formats::>( + rng, + ); + test_encode_all_formats::>(rng); } #[test] 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 f1761e8ff8f9..1ad688ed14cb 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 @@ -111,6 +111,7 @@ impl TempConfigStore { snapshot_recovery: self.snapshot_recovery.clone(), pruning: self.pruning.clone(), external_price_api_client_config: self.external_price_api_client_config.clone(), + consensus_config: None, } }