Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Summary bug fix (#178)
Browse files Browse the repository at this point in the history
* fix the bug with flushing

* yank version
  • Loading branch information
ozgunozerk authored Apr 18, 2023
1 parent 0c1a788 commit c452f12
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subspace-cli"
version = "0.3.2"
version = "0.3.3"
edition = "2021"

[dependencies]
Expand Down
6 changes: 1 addition & 5 deletions src/commands/farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
20 changes: 8 additions & 12 deletions src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand All @@ -124,7 +124,7 @@ impl SummaryFilePointer {
is_new_vote,
maybe_new_reward,
}: SummaryUpdateFields,
) -> Result<()> {
) -> Result<Summary> {
let mut summary = self.parse_summary().await?;

if is_plotting_finished {
Expand All @@ -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`]
Expand Down

0 comments on commit c452f12

Please sign in to comment.