Skip to content

Commit 45dd135

Browse files
committed
Fix csBestBlock/cvBlockChange waiting in rpc/mining
1 parent ad960f5 commit 45dd135

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/rpc/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
471471
checktxtime = std::chrono::steady_clock::now() + std::chrono::minutes(1);
472472

473473
WaitableLock lock(csBestBlock);
474-
while (chainActive.Tip()->GetBlockHash() == hashWatchedChain && IsRPCRunning())
474+
while (hashBestBlock == hashWatchedChain && IsRPCRunning())
475475
{
476476
if (cvBlockChange.wait_until(lock, checktxtime) == std::cv_status::timeout)
477477
{

src/validation.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ CChain& chainActive = g_chainstate.chainActive;
204204
CBlockIndex *pindexBestHeader = nullptr;
205205
CWaitableCriticalSection csBestBlock;
206206
CConditionVariable cvBlockChange;
207+
uint256 hashBestBlock;
207208
int nScriptCheckThreads = 0;
208209
std::atomic_bool fImporting(false);
209210
std::atomic_bool fReindex(false);
@@ -2195,7 +2196,11 @@ void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainPar
21952196
// New best block
21962197
mempool.AddTransactionsUpdated(1);
21972198

2198-
cvBlockChange.notify_all();
2199+
{
2200+
WaitableLock lock(csBestBlock);
2201+
hashBestBlock = pindexNew->GetBlockHash();
2202+
cvBlockChange.notify_all();
2203+
}
21992204

22002205
std::vector<std::string> warningMessages;
22012206
if (!IsInitialBlockDownload())

src/validation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ extern uint64_t nLastBlockWeight;
166166
extern const std::string strMessageMagic;
167167
extern CWaitableCriticalSection csBestBlock;
168168
extern CConditionVariable cvBlockChange;
169+
extern uint256 hashBestBlock;
169170
extern std::atomic_bool fImporting;
170171
extern std::atomic_bool fReindex;
171172
extern int nScriptCheckThreads;

0 commit comments

Comments
 (0)