Skip to content

Commit

Permalink
Merge pull request #283 from autonomys/fix-division-by-zero
Browse files Browse the repository at this point in the history
Fix division by zero
  • Loading branch information
nazar-pc authored Aug 9, 2024
2 parents e7da401 + 0918018 commit 7c31a88
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 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
Expand Up @@ -2,7 +2,7 @@
name = "space-acres"
description = "Space Acres is an opinionated GUI application for farming on Autonomys Network"
license = "0BSD"
version = "0.1.33"
version = "0.1.34"
authors = ["Nazar Mokrynskyi <[email protected]>"]
repository = "https://github.com/autonomys/space-acres"
edition = "2021"
Expand Down
16 changes: 10 additions & 6 deletions src/frontend/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,23 @@ impl RunningView {
u128::from(network_voting_space_pledged_sectors) * 2 * Piece::SIZE as u128;

// Take into consideration how much space was plotted so far
let local_space_pledged = self.farmer_state.local_space_pledged
* u64::from(self.farmer_state.sectors_plotted)
/ u64::from(self.farmer_state.sectors_total)
* u64::from(self.farmer_state.cache_percentage.get())
/ 100;
let local_space_pledged = if self.farmer_state.sectors_total == 0 {
0
} else {
self.farmer_state.local_space_pledged * u64::from(self.farmer_state.sectors_plotted)
/ u64::from(self.farmer_state.sectors_total)
* u64::from(self.farmer_state.cache_percentage.get())
/ 100
};

// network_voting_space_pledged/local_space_pledged is a time multiplier based on how much
// smaller space pledged is comparing to network space pledged, then we also account for
// slot probability. The fact that we have votes and blocks is accounted for by using
// solution range to calculate space pledged as explained above.
let expected_reward_interval = self.farmer_state.slot_duration.as_millis()
* network_voting_space_pledged
/ u128::from(local_space_pledged)
// Just to avoid division by zero
/ u128::from(local_space_pledged.max(1))
/ u128::from(self.farmer_state.slot_probability.0)
* u128::from(self.farmer_state.slot_probability.1);
let expected_reward_interval = Duration::from_millis(expected_reward_interval as u64);
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/running/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ impl NodeView {
},
NodeInput::OpenNodeFolder => {
let node_path = self.node_path.lock().clone();
open::that_detached(node_path.as_os_str()).unwrap();
if let Err(error) = open::that_detached(&node_path) {
error!(%error, path = %node_path.display(), "Failed to open node folder");
}
}
}
}
Expand Down

0 comments on commit 7c31a88

Please sign in to comment.