Skip to content

Commit 9f48e9e

Browse files
committed
fix core pinning
1 parent 5c41cf1 commit 9f48e9e

File tree

3 files changed

+47
-42
lines changed

3 files changed

+47
-42
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ore-cli"
3-
version = "1.1.1"
3+
version = "2.0.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
description = "A command line interface for ORE cryptocurrency mining."

src/mine.rs

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -86,53 +86,58 @@ impl Miner {
8686
let progress_bar = progress_bar.clone();
8787
let mut memory = equix::SolverMemory::new();
8888
move || {
89-
let res = core_affinity::set_for_current(i);
90-
if res {
91-
let timer = Instant::now();
92-
let mut nonce =
93-
u64::MAX.saturating_div(cores).saturating_mul(i.id as u64);
94-
let mut best_nonce = nonce;
95-
let mut best_difficulty = 0;
96-
let mut best_hash = Hash::default();
97-
loop {
98-
// Create hash
99-
if let Ok(hx) = drillx::hash_with_memory(
100-
&mut memory,
101-
&proof.challenge,
102-
&nonce.to_le_bytes(),
103-
) {
104-
let difficulty = hx.difficulty();
105-
if difficulty.gt(&best_difficulty) {
106-
best_nonce = nonce;
107-
best_difficulty = difficulty;
108-
best_hash = hx;
109-
}
89+
// Return if core should not be used
90+
if (i.id as u64).ge(&cores) {
91+
return (0, 0, Hash::default());
92+
}
93+
94+
// Pin to core
95+
if !core_affinity::set_for_current(i) {
96+
return (0, 0, Hash::default());
97+
}
98+
99+
// Start hashing
100+
let timer = Instant::now();
101+
let mut nonce = u64::MAX.saturating_div(cores).saturating_mul(i.id as u64);
102+
let mut best_nonce = nonce;
103+
let mut best_difficulty = 0;
104+
let mut best_hash = Hash::default();
105+
loop {
106+
// Create hash
107+
if let Ok(hx) = drillx::hash_with_memory(
108+
&mut memory,
109+
&proof.challenge,
110+
&nonce.to_le_bytes(),
111+
) {
112+
let difficulty = hx.difficulty();
113+
if difficulty.gt(&best_difficulty) {
114+
best_nonce = nonce;
115+
best_difficulty = difficulty;
116+
best_hash = hx;
110117
}
118+
}
111119

112-
// Exit if time has elapsed
113-
if nonce % 100 == 0 {
114-
if timer.elapsed().as_secs().ge(&cutoff_time) {
115-
if best_difficulty.ge(&min_difficulty) {
116-
// Mine until min difficulty has been met
117-
break;
118-
}
119-
} else if cores == 0 {
120-
progress_bar.set_message(format!(
121-
"Mining... ({} sec remaining)",
122-
cutoff_time.saturating_sub(timer.elapsed().as_secs()),
123-
));
120+
// Exit if time has elapsed
121+
if nonce % 100 == 0 {
122+
if timer.elapsed().as_secs().ge(&cutoff_time) {
123+
if best_difficulty.ge(&min_difficulty) {
124+
// Mine until min difficulty has been met
125+
break;
124126
}
127+
} else if cores == 0 {
128+
progress_bar.set_message(format!(
129+
"Mining... ({} sec remaining)",
130+
cutoff_time.saturating_sub(timer.elapsed().as_secs()),
131+
));
125132
}
126-
127-
// Increment nonce
128-
nonce += 1;
129133
}
130134

131-
// Return the best nonce
132-
(best_nonce, best_difficulty, best_hash)
133-
} else {
134-
(0, 0, Hash::default())
135+
// Increment nonce
136+
nonce += 1;
135137
}
138+
139+
// Return the best nonce
140+
(best_nonce, best_difficulty, best_hash)
136141
}
137142
})
138143
})

0 commit comments

Comments
 (0)