Skip to content

Commit 6339ffd

Browse files
Update mine.rs
little update for see update on best difficulty and update best difficulty build with support from OneOkRock Renegades Song :)
1 parent 45a09e1 commit 6339ffd

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/mine.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{sync::Arc, time::Instant};
1+
use std::{sync::Arc, sync::RwLock, time::Instant};
22

33
use colored::*;
44
use drillx::{
@@ -35,6 +35,7 @@ impl Miner {
3535

3636
// Start mining loop
3737
let mut last_hash_at = 0;
38+
let mut last_balance = 0;
3839
loop {
3940
// Fetch proof
4041
let config = get_config(&self.rpc_client).await;
@@ -43,11 +44,12 @@ impl Miner {
4344
.await;
4445
last_hash_at = proof.last_hash_at;
4546
println!(
46-
"\nStake: {} ORE\n Multiplier: {:12}x",
47+
"\nStake: {} ORE \n balance change:{} ORE\n Multiplier: {:12}x",
4748
amount_u64_to_string(proof.balance),
49+
amount_u64_to_string(proof.balance.saturating_sub(last_balance)),
4850
calculate_multiplier(proof.balance, config.top_balance)
4951
);
50-
52+
last_balance = proof.balance;
5153
// Calculate cutoff time
5254
let cutoff_time = self.get_cutoff(proof, args.buffer_time).await;
5355

@@ -87,11 +89,13 @@ impl Miner {
8789
) -> Solution {
8890
// Dispatch job to each thread
8991
let progress_bar = Arc::new(spinner::new_progress_bar());
92+
let global_best_difficulty = Arc::new(RwLock::new(0u32));
9093
progress_bar.set_message("Mining...");
9194
let core_ids = core_affinity::get_core_ids().unwrap();
9295
let handles: Vec<_> = core_ids
9396
.into_iter()
9497
.map(|i| {
98+
let global_best_difficulty = Arc::clone(&global_best_difficulty);
9599
std::thread::spawn({
96100
let proof = proof.clone();
97101
let progress_bar = progress_bar.clone();
@@ -123,24 +127,39 @@ impl Miner {
123127
best_nonce = nonce;
124128
best_difficulty = difficulty;
125129
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 }}
126135
}
127136
}
128137

129138
// Exit if time has elapsed
130139
if nonce % 100 == 0 {
140+
let global_best_difficulty = *global_best_difficulty.read().unwrap();
131141
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) {
133150
// Mine until min difficulty has been met
134151
break;
135152
}
136153
} else if i.id == 0 {
137154
progress_bar.set_message(format!(
138-
"Mining... ({} sec remaining)",
155+
"Mining... ({} / {} difficulty, {} sec remaining)",
156+
global_best_difficulty,
157+
min_difficulty,
139158
cutoff_time.saturating_sub(timer.elapsed().as_secs()),
140159
));
141160
}
142161
}
143-
162+
144163
// Increment nonce
145164
nonce += 1;
146165
}

0 commit comments

Comments
 (0)