miner: allow zero background mining sleep
What changed, and why it matters
This commit tweaks how Monero's built-in background miner decides how long to rest between attempts. Previously the miner was forced to sleep at least 5 milliseconds; now it can sleep zero milliseconds. This is a small behavior change in a non-default, local-only feature and does not appear to be a security fix or vulnerability on its own.
No security action required. Treat as a normal functional/mining-behavior commit. If reviewing for resource exhaustion, note that allowing zero extra sleep could increase CPU consumption when background mining is enabled and the target is set aggressively, but this is user-configurable local behavior.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change removes a 5 ms floor on m_miner_extra_sleep in the background mining loop, allowing it to drop to 0. The formula is also inverted so the sleep increases when CPU usage is above target and decreases (toward zero) when below target. The commit message frames this as a functional/mining-tuning change, not a security patch. There is no evidence in the diff or supplied references of a vulnerability, exploit, or security disclosure.
Changed components
src/cryptonote_basic/miner.cpp background mining sleep adjustmentInspect captured patch +7 / −6
diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp
index c9f3171..6258c93 100644
--- a/src/cryptonote_basic/miner.cpp
+++ b/src/cryptonote_basic/miner.cpp
@@ -782,12 +782,13 @@ namespace cryptonote
previous_process_time = current_process_time;
// adjust the miner extra sleep variable
- int64_t miner_extra_sleep_change = (-1 * (get_mining_target() - process_percentage) );
- int64_t new_miner_extra_sleep = m_miner_extra_sleep + miner_extra_sleep_change;
- // if you start the miner with few threads on a multicore system, this could
- // fall below zero because all the time functions aggregate across all processors.
- // I'm just hard limiting to 5 millis min sleep here, other options?
- m_miner_extra_sleep = std::max( new_miner_extra_sleep , (int64_t)5 );
+ const int64_t miner_extra_sleep_change =
+ int64_t{process_percentage} - int64_t{get_mining_target()};
+ const int64_t new_miner_extra_sleep =
+ static_cast<int64_t>(m_miner_extra_sleep.load()) + miner_extra_sleep_change;
+ // A target above the available mining threads' capacity can drive this
+ // below zero because the time functions aggregate across all processors.
+ m_miner_extra_sleep = std::max(new_miner_extra_sleep, int64_t{0});
MDEBUG("m_miner_extra_sleep " << m_miner_extra_sleep);
}
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.