From 154573153a1ed52ff7d7e48871f77af687cd4d5d Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Wed, 30 Oct 2024 15:17:58 +0200 Subject: [PATCH] chore(sequencer_node): set chain_id as required param commit-id:a52a7e16 --- config/mempool/default_config.json | 6 +++--- .../mempool_node/src/config/component_config.rs | 3 +-- crates/mempool_node/src/config/config_test.rs | 9 +++------ crates/mempool_node/src/config/node_config.rs | 17 ++++++++++++----- .../src/integration_test_config_utils.rs | 7 +++++-- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/config/mempool/default_config.json b/config/mempool/default_config.json index 787614c0a0..f3156b1dfc 100644 --- a/config/mempool/default_config.json +++ b/config/mempool/default_config.json @@ -195,9 +195,9 @@ "value": "StateOnly" }, "chain_id": { - "description": "The chain to follow.", - "privacy": "TemporaryValue", - "value": "SN_MAIN" + "description": "A required param! The chain to follow.", + "param_type": "String", + "privacy": "TemporaryValue" }, "compiler_config.max_bytecode_size": { "description": "Limitation of contract bytecode size.", diff --git a/crates/mempool_node/src/config/component_config.rs b/crates/mempool_node/src/config/component_config.rs index f957d46095..7c7be88a1f 100644 --- a/crates/mempool_node/src/config/component_config.rs +++ b/crates/mempool_node/src/config/component_config.rs @@ -42,8 +42,7 @@ impl Default for ComponentConfig { impl SerializeConfig for ComponentConfig { fn dump(&self) -> BTreeMap { - #[allow(unused_mut)] - let mut sub_configs = vec![ + let sub_configs = vec![ append_sub_config_name(self.batcher.dump(), "batcher"), append_sub_config_name(self.consensus_manager.dump(), "consensus_manager"), append_sub_config_name(self.gateway.dump(), "gateway"), diff --git a/crates/mempool_node/src/config/config_test.rs b/crates/mempool_node/src/config/config_test.rs index c61f3217e7..33a8948c7e 100644 --- a/crates/mempool_node/src/config/config_test.rs +++ b/crates/mempool_node/src/config/config_test.rs @@ -16,7 +16,7 @@ use starknet_sequencer_infra::component_definitions::{ use validator::Validate; use crate::config::{ - node_command, + create_test_config_load_args, ComponentExecutionConfig, ComponentExecutionMode, SequencerNodeConfig, @@ -93,11 +93,8 @@ fn test_default_config_file_is_up_to_date() { /// Tests parsing a node config without additional args. #[test] fn test_config_parsing() { - let config_file_name = get_absolute_path(DEFAULT_CONFIG_PATH); - let config = SequencerNodeConfig::load_and_process_file( - vec![node_command().to_string()], - config_file_name.to_str().unwrap(), - ); + let args = create_test_config_load_args(&CONFIG_POINTERS); + let config = SequencerNodeConfig::load_and_process(args); let config = config.expect("Parsing function failed."); let result = config_validate(&config); diff --git a/crates/mempool_node/src/config/node_config.rs b/crates/mempool_node/src/config/node_config.rs index afc9cfb1be..636618089d 100644 --- a/crates/mempool_node/src/config/node_config.rs +++ b/crates/mempool_node/src/config/node_config.rs @@ -4,14 +4,16 @@ use std::path::Path; use std::sync::LazyLock; use clap::Command; -use papyrus_config::dumping::{append_sub_config_name, ser_pointer_target_param, SerializeConfig}; +use papyrus_config::dumping::{ + append_sub_config_name, + ser_pointer_target_required_param, + SerializeConfig, +}; use papyrus_config::loading::load_and_process_config; use papyrus_config::validators::validate_ascii; #[cfg(any(feature = "testing", test))] -use papyrus_config::SerializationType; -#[cfg(any(feature = "testing", test))] use papyrus_config::SerializedContent; -use papyrus_config::{ConfigError, ParamPath, SerializedParam}; +use papyrus_config::{ConfigError, ParamPath, SerializationType, SerializedParam}; use serde::{Deserialize, Serialize}; use starknet_api::core::ChainId; use starknet_batcher::config::BatcherConfig; @@ -33,9 +35,14 @@ pub const DEFAULT_CONFIG_PATH: &str = "config/mempool/default_config.json"; // Configuration parameters that share the same value across multiple components. type ConfigPointers = Vec<((ParamPath, SerializedParam), Vec)>; pub const DEFAULT_CHAIN_ID: ChainId = ChainId::Mainnet; +// TODO(Tsabary/AlonH): Discuss testing of required parameters. pub static CONFIG_POINTERS: LazyLock = LazyLock::new(|| { vec![( - ser_pointer_target_param("chain_id", &DEFAULT_CHAIN_ID, "The chain to follow."), + ser_pointer_target_required_param( + "chain_id", + SerializationType::String, + "The chain to follow.", + ), vec![ "batcher_config.block_builder_config.chain_info.chain_id".to_owned(), "batcher_config.storage.db_config.chain_id".to_owned(), diff --git a/crates/tests-integration/src/integration_test_config_utils.rs b/crates/tests-integration/src/integration_test_config_utils.rs index 851f7880ff..b393f2cd50 100644 --- a/crates/tests-integration/src/integration_test_config_utils.rs +++ b/crates/tests-integration/src/integration_test_config_utils.rs @@ -58,8 +58,11 @@ pub fn dump_config_file_changes(config: SequencerNodeConfig) -> anyhow::Result<( dump_json_data(json_data, NODE_CONFIG_CHANGES_FILE_PATH)?; // Dump config changes file for the transaction generator. - let json_data = - config_fields_to_json!(config.http_server_config.ip, config.http_server_config.port,); + let json_data = config_fields_to_json!( + config.chain_id, + config.http_server_config.ip, + config.http_server_config.port, + ); dump_json_data(json_data, TX_GEN_CONFIG_CHANGES_FILE_PATH)?; Ok(())