Remove unused partition check code
This code is unused and was disabled in BTC core and then deleted, since it didn't work correctly: https://github.com/bitcoin/bitcoin/pull/8275
This commit is contained in:
73
src/main.cpp
73
src/main.cpp
@@ -3043,77 +3043,12 @@ void ThreadScriptCheck() {
|
|||||||
scriptcheckqueue.Thread();
|
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;
|
static int64_t nTimeVerify = 0;
|
||||||
int64_t now = GetTime();
|
static int64_t nTimeConnect = 0;
|
||||||
if (lastAlertTime > now-60*60*24) return; // Alert at most once per day
|
static int64_t nTimeIndex = 0;
|
||||||
|
|
||||||
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 = GetTime()-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 synced
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 (bestHeader->GetHeight() > BLOCKS_EXPECTED)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
CAlert::Notify(strWarning, true);
|
|
||||||
lastAlertTime = now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int64_t nTimeVerify = 0;
|
|
||||||
static int64_t nTimeConnect = 0;
|
|
||||||
static int64_t nTimeIndex = 0;
|
|
||||||
static int64_t nTimeCallbacks = 0;
|
static int64_t nTimeCallbacks = 0;
|
||||||
static int64_t nTimeTotal = 0;
|
static int64_t nTimeTotal = 0;
|
||||||
bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false);
|
bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false);
|
||||||
bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos);
|
bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos);
|
||||||
|
|
||||||
|
|||||||
@@ -239,8 +239,7 @@ bool ProcessMessages(CNode* pfrom);
|
|||||||
bool SendMessages(CNode* pto, bool fSendTrickle);
|
bool SendMessages(CNode* pto, bool fSendTrickle);
|
||||||
/** Run an instance of the script checking thread */
|
/** Run an instance of the script checking thread */
|
||||||
void ThreadScriptCheck();
|
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) */
|
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
|
||||||
bool IsInitialBlockDownload();
|
bool IsInitialBlockDownload();
|
||||||
/** Check if the daemon is in sync, if not, it returns 1 or if due to best header only, the difference in best
|
/** Check if the daemon is in sync, if not, it returns 1 or if due to best header only, the difference in best
|
||||||
|
|||||||
Reference in New Issue
Block a user