Skip to content

Commit 508404d

Browse files
committed
Merge #9053: IBD using chainwork instead of height and not using header timestamps
e141beb IsInitialBlockDownload no longer uses header-only timestamps. (Gregory Maxwell) 2082b55 Remove GetTotalBlocksEstimate and checkpoint tests that test nothing. (Gregory Maxwell) fd46136 IBD check uses minimumchain work instead of checkpoints. (Gregory Maxwell)
2 parents ed0cc50 + e141beb commit 508404d

File tree

8 files changed

+20
-48
lines changed

8 files changed

+20
-48
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/Makefile.test.include

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ BITCOIN_TESTS =\
5050
test/bip32_tests.cpp \
5151
test/blockencodings_tests.cpp \
5252
test/bloom_tests.cpp \
53-
test/Checkpoints_tests.cpp \
5453
test/coins_tests.cpp \
5554
test/compress_tests.cpp \
5655
test/crypto_tests.cpp \

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/checkpoints.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@ namespace Checkpoints {
5555
return fWorkBefore / (fWorkBefore + fWorkAfter);
5656
}
5757

58-
int GetTotalBlocksEstimate(const CCheckpointData& data)
59-
{
60-
const MapCheckpoints& checkpoints = data.mapCheckpoints;
61-
62-
if (checkpoints.empty())
63-
return 0;
64-
65-
return checkpoints.rbegin()->first;
66-
}
67-
6858
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
6959
{
7060
const MapCheckpoints& checkpoints = data.mapCheckpoints;

src/checkpoints.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ struct CCheckpointData;
1919
namespace Checkpoints
2020
{
2121

22-
//! Return conservative estimate of total number of blocks, 0 if unknown
23-
int GetTotalBlocksEstimate(const CCheckpointData& data);
24-
2522
//! Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
2623
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data);
2724

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: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,13 +1746,14 @@ bool IsInitialBlockDownload()
17461746
return false;
17471747
if (fImporting || fReindex)
17481748
return true;
1749-
if (fCheckpointsEnabled && chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints()))
1749+
if (chainActive.Tip() == NULL)
17501750
return true;
1751-
bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 ||
1752-
std::max(chainActive.Tip()->GetBlockTime(), pindexBestHeader->GetBlockTime()) < GetTime() - nMaxTipAge);
1753-
if (!state)
1754-
latchToFalse.store(true, std::memory_order_relaxed);
1755-
return state;
1751+
if (chainActive.Tip()->nChainWork < UintToArith256(chainParams.GetConsensus().nMinimumChainWork))
1752+
return true;
1753+
if (chainActive.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge))
1754+
return true;
1755+
latchToFalse.store(true, std::memory_order_relaxed);
1756+
return false;
17561757
}
17571758

17581759
bool fLargeWorkForkFound = false;
@@ -1780,7 +1781,7 @@ void CheckForkWarningConditions()
17801781
{
17811782
AssertLockHeld(cs_main);
17821783
// Before we get past initial download, we cannot reliably alert about forks
1783-
// (we assume we don't get stuck on a fork before the last checkpoint)
1784+
// (we assume we don't get stuck on a fork before finishing our initial sync)
17841785
if (IsInitialBlockDownload())
17851786
return;
17861787

src/test/Checkpoints_tests.cpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)