aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2019-04-01 17:28:55 +0200
committerRiccardo Spagni <ric@spagni.net>2019-04-01 17:28:55 +0200
commit55d7eb06a8d51449c2018bcbe1bbf4c1c3b2c17b (patch)
tree72b9de4a4babecf84c86038c779e88b420922775 /src/cryptonote_core
parentMerge pull request #5313 (diff)
parentcore: improve block rate monitor trigger probabilities (diff)
downloadmonero-55d7eb06a8d51449c2018bcbe1bbf4c1c3b2c17b.tar.xz
Merge pull request #5317
1730a44f core: improve block rate monitor trigger probabilities (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 387203cc0..da413bbe2 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -1784,12 +1784,28 @@ 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);
+ }
+ return p;
+ }
+ //-----------------------------------------------------------------------------------------------
bool core::check_block_rate()
{
if (m_offline || m_target_blockchain_height > get_current_blockchain_height())