diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -1172,7 +1172,8 @@ /** * Check warning conditions and do some notifications on new chain tip set. */ - void UpdateTip(CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + void UpdateTip(const CBlockIndex *pindexNew) + EXCLUSIVE_LOCKS_REQUIRED(::cs_main); friend ChainstateManager; }; diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2117,7 +2117,39 @@ } } -void CChainState::UpdateTip(CBlockIndex *pindexNew) { +static void UpdateTipLog(const CCoinsViewCache &coins_tip, + const CBlockIndex *tip, const CChainParams ¶ms, + const std::string &func_name, + const std::string &prefix) + EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { + AssertLockHeld(::cs_main); + LogPrintf("%s%s: new best=%s height=%d version=0x%08x log2_work=%f tx=%ld " + "date='%s' progress=%f cache=%.1fMiB(%utxo)\n", + prefix, func_name, tip->GetBlockHash().ToString(), tip->nHeight, + tip->nVersion, log(tip->nChainWork.getdouble()) / log(2.0), + tip->GetChainTxCount(), + FormatISO8601DateTime(tip->GetBlockTime()), + GuessVerificationProgress(params.TxData(), tip), + coins_tip.DynamicMemoryUsage() * (1.0 / (1 << 20)), + coins_tip.GetCacheSize()); +} + +void CChainState::UpdateTip(const CBlockIndex *pindexNew) { + const auto &coins_tip = CoinsTip(); + + // The remainder of the function isn't relevant if we are not acting on + // the active chainstate, so return if need be. + if (this != &m_chainman.ActiveChainstate()) { + // Only log every so often so that we don't bury log messages at the + // tip. + constexpr int BACKGROUND_LOG_INTERVAL = 2000; + if (pindexNew->nHeight % BACKGROUND_LOG_INTERVAL == 0) { + UpdateTipLog(coins_tip, pindexNew, m_params, __func__, + "[background validation] "); + } + return; + } + // New best block if (m_mempool) { m_mempool->AddTransactionsUpdated(1); @@ -2129,16 +2161,7 @@ g_best_block_cv.notify_all(); } - LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%f tx=%ld " - "date='%s' progress=%f cache=%.1fMiB(%utxo)\n", - __func__, pindexNew->GetBlockHash().ToString(), - pindexNew->nHeight, pindexNew->nVersion, - log(pindexNew->nChainWork.getdouble()) / log(2.0), - pindexNew->GetChainTxCount(), - FormatISO8601DateTime(pindexNew->GetBlockTime()), - GuessVerificationProgress(m_params.TxData(), pindexNew), - CoinsTip().DynamicMemoryUsage() * (1.0 / (1 << 20)), - CoinsTip().GetCacheSize()); + UpdateTipLog(coins_tip, pindexNew, m_params, __func__, ""); } /**