File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 1
- use std:: { sync:: Arc , time:: Instant } ;
1
+ use std:: { sync:: Arc , sync :: RwLock , time:: Instant } ;
2
2
3
3
use colored:: * ;
4
4
use drillx:: {
@@ -80,8 +80,10 @@ impl Miner {
80
80
// Dispatch job to each thread
81
81
let progress_bar = Arc :: new ( spinner:: new_progress_bar ( ) ) ;
82
82
progress_bar. set_message ( "Mining..." ) ;
83
+ let global_best_difficulty = Arc :: new ( RwLock :: new ( 0u32 ) ) ;
83
84
let handles: Vec < _ > = ( 0 ..threads)
84
85
. map ( |i| {
86
+ let global_best_difficulty = Arc :: clone ( & global_best_difficulty) ;
85
87
std:: thread:: spawn ( {
86
88
let proof = proof. clone ( ) ;
87
89
let progress_bar = progress_bar. clone ( ) ;
@@ -104,13 +106,17 @@ impl Miner {
104
106
best_nonce = nonce;
105
107
best_difficulty = difficulty;
106
108
best_hash = hx;
109
+ if best_difficulty. gt ( & * global_best_difficulty. read ( ) . unwrap ( ) ) {
110
+ * global_best_difficulty. write ( ) . unwrap ( ) = best_difficulty;
111
+ }
107
112
}
108
113
}
109
114
110
115
// Exit if time has elapsed
111
116
if nonce % 100 == 0 {
117
+ let global_best_difficulty = * global_best_difficulty. read ( ) . unwrap ( ) ;
112
118
if timer. elapsed ( ) . as_secs ( ) . ge ( & cutoff_time) {
113
- if best_difficulty . ge ( & min_difficulty) {
119
+ if global_best_difficulty . ge ( & min_difficulty) {
114
120
// Mine until min difficulty has been met
115
121
break ;
116
122
}
You can’t perform that action at this time.
0 commit comments