Skip to content

Commit

Permalink
Fix division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Aug 9, 2024
1 parent e7da401 commit 11fbf81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
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 11fbf81

Please sign in to comment.