src/validation.cpp
/** Check warning conditions and do some notifications on new chain tip set. */
Check warning conditions and do some notifications on new chain tip set.
Check warning conditions and do some notifications on new chain tip set .
void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainParams) {
    mempool.AddTransactionsUpdated(1);
    {
        LOCK(g_best_block_mutex);
        g_best_block = pindexNew->GetBlockHash();
        g_best_block_cv.notify_all();
    }
    std::string warningMessages;
    if (!IsInitialBlockDownload())
    {
        int nUpgraded = 0;
        const CBlockIndex* pindex = pindexNew;
        for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) {
            WarningBitsConditionChecker checker(bit);
            ThresholdState state = checker.GetStateFor(pindex, chainParams.GetConsensus(), warningcache[bit]);
            if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
                const std::string strWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit);
                if (state == ThresholdState::ACTIVE) {
                    DoWarning(strWarning);
                } else {
                    AppendWarning(warningMessages, strWarning);
                }
            }
        }
        for (int i = 0; i < 100 && pindex != nullptr; i++)
        {
            int32_t nExpectedVersion = ComputeBlockVersion(pindex->pprev, chainParams.GetConsensus());
            if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && (pindex->nVersion & ~nExpectedVersion) != 0)
                ++nUpgraded;
            pindex = pindex->pprev;
        }
        if (nUpgraded > 0)
            AppendWarning(warningMessages, strprintf(_("%d of last 100 blocks have unexpected version"), nUpgraded));
    }
    LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)", __func__, 
      pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, pindexNew->nVersion,
      log(pindexNew->nChainWork.getdouble())/log(2.0), (unsigned long)pindexNew->nChainTx,
      FormatISO8601DateTime(pindexNew->GetBlockTime()),
      GuessVerificationProgress(chainParams.TxData(), pindexNew), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
    if (!warningMessages.empty())
        LogPrintf(" warning='%s'", warningMessages); 
    LogPrintf("\n");
}
void static UpdateTip ( const CBlockIndex * pindexNew , const CChainParams & chainParams ) { mempool . AddTransactionsUpdated ( 1 ) ; { LOCK ( g_best_block_mutex ) ; g_best_block = pindexNew -> GetBlockHash ( ) ; g_best_block_cv . notify_all ( ) ; } std :: string warningMessages ; if ( ! IsInitialBlockDownload ( ) ) { int nUpgraded = 0 ; const CBlockIndex * pindex = pindexNew ; for ( int bit = 0 ; bit < VERSIONBITS_NUM_BITS ; bit ++ ) { WarningBitsConditionChecker checker ( bit ) ; ThresholdState state = checker . GetStateFor ( pindex , chainParams . GetConsensus ( ) , warningcache [ bit ] ) ; if ( state == ThresholdState :: ACTIVE || state == ThresholdState :: LOCKED_IN ) { const std :: string strWarning = strprintf ( _ ( " " ) , bit ) ; if ( state == ThresholdState :: ACTIVE ) { DoWarning ( strWarning ) ; } else { AppendWarning ( warningMessages , strWarning ) ; } } } for ( int i = 0 ; i < 100 && pindex != nullptr ; i ++ ) { int32_t nExpectedVersion = ComputeBlockVersion ( pindex -> pprev , chainParams . GetConsensus ( ) ) ; if ( pindex -> nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && ( pindex -> nVersion & ~ nExpectedVersion ) != 0 ) ++ nUpgraded ; pindex = pindex -> pprev ; } if ( nUpgraded > 0 ) AppendWarning ( warningMessages , strprintf ( _ ( " " ) , nUpgraded ) ) ; } LogPrintf ( " " , __func__ , pindexNew -> GetBlockHash ( ) . ToString ( ) , pindexNew -> nHeight , pindexNew -> nVersion , log ( pindexNew -> nChainWork . getdouble ( ) ) / log ( 2.0 ) , ( unsigned long ) pindexNew -> nChainTx , FormatISO8601DateTime ( pindexNew -> GetBlockTime ( ) ) , GuessVerificationProgress ( chainParams . TxData ( ) , pindexNew ) , pcoinsTip -> DynamicMemoryUsage ( ) * ( 1.0 / ( 1 << 20 ) ) , pcoinsTip -> GetCacheSize ( ) ) ; if ( ! warningMessages . empty ( ) ) LogPrintf ( " " , warningMessages ) ; LogPrintf ( " \n " ) ; }
Check warning conditions and do some notifications on new chain tip set.
Check warning conditions and do some notifications on new chain tip set .
// New best block // Check the version of the last 100 blocks to see if we need to upgrade: /* Continued */ /* Continued */