validation: follow-up nits for lock-free `IsInitialBlockDownload()`
What changed, and why it matters
This is a minor code cleanup following a previous change. It adds a safety check confirming a lock is already held, fixes an outdated comment, and marks a function as not throwing exceptions. There is no security issue here.
No action needed. This is a routine cleanup commit with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit is a follow-up to PR #34253. It adds AssertLockHeld(cs_main) to ChainstateManager::UpdateIBDStatus(), which already had EXCLUSIVE_LOCKS_REQUIRED(cs_main) in the header. It removes an obsolete comment about const correctness for IsInitialBlockDownload() and marks the method noexcept. These are non-functional nits; the lock assertion is a compile-time/runtime guard for an already-required lock, not a fix for a bug.
Changed components
src/validation.cppsrc/validation.hInspect captured patch +4 / −8
diff --git a/src/validation.cpp b/src/validation.cpp
index 3330d261..35927ae9 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1934,13 +1934,8 @@ void Chainstate::InitCoinsCache(size_t cache_size_bytes)
m_coins_views->InitCache();
}
-// This function must be marked `const` so that `CValidationInterface` clients
-// (which are given a `const Chainstate*`) can call it.
-//
-// It is lock-free and depends on `m_cached_is_ibd`, which is latched by
-// `UpdateIBDStatus()`.
-//
-bool ChainstateManager::IsInitialBlockDownload() const
+// Lock-free: depends on `m_cached_is_ibd`, which is latched by `UpdateIBDStatus()`.
+bool ChainstateManager::IsInitialBlockDownload() const noexcept
{
return m_cached_is_ibd.load(std::memory_order_relaxed);
}
@@ -3322,6 +3317,7 @@ static SynchronizationState GetSynchronizationState(bool init, bool blockfiles_i
void ChainstateManager::UpdateIBDStatus()
{
+ AssertLockHeld(cs_main);
if (!m_cached_is_ibd.load(std::memory_order_relaxed)) return;
if (m_blockman.LoadingBlocks()) return;
if (!CurrentChainstate().m_chain.IsTipRecent(MinimumChainWork(), m_options.max_tip_age)) return;
diff --git a/src/validation.h b/src/validation.h
index ee7257b3..bfe3605e 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -1182,7 +1182,7 @@ public:
mutable VersionBitsCache m_versionbitscache;
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
- bool IsInitialBlockDownload() const;
+ bool IsInitialBlockDownload() const noexcept;
/** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */
double GuessVerificationProgress(const CBlockIndex* pindex) const EXCLUSIVE_LOCKS_REQUIRED(GetMutex());
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.