mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02:00
Merge bitcoin/bitcoin#30466: refactor: Make m_last_notified_header private
fa927055ddrefactor: Make m_last_notified_header private (MarcoFalke) Pull request description: Seems brittle to expose mutable fields public. Fix it by making it private. Fixes https://github.com/bitcoin/bitcoin/pull/30425#discussion_r1677633601 ACKs for top commit: dergoegge: utACKfa927055ddTree-SHA512: d9841c42571144ced0edeaa4bb1d96a177a011dca37c8342c66513477c37278602a1b88beb93068b94fc4443b1552c8fc9f98bcf0bda7d0fc101e61e90c33944
This commit is contained in:
commit
bfce85d135
2 changed files with 17 additions and 15 deletions
|
|
@ -3405,24 +3405,24 @@ static SynchronizationState GetSynchronizationState(bool init, bool blockfiles_i
|
||||||
return SynchronizationState::INIT_DOWNLOAD;
|
return SynchronizationState::INIT_DOWNLOAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool NotifyHeaderTip(ChainstateManager& chainman) LOCKS_EXCLUDED(cs_main)
|
bool ChainstateManager::NotifyHeaderTip()
|
||||||
{
|
{
|
||||||
bool fNotify = false;
|
bool fNotify = false;
|
||||||
bool fInitialBlockDownload = false;
|
bool fInitialBlockDownload = false;
|
||||||
CBlockIndex* pindexHeader = nullptr;
|
CBlockIndex* pindexHeader = nullptr;
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(GetMutex());
|
||||||
pindexHeader = chainman.m_best_header;
|
pindexHeader = m_best_header;
|
||||||
|
|
||||||
if (pindexHeader != chainman.m_last_notified_header) {
|
if (pindexHeader != m_last_notified_header) {
|
||||||
fNotify = true;
|
fNotify = true;
|
||||||
fInitialBlockDownload = chainman.IsInitialBlockDownload();
|
fInitialBlockDownload = IsInitialBlockDownload();
|
||||||
chainman.m_last_notified_header = pindexHeader;
|
m_last_notified_header = pindexHeader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Send block tip changed notifications without cs_main
|
// Send block tip changed notifications without the lock held
|
||||||
if (fNotify) {
|
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;
|
return fNotify;
|
||||||
}
|
}
|
||||||
|
|
@ -4378,7 +4378,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (NotifyHeaderTip(*this)) {
|
if (NotifyHeaderTip()) {
|
||||||
if (IsInitialBlockDownload() && ppindex && *ppindex) {
|
if (IsInitialBlockDownload() && ppindex && *ppindex) {
|
||||||
const CBlockIndex& last_accepted{**ppindex};
|
const CBlockIndex& last_accepted{**ppindex};
|
||||||
int64_t blocks_left{(NodeClock::now() - last_accepted.Time()) / GetConsensus().PowTargetSpacing()};
|
int64_t blocks_left{(NodeClock::now() - last_accepted.Time()) / GetConsensus().PowTargetSpacing()};
|
||||||
|
|
@ -4549,7 +4549,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
|
BlockValidationState state; // Only used to report errors, not invalidity - ignore it
|
||||||
if (!ActiveChainstate().ActivateBestChain(state, block)) {
|
if (!ActiveChainstate().ActivateBestChain(state, block)) {
|
||||||
|
|
@ -5126,7 +5126,7 @@ void ChainstateManager::LoadExternalBlockFile(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyHeaderTip(*this);
|
NotifyHeaderTip();
|
||||||
|
|
||||||
if (!blocks_with_unknown_parent) continue;
|
if (!blocks_with_unknown_parent) continue;
|
||||||
|
|
||||||
|
|
@ -5152,7 +5152,7 @@ void ChainstateManager::LoadExternalBlockFile(
|
||||||
}
|
}
|
||||||
range.first++;
|
range.first++;
|
||||||
blocks_with_unknown_parent->erase(it);
|
blocks_with_unknown_parent->erase(it);
|
||||||
NotifyHeaderTip(*this);
|
NotifyHeaderTip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
|
|
|
||||||
|
|
@ -906,6 +906,11 @@ private:
|
||||||
|
|
||||||
CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};
|
CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};
|
||||||
|
|
||||||
|
/** The last header for which a headerTip notification was issued. */
|
||||||
|
CBlockIndex* m_last_notified_header GUARDED_BY(GetMutex()){nullptr};
|
||||||
|
|
||||||
|
bool NotifyHeaderTip() LOCKS_EXCLUDED(GetMutex());
|
||||||
|
|
||||||
//! Internal helper for ActivateSnapshot().
|
//! Internal helper for ActivateSnapshot().
|
||||||
//!
|
//!
|
||||||
//! De-serialization of a snapshot that is created with
|
//! De-serialization of a snapshot that is created with
|
||||||
|
|
@ -1063,9 +1068,6 @@ public:
|
||||||
/** Best header we've seen so far (used for getheaders queries' starting points). */
|
/** Best header we've seen so far (used for getheaders queries' starting points). */
|
||||||
CBlockIndex* m_best_header GUARDED_BY(::cs_main){nullptr};
|
CBlockIndex* m_best_header GUARDED_BY(::cs_main){nullptr};
|
||||||
|
|
||||||
/** The last header for which a headerTip notification was issued. */
|
|
||||||
CBlockIndex* m_last_notified_header GUARDED_BY(::cs_main){nullptr};
|
|
||||||
|
|
||||||
//! The total number of bytes available for us to use across all in-memory
|
//! The total number of bytes available for us to use across all in-memory
|
||||||
//! coins caches. This will be split somehow across chainstates.
|
//! coins caches. This will be split somehow across chainstates.
|
||||||
int64_t m_total_coinstip_cache{0};
|
int64_t m_total_coinstip_cache{0};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue