aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-07-06 07:35:39 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-07-06 07:35:54 +0200
commit042c323922fce00a1cd0d955a0c8b8bfa80e4045 (patch)
tree0e2814e730c5b0672621cf6926c59c3ae23e7abb /src
parentaef381161f3bac4a720d9134920b8836a09fb280 (diff)
parentab8be98fdb25b678a8cd7e89adf06d1b1f6bdd62 (diff)
downloadbitcoin-042c323922fce00a1cd0d955a0c8b8bfa80e4045.tar.xz
Merge #8275: Remove bad chain alert partition check
ab8be98 Remove bad chain alert partition check (BtcDrak)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.test.include1
-rw-r--r--src/init.cpp6
-rw-r--r--src/main.cpp62
-rw-r--r--src/main.h2
-rw-r--r--src/test/alert_tests.cpp79
5 files changed, 0 insertions, 150 deletions
diff --git a/src/Makefile.test.include b/src/Makefile.test.include
index c8918eb53f..27e7694748 100644
--- a/src/Makefile.test.include
+++ b/src/Makefile.test.include
@@ -38,7 +38,6 @@ BITCOIN_TESTS =\
test/arith_uint256_tests.cpp \
test/scriptnum10.h \
test/addrman_tests.cpp \
- test/alert_tests.cpp \
test/amount_tests.cpp \
test/allocator_tests.cpp \
test/base32_tests.cpp \
diff --git a/src/init.cpp b/src/init.cpp
index ea4ccaddfc..0f641821d4 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1447,12 +1447,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
StartNode(threadGroup, scheduler);
- // Monitor the chain, and alert if we get blocks much quicker or slower than expected
- int64_t nPowTargetSpacing = Params().GetConsensus().nPowTargetSpacing;
- CScheduler::Function f = boost::bind(&PartitionCheck, &IsInitialBlockDownload,
- boost::ref(cs_main), boost::cref(pindexBestHeader), nPowTargetSpacing);
- scheduler.scheduleEvery(f, nPowTargetSpacing);
-
// ********************************************************* Step 12: finished
SetRPCWarmupFinished();
diff --git a/src/main.cpp b/src/main.cpp
index e26a73bc4b..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;
diff --git a/src/main.h b/src/main.h
index 2ffe5770dc..7ea570d859 100644
--- a/src/main.h
+++ b/src/main.h
@@ -247,8 +247,6 @@ bool ProcessMessages(CNode* pfrom);
bool SendMessages(CNode* pto);
/** Run an instance of the script checking thread */
void ThreadScriptCheck();
-/** Try to detect Partition (network isolation) attacks against us */
-void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const CBlockIndex *const &bestHeader, int64_t nPowTargetSpacing);
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
bool IsInitialBlockDownload();
/** Format a string that describes several potential problems detected by the core.
diff --git a/src/test/alert_tests.cpp b/src/test/alert_tests.cpp
deleted file mode 100644
index 70f1f12273..0000000000
--- a/src/test/alert_tests.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) 2013-2015 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-// Unit tests for alert system
-
-#include "chainparams.h"
-#include "main.h" // For PartitionCheck
-
-#include "test/testutil.h"
-#include "test/test_bitcoin.h"
-
-#include <boost/test/unit_test.hpp>
-
-BOOST_FIXTURE_TEST_SUITE(Alert_tests, TestingSetup)
-
-
-static bool falseFunc() { return false; }
-
-BOOST_AUTO_TEST_CASE(PartitionAlert)
-{
- // Test PartitionCheck
- CCriticalSection csDummy;
- CBlockIndex indexDummy[100];
- CChainParams& params = Params(CBaseChainParams::MAIN);
- int64_t nPowTargetSpacing = params.GetConsensus().nPowTargetSpacing;
-
- // Generate fake blockchain timestamps relative to
- // an arbitrary time:
- int64_t now = 1427379054;
- SetMockTime(now);
- for (int i = 0; i < 100; i++)
- {
- indexDummy[i].phashBlock = NULL;
- if (i == 0) indexDummy[i].pprev = NULL;
- else indexDummy[i].pprev = &indexDummy[i-1];
- indexDummy[i].nHeight = i;
- indexDummy[i].nTime = now - (100-i)*nPowTargetSpacing;
- // Other members don't matter, the partition check code doesn't
- // use them
- }
-
- strMiscWarning = "";
-
- // Test 1: chain with blocks every nPowTargetSpacing seconds,
- // as normal, no worries:
- PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing);
- BOOST_CHECK_MESSAGE(strMiscWarning.empty(), strMiscWarning);
-
- // Test 2: go 3.5 hours without a block, expect a warning:
- now += 3*60*60+30*60;
- SetMockTime(now);
- PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing);
- BOOST_CHECK(!strMiscWarning.empty());
- BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning);
- strMiscWarning = "";
-
- // Test 3: test the "partition alerts only go off once per day"
- // code:
- now += 60*10;
- SetMockTime(now);
- PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing);
- BOOST_CHECK(strMiscWarning.empty());
-
- // Test 4: get 2.5 times as many blocks as expected:
- now += 60*60*24; // Pretend it is a day later
- SetMockTime(now);
- int64_t quickSpacing = nPowTargetSpacing*2/5;
- for (int i = 0; i < 100; i++) // Tweak chain timestamps:
- indexDummy[i].nTime = now - (100-i)*quickSpacing;
- PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing);
- BOOST_CHECK(!strMiscWarning.empty());
- BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning);
- strMiscWarning = "";
-
- SetMockTime(0);
-}
-
-BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file