From 45dd13503918e75a45ce33eb5c934b998790fdc8 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 20 Mar 2018 21:04:27 -0700 Subject: Fix csBestBlock/cvBlockChange waiting in rpc/mining --- src/rpc/mining.cpp | 2 +- src/validation.cpp | 7 ++++++- src/validation.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 06882c0dfd..5a5ff06fe3 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -471,7 +471,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) checktxtime = std::chrono::steady_clock::now() + std::chrono::minutes(1); WaitableLock lock(csBestBlock); - while (chainActive.Tip()->GetBlockHash() == hashWatchedChain && IsRPCRunning()) + while (hashBestBlock == hashWatchedChain && IsRPCRunning()) { if (cvBlockChange.wait_until(lock, checktxtime) == std::cv_status::timeout) { diff --git a/src/validation.cpp b/src/validation.cpp index df8729e382..c3e411f1fc 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -204,6 +204,7 @@ CChain& chainActive = g_chainstate.chainActive; CBlockIndex *pindexBestHeader = nullptr; CWaitableCriticalSection csBestBlock; CConditionVariable cvBlockChange; +uint256 hashBestBlock; int nScriptCheckThreads = 0; std::atomic_bool fImporting(false); std::atomic_bool fReindex(false); @@ -2195,7 +2196,11 @@ void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainPar // New best block mempool.AddTransactionsUpdated(1); - cvBlockChange.notify_all(); + { + WaitableLock lock(csBestBlock); + hashBestBlock = pindexNew->GetBlockHash(); + cvBlockChange.notify_all(); + } std::vector warningMessages; if (!IsInitialBlockDownload()) diff --git a/src/validation.h b/src/validation.h index 95c31bf0fc..b51ad9fc76 100644 --- a/src/validation.h +++ b/src/validation.h @@ -166,6 +166,7 @@ extern uint64_t nLastBlockWeight; extern const std::string strMessageMagic; extern CWaitableCriticalSection csBestBlock; extern CConditionVariable cvBlockChange; +extern uint256 hashBestBlock; extern std::atomic_bool fImporting; extern std::atomic_bool fReindex; extern int nScriptCheckThreads; -- cgit v1.2.3