Merge pull request #4733

b3067962 cryptonote_core: avoid gratuitous recalculations in check_block_rate() (xiphon)
This commit is contained in:
Riccardo Spagni 2018-11-06 21:30:52 +02:00
commit 0991aa8964
No known key found for this signature in database
GPG Key ID: 55432DF31CCD4FCD

View File

@ -1716,7 +1716,8 @@ namespace cryptonote
for (size_t n = 0; n < sizeof(seconds)/sizeof(seconds[0]); ++n) for (size_t n = 0; n < sizeof(seconds)/sizeof(seconds[0]); ++n)
{ {
unsigned int b = 0; unsigned int b = 0;
for (time_t ts: timestamps) b += ts >= now - static_cast<time_t>(seconds[n]); const time_t time_boundary = now - static_cast<time_t>(seconds[n]);
for (time_t ts: timestamps) b += ts >= time_boundary;
const double p = probability(b, seconds[n] / DIFFICULTY_TARGET_V2); const double p = probability(b, seconds[n] / DIFFICULTY_TARGET_V2);
MDEBUG("blocks in the last " << seconds[n] / 60 << " minutes: " << b << " (probability " << p << ")"); MDEBUG("blocks in the last " << seconds[n] / 60 << " minutes: " << b << " (probability " << p << ")");
if (p < threshold) if (p < threshold)