Skip to content

Commit b217020

Browse files
jamesobjonatack
andcommitted
validation: change UpdateTip for multiple chainstates
Only perform certain behavior (namely that related to servicing the getblocktemplate RPC call) for the active chainstate when calling UpdateTip. Co-authored-by: Jon Atack <[email protected]>
1 parent 665072a commit b217020

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

src/validation.cpp

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,8 +2208,42 @@ static void AppendWarning(bilingual_str& res, const bilingual_str& warn)
22082208
res += warn;
22092209
}
22102210

2211+
static void UpdateTipLog(
2212+
const CCoinsViewCache& coins_tip,
2213+
const CBlockIndex* tip,
2214+
const CChainParams& params,
2215+
const std::string& func_name,
2216+
const std::string& prefix,
2217+
const std::string& warning_messages) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
2218+
{
2219+
2220+
AssertLockHeld(::cs_main);
2221+
LogPrintf("%s%s: new best=%s height=%d version=0x%08x log2_work=%f tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)%s\n",
2222+
prefix, func_name,
2223+
tip->GetBlockHash().ToString(), tip->nHeight, tip->nVersion,
2224+
log(tip->nChainWork.getdouble()) / log(2.0), (unsigned long)tip->nChainTx,
2225+
FormatISO8601DateTime(tip->GetBlockTime()),
2226+
GuessVerificationProgress(params.TxData(), tip),
2227+
coins_tip.DynamicMemoryUsage() * (1.0 / (1 << 20)),
2228+
coins_tip.GetCacheSize(),
2229+
!warning_messages.empty() ? strprintf(" warning='%s'", warning_messages) : "");
2230+
}
2231+
22112232
void CChainState::UpdateTip(const CBlockIndex* pindexNew)
22122233
{
2234+
const auto& coins_tip = this->CoinsTip();
2235+
2236+
// The remainder of the function isn't relevant if we are not acting on
2237+
// the active chainstate, so return if need be.
2238+
if (this != &m_chainman.ActiveChainstate()) {
2239+
// Only log every so often so that we don't bury log messages at the tip.
2240+
constexpr int BACKGROUND_LOG_INTERVAL = 2000;
2241+
if (pindexNew->nHeight % BACKGROUND_LOG_INTERVAL == 0) {
2242+
UpdateTipLog(coins_tip, pindexNew, m_params, __func__, "[background validation] ", "");
2243+
}
2244+
return;
2245+
}
2246+
22132247
// New best block
22142248
if (m_mempool) {
22152249
m_mempool->AddTransactionsUpdated(1);
@@ -2237,12 +2271,7 @@ void CChainState::UpdateTip(const CBlockIndex* pindexNew)
22372271
}
22382272
}
22392273
}
2240-
LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%f tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)%s\n", __func__,
2241-
pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, pindexNew->nVersion,
2242-
log(pindexNew->nChainWork.getdouble())/log(2.0), (unsigned long)pindexNew->nChainTx,
2243-
FormatISO8601DateTime(pindexNew->GetBlockTime()),
2244-
GuessVerificationProgress(m_params.TxData(), pindexNew), this->CoinsTip().DynamicMemoryUsage() * (1.0 / (1<<20)), this->CoinsTip().GetCacheSize(),
2245-
!warning_messages.empty() ? strprintf(" warning='%s'", warning_messages.original) : "");
2274+
UpdateTipLog(coins_tip, pindexNew, m_params, __func__, "", warning_messages.original);
22462275
}
22472276

22482277
/** Disconnect m_chain's tip.

0 commit comments

Comments
 (0)