aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2018-03-20 21:04:27 -0700
committerMarcoFalke <falke.marco@gmail.com>2018-07-13 12:23:39 -0400
commit657dfc5bca2bd476d124f51f711e889f98f1e7d6 (patch)
tree6af07143addfc483114fdb7c7c1aed06b368a80d
parent88d1a649a2e9cfa471fc00f8c853e53383eb4695 (diff)
Fix csBestBlock/cvBlockChange waiting in rpc/mining
Github-Pull: #12743 Rebased-From: 45dd13503918e75a45ce33eb5c934b998790fdc8
-rw-r--r--src/rpc/mining.cpp2
-rw-r--r--src/validation.cpp7
-rw-r--r--src/validation.h1
3 files changed, 8 insertions, 2 deletions
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index c22d0ac377..f029be7fa3 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -477,7 +477,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 2c5b5a1a31..7795905c48 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -210,6 +210,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);
@@ -2151,7 +2152,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<std::string> warningMessages;
if (!IsInitialBlockDownload())
diff --git a/src/validation.h b/src/validation.h
index cd243e2049..e9a1eabdf1 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;