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:: {
@@ -35,6 +35,7 @@ impl Miner {
35
35
36
36
// Start mining loop
37
37
let mut last_hash_at = 0 ;
38
+ let mut last_balance = 0 ;
38
39
loop {
39
40
// Fetch proof
40
41
let config = get_config ( & self . rpc_client ) . await ;
@@ -43,11 +44,12 @@ impl Miner {
43
44
. await ;
44
45
last_hash_at = proof. last_hash_at ;
45
46
println ! (
46
- "\n Stake: {} ORE\n Multiplier: {:12}x" ,
47
+ "\n Stake: {} ORE \n balance change:{} ORE \n Multiplier: {:12}x" ,
47
48
amount_u64_to_string( proof. balance) ,
49
+ amount_u64_to_string( proof. balance. saturating_sub( last_balance) ) ,
48
50
calculate_multiplier( proof. balance, config. top_balance)
49
51
) ;
50
-
52
+ last_balance = proof . balance ;
51
53
// Calculate cutoff time
52
54
let cutoff_time = self . get_cutoff ( proof, args. buffer_time ) . await ;
53
55
@@ -87,11 +89,13 @@ impl Miner {
87
89
) -> Solution {
88
90
// Dispatch job to each thread
89
91
let progress_bar = Arc :: new ( spinner:: new_progress_bar ( ) ) ;
92
+ let global_best_difficulty = Arc :: new ( RwLock :: new ( 0u32 ) ) ;
90
93
progress_bar. set_message ( "Mining..." ) ;
91
94
let core_ids = core_affinity:: get_core_ids ( ) . unwrap ( ) ;
92
95
let handles: Vec < _ > = core_ids
93
96
. into_iter ( )
94
97
. map ( |i| {
98
+ let global_best_difficulty = Arc :: clone ( & global_best_difficulty) ;
95
99
std:: thread:: spawn ( {
96
100
let proof = proof. clone ( ) ;
97
101
let progress_bar = progress_bar. clone ( ) ;
@@ -123,24 +127,39 @@ impl Miner {
123
127
best_nonce = nonce;
124
128
best_difficulty = difficulty;
125
129
best_hash = hx;
130
+ // {{ edit_1 }}
131
+ if best_difficulty. gt ( & * global_best_difficulty. read ( ) . unwrap ( ) ) {
132
+ * global_best_difficulty. write ( ) . unwrap ( ) = best_difficulty;
133
+ }
134
+ // {{ edit_1 }}
126
135
}
127
136
}
128
137
129
138
// Exit if time has elapsed
130
139
if nonce % 100 == 0 {
140
+ let global_best_difficulty = * global_best_difficulty. read ( ) . unwrap ( ) ;
131
141
if timer. elapsed ( ) . as_secs ( ) . ge ( & cutoff_time) {
132
- if best_difficulty. ge ( & min_difficulty) {
142
+ if i. id == 0 {
143
+ progress_bar. set_message ( format ! (
144
+ "Mining... ({} / {} difficulty)" ,
145
+ global_best_difficulty,
146
+ min_difficulty,
147
+ ) ) ;
148
+ }
149
+ if global_best_difficulty. ge ( & min_difficulty) {
133
150
// Mine until min difficulty has been met
134
151
break ;
135
152
}
136
153
} else if i. id == 0 {
137
154
progress_bar. set_message ( format ! (
138
- "Mining... ({} sec remaining)" ,
155
+ "Mining... ({} / {} difficulty, {} sec remaining)" ,
156
+ global_best_difficulty,
157
+ min_difficulty,
139
158
cutoff_time. saturating_sub( timer. elapsed( ) . as_secs( ) ) ,
140
159
) ) ;
141
160
}
142
161
}
143
-
162
+
144
163
// Increment nonce
145
164
nonce += 1 ;
146
165
}
0 commit comments