mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Merge pull request #6256
65b9454 Use best header chain timestamps to detect partitioning (Gavin Andresen)
This commit is contained in:
16
src/main.cpp
16
src/main.cpp
@@ -1723,9 +1723,10 @@ void ThreadScriptCheck() {
|
||||
// we're being fed a bad chain (blocks being generated much
|
||||
// too slowly or too quickly).
|
||||
//
|
||||
void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const CChain& chain, int64_t nPowTargetSpacing)
|
||||
void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const CBlockIndex *const &bestHeader,
|
||||
int64_t nPowTargetSpacing)
|
||||
{
|
||||
if (initialDownloadCheck()) return;
|
||||
if (bestHeader == NULL || initialDownloadCheck()) return;
|
||||
|
||||
static int64_t lastAlertTime = 0;
|
||||
int64_t now = GetAdjustedTime();
|
||||
@@ -1741,10 +1742,13 @@ void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const
|
||||
int64_t startTime = GetAdjustedTime()-SPAN_SECONDS;
|
||||
|
||||
LOCK(cs);
|
||||
int h = chain.Height();
|
||||
while (h > 0 && chain[h]->GetBlockTime() >= startTime)
|
||||
--h;
|
||||
int nBlocks = chain.Height()-h;
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user