Skip to content

Commit

Permalink
fix core pinning
Browse files Browse the repository at this point in the history
  • Loading branch information
HardhatChad committed Aug 8, 2024
1 parent 5c41cf1 commit 9f48e9e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ore-cli"
version = "1.1.1"
version = "2.0.0"
edition = "2021"
license = "Apache-2.0"
description = "A command line interface for ORE cryptocurrency mining."
Expand Down
85 changes: 45 additions & 40 deletions src/mine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,53 +86,58 @@ impl Miner {
let progress_bar = progress_bar.clone();
let mut memory = equix::SolverMemory::new();
move || {
let res = core_affinity::set_for_current(i);
if res {
let timer = Instant::now();
let mut nonce =
u64::MAX.saturating_div(cores).saturating_mul(i.id as u64);
let mut best_nonce = nonce;
let mut best_difficulty = 0;
let mut best_hash = Hash::default();
loop {
// Create hash
if let Ok(hx) = drillx::hash_with_memory(
&mut memory,
&proof.challenge,
&nonce.to_le_bytes(),
) {
let difficulty = hx.difficulty();
if difficulty.gt(&best_difficulty) {
best_nonce = nonce;
best_difficulty = difficulty;
best_hash = hx;
}
// Return if core should not be used
if (i.id as u64).ge(&cores) {
return (0, 0, Hash::default());
}

// Pin to core
if !core_affinity::set_for_current(i) {
return (0, 0, Hash::default());
}

// Start hashing
let timer = Instant::now();
let mut nonce = u64::MAX.saturating_div(cores).saturating_mul(i.id as u64);
let mut best_nonce = nonce;
let mut best_difficulty = 0;
let mut best_hash = Hash::default();
loop {
// Create hash
if let Ok(hx) = drillx::hash_with_memory(
&mut memory,
&proof.challenge,
&nonce.to_le_bytes(),
) {
let difficulty = hx.difficulty();
if difficulty.gt(&best_difficulty) {
best_nonce = nonce;
best_difficulty = difficulty;
best_hash = hx;
}
}

// Exit if time has elapsed
if nonce % 100 == 0 {
if timer.elapsed().as_secs().ge(&cutoff_time) {
if best_difficulty.ge(&min_difficulty) {
// Mine until min difficulty has been met
break;
}
} else if cores == 0 {
progress_bar.set_message(format!(
"Mining... ({} sec remaining)",
cutoff_time.saturating_sub(timer.elapsed().as_secs()),
));
// Exit if time has elapsed
if nonce % 100 == 0 {
if timer.elapsed().as_secs().ge(&cutoff_time) {
if best_difficulty.ge(&min_difficulty) {
// Mine until min difficulty has been met
break;
}
} else if cores == 0 {
progress_bar.set_message(format!(
"Mining... ({} sec remaining)",
cutoff_time.saturating_sub(timer.elapsed().as_secs()),
));
}

// Increment nonce
nonce += 1;
}

// Return the best nonce
(best_nonce, best_difficulty, best_hash)
} else {
(0, 0, Hash::default())
// Increment nonce
nonce += 1;
}

// Return the best nonce
(best_nonce, best_difficulty, best_hash)
}
})
})
Expand Down

0 comments on commit 9f48e9e

Please sign in to comment.