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