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

[NOT FOR MERGE]: Tool for migrating from env based configs to file based #2370

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
# Binaries
"core/bin/block_reverter",
"core/bin/contract-verifier",
"core/bin/envs_to_files",
"core/bin/external_node",
"core/bin/merkle_tree_consistency_checker",
"core/bin/snapshots_creator",
Expand Down
24 changes: 24 additions & 0 deletions core/bin/envs_to_files/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "envs_to_files"
version.workspace = true
edition.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true
keywords.workspace = true
categories.workspace = true

[dependencies]
zksync_config.workspace = true
zksync_env_config.workspace = true
zksync_protobuf_config.workspace = true
zksync_core_leftovers.workspace = true
anyhow.workspace = true
clap = { workspace = true, features = ["derive"] }
serde_json.workspace = true
tokio = { workspace = true, features = ["full"] }
tracing.workspace = true
futures.workspace = true
serde_yaml.workspace = true
zksync_protobuf.workspace = true
115 changes: 115 additions & 0 deletions core/bin/envs_to_files/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
use std::fs;

use serde_yaml::Serializer;
use zksync_config::{
configs::{
api::{HealthCheckConfig, MerkleTreeApiConfig, Web3JsonRpcConfig},
chain::{
CircuitBreakerConfig, MempoolConfig, NetworkConfig, OperationsManagerConfig,
StateKeeperConfig, TimestampAsserterConfig,
},
fri_prover_group::FriProverGroupConfig,
house_keeper::HouseKeeperConfig,
BasicWitnessInputProducerConfig, DataAvailabilitySecrets, DatabaseSecrets,
ExperimentalVmConfig, ExternalPriceApiClientConfig, FriProofCompressorConfig,
FriProverConfig, FriProverGatewayConfig, FriWitnessGeneratorConfig,
FriWitnessVectorGeneratorConfig, L1Secrets, ObjectStoreConfig, ObservabilityConfig,
PrometheusConfig, ProofDataHandlerConfig, ProtectiveReadsWriterConfig,
ProverJobMonitorConfig,
},
ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, ContractsConfig, DAClientConfig,
DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig, ExternalProofIntegrationApiConfig,
GasAdjusterConfig, GenesisConfig, PostgresConfig, SnapshotsCreatorConfig,
};
use zksync_core_leftovers::temp_config_store::TempConfigStore;
use zksync_env_config::FromEnv;
use zksync_protobuf::{
build::{prost_reflect, prost_reflect::ReflectMessage},
ProtoRepr,
};
use zksync_protobuf_config::proto::{
contracts::Contracts as ProtoContracts, general::GeneralConfig as ProtoGeneral,
genesis::Genesis as ProtoGenesis, secrets::Secrets as ProtoSecrets,
wallets::Wallets as ProtoWallets,
};

fn load_env_config() -> TempConfigStore {
TempConfigStore {
postgres_config: PostgresConfig::from_env().ok(),
health_check_config: HealthCheckConfig::from_env().ok(),
merkle_tree_api_config: MerkleTreeApiConfig::from_env().ok(),
web3_json_rpc_config: Web3JsonRpcConfig::from_env().ok(),
circuit_breaker_config: CircuitBreakerConfig::from_env().ok(),
mempool_config: MempoolConfig::from_env().ok(),
network_config: NetworkConfig::from_env().ok(),
contract_verifier: ContractVerifierConfig::from_env().ok(),
operations_manager_config: OperationsManagerConfig::from_env().ok(),
state_keeper_config: StateKeeperConfig::from_env().ok(),
house_keeper_config: HouseKeeperConfig::from_env().ok(),
fri_proof_compressor_config: FriProofCompressorConfig::from_env().ok(),
fri_prover_config: FriProverConfig::from_env().ok(),
fri_prover_group_config: FriProverGroupConfig::from_env().ok(),
fri_prover_gateway_config: FriProverGatewayConfig::from_env().ok(),
fri_witness_vector_generator: FriWitnessVectorGeneratorConfig::from_env().ok(),
fri_witness_generator_config: FriWitnessGeneratorConfig::from_env().ok(),
prometheus_config: PrometheusConfig::from_env().ok(),
proof_data_handler_config: ProofDataHandlerConfig::from_env().ok(),
api_config: ApiConfig::from_env().ok(),
db_config: DBConfig::from_env().ok(),
eth_sender_config: EthConfig::from_env().ok(),
eth_watch_config: EthWatchConfig::from_env().ok(),
gas_adjuster_config: GasAdjusterConfig::from_env().ok(),
observability: ObservabilityConfig::from_env().ok(),
snapshot_creator: SnapshotsCreatorConfig::from_env().ok(),
da_client_config: DAClientConfig::from_env().ok(),
da_dispatcher_config: DADispatcherConfig::from_env().ok(),
protective_reads_writer_config: ProtectiveReadsWriterConfig::from_env().ok(),
basic_witness_input_producer_config: BasicWitnessInputProducerConfig::from_env().ok(),
core_object_store: ObjectStoreConfig::from_env().ok(),
base_token_adjuster_config: BaseTokenAdjusterConfig::from_env().ok(),
commitment_generator: None,
pruning: None,
snapshot_recovery: None,
external_price_api_client_config: ExternalPriceApiClientConfig::from_env().ok(),
external_proof_integration_api_config: ExternalProofIntegrationApiConfig::from_env().ok(),
experimental_vm_config: ExperimentalVmConfig::from_env().ok(),
prover_job_monitor_config: ProverJobMonitorConfig::from_env().ok(),
timestamp_asserter_config: TimestampAsserterConfig::from_env().ok(),
}
}

fn main() {
let config = load_env_config();

let contracts = ContractsConfig::from_env().unwrap();
let general = config.general();
let wallets = config.wallets();
let genesis = GenesisConfig::from_env().unwrap();
let secrets = zksync_config::configs::Secrets {
consensus: None,
database: DatabaseSecrets::from_env().ok(),
l1: L1Secrets::from_env().ok(),
data_availability: DataAvailabilitySecrets::from_env().ok(),
};

let data = encode_yaml(&ProtoGeneral::build(&general)).unwrap();
fs::write("./general.yaml", data).unwrap();
let data = encode_yaml(&ProtoGenesis::build(&genesis)).unwrap();
fs::write("./genesis.yaml", data).unwrap();
let data = encode_yaml(&ProtoWallets::build(&wallets)).unwrap();
fs::write("./wallets.yaml", data).unwrap();
let data = encode_yaml(&ProtoSecrets::build(&secrets)).unwrap();
fs::write("./secrets.yaml", data).unwrap();
let data = encode_yaml(&ProtoContracts::build(&contracts)).unwrap();
fs::write("./contracts.yaml", data).unwrap();
}

pub(crate) fn encode_yaml<T: ReflectMessage>(x: &T) -> anyhow::Result<String> {
let mut serializer = Serializer::new(vec![]);
let opts = prost_reflect::SerializeOptions::new()
.use_proto_field_name(true)
.stringify_64_bit_integers(false);
x.transcode_to_dynamic()
.serialize_with_options(&mut serializer, &opts)?;
Ok(String::from_utf8_lossy(&serializer.into_inner()?).to_string())
}
Loading