Browse Source

checkpoints: move the checkpoints enable boolean into main

This pertains to app-state, so it doesn't make sense to handle inside the
checkpoint functions.
0.13
Cory Fields 10 years ago
parent
commit
a8cdaf5c96
  1. 14
      src/checkpoints.cpp
  2. 2
      src/checkpoints.h
  3. 2
      src/init.cpp
  4. 14
      src/main.cpp
  5. 1
      src/main.h
  6. 4
      src/test/miner_tests.cpp

14
src/checkpoints.cpp

@ -23,13 +23,8 @@ namespace Checkpoints { @@ -23,13 +23,8 @@ namespace Checkpoints {
*/
static const double SIGCHECK_VERIFICATION_FACTOR = 5.0;
bool fEnabled = true;
bool CheckBlock(const CCheckpointData& data, int nHeight, const uint256& hash)
{
if (!fEnabled)
return true;
const MapCheckpoints& checkpoints = data.mapCheckpoints;
MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
@ -69,19 +64,16 @@ namespace Checkpoints { @@ -69,19 +64,16 @@ namespace Checkpoints {
int GetTotalBlocksEstimate(const CCheckpointData& data)
{
if (!fEnabled)
return 0;
const MapCheckpoints& checkpoints = data.mapCheckpoints;
if (checkpoints.empty())
return 0;
return checkpoints.rbegin()->first;
}
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
{
if (!fEnabled)
return NULL;
const MapCheckpoints& checkpoints = data.mapCheckpoints;
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)

2
src/checkpoints.h

@ -37,8 +37,6 @@ CBlockIndex* GetLastCheckpoint(const CCheckpointData& data); @@ -37,8 +37,6 @@ CBlockIndex* GetLastCheckpoint(const CCheckpointData& data);
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex* pindex, bool fSigchecks = true);
extern bool fEnabled;
} //namespace Checkpoints
#endif // BITCOIN_CHECKPOINTS_H

2
src/init.cpp

@ -741,7 +741,7 @@ bool AppInit2(boost::thread_group& threadGroup) @@ -741,7 +741,7 @@ bool AppInit2(boost::thread_group& threadGroup)
// Checkmempool and checkblockindex default to true in regtest mode
mempool.setSanityCheck(GetBoolArg("-checkmempool", chainparams.DefaultConsistencyChecks()));
fCheckBlockIndex = GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
Checkpoints::fEnabled = GetBoolArg("-checkpoints", true);
fCheckpointsEnabled = GetBoolArg("-checkpoints", true);
// -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency
nScriptCheckThreads = GetArg("-par", DEFAULT_SCRIPTCHECK_THREADS);

14
src/main.cpp

@ -56,6 +56,7 @@ bool fHavePruned = false; @@ -56,6 +56,7 @@ bool fHavePruned = false;
bool fPruneMode = false;
bool fIsBareMultisigStd = true;
bool fCheckBlockIndex = false;
bool fCheckpointsEnabled = true;
unsigned int nCoinCacheSize = 5000;
uint64_t nPruneTarget = 0;
@ -1206,7 +1207,9 @@ bool IsInitialBlockDownload() @@ -1206,7 +1207,9 @@ bool IsInitialBlockDownload()
{
const CChainParams& chainParams = Params();
LOCK(cs_main);
if (fImporting || fReindex || chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints()))
if (fImporting || fReindex)
return true;
if (fCheckpointsEnabled && chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints()))
return true;
static bool lockIBDState = false;
if (lockIBDState)
@ -1710,7 +1713,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin @@ -1710,7 +1713,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
return true;
}
bool fScriptChecks = pindex->nHeight >= Checkpoints::GetTotalBlocksEstimate(chainparams.Checkpoints());
bool fScriptChecks = (!fCheckpointsEnabled || pindex->nHeight >= Checkpoints::GetTotalBlocksEstimate(chainparams.Checkpoints()));
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
// unless those are already completely spent.
@ -2274,7 +2277,9 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) { @@ -2274,7 +2277,9 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) {
if (!fInitialDownload) {
uint256 hashNewTip = pindexNewTip->GetBlockHash();
// Relay inventory, but don't relay old inventory during initial block download.
int nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints());
int nBlockEstimate = 0;
if (fCheckpointsEnabled)
nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints());
// Don't relay blocks if pruning -- could cause a peer to try to download, resulting
// in a stalled download if the block file is pruned before the request.
if (nLocalServices & NODE_NETWORK) {
@ -2624,6 +2629,8 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta @@ -2624,6 +2629,8 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
return state.Invalid(error("%s: block's timestamp is too early", __func__),
REJECT_INVALID, "time-too-old");
if(fCheckpointsEnabled)
{
// Check that the block chain matches the known block chain up to a checkpoint
if (!Checkpoints::CheckBlock(chainParams.Checkpoints(), nHeight, hash))
return state.DoS(100, error("%s: rejected by checkpoint lock-in at %d", __func__, nHeight),
@ -2633,6 +2640,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta @@ -2633,6 +2640,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints());
if (pcheckpoint && nHeight < pcheckpoint->nHeight)
return state.DoS(100, error("%s: forked chain older than last checkpoint (height %d)", __func__, nHeight));
}
// Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded:
if (block.nVersion < 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityRejectBlockOutdated))

1
src/main.h

@ -118,6 +118,7 @@ extern int nScriptCheckThreads; @@ -118,6 +118,7 @@ extern int nScriptCheckThreads;
extern bool fTxIndex;
extern bool fIsBareMultisigStd;
extern bool fCheckBlockIndex;
extern bool fCheckpointsEnabled;
extern unsigned int nCoinCacheSize;
extern CFeeRate minRelayTxFee;

4
src/test/miner_tests.cpp

@ -59,7 +59,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) @@ -59,7 +59,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
uint256 hash;
LOCK(cs_main);
Checkpoints::fEnabled = false;
fCheckpointsEnabled = false;
// Simple block creation, nothing special yet:
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) @@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
BOOST_FOREACH(CTransaction *tx, txFirst)
delete tx;
Checkpoints::fEnabled = true;
fCheckpointsEnabled = true;
}
BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save