From a4cfebcd1be55ba63bb44e820b4ac78023256167 Mon Sep 17 00:00:00 2001 From: Philip White Date: Sat, 14 Sep 2024 18:39:06 -0700 Subject: [PATCH] Clarify warning about too-few blocks Today, the warning about too-few blocks is not clear about what happened versus what was expected; that's the main thing I want to address. Clarifying this makes the message somewhat longer, so I reduce its length by removing some redundant or meaningless (IMO) reasons for the symptoms. --- src/cryptonote_core/cryptonote_core.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index d34c92723..fe253d588 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -47,6 +47,7 @@ using namespace epee; #include "cryptonote_config.h" #include "misc_language.h" #include "file_io_utils.h" +#include #include #include "checkpoints/checkpoints.h" #include "ringct/rctTypes.h" @@ -2048,14 +2049,17 @@ namespace cryptonote static const unsigned int seconds[] = { 5400, 3600, 1800, 1200, 600 }; for (size_t n = 0; n < sizeof(seconds)/sizeof(seconds[0]); ++n) { - unsigned int b = 0; + unsigned int b = 0; // quantity of blocks between `time_boundary` and `now` const time_t time_boundary = now - static_cast(seconds[n]); for (time_t ts: timestamps) b += ts >= time_boundary; - const double p = probability(b, seconds[n] / DIFFICULTY_TARGET_V2); - MDEBUG("blocks in the last " << seconds[n] / 60 << " minutes: " << b << " (probability " << p << ")"); + // expected qty of blocks in the time measured = (time measured) / (expected time per block) + const double b_exp = seconds[n] / DIFFICULTY_TARGET_V2; + const double p = probability(b, b_exp); + MDEBUG("blocks in the last " << seconds[n] / 60 << " minutes: " << b << " (probability actual " << p << ", expected >=" << threshold << ")"); if (p < threshold) { - MWARNING("There were " << b << (b == max_blocks_checked ? " or more" : "") << " blocks in the last " << seconds[n] / 60 << " minutes, there might be large hash rate changes, or we might be partitioned, cut off from the Monero network or under attack, or your computer's time is off. Or it could be just sheer bad luck."); + const long b_min_exp = std::lround(threshold * b_exp); // lower bound on blocks we expect during measurement + MWARNING("There were " << b << (b == max_blocks_checked ? " or more" : "") << " blocks in the last " << seconds[n] / 60 << " minutes, while we expected >=" << b_min_exp << ". There might be large hash rate changes, we might be partitioned, cut off from the Monero network or under attack, or your computer's time is off."); std::shared_ptr block_rate_notify = m_block_rate_notify; if (block_rate_notify)