@@ -704,8 +704,6 @@ static RPCHelpMan getblocktemplate()
704
704
NodeContext& node = EnsureAnyNodeContext (request.context );
705
705
ChainstateManager& chainman = EnsureChainman (node);
706
706
Mining& miner = EnsureMining (node);
707
- WAIT_LOCK (cs_main, csmain_lock);
708
- uint256 tip{CHECK_NONFATAL (miner.getTip ()).value ().hash };
709
707
710
708
std::string strMode = " template" ;
711
709
UniValue lpval = NullUniValue;
@@ -734,6 +732,7 @@ static RPCHelpMan getblocktemplate()
734
732
if (!DecodeHexBlk (block, dataval.get_str ()))
735
733
throw JSONRPCError (RPC_DESERIALIZATION_ERROR, " Block decode failed" );
736
734
735
+ LOCK (cs_main);
737
736
uint256 hash = block.GetHash ();
738
737
const CBlockIndex* pindex = chainman.m_blockman .LookupBlockIndex (hash);
739
738
if (pindex) {
@@ -773,6 +772,9 @@ static RPCHelpMan getblocktemplate()
773
772
static unsigned int nTransactionsUpdatedLast;
774
773
const CTxMemPool& mempool = EnsureMemPool (node);
775
774
775
+ WAIT_LOCK (cs_main, cs_main_lock);
776
+ uint256 tip{CHECK_NONFATAL (miner.getTip ()).value ().hash };
777
+
776
778
// Long Polling (BIP22)
777
779
if (!lpval.isNull ()) {
778
780
/* *
@@ -811,7 +813,7 @@ static RPCHelpMan getblocktemplate()
811
813
812
814
// Release lock while waiting
813
815
{
814
- REVERSE_LOCK (csmain_lock , cs_main);
816
+ REVERSE_LOCK (cs_main_lock , cs_main);
815
817
MillisecondsDouble checktxtime{std::chrono::minutes (1 )};
816
818
while (IsRPCRunning ()) {
817
819
// If hashWatchedChain is not a real block hash, this will
0 commit comments