diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 36adf154f15..b710c605bcb 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -704,7 +704,7 @@ static RPCHelpMan getblocktemplate() NodeContext& node = EnsureAnyNodeContext(request.context); ChainstateManager& chainman = EnsureChainman(node); Mining& miner = EnsureMining(node); - LOCK(cs_main); + WAIT_LOCK(cs_main, csmain_lock); uint256 tip{CHECK_NONFATAL(miner.getTip()).value().hash}; std::string strMode = "template"; @@ -810,8 +810,8 @@ static RPCHelpMan getblocktemplate() } // Release lock while waiting - LEAVE_CRITICAL_SECTION(cs_main); { + REVERSE_LOCK(csmain_lock, cs_main); MillisecondsDouble checktxtime{std::chrono::minutes(1)}; while (IsRPCRunning()) { // If hashWatchedChain is not a real block hash, this will @@ -830,8 +830,6 @@ static RPCHelpMan getblocktemplate() checktxtime = std::chrono::seconds(10); } } - ENTER_CRITICAL_SECTION(cs_main); - tip = CHECK_NONFATAL(miner.getTip()).value().hash; if (!IsRPCRunning())