Skip to content

Commit 042c323

Browse files
committed
Merge #8275: Remove bad chain alert partition check
ab8be98 Remove bad chain alert partition check (BtcDrak)
2 parents aef3811 + ab8be98 commit 042c323

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
@@ -1447,12 +1447,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
14471447

14481448
StartNode(threadGroup, scheduler);
14491449

1450-
// Monitor the chain, and alert if we get blocks much quicker or slower than expected
1451-
int64_t nPowTargetSpacing = Params().GetConsensus().nPowTargetSpacing;
1452-
CScheduler::Function f = boost::bind(&PartitionCheck, &IsInitialBlockDownload,
1453-
boost::ref(cs_main), boost::cref(pindexBestHeader), nPowTargetSpacing);
1454-
scheduler.scheduleEvery(f, nPowTargetSpacing);
1455-
14561450
// ********************************************************* Step 12: finished
14571451

14581452
SetRPCWarmupFinished();

src/main.cpp

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,68 +2240,6 @@ void ThreadScriptCheck() {
22402240
scriptcheckqueue.Thread();
22412241
}
22422242

2243-
//
2244-
// Called periodically asynchronously; alerts if it smells like
2245-
// we're being fed a bad chain (blocks being generated much
2246-
// too slowly or too quickly).
2247-
//
2248-
void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const CBlockIndex *const &bestHeader,
2249-
int64_t nPowTargetSpacing)
2250-
{
2251-
if (bestHeader == NULL || initialDownloadCheck()) return;
2252-
2253-
static int64_t lastAlertTime = 0;
2254-
int64_t now = GetAdjustedTime();
2255-
if (lastAlertTime > now-60*60*24) return; // Alert at most once per day
2256-
2257-
const int SPAN_HOURS=4;
2258-
const int SPAN_SECONDS=SPAN_HOURS*60*60;
2259-
int BLOCKS_EXPECTED = SPAN_SECONDS / nPowTargetSpacing;
2260-
2261-
boost::math::poisson_distribution<double> poisson(BLOCKS_EXPECTED);
2262-
2263-
std::string strWarning;
2264-
int64_t startTime = GetAdjustedTime()-SPAN_SECONDS;
2265-
2266-
LOCK(cs);
2267-
const CBlockIndex* i = bestHeader;
2268-
int nBlocks = 0;
2269-
while (i->GetBlockTime() >= startTime) {
2270-
++nBlocks;
2271-
i = i->pprev;
2272-
if (i == NULL) return; // Ran out of chain, we must not be fully sync'ed
2273-
}
2274-
2275-
// How likely is it to find that many by chance?
2276-
double p = boost::math::pdf(poisson, nBlocks);
2277-
2278-
LogPrint("partitioncheck", "%s: Found %d blocks in the last %d hours\n", __func__, nBlocks, SPAN_HOURS);
2279-
LogPrint("partitioncheck", "%s: likelihood: %g\n", __func__, p);
2280-
2281-
// Aim for one false-positive about every fifty years of normal running:
2282-
const int FIFTY_YEARS = 50*365*24*60*60;
2283-
double alertThreshold = 1.0 / (FIFTY_YEARS / SPAN_SECONDS);
2284-
2285-
if (p <= alertThreshold && nBlocks < BLOCKS_EXPECTED)
2286-
{
2287-
// Many fewer blocks than expected: alert!
2288-
strWarning = strprintf(_("WARNING: check your network connection, %d blocks received in the last %d hours (%d expected)"),
2289-
nBlocks, SPAN_HOURS, BLOCKS_EXPECTED);
2290-
}
2291-
else if (p <= alertThreshold && nBlocks > BLOCKS_EXPECTED)
2292-
{
2293-
// Many more blocks than expected: alert!
2294-
strWarning = strprintf(_("WARNING: abnormally high number of blocks generated, %d blocks received in the last %d hours (%d expected)"),
2295-
nBlocks, SPAN_HOURS, BLOCKS_EXPECTED);
2296-
}
2297-
if (!strWarning.empty())
2298-
{
2299-
strMiscWarning = strWarning;
2300-
AlertNotify(strWarning);
2301-
lastAlertTime = now;
2302-
}
2303-
}
2304-
23052243
// Protected by cs_main
23062244
VersionBitsCache versionbitscache;
23072245

src/main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,6 @@ bool ProcessMessages(CNode* pfrom);
247247
bool SendMessages(CNode* pto);
248248
/** Run an instance of the script checking thread */
249249
void ThreadScriptCheck();
250-
/** Try to detect Partition (network isolation) attacks against us */
251-
void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const CBlockIndex *const &bestHeader, int64_t nPowTargetSpacing);
252250
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
253251
bool IsInitialBlockDownload();
254252
/** 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)