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
Show file tree
Hide file tree
Changes from 2 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
21 changes: 16 additions & 5 deletions core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
// Tallback to the consensus_config.yaml file.
pompon0 marked this conversation as resolved.
Show resolved Hide resolved
// 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
}
};

Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 3 additions & 1 deletion core/lib/config/src/configs/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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>,
Expand Down Expand Up @@ -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
Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -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
Expand Up @@ -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")?,
})
}

Expand Down Expand Up @@ -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),
}
}
}
60 changes: 31 additions & 29 deletions core/lib/protobuf_config/src/proto/config/general.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 12 additions & 0 deletions core/lib/protobuf_config/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ fn test_encoding() {
test_encode_all_formats::<ReprConv<proto::wallets::Wallets>>(rng);
test_encode_all_formats::<ReprConv<proto::genesis::Genesis>>(rng);
test_encode_all_formats::<ReprConv<proto::en::ExternalNode>>(rng);
test_encode_all_formats::<ReprConv<proto::da_dispatcher::DataAvailabilityDispatcher>>(rng);
test_encode_all_formats::<ReprConv<proto::vm_runner::ProtectiveReadsWriter>>(rng);
test_encode_all_formats::<ReprConv<proto::vm_runner::BasicWitnessInputProducer>>(rng);
test_encode_all_formats::<ReprConv<proto::commitment_generator::CommitmentGenerator>>(rng);
test_encode_all_formats::<ReprConv<proto::snapshot_recovery::Postgres>>(rng);
test_encode_all_formats::<ReprConv<proto::snapshot_recovery::SnapshotRecovery>>(rng);
test_encode_all_formats::<ReprConv<proto::pruning::Pruning>>(rng);
test_encode_all_formats::<ReprConv<proto::base_token_adjuster::BaseTokenAdjuster>>(rng);
test_encode_all_formats::<ReprConv<proto::external_price_api_client::ExternalPriceApiClient>>(
rng,
);
test_encode_all_formats::<ReprConv<proto::general::GeneralConfig>>(rng);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Deniallugo marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading