diff --git a/Cargo.lock b/Cargo.lock index f9e754902f61..028b06a94cb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2859,6 +2859,24 @@ dependencies = [ "log", ] +[[package]] +name = "envs_to_files" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap 4.5.20", + "futures 0.3.31", + "serde_json", + "serde_yaml", + "tokio", + "tracing", + "zksync_config", + "zksync_core_leftovers", + "zksync_env_config", + "zksync_protobuf", + "zksync_protobuf_config", +] + [[package]] name = "envy" version = "0.4.2" diff --git a/Cargo.toml b/Cargo.toml index 60099874cf39..6dc65ad0904d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/core/bin/envs_to_files/Cargo.toml b/core/bin/envs_to_files/Cargo.toml new file mode 100644 index 000000000000..54992818c0cb --- /dev/null +++ b/core/bin/envs_to_files/Cargo.toml @@ -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 diff --git a/core/bin/envs_to_files/src/main.rs b/core/bin/envs_to_files/src/main.rs new file mode 100644 index 000000000000..767f964cf468 --- /dev/null +++ b/core/bin/envs_to_files/src/main.rs @@ -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(x: &T) -> anyhow::Result { + 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()) +}