aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp71
1 files changed, 1 insertions, 70 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 6cdd55e397..b86bbda1b8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2240,68 +2240,6 @@ void ThreadScriptCheck() {
scriptcheckqueue.Thread();
}
-//
-// Called periodically asynchronously; alerts if it smells like
-// we're being fed a bad chain (blocks being generated much
-// too slowly or too quickly).
-//
-void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const CBlockIndex *const &bestHeader,
- int64_t nPowTargetSpacing)
-{
- if (bestHeader == NULL || initialDownloadCheck()) return;
-
- static int64_t lastAlertTime = 0;
- int64_t now = GetAdjustedTime();
- if (lastAlertTime > now-60*60*24) return; // Alert at most once per day
-
- const int SPAN_HOURS=4;
- const int SPAN_SECONDS=SPAN_HOURS*60*60;
- int BLOCKS_EXPECTED = SPAN_SECONDS / nPowTargetSpacing;
-
- boost::math::poisson_distribution<double> poisson(BLOCKS_EXPECTED);
-
- std::string strWarning;
- int64_t startTime = GetAdjustedTime()-SPAN_SECONDS;
-
- LOCK(cs);
- const CBlockIndex* i = bestHeader;
- int nBlocks = 0;
- while (i->GetBlockTime() >= startTime) {
- ++nBlocks;
- i = i->pprev;
- if (i == NULL) return; // Ran out of chain, we must not be fully sync'ed
- }
-
- // How likely is it to find that many by chance?
- double p = boost::math::pdf(poisson, nBlocks);
-
- LogPrint("partitioncheck", "%s: Found %d blocks in the last %d hours\n", __func__, nBlocks, SPAN_HOURS);
- LogPrint("partitioncheck", "%s: likelihood: %g\n", __func__, p);
-
- // Aim for one false-positive about every fifty years of normal running:
- const int FIFTY_YEARS = 50*365*24*60*60;
- double alertThreshold = 1.0 / (FIFTY_YEARS / SPAN_SECONDS);
-
- if (p <= alertThreshold && nBlocks < BLOCKS_EXPECTED)
- {
- // Many fewer blocks than expected: alert!
- strWarning = strprintf(_("WARNING: check your network connection, %d blocks received in the last %d hours (%d expected)"),
- nBlocks, SPAN_HOURS, BLOCKS_EXPECTED);
- }
- else if (p <= alertThreshold && nBlocks > BLOCKS_EXPECTED)
- {
- // Many more blocks than expected: alert!
- strWarning = strprintf(_("WARNING: abnormally high number of blocks generated, %d blocks received in the last %d hours (%d expected)"),
- nBlocks, SPAN_HOURS, BLOCKS_EXPECTED);
- }
- if (!strWarning.empty())
- {
- strMiscWarning = strWarning;
- AlertNotify(strWarning);
- lastAlertTime = now;
- }
-}
-
// Protected by cs_main
VersionBitsCache versionbitscache;
@@ -5835,13 +5773,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
return true;
}
- // If we already know the last header in the message, then it contains
- // no new information for us. In this case, we do not request
- // more headers later. This prevents multiple chains of redundant
- // getheader requests from running in parallel if triggered by incoming
- // blocks while the node is still in initial headers sync.
- const bool hasNewHeaders = (mapBlockIndex.count(headers.back().GetHash()) == 0);
-
CBlockIndex *pindexLast = NULL;
BOOST_FOREACH(const CBlockHeader& header, headers) {
CValidationState state;
@@ -5862,7 +5793,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
assert(pindexLast);
UpdateBlockAvailability(pfrom->GetId(), pindexLast->GetBlockHash());
- if (nCount == MAX_HEADERS_RESULTS && hasNewHeaders) {
+ if (nCount == MAX_HEADERS_RESULTS) {
// Headers message had its maximum size; the peer may have more headers.
// TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue
// from there instead.