@@ -56,6 +56,7 @@ bool fHavePruned = false;
56
56
bool fPruneMode = false ;
57
57
bool fIsBareMultisigStd = true ;
58
58
bool fCheckBlockIndex = false ;
59
+ bool fCheckpointsEnabled = true ;
59
60
unsigned int nCoinCacheSize = 5000 ;
60
61
uint64_t nPruneTarget = 0 ;
61
62
@@ -1205,8 +1206,11 @@ CAmount GetBlockValue(int nHeight, const CAmount& nFees)
1205
1206
1206
1207
bool IsInitialBlockDownload ()
1207
1208
{
1209
+ const CChainParams& chainParams = Params ();
1208
1210
LOCK (cs_main);
1209
- if (fImporting || fReindex || chainActive.Height () < Checkpoints::GetTotalBlocksEstimate ())
1211
+ if (fImporting || fReindex )
1212
+ return true ;
1213
+ if (fCheckpointsEnabled && chainActive.Height () < Checkpoints::GetTotalBlocksEstimate (chainParams.Checkpoints ()))
1210
1214
return true ;
1211
1215
static bool lockIBDState = false ;
1212
1216
if (lockIBDState)
@@ -1710,7 +1714,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
1710
1714
return true ;
1711
1715
}
1712
1716
1713
- bool fScriptChecks = pindex->nHeight >= Checkpoints::GetTotalBlocksEstimate ();
1717
+ bool fScriptChecks = (! fCheckpointsEnabled || pindex->nHeight >= Checkpoints::GetTotalBlocksEstimate (chainparams. Checkpoints ()) );
1714
1718
1715
1719
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
1716
1720
// unless those are already completely spent.
@@ -1955,6 +1959,7 @@ void PruneAndFlush() {
1955
1959
1956
1960
/* * Update chainActive and related internal data structures. */
1957
1961
void static UpdateTip (CBlockIndex *pindexNew) {
1962
+ const CChainParams& chainParams = Params ();
1958
1963
chainActive.SetTip (pindexNew);
1959
1964
1960
1965
// New best block
@@ -1964,7 +1969,7 @@ void static UpdateTip(CBlockIndex *pindexNew) {
1964
1969
LogPrintf (" %s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%u\n " , __func__,
1965
1970
chainActive.Tip ()->GetBlockHash ().ToString (), chainActive.Height (), log (chainActive.Tip ()->nChainWork .getdouble ())/log (2.0 ), (unsigned long )chainActive.Tip ()->nChainTx ,
1966
1971
DateTimeStrFormat (" %Y-%m-%d %H:%M:%S" , chainActive.Tip ()->GetBlockTime ()),
1967
- Checkpoints::GuessVerificationProgress (chainActive.Tip ()), (unsigned int )pcoinsTip->GetCacheSize ());
1972
+ Checkpoints::GuessVerificationProgress (chainParams. Checkpoints (), chainActive.Tip ()), (unsigned int )pcoinsTip->GetCacheSize ());
1968
1973
1969
1974
cvBlockChange.notify_all ();
1970
1975
@@ -2248,6 +2253,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
2248
2253
bool ActivateBestChain (CValidationState &state, CBlock *pblock) {
2249
2254
CBlockIndex *pindexNewTip = NULL ;
2250
2255
CBlockIndex *pindexMostWork = NULL ;
2256
+ const CChainParams& chainParams = Params ();
2251
2257
do {
2252
2258
boost::this_thread::interruption_point ();
2253
2259
@@ -2272,7 +2278,9 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) {
2272
2278
if (!fInitialDownload ) {
2273
2279
uint256 hashNewTip = pindexNewTip->GetBlockHash ();
2274
2280
// Relay inventory, but don't relay old inventory during initial block download.
2275
- int nBlockEstimate = Checkpoints::GetTotalBlocksEstimate ();
2281
+ int nBlockEstimate = 0 ;
2282
+ if (fCheckpointsEnabled )
2283
+ nBlockEstimate = Checkpoints::GetTotalBlocksEstimate (chainParams.Checkpoints ());
2276
2284
// Don't relay blocks if pruning -- could cause a peer to try to download, resulting
2277
2285
// in a stalled download if the block file is pruned before the request.
2278
2286
if (nLocalServices & NODE_NETWORK) {
@@ -2602,7 +2610,8 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
2602
2610
2603
2611
bool ContextualCheckBlockHeader (const CBlockHeader& block, CValidationState& state, CBlockIndex * const pindexPrev)
2604
2612
{
2605
- const Consensus::Params& consensusParams = Params ().GetConsensus ();
2613
+ const CChainParams& chainParams = Params ();
2614
+ const Consensus::Params& consensusParams = chainParams.GetConsensus ();
2606
2615
uint256 hash = block.GetHash ();
2607
2616
if (hash == consensusParams.hashGenesisBlock )
2608
2617
return true ;
@@ -2612,7 +2621,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
2612
2621
int nHeight = pindexPrev->nHeight +1 ;
2613
2622
2614
2623
// Check proof of work
2615
- if (block.nBits != GetNextWorkRequired (pindexPrev, &block, Params (). GetConsensus () ))
2624
+ if (block.nBits != GetNextWorkRequired (pindexPrev, &block, consensusParams ))
2616
2625
return state.DoS (100 , error (" %s: incorrect proof of work" , __func__),
2617
2626
REJECT_INVALID, " bad-diffbits" );
2618
2627
@@ -2621,25 +2630,28 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
2621
2630
return state.Invalid (error (" %s: block's timestamp is too early" , __func__),
2622
2631
REJECT_INVALID, " time-too-old" );
2623
2632
2624
- // Check that the block chain matches the known block chain up to a checkpoint
2625
- if (!Checkpoints::CheckBlock (nHeight, hash))
2626
- return state.DoS (100 , error (" %s: rejected by checkpoint lock-in at %d" , __func__, nHeight),
2627
- REJECT_CHECKPOINT, " checkpoint mismatch" );
2633
+ if (fCheckpointsEnabled )
2634
+ {
2635
+ // Check that the block chain matches the known block chain up to a checkpoint
2636
+ if (!Checkpoints::CheckBlock (chainParams.Checkpoints (), nHeight, hash))
2637
+ return state.DoS (100 , error (" %s: rejected by checkpoint lock-in at %d" , __func__, nHeight),
2638
+ REJECT_CHECKPOINT, " checkpoint mismatch" );
2628
2639
2629
- // Don't accept any forks from the main chain prior to last checkpoint
2630
- CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint ();
2631
- if (pcheckpoint && nHeight < pcheckpoint->nHeight )
2632
- return state.DoS (100 , error (" %s: forked chain older than last checkpoint (height %d)" , __func__, nHeight));
2640
+ // Don't accept any forks from the main chain prior to last checkpoint
2641
+ CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint (chainParams.Checkpoints ());
2642
+ if (pcheckpoint && nHeight < pcheckpoint->nHeight )
2643
+ return state.DoS (100 , error (" %s: forked chain older than last checkpoint (height %d)" , __func__, nHeight));
2644
+ }
2633
2645
2634
2646
// Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded:
2635
- if (block.nVersion < 2 && IsSuperMajority (2 , pindexPrev, Params (). RejectBlockOutdatedMajority () ))
2647
+ if (block.nVersion < 2 && IsSuperMajority (2 , pindexPrev, consensusParams. nMajorityRejectBlockOutdated ))
2636
2648
{
2637
2649
return state.Invalid (error (" %s: rejected nVersion=1 block" , __func__),
2638
2650
REJECT_OBSOLETE, " bad-version" );
2639
2651
}
2640
2652
2641
2653
// Reject block.nVersion=2 blocks when 95% (75% on testnet) of the network has upgraded:
2642
- if (block.nVersion < 3 && IsSuperMajority (3 , pindexPrev, Params (). RejectBlockOutdatedMajority () ))
2654
+ if (block.nVersion < 3 && IsSuperMajority (3 , pindexPrev, consensusParams. nMajorityRejectBlockOutdated ))
2643
2655
{
2644
2656
return state.Invalid (error (" %s : rejected nVersion=2 block" , __func__),
2645
2657
REJECT_OBSOLETE, " bad-version" );
@@ -3026,6 +3038,7 @@ CBlockIndex * InsertBlockIndex(uint256 hash)
3026
3038
3027
3039
bool static LoadBlockIndexDB ()
3028
3040
{
3041
+ const CChainParams& chainparams = Params ();
3029
3042
if (!pblocktree->LoadBlockIndexGuts ())
3030
3043
return false ;
3031
3044
@@ -3128,7 +3141,7 @@ bool static LoadBlockIndexDB()
3128
3141
LogPrintf (" %s: hashBestChain=%s height=%d date=%s progress=%f\n " , __func__,
3129
3142
chainActive.Tip ()->GetBlockHash ().ToString (), chainActive.Height (),
3130
3143
DateTimeStrFormat (" %Y-%m-%d %H:%M:%S" , chainActive.Tip ()->GetBlockTime ()),
3131
- Checkpoints::GuessVerificationProgress (chainActive.Tip ()));
3144
+ Checkpoints::GuessVerificationProgress (chainparams. Checkpoints (), chainActive.Tip ()));
3132
3145
3133
3146
return true ;
3134
3147
}
0 commit comments