Skip to content

Commit

Permalink
Avoid divided by 0 problems
Browse files Browse the repository at this point in the history
  • Loading branch information
brianp committed Sep 9, 2024
1 parent 8b49370 commit d23bb60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/run_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ fn thread_work<'a>(
}

let elapsed_since_last_check = Instant::now().duration_since(stats_last_check_time);
// Add a little entropy on the check time to try and lower the frequency of threads attempting to update
// the AtomicU64
// Spread out the updates by a few MS to reduce the chances of multiple threads trying to update
// the AtomicU64 at the same time.
let check_time =
Duration::from_secs(5) + Duration::from_millis((num_threads * 100 / thread_number) as u64);
Duration::from_secs(5) + Duration::from_millis((num_threads * 100 / (thread_number+1)) as u64);
if elapsed_since_last_check >= check_time {
info!(target: LOG_TARGET, "{}", stats_store.pretty_print(thread_number, nonce, cycle_start.elapsed().as_secs(), max_difficulty_reached, block_template.difficulty));
stats_last_check_time = Instant::now();
Expand Down
4 changes: 4 additions & 0 deletions src/stats_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ impl StatsStore {
}

pub fn hashes_per_second(&self) -> u64 {
if self.elapsed_time() == 0 {
return 0;
}

self.hashed_count.load(Ordering::SeqCst) / self.elapsed_time()
}

Expand Down

0 comments on commit d23bb60

Please sign in to comment.