From d75daef2a08ed4e762b590f2d7682a8485ec57cf Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Tue, 12 Nov 2024 09:50:11 +0200 Subject: [PATCH] chore(config): use sub types for config pointers commit-id:e8a86ffc --- crates/papyrus_config/src/dumping.rs | 17 +++++++++++------ crates/papyrus_node/src/config/pointers.rs | 3 ++- crates/sequencer_node/src/config/node_config.rs | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/papyrus_config/src/dumping.rs b/crates/papyrus_config/src/dumping.rs index b89c62dd08..fbefc6d627 100644 --- a/crates/papyrus_config/src/dumping.rs +++ b/crates/papyrus_config/src/dumping.rs @@ -54,9 +54,14 @@ use crate::{ IS_NONE_MARK, }; -// TODO(Tsabary): introduce sub-types, and replace throughout. +/// Type alias for a pointer parameter and its serialized representation. +type PointerTarget = (ParamPath, SerializedParam); + +/// Type alias for a set of pointing parameters. +pub type Pointers = HashSet; + /// Detailing pointers in the config map. -pub type ConfigPointers = Vec<((ParamPath, SerializedParam), HashSet)>; +pub type ConfigPointers = Vec<(PointerTarget, Pointers)>; /// Serialization for configs. pub trait SerializeConfig { @@ -105,7 +110,7 @@ pub trait SerializeConfig { fn dump_to_file( &self, config_pointers: &ConfigPointers, - non_pointer_params: &HashSet, + non_pointer_params: &Pointers, file_path: &str, ) -> Result<(), ConfigError> { let combined_map = @@ -302,7 +307,7 @@ pub fn ser_pointer_target_required_param( pub(crate) fn combine_config_map_and_pointers( mut config_map: BTreeMap, pointers: &ConfigPointers, - non_pointer_params: &HashSet, + non_pointer_params: &Pointers, ) -> Result { // Update config with target params. for ((target_param, serialized_pointer), pointing_params_vec) in pointers { @@ -332,7 +337,7 @@ pub(crate) fn combine_config_map_and_pointers( } /// Creates a set of pointing params, ensuring no duplications. -pub fn set_pointing_param_paths(param_path_list: &[&str]) -> HashSet { +pub fn set_pointing_param_paths(param_path_list: &[&str]) -> Pointers { let mut param_paths = HashSet::new(); for ¶m_path in param_path_list { assert!( @@ -352,7 +357,7 @@ pub(crate) fn required_param_description(description: &str) -> String { fn verify_pointing_params_by_name( config_map: &BTreeMap, pointers: &ConfigPointers, - non_pointer_params: &HashSet, + non_pointer_params: &Pointers, ) { // Iterate over the config, check that all parameters whose name matches a pointer target either // point at it or are in the whitelist. diff --git a/crates/papyrus_node/src/config/pointers.rs b/crates/papyrus_node/src/config/pointers.rs index b40f287ef6..850b35cc2c 100644 --- a/crates/papyrus_node/src/config/pointers.rs +++ b/crates/papyrus_node/src/config/pointers.rs @@ -20,6 +20,7 @@ use papyrus_config::dumping::{ ser_pointer_target_param, set_pointing_param_paths, ConfigPointers, + Pointers, SerializeConfig, }; use papyrus_config::loading::load_and_process_config; @@ -90,5 +91,5 @@ pub static CONFIG_POINTERS: LazyLock = LazyLock::new(|| { /// Parameters that should 1) not be pointers, and 2) have a name matching a pointer target /// param. Used in verification. -pub static CONFIG_NON_POINTERS_WHITELIST: LazyLock> = +pub static CONFIG_NON_POINTERS_WHITELIST: LazyLock = LazyLock::new(HashSet::::new); diff --git a/crates/sequencer_node/src/config/node_config.rs b/crates/sequencer_node/src/config/node_config.rs index 72329be7cf..323eb5da42 100644 --- a/crates/sequencer_node/src/config/node_config.rs +++ b/crates/sequencer_node/src/config/node_config.rs @@ -10,6 +10,7 @@ use papyrus_config::dumping::{ ser_pointer_target_required_param, set_pointing_param_paths, ConfigPointers, + Pointers, SerializeConfig, }; use papyrus_config::loading::load_and_process_config; @@ -88,7 +89,7 @@ pub static CONFIG_POINTERS: LazyLock = LazyLock::new(|| { }); // Parameters that should 1) not be pointers, and 2) have a name matching a pointer target param. -pub static CONFIG_NON_POINTERS_WHITELIST: LazyLock> = +pub static CONFIG_NON_POINTERS_WHITELIST: LazyLock = LazyLock::new(HashSet::::new); // TODO(yair): Make the GW and batcher execution config point to the same values.