Skip to content

Commit fd46136

Browse files
committed
IBD check uses minimumchain work instead of checkpoints.
This introduces a 'minimum chain work' chainparam which is intended to be the known amount of work in the chain for the network at the time of software release. If you don't have this much work, you're not yet caught up. This is used instead of the count of blocks test from checkpoints. This criteria is trivial to keep updated as there is no element of subjectivity, trust, or position dependence to it. It is also a more reliable metric of sync status than a block count.
1 parent 3d69ecb commit fd46136

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

doc/release-process.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Before every minor and major release:
1212
* Update [bips.md](bips.md) to account for changes since the last release.
1313
* Update version in sources (see below)
1414
* Write release notes (see below)
15+
* Update `src/chainparams.cpp` nMinimumChainWork with information from the getblockchaininfo rpc.
1516

1617
Before every major release:
1718

src/chainparams.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class CMainParams : public CChainParams {
9696
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1479168000; // November 15th, 2016.
9797
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1510704000; // November 15th, 2017.
9898

99+
// The best chain should have at least this much work.
100+
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000002cb971dd56d1c583c20f90");
101+
99102
/**
100103
* The message start string is designed to be unlikely to occur in normal data.
101104
* The characters are rarely used upper ASCII, not valid as UTF-8, and produce
@@ -191,6 +194,9 @@ class CTestNetParams : public CChainParams {
191194
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1462060800; // May 1st 2016
192195
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1493596800; // May 1st 2017
193196

197+
// The best chain should have at least this much work.
198+
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000198b4def2baa9338d6");
199+
194200
pchMessageStart[0] = 0x0b;
195201
pchMessageStart[1] = 0x11;
196202
pchMessageStart[2] = 0x09;
@@ -224,6 +230,7 @@ class CTestNetParams : public CChainParams {
224230
fRequireStandard = false;
225231
fMineBlocksOnDemand = false;
226232

233+
227234
checkpointData = (CCheckpointData) {
228235
boost::assign::map_list_of
229236
( 546, uint256S("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")),
@@ -265,6 +272,9 @@ class CRegTestParams : public CChainParams {
265272
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 0;
266273
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 999999999999ULL;
267274

275+
// The best chain should have at least this much work.
276+
consensus.nMinimumChainWork = uint256S("0x00");
277+
268278
pchMessageStart[0] = 0xfa;
269279
pchMessageStart[1] = 0xbf;
270280
pchMessageStart[2] = 0xb5;

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct Params {
6161
int64_t nPowTargetSpacing;
6262
int64_t nPowTargetTimespan;
6363
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
64+
uint256 nMinimumChainWork;
6465
};
6566
} // namespace Consensus
6667

src/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,9 @@ bool IsInitialBlockDownload()
17401740
return false;
17411741
if (fImporting || fReindex)
17421742
return true;
1743-
if (fCheckpointsEnabled && chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints()))
1743+
if (chainActive.Tip() == NULL)
1744+
return true;
1745+
if (chainActive.Tip()->nChainWork < UintToArith256(chainParams.GetConsensus().nMinimumChainWork))
17441746
return true;
17451747
bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 ||
17461748
std::max(chainActive.Tip()->GetBlockTime(), pindexBestHeader->GetBlockTime()) < GetTime() - nMaxTipAge);
@@ -1774,7 +1776,7 @@ void CheckForkWarningConditions()
17741776
{
17751777
AssertLockHeld(cs_main);
17761778
// Before we get past initial download, we cannot reliably alert about forks
1777-
// (we assume we don't get stuck on a fork before the last checkpoint)
1779+
// (we assume we don't get stuck on a fork before finishing our initial sync)
17781780
if (IsInitialBlockDownload())
17791781
return;
17801782

0 commit comments

Comments
 (0)