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: added consensus_config to general config #2462

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Changes from all 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
30 changes: 17 additions & 13 deletions core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
@@ -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::<zksync_protobuf_config::proto::general::GeneralConfig>(&yaml)
.context("failed decoding general YAML config")?
let mut configs =
decode_yaml_repr::<zksync_protobuf_config::proto::general::GeneralConfig>(&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.
9 changes: 2 additions & 7 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
@@ -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<ConsensusConfig>,
}

impl MainNodeBuilder {
@@ -96,7 +92,6 @@ impl MainNodeBuilder {
genesis_config: GenesisConfig,
contracts_config: ContractsConfig,
secrets: Secrets,
consensus_config: Option<ConsensusConfig>,
) -> 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> {
self.node.add_layer(MainNodeConsensusLayer {
config: self
.configs
.consensus_config
.clone()
.context("Consensus config has to be provided")?,
4 changes: 3 additions & 1 deletion core/lib/config/src/configs/general.rs
Original file line number Diff line number Diff line change
@@ -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<PostgresConfig>,
pub api_config: Option<ApiConfig>,
@@ -48,4 +49,5 @@ pub struct GeneralConfig {
pub core_object_store: Option<ObjectStoreConfig>,
pub base_token_adjuster: Option<BaseTokenAdjusterConfig>,
pub external_price_api_client_config: Option<ExternalPriceApiClientConfig>,
pub consensus_config: Option<ConsensusConfig>,
}
195 changes: 178 additions & 17 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
@@ -235,24 +235,24 @@ impl Distribution<configs::ContractVerifierConfig> for EncodeDist {
}

impl Distribution<configs::ContractsConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, g: &mut R) -> configs::ContractsConfig {
fn sample<R: Rng + ?Sized>(&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<configs::en_config::ENConfig> for EncodeDist {
}
}
}

impl Distribution<configs::da_dispatcher::DADispatcherConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&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<configs::vm_runner::ProtectiveReadsWriterConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(
&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<configs::vm_runner::BasicWitnessInputProducerConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(
&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<configs::CommitmentGeneratorConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::CommitmentGeneratorConfig {
configs::CommitmentGeneratorConfig {
max_parallelism: self.sample(rng),
}
}
}

impl Distribution<configs::snapshot_recovery::TreeRecoveryConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(
&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<configs::snapshot_recovery::PostgresRecoveryConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(
&self,
rng: &mut R,
) -> configs::snapshot_recovery::PostgresRecoveryConfig {
configs::snapshot_recovery::PostgresRecoveryConfig {
max_concurrency: self.sample_opt(|| rng.gen()),
}
}
}

impl Distribution<configs::snapshot_recovery::SnapshotRecoveryConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(
&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<configs::pruning::PruningConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&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<configs::base_token_adjuster::BaseTokenAdjusterConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(
&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<configs::external_price_api_client::ExternalPriceApiClientConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(
&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<configs::GeneralConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&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),
}
}
}
2 changes: 2 additions & 0 deletions core/lib/protobuf_config/src/general.rs
Original file line number Diff line number Diff line change
@@ -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),
}
}
}
Loading