Skip to content

Commit

Permalink
chore(config): ensure no duplicated config pointer params
Browse files Browse the repository at this point in the history
commit-id:6c4bd915
  • Loading branch information
Itay-Tsabary-Starkware committed Nov 5, 2024
1 parent e1f8395 commit f764a07
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
15 changes: 15 additions & 0 deletions crates/papyrus_config/src/dumping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParamPath> {
let mut param_paths = HashSet::new();
for &param_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)
}
Expand Down Expand Up @@ -361,4 +374,6 @@ fn verify_pointing_params_by_name(
};
}
});

Ok(json!(config_map))
}
23 changes: 12 additions & 11 deletions crates/papyrus_node/src/config/pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -54,10 +55,10 @@ pub static CONFIG_POINTERS: LazyLock<ConfigPointers> = 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",
])
),
(
Expand All @@ -66,10 +67,10 @@ pub static CONFIG_POINTERS: LazyLock<ConfigPointers> = 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",
])
),
(
Expand All @@ -78,9 +79,9 @@ pub static CONFIG_POINTERS: LazyLock<ConfigPointers> = 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",
])
),
]
Expand Down
25 changes: 12 additions & 13 deletions crates/sequencer_node/src/config/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -41,11 +42,11 @@ pub static REQUIRED_PARAM_CONFIG_POINTERS: LazyLock<ConfigPointers> = 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",
]),
),
(
Expand All @@ -54,11 +55,10 @@ pub static REQUIRED_PARAM_CONFIG_POINTERS: LazyLock<ConfigPointers> = 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",
]),
),
(
Expand All @@ -67,11 +67,10 @@ pub static REQUIRED_PARAM_CONFIG_POINTERS: LazyLock<ConfigPointers> = 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",
]),
),
]
Expand Down

0 comments on commit f764a07

Please sign in to comment.