Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions crates/apollo_config/src/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,58 +328,6 @@ where
.collect()
}

/// Serializes an optional list into a comma-separated string.
/// Returns `None` if the input is `None`.
pub fn serialize_optional_comma_separated<T>(list: &Option<Vec<T>>) -> Option<String>
where
T: ToString,
{
match list {
None => None,
Some(list) => Some(list.iter().map(|item| item.to_string()).collect::<Vec<_>>().join(",")),
}
}

/// Serializes an optional list into a comma-separated string, for use as
/// `#[serde(serialize_with)]`. Counterpart of `deserialize_comma_separated_str`: `None` and
/// `Some(empty)` both serialize to the empty string, which that deserializer reads back as `None`.
pub fn serialize_optional_comma_separated_str<S, T>(
list: &Option<Vec<T>>,
se: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: ToString,
{
se.serialize_str(&serialize_optional_comma_separated(list).unwrap_or_default())
}

/// Deserializes an optional comma-separated list of values implementing `FromStr` into
/// `Option<Vec<T>>`. Returns `None` for empty or missing strings.
pub fn deserialize_comma_separated_str<'de, D, T>(de: D) -> Result<Option<Vec<T>>, D::Error>
where
D: Deserializer<'de>,
T: FromStr,
<T as FromStr>::Err: std::fmt::Display,
{
let raw = String::deserialize(de).unwrap_or_default();
if raw.trim().is_empty() {
return Ok(None);
}

let mut output: Vec<T> = Vec::new();
for part in raw.split(',').filter(|s| !s.is_empty()) {
let value = T::from_str(part)
.map_err(|e| D::Error::custom(format!("Invalid value '{part}': {e}")))?;
output.push(value);
}

if output.is_empty() {
return Ok(None);
}
Ok(Some(output))
}

/// Deserializes a sensitive `Vec<u8>` from hex string structure.
pub fn deserialize_optional_sensitive_vec_u8<'de, D>(
de: D,
Expand Down
20 changes: 0 additions & 20 deletions crates/apollo_config/src/converters_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ use std::time::Duration;
use serde::{Deserialize, Serialize};

use super::{
deserialize_comma_separated_str,
deserialize_float_seconds_to_duration,
deserialize_milliseconds_to_duration,
deserialize_seconds_to_duration,
serialize_duration_as_float_seconds,
serialize_duration_as_milliseconds,
serialize_duration_as_seconds,
serialize_optional_comma_separated_str,
};

// These wrappers mirror the `#[serde(deserialize_with = ..., serialize_with = ...)]` pairings used
Expand Down Expand Up @@ -45,17 +43,6 @@ struct FloatSecondsWrapper {
duration: Duration,
}

// `deserialize_comma_separated_str`/`serialize_optional_comma_separated_str` are generic over any
// `T: FromStr + ToString`; `u64` exercises the same code path without pulling in `starknet_api`.
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct CommaSeparatedWrapper {
#[serde(
deserialize_with = "deserialize_comma_separated_str",
serialize_with = "serialize_optional_comma_separated_str"
)]
list: Option<Vec<u64>>,
}

fn assert_round_trips<T>(value: T)
where
T: Serialize + serde::de::DeserializeOwned + PartialEq + std::fmt::Debug,
Expand Down Expand Up @@ -85,10 +72,3 @@ fn float_seconds_duration_round_trips() {
// representable to avoid float rounding noise in the equality assertion.
assert_round_trips(FloatSecondsWrapper { duration: Duration::from_secs_f64(1.5) });
}

#[test]
fn comma_separated_list_round_trips() {
// `None` (the default) and a populated list.
assert_round_trips(CommaSeparatedWrapper { list: None });
assert_round_trips(CommaSeparatedWrapper { list: Some(vec![1, 22, 333]) });
}
6 changes: 0 additions & 6 deletions crates/apollo_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,9 @@ use std::collections::HashSet;
use std::time::Duration;

use apollo_config::converters::{
deserialize_comma_separated_str,
deserialize_optional_sensitive_vec_u8,
deserialize_seconds_to_duration,
serialize_duration_as_seconds,
serialize_optional_comma_separated_str,
};
use apollo_config::secrets::Sensitive;
use apollo_config::validators::validate_optional_sensitive_vec_u256;
Expand Down Expand Up @@ -321,10 +319,6 @@ pub struct NetworkConfig {

/// Bootstrap peer multiaddresses for initial connectivity. Each must include a valid peer ID.
/// Format: `/ip4/1.2.3.4/tcp/10000/p2p/<peer-id>`. Default: None
#[serde(
deserialize_with = "deserialize_comma_separated_str",
serialize_with = "serialize_optional_comma_separated_str"
)]
#[validate(custom(function = "validate_bootstrap_peer_multiaddr_list"))]
pub bootstrap_peer_multiaddr: Option<Vec<Multiaddr>>,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn consensus_manager_config_round_trips() {
fn network_config_round_trips() {
// Covers apollo_network directly: NetworkConfig::{session_timeout, idle_connection_timeout,
// prune_dead_connections_ping_interval, prune_dead_connections_ping_timeout (seconds),
// bootstrap_peer_multiaddr (comma-separated list)}, and (via sub-structs)
// bootstrap_peer_multiaddr (native JSON array)}, and (via sub-structs)
// DiscoveryConfig::heartbeat_interval, RetryConfig::{max_delay_seconds,
// new_connection_stabilization_millis}, PeerManagerConfig::{malicious_timeout_seconds,
// unstable_timeout_millis}.
Expand Down
2 changes: 1 addition & 1 deletion deployments/monitoring/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ services:
jq '.components.l1_gas_price_scraper.execution_mode = "Disabled"' "$$cfg" | sponge "$$cfg"
if [ "$$N_NODES" -gt 1 ]; then
for key in consensus_manager_config.network_config.bootstrap_peer_multiaddr mempool_p2p_config.network_config.bootstrap_peer_multiaddr state_sync_config.static_config.network_config.bootstrap_peer_multiaddr; do
jq --arg k "$$key" '($$k / ".") as $$p | if getpath($$p) == null then . else setpath($$p; getpath($$p) | split(",") | to_entries | map(.key as $$j | .value | sub("/ip4/[0-9.]+/"; "/dns4/sequencer-node-\($$j)/")) | join(",")) end' "$$cfg" | sponge "$$cfg"
jq --arg k "$$key" '($$k / ".") as $$p | if getpath($$p) == null then . else setpath($$p; getpath($$p) | to_entries | map(.key as $$j | .value | sub("/ip4/[0-9.]+/"; "/dns4/sequencer-node-\($$j)/"))) end' "$$cfg" | sponge "$$cfg"
done
fi
done
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
advertisedMultiaddr(bootstrap_peer_multiaddr, node_index, nodes_at_same_cluster)::
if !nodes_at_same_cluster && bootstrap_peer_multiaddr != null
then std.split(bootstrap_peer_multiaddr, ',')[node_index]
then bootstrap_peer_multiaddr[node_index]
else null,
}
Loading