diff --git a/src/mine.rs b/src/mine.rs index 13e82752..d0886a2c 100644 --- a/src/mine.rs +++ b/src/mine.rs @@ -1,4 +1,4 @@ -use std::{sync::Arc, time::Instant}; +use std::{sync::Arc, sync::RwLock, time::Instant}; use colored::*; use drillx::{ @@ -81,8 +81,10 @@ impl Miner { // Dispatch job to each thread let progress_bar = Arc::new(spinner::new_progress_bar()); progress_bar.set_message("Mining..."); + let global_best_difficulty = Arc::new(RwLock::new(0u32)); let handles: Vec<_> = (0..threads) .map(|i| { + let global_best_difficulty = Arc::clone(&global_best_difficulty); std::thread::spawn({ let proof = proof.clone(); let progress_bar = progress_bar.clone(); @@ -105,19 +107,32 @@ impl Miner { best_nonce = nonce; best_difficulty = difficulty; best_hash = hx; + if best_difficulty.gt(&*global_best_difficulty.read().unwrap()) { + *global_best_difficulty.write().unwrap() = best_difficulty; + } } } // Exit if time has elapsed if nonce % 100 == 0 { + let global_best_difficulty = *global_best_difficulty.read().unwrap(); if timer.elapsed().as_secs().ge(&cutoff_time) { - if best_difficulty.ge(&min_difficulty) { + if i == 0 { + progress_bar.set_message(format!( + "Mining... ({} / {} difficulty)", + global_best_difficulty, + min_difficulty, + )); + } + if global_best_difficulty.ge(&min_difficulty) { // Mine until min difficulty has been met break; } } else if i == 0 { progress_bar.set_message(format!( - "Mining... ({} sec remaining)", + "Mining... ({} / {} difficulty, {} sec remaining)", + global_best_difficulty, + min_difficulty, cutoff_time.saturating_sub(timer.elapsed().as_secs()), )); }