Skip to content

Commit ab8be98

Browse files
committed
Remove bad chain alert partition check
As per meeting 2016-03-31 https://bitcoincore.org/en/meetings/2016/03/31/#bad-chain-alerts The partition checker was producing huge number of false-positives and was disabled in 0.12.1 on the understanding it would either be fixed in 0.13 or removed entirely from master if not.
1 parent 5201614 commit ab8be98

File tree

5 files changed

+0
-150
lines changed

5 files changed

+0
-150
lines changed

src/Makefile.test.include

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ BITCOIN_TESTS =\
3838
test/arith_uint256_tests.cpp \
3939
test/scriptnum10.h \
4040
test/addrman_tests.cpp \
41-
test/alert_tests.cpp \
4241
test/amount_tests.cpp \
4342
test/allocator_tests.cpp \
4443
test/base32_tests.cpp \

src/init.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,12 +1416,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
14161416

14171417
StartNode(threadGroup, scheduler);
14181418

1419-
// Monitor the chain, and alert if we get blocks much quicker or slower than expected
1420-
int64_t nPowTargetSpacing = Params().GetConsensus().nPowTargetSpacing;
1421-
CScheduler::Function f = boost::bind(&PartitionCheck, &IsInitialBlockDownload,
1422-
boost::ref(cs_main), boost::cref(pindexBestHeader), nPowTargetSpacing);
1423-
scheduler.scheduleEvery(f, nPowTargetSpacing);
1424-
14251419
// ********************************************************* Step 12: finished
14261420

14271421
SetRPCWarmupFinished();

src/main.cpp

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,68 +2118,6 @@ void ThreadScriptCheck() {
21182118
scriptcheckqueue.Thread();
21192119
}
21202120

2121-
//
2122-
// Called periodically asynchronously; alerts if it smells like
2123-
// we're being fed a bad chain (blocks being generated much
2124-
// too slowly or too quickly).
2125-
//
2126-
void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const CBlockIndex *const &bestHeader,
2127-
int64_t nPowTargetSpacing)
2128-
{
2129-
if (bestHeader == NULL || initialDownloadCheck()) return;
2130-
2131-
static int64_t lastAlertTime = 0;
2132-
int64_t now = GetAdjustedTime();
2133-
if (lastAlertTime > now-60*60*24) return; // Alert at most once per day
2134-
2135-
const int SPAN_HOURS=4;
2136-
const int SPAN_SECONDS=SPAN_HOURS*60*60;
2137-
int BLOCKS_EXPECTED = SPAN_SECONDS / nPowTargetSpacing;
2138-
2139-
boost::math::poisson_distribution<double> poisson(BLOCKS_EXPECTED);
2140-
2141-
std::string strWarning;
2142-
int64_t startTime = GetAdjustedTime()-SPAN_SECONDS;
2143-
2144-
LOCK(cs);
2145-
const CBlockIndex* i = bestHeader;
2146-
int nBlocks = 0;
2147-
while (i->GetBlockTime() >= startTime) {
2148-
++nBlocks;
2149-
i = i->pprev;
2150-
if (i == NULL) return; // Ran out of chain, we must not be fully sync'ed
2151-
}
2152-
2153-
// How likely is it to find that many by chance?
2154-
double p = boost::math::pdf(poisson, nBlocks);
2155-
2156-
LogPrint("partitioncheck", "%s: Found %d blocks in the last %d hours\n", __func__, nBlocks, SPAN_HOURS);
2157-
LogPrint("partitioncheck", "%s: likelihood: %g\n", __func__, p);
2158-
2159-
// Aim for one false-positive about every fifty years of normal running:
2160-
const int FIFTY_YEARS = 50*365*24*60*60;
2161-
double alertThreshold = 1.0 / (FIFTY_YEARS / SPAN_SECONDS);
2162-
2163-
if (p <= alertThreshold && nBlocks < BLOCKS_EXPECTED)
2164-
{
2165-
// Many fewer blocks than expected: alert!
2166-
strWarning = strprintf(_("WARNING: check your network connection, %d blocks received in the last %d hours (%d expected)"),
2167-
nBlocks, SPAN_HOURS, BLOCKS_EXPECTED);
2168-
}
2169-
else if (p <= alertThreshold && nBlocks > BLOCKS_EXPECTED)
2170-
{
2171-
// Many more blocks than expected: alert!
2172-
strWarning = strprintf(_("WARNING: abnormally high number of blocks generated, %d blocks received in the last %d hours (%d expected)"),
2173-
nBlocks, SPAN_HOURS, BLOCKS_EXPECTED);
2174-
}
2175-
if (!strWarning.empty())
2176-
{
2177-
strMiscWarning = strWarning;
2178-
AlertNotify(strWarning);
2179-
lastAlertTime = now;
2180-
}
2181-
}
2182-
21832121
// Protected by cs_main
21842122
VersionBitsCache versionbitscache;
21852123

src/main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ bool ProcessMessages(CNode* pfrom);
242242
bool SendMessages(CNode* pto);
243243
/** Run an instance of the script checking thread */
244244
void ThreadScriptCheck();
245-
/** Try to detect Partition (network isolation) attacks against us */
246-
void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const CBlockIndex *const &bestHeader, int64_t nPowTargetSpacing);
247245
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
248246
bool IsInitialBlockDownload();
249247
/** Format a string that describes several potential problems detected by the core.

src/test/alert_tests.cpp

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)