mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-11 08:07:33 +02:00
log: update progress calculations for background validation
updates estimations to the block snapshot instead of the main chain tip as it will stop validation after reaching that height
This commit is contained in:
@@ -2858,7 +2858,8 @@ static void UpdateTipLog(
|
||||
const CBlockIndex* tip,
|
||||
const std::string& func_name,
|
||||
const std::string& prefix,
|
||||
const std::string& warning_messages) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
|
||||
const std::string& warning_messages,
|
||||
const bool background_validation) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
|
||||
{
|
||||
|
||||
AssertLockHeld(::cs_main);
|
||||
@@ -2869,7 +2870,7 @@ static void UpdateTipLog(
|
||||
tip->GetBlockHash().ToString(), tip->nHeight, tip->nVersion,
|
||||
log(tip->nChainWork.getdouble()) / log(2.0), tip->m_chain_tx_count,
|
||||
FormatISO8601DateTime(tip->GetBlockTime()),
|
||||
chainman.GuessVerificationProgress(tip),
|
||||
background_validation ? chainman.GetBackgroundVerificationProgress(*tip) : chainman.GuessVerificationProgress(tip),
|
||||
coins_tip.DynamicMemoryUsage() * (1.0 / (1 << 20)),
|
||||
coins_tip.GetCacheSize(),
|
||||
!warning_messages.empty() ? strprintf(" warning='%s'", warning_messages) : "");
|
||||
@@ -2886,7 +2887,7 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
|
||||
// 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(m_chainman, coins_tip, pindexNew, __func__, "[background validation] ", "");
|
||||
UpdateTipLog(m_chainman, coins_tip, pindexNew, __func__, "[background validation] ", "", /*background_validation=*/true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -2909,7 +2910,7 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
|
||||
}
|
||||
}
|
||||
UpdateTipLog(m_chainman, coins_tip, pindexNew, __func__, "",
|
||||
util::Join(warning_messages, Untranslated(", ")).original);
|
||||
util::Join(warning_messages, Untranslated(", ")).original, /*background_validation=*/false);
|
||||
}
|
||||
|
||||
/** Disconnect m_chain's tip.
|
||||
@@ -5520,6 +5521,19 @@ double ChainstateManager::GuessVerificationProgress(const CBlockIndex* pindex) c
|
||||
return std::min<double>(pindex->m_chain_tx_count / fTxTotal, 1.0);
|
||||
}
|
||||
|
||||
double ChainstateManager::GetBackgroundVerificationProgress(const CBlockIndex& pindex) const
|
||||
{
|
||||
AssertLockHeld(GetMutex());
|
||||
Assert(HistoricalChainstate());
|
||||
auto target_block = HistoricalChainstate()->TargetBlock();
|
||||
|
||||
if (pindex.m_chain_tx_count == 0 || target_block->m_chain_tx_count == 0) {
|
||||
LogDebug(BCLog::VALIDATION, "[background validation] Block %d has unset m_chain_tx_count. Unable to estimate verification progress.", pindex.nHeight);
|
||||
return 0.0;
|
||||
}
|
||||
return static_cast<double>(pindex.m_chain_tx_count) / static_cast<double>(target_block->m_chain_tx_count);
|
||||
}
|
||||
|
||||
Chainstate& ChainstateManager::InitializeChainstate(CTxMemPool* mempool)
|
||||
{
|
||||
AssertLockHeld(::cs_main);
|
||||
|
||||
Reference in New Issue
Block a user