Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Stability] Config file changes #2219

Merged
merged 3 commits into from
Dec 14, 2023
Merged
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
26 changes: 14 additions & 12 deletions crates/orchestrator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ pub enum NetworkConfigError {
#[error("Failed to read NetworkConfig from file")]
ReadFromFileError(std::io::Error),
#[error("Failed to deserialize loaded NetworkConfig")]
DeserializeError(bincode::Error),
DeserializeError(serde_json::Error),
#[error("Failed to write NetworkConfig to file")]
WriteToFileError(std::io::Error),
#[error("Failed to serialize NetworkConfig")]
SerializeError(bincode::Error),
SerializeError(serde_json::Error),
#[error("Failed to recursively create path to NetworkConfig")]
FailedToCreatePath(std::io::Error),
}

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -144,13 +146,6 @@ impl<K: SignatureKey, E: ElectionConfig> NetworkConfig<K, E> {
let config = client.get_config(client.identity.clone()).await;

// save to file if we fell back
// ensure the directory containing the config file exists
if let Some(dir) = Path::new(&file).parent() {
if let Err(e) = fs::create_dir_all(dir) {
error!("Failed to recursively create path to config file: {e}")
}
}

if let Err(e) = config.to_file(file) {
error!("{e}");
};
Expand Down Expand Up @@ -201,15 +196,15 @@ impl<K: SignatureKey, E: ElectionConfig> NetworkConfig<K, E> {
};

// deserialize
match bincode::deserialize(&data) {
match serde_json::from_slice(&data) {
Ok(data) => Ok(data),
Err(e) => Err(NetworkConfigError::DeserializeError(e)),
}
}

/// Serializes the `NetworkConfig` and writes it to a file.
///
/// This function takes a file path as a string, serializes the `NetworkConfig` into binary format using `bincode`, and then writes the serialized data to the file.
/// This function takes a file path as a string, serializes the `NetworkConfig` into JSON format using `serde_json` and then writes the serialized data to the file.
///
/// # Arguments
///
Expand All @@ -231,8 +226,15 @@ impl<K: SignatureKey, E: ElectionConfig> NetworkConfig<K, E> {
/// config.to_file(file).unwrap();
/// ```
pub fn to_file(&self, file: String) -> Result<(), NetworkConfigError> {
// ensure the directory containing the config file exists
if let Some(dir) = Path::new(&file).parent() {
if let Err(e) = fs::create_dir_all(dir) {
return Err(NetworkConfigError::FailedToCreatePath(e));
}
}

// serialize
let serialized = match bincode::serialize(self) {
let serialized = match serde_json::to_string_pretty(self) {
Ok(data) => data,
Err(e) => {
return Err(NetworkConfigError::SerializeError(e));
Expand Down
3 changes: 2 additions & 1 deletion crates/task-impls/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,8 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
let high_qc = self.consensus.read().await.high_qc.clone();
let leader_view = high_qc.get_view_number() + 1;
if self.quorum_membership.get_leader(leader_view) == self.public_key {
self.publish_proposal_if_able(high_qc, leader_view, None).await;
self.publish_proposal_if_able(high_qc, leader_view, None)
.await;
}
}
_ => {}
Expand Down