diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-06-12 16:41:21 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-06-12 16:44:36 +0200 |
commit | 8ccc07c077d338bbfc673afd1a9a188038df70d3 (patch) | |
tree | a48c9b586b8b59e08586b934e867ea40bc167854 /src/main.cpp | |
parent | ebab5d3c59558000f0e0fd18b7f26ed6f31ac21a (diff) | |
parent | 65b94545036ae6e38e79e9c7166a3ba1ddb83f66 (diff) |
Merge pull request #6256
65b9454 Use best header chain timestamps to detect partitioning (Gavin Andresen)
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp index 69c972a79f..082ef6b6b2 100644 --- a/src/main.cpp +++ b/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); |