@ -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 ;
@ -1205,8 +1206,11 @@ CAmount GetBlockValue(int nHeight, const CAmount& nFees)
@@ -1205,8 +1206,11 @@ CAmount GetBlockValue(int nHeight, const CAmount& nFees)
bool IsInitialBlockDownload ( )
{
const CChainParams & chainParams = Params ( ) ;
LOCK ( cs_main ) ;
if ( fImporting | | fReindex | | chainActive . Height ( ) < Checkpoints : : GetTotalBlocksEstimate ( ) )
if ( fImporting | | fReindex )
return true ;
if ( fCheckpointsEnabled & & chainActive . Height ( ) < Checkpoints : : GetTotalBlocksEstimate ( chainParams . Checkpoints ( ) ) )
return true ;
static bool lockIBDState = false ;
if ( lockIBDState )
@ -1710,7 +1714,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
@@ -1710,7 +1714,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
return true ;
}
bool fScriptChecks = pindex - > nHeight > = Checkpoints : : GetTotalBlocksEstimate ( ) ;
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.
@ -1955,6 +1959,7 @@ void PruneAndFlush() {
@@ -1955,6 +1959,7 @@ void PruneAndFlush() {
/** Update chainActive and related internal data structures. */
void static UpdateTip ( CBlockIndex * pindexNew ) {
const CChainParams & chainParams = Params ( ) ;
chainActive . SetTip ( pindexNew ) ;
// New best block
@ -1964,7 +1969,7 @@ void static UpdateTip(CBlockIndex *pindexNew) {
@@ -1964,7 +1969,7 @@ void static UpdateTip(CBlockIndex *pindexNew) {
LogPrintf ( " %s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%u \n " , __func__ ,
chainActive . Tip ( ) - > GetBlockHash ( ) . ToString ( ) , chainActive . Height ( ) , log ( chainActive . Tip ( ) - > nChainWork . getdouble ( ) ) / log ( 2.0 ) , ( unsigned long ) chainActive . Tip ( ) - > nChainTx ,
DateTimeStrFormat ( " %Y-%m-%d %H:%M:%S " , chainActive . Tip ( ) - > GetBlockTime ( ) ) ,
Checkpoints : : GuessVerificationProgress ( chainActive . Tip ( ) ) , ( unsigned int ) pcoinsTip - > GetCacheSize ( ) ) ;
Checkpoints : : GuessVerificationProgress ( chainParams . Checkpoints ( ) , chain Active . Tip ( ) ) , ( unsigned int ) pcoinsTip - > GetCacheSize ( ) ) ;
cvBlockChange . notify_all ( ) ;
@ -2248,6 +2253,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
@@ -2248,6 +2253,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
bool ActivateBestChain ( CValidationState & state , CBlock * pblock ) {
CBlockIndex * pindexNewTip = NULL ;
CBlockIndex * pindexMostWork = NULL ;
const CChainParams & chainParams = Params ( ) ;
do {
boost : : this_thread : : interruption_point ( ) ;
@ -2272,7 +2278,9 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) {
@@ -2272,7 +2278,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 ( ) ;
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 ) {
@ -2602,7 +2610,8 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
@@ -2602,7 +2610,8 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
bool ContextualCheckBlockHeader ( const CBlockHeader & block , CValidationState & state , CBlockIndex * const pindexPrev )
{
const Consensus : : Params & consensusParams = Params ( ) . GetConsensus ( ) ;
const CChainParams & chainParams = Params ( ) ;
const Consensus : : Params & consensusParams = chainParams . GetConsensus ( ) ;
uint256 hash = block . GetHash ( ) ;
if ( hash = = consensusParams . hashGenesisBlock )
return true ;
@ -2612,7 +2621,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
@@ -2612,7 +2621,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
int nHeight = pindexPrev - > nHeight + 1 ;
// Check proof of work
if ( block . nBits ! = GetNextWorkRequired ( pindexPrev , & block , Params ( ) . GetConsensus ( ) ) )
if ( block . nBits ! = GetNextWorkRequired ( pindexPrev , & block , consensusParams ) )
return state . DoS ( 100 , error ( " %s: incorrect proof of work " , __func__ ) ,
REJECT_INVALID , " bad-diffbits " ) ;
@ -2621,25 +2630,28 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
@@ -2621,25 +2630,28 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
return state . Invalid ( error ( " %s: block's timestamp is too early " , __func__ ) ,
REJECT_INVALID , " time-too-old " ) ;
// Check that the block chain matches the known block chain up to a checkpoint
if ( ! Checkpoints : : CheckBlock ( nHeight , hash ) )
return state . DoS ( 100 , error ( " %s: rejected by checkpoint lock-in at %d " , __func__ , nHeight ) ,
REJECT_CHECKPOINT , " checkpoint mismatch " ) ;
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 ) ,
REJECT_CHECKPOINT , " checkpoint mismatch " ) ;
// Don't accept any forks from the main chain prior to last checkpoint
CBlockIndex * pcheckpoint = Checkpoints : : GetLastCheckpoint ( ) ;
if ( pcheckpoint & & nHeight < pcheckpoint - > nHeight )
return state . DoS ( 100 , error ( " %s: forked chain older than last checkpoint (height %d) " , __func__ , nHeight ) ) ;
// Don't accept any forks from the main chain prior to last checkpoint
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 , Params ( ) . RejectBlockOutdatedMajority ( ) ) )
if ( block . nVersion < 2 & & IsSuperMajority ( 2 , pindexPrev , consensusParams . nMajorityRejectBlockOutdated ) )
{
return state . Invalid ( error ( " %s: rejected nVersion=1 block " , __func__ ) ,
REJECT_OBSOLETE , " bad-version " ) ;
}
// Reject block.nVersion=2 blocks when 95% (75% on testnet) of the network has upgraded:
if ( block . nVersion < 3 & & IsSuperMajority ( 3 , pindexPrev , Params ( ) . RejectBlockOutdatedMajority ( ) ) )
if ( block . nVersion < 3 & & IsSuperMajority ( 3 , pindexPrev , consensusParams . nMajorityRejectBlockOutdated ) )
{
return state . Invalid ( error ( " %s : rejected nVersion=2 block " , __func__ ) ,
REJECT_OBSOLETE , " bad-version " ) ;
@ -3026,6 +3038,7 @@ CBlockIndex * InsertBlockIndex(uint256 hash)
@@ -3026,6 +3038,7 @@ CBlockIndex * InsertBlockIndex(uint256 hash)
bool static LoadBlockIndexDB ( )
{
const CChainParams & chainparams = Params ( ) ;
if ( ! pblocktree - > LoadBlockIndexGuts ( ) )
return false ;
@ -3128,7 +3141,7 @@ bool static LoadBlockIndexDB()
@@ -3128,7 +3141,7 @@ bool static LoadBlockIndexDB()
LogPrintf ( " %s: hashBestChain=%s height=%d date=%s progress=%f \n " , __func__ ,
chainActive . Tip ( ) - > GetBlockHash ( ) . ToString ( ) , chainActive . Height ( ) ,
DateTimeStrFormat ( " %Y-%m-%d %H:%M:%S " , chainActive . Tip ( ) - > GetBlockTime ( ) ) ,
Checkpoints : : GuessVerificationProgress ( chainActive . Tip ( ) ) ) ;
Checkpoints : : GuessVerificationProgress ( chainparams . Checkpoints ( ) , chain Active . Tip ( ) ) ) ;
return true ;
}