Skip to content
Permalink
Browse files

core: improve block rate monitor trigger probabilities

The original intent of one false positive a week on average
was not met, since what we really want is not the probability
of having N blocks in T seconds, but either N blocks of fewer
in T seconds, or N blocks or more in T seconds.

Some of this could be cached since it calculates the same fairly
complex floating point values, but it seems pretty fast already.
  • Loading branch information...
moneromooo-monero committed Mar 19, 2019
1 parent ea07a9b commit 186a3d2b174bebe572f1c3cfe20e32f84762e0e3
Showing with 19 additions and 1 deletion.
  1. +19 −1 src/cryptonote_core/cryptonote_core.cpp
@@ -1782,12 +1782,30 @@ namespace cryptonote
return f;
}
//-----------------------------------------------------------------------------------------------
static double probability(unsigned int blocks, unsigned int expected)
static double probability1(unsigned int blocks, unsigned int expected)
{
// https://www.umass.edu/wsp/resources/poisson/#computing
return pow(expected, blocks) / (factorial(blocks) * exp(expected));
}
//-----------------------------------------------------------------------------------------------
static double probability(unsigned int blocks, unsigned int expected)
{
double p = 0.0;
if (blocks < expected)
{
for (unsigned int b = 0; b <= blocks; ++b)
p += probability1(b, expected);
}
else if (blocks > expected)
{
for (unsigned int b = blocks; b <= expected * 3 /* close enough */; ++b)
p += probability1(b, expected);
}
else
p = probability1(blocks, expected);
return p;
}
//-----------------------------------------------------------------------------------------------
bool core::check_block_rate()
{
if (m_offline || m_target_blockchain_height > get_current_blockchain_height())

0 comments on commit 186a3d2

Please sign in to comment.
You can’t perform that action at this time.