Skip to content

Commit 39e0c65

Browse files
committed
Merge #12988: Hold cs_main while calling UpdatedBlockTip() signal
d86edd3 Hold cs_main while calling UpdatedBlockTip() and ui.NotifyBlockTip (Jesse Cohen) Pull request description: Resolves #12978 Tree-SHA512: 2aed09434cd8dbf541ea75462070b73ee87ff31409bede210f6999ffee4a37e32202a289efd37609485d4cbdfe134fe4660a10bfb41e8a8acdba7cd0b61b8780
2 parents 434150a + d86edd3 commit 39e0c65

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/validation.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool
354354

355355
CBlockIndex* tip = chainActive.Tip();
356356
assert(tip != nullptr);
357-
357+
358358
CBlockIndex index;
359359
index.pprev = tip;
360360
// CheckSequenceLocks() uses chainActive.Height()+1 to evaluate
@@ -2678,18 +2678,17 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
26782678
assert(trace.pblock && trace.pindex);
26792679
GetMainSignals().BlockConnected(trace.pblock, trace.pindex, trace.conflictedTxs);
26802680
}
2681-
}
2682-
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
26832681

2684-
// Notifications/callbacks that can run without cs_main
2682+
// Notify external listeners about the new tip.
2683+
// Enqueue while holding cs_main to ensure that UpdatedBlockTip is called in the order in which blocks are connected
2684+
GetMainSignals().UpdatedBlockTip(pindexNewTip, pindexFork, fInitialDownload);
26852685

2686-
// Notify external listeners about the new tip.
2687-
GetMainSignals().UpdatedBlockTip(pindexNewTip, pindexFork, fInitialDownload);
2688-
2689-
// Always notify the UI if a new block tip was connected
2690-
if (pindexFork != pindexNewTip) {
2691-
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);
2686+
// Always notify the UI if a new block tip was connected
2687+
if (pindexFork != pindexNewTip) {
2688+
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);
2689+
}
26922690
}
2691+
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
26932692

26942693
if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) StartShutdown();
26952694

src/validationinterface.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ void CMainSignals::MempoolEntryRemoved(CTransactionRef ptx, MemPoolRemovalReason
139139
}
140140

141141
void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
142+
// Dependencies exist that require UpdatedBlockTip events to be delivered in the order in which
143+
// the chain actually updates. One way to ensure this is for the caller to invoke this signal
144+
// in the same critical section where the chain is updated
145+
142146
m_internals->m_schedulerClient.AddToProcessQueue([pindexNew, pindexFork, fInitialDownload, this] {
143147
m_internals->UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
144148
});

0 commit comments

Comments
 (0)