From 64e1d17d094be5bc7b52f0e481e383351536aa89 Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Mon, 4 Nov 2024 13:36:33 +0200 Subject: [PATCH] chore(config): ensure no duplicated config pointer params commit-id:6c4bd915 --- crates/papyrus_config/src/dumping.rs | 13 ++++++++++ crates/papyrus_node/src/config/pointers.rs | 23 +++++++++-------- .../sequencer_node/src/config/node_config.rs | 25 +++++++++---------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/crates/papyrus_config/src/dumping.rs b/crates/papyrus_config/src/dumping.rs index a0c50e23c3..b89c62dd08 100644 --- a/crates/papyrus_config/src/dumping.rs +++ b/crates/papyrus_config/src/dumping.rs @@ -331,6 +331,19 @@ pub(crate) fn combine_config_map_and_pointers( Ok(json!(config_map)) } +/// Creates a set of pointing params, ensuring no duplications. +pub fn set_pointing_param_paths(param_path_list: &[&str]) -> HashSet { + let mut param_paths = HashSet::new(); + for ¶m_path in param_path_list { + assert!( + param_paths.insert(param_path.to_string()), + "Duplicate parameter path found: {}", + param_path + ); + } + param_paths +} + pub(crate) fn required_param_description(description: &str) -> String { format!("A required param! {}", description) } diff --git a/crates/papyrus_node/src/config/pointers.rs b/crates/papyrus_node/src/config/pointers.rs index 751f162ff2..4e05e022b0 100644 --- a/crates/papyrus_node/src/config/pointers.rs +++ b/crates/papyrus_node/src/config/pointers.rs @@ -18,6 +18,7 @@ use papyrus_config::dumping::{ append_sub_config_name, ser_optional_sub_config, ser_pointer_target_param, + set_pointing_param_paths, ConfigPointers, SerializeConfig, }; @@ -54,10 +55,10 @@ pub static CONFIG_POINTERS: LazyLock = LazyLock::new(|| { &ChainId::Mainnet, "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.", ), - HashSet::from([ - "storage.db_config.chain_id".to_owned(), - "rpc.chain_id".to_owned(), - "network.chain_id".to_owned(), + set_pointing_param_paths(&[ + "storage.db_config.chain_id", + "rpc.chain_id", + "network.chain_id", ]) ), ( @@ -66,10 +67,10 @@ pub static CONFIG_POINTERS: LazyLock = LazyLock::new(|| { &"https://alpha-mainnet.starknet.io/".to_string(), "The URL of a centralized Starknet gateway.", ), - HashSet::from([ - "rpc.starknet_url".to_owned(), - "central.starknet_url".to_owned(), - "monitoring_gateway.starknet_url".to_owned(), + set_pointing_param_paths(&[ + "rpc.starknet_url", + "central.starknet_url", + "monitoring_gateway.starknet_url", ]) ), ( @@ -78,9 +79,9 @@ pub static CONFIG_POINTERS: LazyLock = LazyLock::new(|| { &false, "If true, collect metrics for the node.", ), - HashSet::from([ - "rpc.collect_metrics".to_owned(), - "monitoring_gateway.collect_metrics".to_owned(), + set_pointing_param_paths(&[ + "rpc.collect_metrics", + "monitoring_gateway.collect_metrics", ]) ), ] diff --git a/crates/sequencer_node/src/config/node_config.rs b/crates/sequencer_node/src/config/node_config.rs index 6f88ebe04e..05216f9618 100644 --- a/crates/sequencer_node/src/config/node_config.rs +++ b/crates/sequencer_node/src/config/node_config.rs @@ -8,6 +8,7 @@ use clap::Command; use papyrus_config::dumping::{ append_sub_config_name, ser_pointer_target_required_param, + set_pointing_param_paths, ConfigPointers, SerializeConfig, }; @@ -41,11 +42,11 @@ pub static REQUIRED_PARAM_CONFIG_POINTERS: LazyLock = LazyLock:: SerializationType::String, "The chain to follow.", ), - HashSet::from([ - "batcher_config.block_builder_config.chain_info.chain_id".to_owned(), - "batcher_config.storage.db_config.chain_id".to_owned(), - "gateway_config.chain_info.chain_id".to_owned(), - "mempool_p2p_config.network_config.chain_id".to_owned(), + set_pointing_param_paths(&[ + "batcher_config.block_builder_config.chain_info.chain_id", + "batcher_config.storage.db_config.chain_id", + "gateway_config.chain_info.chain_id", + "mempool_p2p_config.network_config.chain_id", ]), ), ( @@ -54,11 +55,10 @@ pub static REQUIRED_PARAM_CONFIG_POINTERS: LazyLock = LazyLock:: SerializationType::String, "Address of the ETH fee token.", ), - HashSet::from([ + set_pointing_param_paths(&[ "batcher_config.block_builder_config.chain_info.fee_token_addresses.\ - eth_fee_token_address" - .to_owned(), - "gateway_config.chain_info.fee_token_addresses.eth_fee_token_address".to_owned(), + eth_fee_token_address", + "gateway_config.chain_info.fee_token_addresses.eth_fee_token_address", ]), ), ( @@ -67,11 +67,10 @@ pub static REQUIRED_PARAM_CONFIG_POINTERS: LazyLock = LazyLock:: SerializationType::String, "Address of the STRK fee token.", ), - HashSet::from([ + set_pointing_param_paths(&[ "batcher_config.block_builder_config.chain_info.fee_token_addresses.\ - strk_fee_token_address" - .to_owned(), - "gateway_config.chain_info.fee_token_addresses.strk_fee_token_address".to_owned(), + strk_fee_token_address", + "gateway_config.chain_info.fee_token_addresses.strk_fee_token_address", ]), ), ]