Skip to content

Commit

Permalink
Merge #8275: Remove bad chain alert partition check
Browse files Browse the repository at this point in the history
ab8be98 Remove bad chain alert partition check (BtcDrak)
  • Loading branch information
laanwj committed Jul 6, 2016
2 parents aef3811 + ab8be98 commit 042c323
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 150 deletions.
1 change: 0 additions & 1 deletion src/Makefile.test.include
Expand Up @@ -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 \
Expand Down
6 changes: 0 additions & 6 deletions src/init.cpp
Expand Up @@ -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();
Expand Down
62 changes: 0 additions & 62 deletions src/main.cpp
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions src/main.h
Expand Up @@ -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.
Expand Down
79 changes: 0 additions & 79 deletions src/test/alert_tests.cpp

This file was deleted.

0 comments on commit 042c323

Please sign in to comment.