Skip to content

Commit

Permalink
chore(config): use sub types for config pointers
Browse files Browse the repository at this point in the history
commit-id:e8a86ffc
  • Loading branch information
Itay-Tsabary-Starkware committed Nov 12, 2024
1 parent 7a0a1f9 commit d75daef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
17 changes: 11 additions & 6 deletions crates/papyrus_config/src/dumping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParamPath>;

/// Detailing pointers in the config map.
pub type ConfigPointers = Vec<((ParamPath, SerializedParam), HashSet<ParamPath>)>;
pub type ConfigPointers = Vec<(PointerTarget, Pointers)>;

/// Serialization for configs.
pub trait SerializeConfig {
Expand Down Expand Up @@ -105,7 +110,7 @@ pub trait SerializeConfig {
fn dump_to_file(
&self,
config_pointers: &ConfigPointers,
non_pointer_params: &HashSet<ParamPath>,
non_pointer_params: &Pointers,
file_path: &str,
) -> Result<(), ConfigError> {
let combined_map =
Expand Down Expand Up @@ -302,7 +307,7 @@ pub fn ser_pointer_target_required_param(
pub(crate) fn combine_config_map_and_pointers(
mut config_map: BTreeMap<ParamPath, SerializedParam>,
pointers: &ConfigPointers,
non_pointer_params: &HashSet<ParamPath>,
non_pointer_params: &Pointers,
) -> Result<Value, ConfigError> {
// Update config with target params.
for ((target_param, serialized_pointer), pointing_params_vec) in pointers {
Expand Down Expand Up @@ -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<ParamPath> {
pub fn set_pointing_param_paths(param_path_list: &[&str]) -> Pointers {
let mut param_paths = HashSet::new();
for &param_path in param_path_list {
assert!(
Expand All @@ -352,7 +357,7 @@ pub(crate) fn required_param_description(description: &str) -> String {
fn verify_pointing_params_by_name(
config_map: &BTreeMap<ParamPath, SerializedParam>,
pointers: &ConfigPointers,
non_pointer_params: &HashSet<ParamPath>,
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.
Expand Down
3 changes: 2 additions & 1 deletion crates/papyrus_node/src/config/pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,5 +91,5 @@ pub static CONFIG_POINTERS: LazyLock<ConfigPointers> = 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<HashSet<ParamPath>> =
pub static CONFIG_NON_POINTERS_WHITELIST: LazyLock<Pointers> =
LazyLock::new(HashSet::<ParamPath>::new);
3 changes: 2 additions & 1 deletion crates/sequencer_node/src/config/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,7 +89,7 @@ pub static CONFIG_POINTERS: LazyLock<ConfigPointers> = 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<HashSet<ParamPath>> =
pub static CONFIG_NON_POINTERS_WHITELIST: LazyLock<Pointers> =
LazyLock::new(HashSet::<ParamPath>::new);

// TODO(yair): Make the GW and batcher execution config point to the same values.
Expand Down

0 comments on commit d75daef

Please sign in to comment.