mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge #12743: Fix csBestBlock/cvBlockChange waiting in rpc/mining
4a6c0e3dcf
Modernize best block mutex/cv/hash variable naming (Pieter Wuille)45dd135039
Fix csBestBlock/cvBlockChange waiting in rpc/mining (Pieter Wuille) Pull request description: This is an alternative to #11694. It reintroduces a uint256 variable with the best block hash, protected by csBestBlock, and only updated while holding it. Also rename the involved variable to modern guidelines, as there are very few uses. Tree-SHA512: 826a86c7d3cee7fe49f99f4398ae99e81cb0563197eaeba77306a3ca6072b67cdb932bc35720fc0f99c2a57b218efa029d0b8bdfb240591a629b2e90efa3199d
This commit is contained in:
commit
4ba6da5574
@ -323,7 +323,7 @@ void OnRPCStopped()
|
||||
{
|
||||
uiInterface.NotifyBlockTip.disconnect(&RPCNotifyBlockChange);
|
||||
RPCNotifyBlockChange(false, nullptr);
|
||||
cvBlockChange.notify_all();
|
||||
g_best_block_cv.notify_all();
|
||||
LogPrint(BCLog::RPC, "RPC stopped.\n");
|
||||
}
|
||||
|
||||
|
@ -471,10 +471,10 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||
{
|
||||
checktxtime = std::chrono::steady_clock::now() + std::chrono::minutes(1);
|
||||
|
||||
WaitableLock lock(csBestBlock);
|
||||
while (chainActive.Tip()->GetBlockHash() == hashWatchedChain && IsRPCRunning())
|
||||
WaitableLock lock(g_best_block_mutex);
|
||||
while (g_best_block == hashWatchedChain && IsRPCRunning())
|
||||
{
|
||||
if (cvBlockChange.wait_until(lock, checktxtime) == std::cv_status::timeout)
|
||||
if (g_best_block_cv.wait_until(lock, checktxtime) == std::cv_status::timeout)
|
||||
{
|
||||
// Timeout: Check transactions for update
|
||||
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
|
||||
|
@ -202,8 +202,9 @@ CCriticalSection cs_main;
|
||||
BlockMap& mapBlockIndex = g_chainstate.mapBlockIndex;
|
||||
CChain& chainActive = g_chainstate.chainActive;
|
||||
CBlockIndex *pindexBestHeader = nullptr;
|
||||
CWaitableCriticalSection csBestBlock;
|
||||
CConditionVariable cvBlockChange;
|
||||
CWaitableCriticalSection g_best_block_mutex;
|
||||
CConditionVariable g_best_block_cv;
|
||||
uint256 g_best_block;
|
||||
int nScriptCheckThreads = 0;
|
||||
std::atomic_bool fImporting(false);
|
||||
std::atomic_bool fReindex(false);
|
||||
@ -2204,7 +2205,11 @@ void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainPar
|
||||
// New best block
|
||||
mempool.AddTransactionsUpdated(1);
|
||||
|
||||
cvBlockChange.notify_all();
|
||||
{
|
||||
WaitableLock lock(g_best_block_mutex);
|
||||
g_best_block = pindexNew->GetBlockHash();
|
||||
g_best_block_cv.notify_all();
|
||||
}
|
||||
|
||||
std::vector<std::string> warningMessages;
|
||||
if (!IsInitialBlockDownload())
|
||||
|
@ -165,8 +165,9 @@ extern BlockMap& mapBlockIndex;
|
||||
extern uint64_t nLastBlockTx;
|
||||
extern uint64_t nLastBlockWeight;
|
||||
extern const std::string strMessageMagic;
|
||||
extern CWaitableCriticalSection csBestBlock;
|
||||
extern CConditionVariable cvBlockChange;
|
||||
extern CWaitableCriticalSection g_best_block_mutex;
|
||||
extern CConditionVariable g_best_block_cv;
|
||||
extern uint256 g_best_block;
|
||||
extern std::atomic_bool fImporting;
|
||||
extern std::atomic_bool fReindex;
|
||||
extern int nScriptCheckThreads;
|
||||
|
Loading…
Reference in New Issue
Block a user