mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-14 17:17:58 +00:00
Hold cs_main while calling UpdatedBlockTip() and ui.NotifyBlockTip
Ensures that callbacks are invoked in the order in which the chain is updated Resolves #12978 GitHub-Pull: #12988 Rebased-From: d86edd3
This commit is contained in:
parent
5ff571e90c
commit
acdf433822
@ -351,7 +351,7 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool
|
|||||||
|
|
||||||
CBlockIndex* tip = chainActive.Tip();
|
CBlockIndex* tip = chainActive.Tip();
|
||||||
assert(tip != nullptr);
|
assert(tip != nullptr);
|
||||||
|
|
||||||
CBlockIndex index;
|
CBlockIndex index;
|
||||||
index.pprev = tip;
|
index.pprev = tip;
|
||||||
// CheckSequenceLocks() uses chainActive.Height()+1 to evaluate
|
// CheckSequenceLocks() uses chainActive.Height()+1 to evaluate
|
||||||
@ -2607,19 +2607,18 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
|
|||||||
assert(trace.pblock && trace.pindex);
|
assert(trace.pblock && trace.pindex);
|
||||||
GetMainSignals().BlockConnected(trace.pblock, trace.pindex, trace.conflictedTxs);
|
GetMainSignals().BlockConnected(trace.pblock, trace.pindex, trace.conflictedTxs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notify external listeners about the new tip.
|
||||||
|
// Enqueue while holding cs_main to ensure that UpdatedBlockTip is called in the order in which blocks are connected
|
||||||
|
GetMainSignals().UpdatedBlockTip(pindexNewTip, pindexFork, fInitialDownload);
|
||||||
|
|
||||||
|
// Always notify the UI if a new block tip was connected
|
||||||
|
if (pindexFork != pindexNewTip) {
|
||||||
|
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
|
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
|
||||||
|
|
||||||
// Notifications/callbacks that can run without cs_main
|
|
||||||
|
|
||||||
// Notify external listeners about the new tip.
|
|
||||||
GetMainSignals().UpdatedBlockTip(pindexNewTip, pindexFork, fInitialDownload);
|
|
||||||
|
|
||||||
// Always notify the UI if a new block tip was connected
|
|
||||||
if (pindexFork != pindexNewTip) {
|
|
||||||
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) StartShutdown();
|
if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) StartShutdown();
|
||||||
|
|
||||||
// We check shutdown only after giving ActivateBestChainStep a chance to run once so that we
|
// We check shutdown only after giving ActivateBestChainStep a chance to run once so that we
|
||||||
|
@ -139,6 +139,10 @@ void CMainSignals::MempoolEntryRemoved(CTransactionRef ptx, MemPoolRemovalReason
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
|
void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
|
||||||
|
// Dependencies exist that require UpdatedBlockTip events to be delivered in the order in which
|
||||||
|
// the chain actually updates. One way to ensure this is for the caller to invoke this signal
|
||||||
|
// in the same critical section where the chain is updated
|
||||||
|
|
||||||
m_internals->m_schedulerClient.AddToProcessQueue([pindexNew, pindexFork, fInitialDownload, this] {
|
m_internals->m_schedulerClient.AddToProcessQueue([pindexNew, pindexFork, fInitialDownload, this] {
|
||||||
m_internals->UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
|
m_internals->UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user