@@ -3405,24 +3405,24 @@ static SynchronizationState GetSynchronizationState(bool init, bool blockfiles_i
34053405 return SynchronizationState::INIT_DOWNLOAD;
34063406}
34073407
3408- static bool NotifyHeaderTip (ChainstateManager& chainman) LOCKS_EXCLUDED(cs_main )
3408+ bool ChainstateManager:: NotifyHeaderTip ()
34093409{
34103410 bool fNotify = false ;
34113411 bool fInitialBlockDownload = false ;
34123412 CBlockIndex* pindexHeader = nullptr ;
34133413 {
3414- LOCK (cs_main );
3415- pindexHeader = chainman. m_best_header ;
3414+ LOCK (GetMutex () );
3415+ pindexHeader = m_best_header;
34163416
3417- if (pindexHeader != chainman. m_last_notified_header ) {
3417+ if (pindexHeader != m_last_notified_header) {
34183418 fNotify = true ;
3419- fInitialBlockDownload = chainman. IsInitialBlockDownload ();
3420- chainman. m_last_notified_header = pindexHeader;
3419+ fInitialBlockDownload = IsInitialBlockDownload ();
3420+ m_last_notified_header = pindexHeader;
34213421 }
34223422 }
3423- // Send block tip changed notifications without cs_main
3423+ // Send block tip changed notifications without the lock held
34243424 if (fNotify ) {
3425- chainman. GetNotifications ().headerTip (GetSynchronizationState (fInitialBlockDownload , chainman. m_blockman .m_blockfiles_indexed ), pindexHeader->nHeight , pindexHeader->nTime , false );
3425+ GetNotifications ().headerTip (GetSynchronizationState (fInitialBlockDownload , m_blockman.m_blockfiles_indexed ), pindexHeader->nHeight , pindexHeader->nTime , false );
34263426 }
34273427 return fNotify ;
34283428}
@@ -4378,7 +4378,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
43784378 }
43794379 }
43804380 }
4381- if (NotifyHeaderTip (* this )) {
4381+ if (NotifyHeaderTip ()) {
43824382 if (IsInitialBlockDownload () && ppindex && *ppindex) {
43834383 const CBlockIndex& last_accepted{**ppindex};
43844384 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
45494549 }
45504550 }
45514551
4552- NotifyHeaderTip (* this );
4552+ NotifyHeaderTip ();
45534553
45544554 BlockValidationState state; // Only used to report errors, not invalidity - ignore it
45554555 if (!ActiveChainstate ().ActivateBestChain (state, block)) {
@@ -5126,7 +5126,7 @@ void ChainstateManager::LoadExternalBlockFile(
51265126 }
51275127 }
51285128
5129- NotifyHeaderTip (* this );
5129+ NotifyHeaderTip ();
51305130
51315131 if (!blocks_with_unknown_parent) continue ;
51325132
@@ -5152,7 +5152,7 @@ void ChainstateManager::LoadExternalBlockFile(
51525152 }
51535153 range.first ++;
51545154 blocks_with_unknown_parent->erase (it);
5155- NotifyHeaderTip (* this );
5155+ NotifyHeaderTip ();
51565156 }
51575157 }
51585158 } catch (const std::exception& e) {
0 commit comments