diff options
| author | Gavin Andresen <[email protected]> | 2015-06-08 16:34:58 -0400 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2015-06-15 10:34:07 +0200 |
| commit | fce474c9dfa1fd3f98f14f7c2866a6001b21ac9a (patch) | |
| tree | 19ffbac3670246fabbf1292ef9f96d4cba9ad66b /src/main.cpp | |
| parent | Add option `-alerts` to opt out of alert system (diff) | |
| download | discoin-fce474c9dfa1fd3f98f14f7c2866a6001b21ac9a.tar.xz discoin-fce474c9dfa1fd3f98f14f7c2866a6001b21ac9a.zip | |
Use best header chain timestamps to detect partitioning
The partition checking code was using chainActive timestamps
to detect partitioning; with headers-first syncing, it should use
(and with this pull request, does use) pIndexBestHeader timestamps.
Fixes issue #6251
Github-Pull: #6256
Rebased-From: 65b94545036ae6e38e79e9c7166a3ba1ddb83f66
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 ae9e57557..e08c3df9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1712,9 +1712,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(); @@ -1730,10 +1731,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); |