From 4f9e09d3f0c9d11d5d4177ad74a9f41049d87528 Mon Sep 17 00:00:00 2001 From: Rob Date: Tue, 12 Dec 2023 15:21:13 -0500 Subject: [PATCH 1/2] move config file creation --- crates/orchestrator/src/config.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index ce69bd7d09..731768c8e4 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -71,6 +71,8 @@ pub enum NetworkConfigError { WriteToFileError(std::io::Error), #[error("Failed to serialize NetworkConfig")] SerializeError(bincode::Error), + #[error("Failed to recursively create path to NetworkConfig")] + FailedToCreatePath(std::io::Error) } #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] @@ -144,13 +146,6 @@ impl NetworkConfig { 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}"); }; @@ -231,6 +226,13 @@ impl NetworkConfig { /// 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) { Ok(data) => data, From c05c89354b3860a6876e0dde0ac34654a0fc8d87 Mon Sep 17 00:00:00 2001 From: Rob Date: Wed, 13 Dec 2023 11:52:56 -0500 Subject: [PATCH 2/2] update config to JSON --- crates/orchestrator/src/config.rs | 14 +++++++------- crates/task-impls/src/consensus.rs | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 731768c8e4..67ae88e5c3 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -66,13 +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) + FailedToCreatePath(std::io::Error), } #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] @@ -196,7 +196,7 @@ impl NetworkConfig { }; // deserialize - match bincode::deserialize(&data) { + match serde_json::from_slice(&data) { Ok(data) => Ok(data), Err(e) => Err(NetworkConfigError::DeserializeError(e)), } @@ -204,7 +204,7 @@ impl NetworkConfig { /// 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 /// @@ -229,12 +229,12 @@ impl NetworkConfig { // 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)) + 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)); diff --git a/crates/task-impls/src/consensus.rs b/crates/task-impls/src/consensus.rs index 7ebebfb849..736de7d33c 100644 --- a/crates/task-impls/src/consensus.rs +++ b/crates/task-impls/src/consensus.rs @@ -997,7 +997,8 @@ impl, A: ConsensusApi + 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; } } _ => {}