From 9f48e9ea5311dd08d5d74df98c60ffea1d80aa97 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Thu, 8 Aug 2024 04:08:36 +0000 Subject: [PATCH] fix core pinning --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/mine.rs | 85 ++++++++++++++++++++++++++++------------------------- 3 files changed, 47 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4789b051..1cddd889 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2772,7 +2772,7 @@ dependencies = [ [[package]] name = "ore-cli" -version = "1.1.1" +version = "2.0.0" dependencies = [ "bincode", "bs58 0.5.1", diff --git a/Cargo.toml b/Cargo.toml index 948d77bd..a50d2534 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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." diff --git a/src/mine.rs b/src/mine.rs index 8cda28ec..d2804408 100644 --- a/src/mine.rs +++ b/src/mine.rs @@ -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) } }) })