From 1bf644c43ff7eda975fbfec1d1ad53db8e0856cf Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Sat, 22 Oct 2016 05:33:25 +0000 Subject: [PATCH] IBD check uses minimumchain work instead of checkpoints. --- src/chainparams.cpp | 10 ++++++++++ src/consensus/params.h | 1 + src/main.cpp | 6 ++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 3d7182423..d4c6e8c59 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -119,6 +119,9 @@ public: consensus.nStakeMinConfirmations = 500; consensus.nStakeMinAge = 8 * 60 * 60; // 8 hours + // The best chain should have at least this much work. + consensus.nMinimumChainWork = uint256S("0x00"); + /** * The message start string is designed to be unlikely to occur in normal data. * The characters are rarely used upper ASCII, not valid as UTF-8, and produce @@ -215,6 +218,10 @@ public: pchMessageStart[3] = 0xef; nDefaultPort = 25714; nMaxTipAge = 0x7fffffff; + + // The best chain should have at least this much work. + consensus.nMinimumChainWork = uint256S("0x00"); + nPruneAfterHeight = 1000; genesis = CreateGenesisBlock(1393221600, 216178, 0x1f00ffff, 1, 0); @@ -280,6 +287,9 @@ public: consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008 consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008 + // The best chain should have at least this much work. + consensus.nMinimumChainWork = uint256S("0x00"); + // Deployment of BIP68, BIP112, and BIP113. // consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0; // consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 999999999999ULL; // never diff --git a/src/consensus/params.h b/src/consensus/params.h index d43c865ec..e59236eed 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -75,6 +75,7 @@ struct Params { int nCoinbaseMaturity; int nStakeMinConfirmations; unsigned int nStakeMinAge; + uint256 nMinimumChainWork; }; } // namespace Consensus diff --git a/src/main.cpp b/src/main.cpp index d8c613f24..0110a8d4b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1698,7 +1698,9 @@ bool IsInitialBlockDownload() LOCK(cs_main); if (fImporting || fReindex) return true; - if (fCheckpointsEnabled && chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints())) + if (chainActive.Tip() == NULL) + return true; + if (chainActive.Tip()->nChainWork < UintToArith256(chainParams.GetConsensus().nMinimumChainWork)) return true; static bool lockIBDState = false; if (lockIBDState) @@ -1738,7 +1740,7 @@ void CheckForkWarningConditions() { AssertLockHeld(cs_main); // Before we get past initial download, we cannot reliably alert about forks - // (we assume we don't get stuck on a fork before the last checkpoint) + // (we assume we don't get stuck on a fork before finishing our initial sync) if (IsInitialBlockDownload()) return;