Merge bfce85d135 into merged_master (Bitcoin PR bitcoin/bitcoin#30466)

This commit is contained in:
ivanlele 2026-03-09 13:00:35 +00:00
commit 4936bb3f99
No known key found for this signature in database
2 changed files with 17 additions and 15 deletions

View file

@ -3867,24 +3867,24 @@ static SynchronizationState GetSynchronizationState(bool init, bool blockfiles_i
return SynchronizationState::INIT_DOWNLOAD;
}
static bool NotifyHeaderTip(ChainstateManager& chainman) LOCKS_EXCLUDED(cs_main)
bool ChainstateManager::NotifyHeaderTip()
{
bool fNotify = false;
bool fInitialBlockDownload = false;
CBlockIndex* pindexHeader = nullptr;
{
LOCK(cs_main);
pindexHeader = chainman.m_best_header;
LOCK(GetMutex());
pindexHeader = m_best_header;
if (pindexHeader != chainman.m_last_notified_header) {
if (pindexHeader != m_last_notified_header) {
fNotify = true;
fInitialBlockDownload = chainman.IsInitialBlockDownload();
chainman.m_last_notified_header = pindexHeader;
fInitialBlockDownload = IsInitialBlockDownload();
m_last_notified_header = pindexHeader;
}
}
// Send block tip changed notifications without cs_main
// Send block tip changed notifications without the lock held
if (fNotify) {
chainman.GetNotifications().headerTip(GetSynchronizationState(fInitialBlockDownload, chainman.m_blockman.m_blockfiles_indexed), pindexHeader->nHeight, pindexHeader->nTime, false);
GetNotifications().headerTip(GetSynchronizationState(fInitialBlockDownload, m_blockman.m_blockfiles_indexed), pindexHeader->nHeight, pindexHeader->nTime, false);
}
return fNotify;
}
@ -4991,7 +4991,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
}
}
}
if (NotifyHeaderTip(*this)) {
if (NotifyHeaderTip()) {
if (IsInitialBlockDownload() && ppindex && *ppindex) {
const CBlockIndex& last_accepted{**ppindex};
int64_t blocks_left{(NodeClock::now() - last_accepted.Time()) / GetConsensus().PowTargetSpacing()};
@ -5163,7 +5163,7 @@ bool ChainstateManager::ProcessNewBlock(const std::shared_ptr<const CBlock>& blo
}
}
NotifyHeaderTip(*this);
NotifyHeaderTip();
BlockValidationState state; // Only used to report errors, not invalidity - ignore it
if (!ActiveChainstate().ActivateBestChain(state, block)) {
@ -5740,7 +5740,7 @@ void ChainstateManager::LoadExternalBlockFile(
}
}
NotifyHeaderTip(*this);
NotifyHeaderTip();
if (!blocks_with_unknown_parent) continue;
@ -5766,7 +5766,7 @@ void ChainstateManager::LoadExternalBlockFile(
}
range.first++;
blocks_with_unknown_parent->erase(it);
NotifyHeaderTip(*this);
NotifyHeaderTip();
}
}
} catch (const std::exception& e) {