diff --git a/Cargo.lock b/Cargo.lock index 408c9136..83f50592 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10265,7 +10265,7 @@ dependencies = [ [[package]] name = "subspace-cli" -version = "0.3.2" +version = "0.3.3" dependencies = [ "bytesize", "bytesize-serde", diff --git a/Cargo.toml b/Cargo.toml index d8d1bc6b..6f769591 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "subspace-cli" -version = "0.3.2" +version = "0.3.3" edition = "2021" [dependencies] diff --git a/src/commands/farm.rs b/src/commands/farm.rs index 1e14db15..28d16b77 100644 --- a/src/commands/farm.rs +++ b/src/commands/farm.rs @@ -279,12 +279,8 @@ async fn subscribe_to_solutions( summary_update_values.is_new_block_farmed = true; } } - let _ = summary.update(summary_update_values).await; // ignore the - // error, we will - // abandon this - // mechanism let Summary { total_rewards, farmed_block_count, vote_count, .. } = - summary.parse_summary().await.context("couldn't parse summary")?; + summary.update(summary_update_values).await.context("couldn't update summary")?; if is_initial_progress_finished.load(Ordering::Relaxed) { print!( diff --git a/src/summary.rs b/src/summary.rs index b99a9244..449791d4 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -79,7 +79,7 @@ impl SummaryFilePointer { .join("subspace-cli"); // providing `Some` value for `user_space_pledged` means, we are creating a new - // file + // file, so, first check if the file exists to not erase its content if let Some(user_space_pledged) = user_space_pledged { // File::create will truncate the existing file, so first // check if the file exists, if not, `open` will return an error @@ -110,7 +110,7 @@ impl SummaryFilePointer { Ok(SummaryFilePointer { file: Arc::new(Mutex::new(summary_path)) }) } - /// updates the summary file + /// updates the summary file, and returns the content of the new summary /// /// this function will be called by the farmer when /// the status of the `plotting_finished` @@ -124,7 +124,7 @@ impl SummaryFilePointer { is_new_vote, maybe_new_reward, }: SummaryUpdateFields, - ) -> Result<()> { + ) -> Result { let mut summary = self.parse_summary().await?; if is_plotting_finished { @@ -143,15 +143,11 @@ impl SummaryFilePointer { let new_summary = toml::to_string(&summary).context("Failed to serialize Summary")?; let guard = self.file.lock().await; - OpenOptions::new() - .write(true) - .truncate(true) - .open(&*guard) - .await? - .write_all(new_summary.as_bytes()) - .await?; - - Ok(()) + let mut buffer = OpenOptions::new().write(true).truncate(true).open(&*guard).await?; + buffer.write_all(new_summary.as_bytes()).await?; + buffer.flush().await?; + + Ok(summary) } /// parses the summary file and returns [`Summary`]