@@ -738,7 +738,6 @@ static RPCHelpMan getblocktemplate()
738738 {
739739 // Wait to respond until either the best block changes, OR a minute has passed and there are more transactions
740740 uint256 hashWatchedChain;
741- std::chrono::steady_clock::time_point checktxtime;
742741 unsigned int nTransactionsUpdatedLastLP;
743742
744743 if (lpval.isStr ())
@@ -759,19 +758,14 @@ static RPCHelpMan getblocktemplate()
759758 // Release lock while waiting
760759 LEAVE_CRITICAL_SECTION (cs_main);
761760 {
762- checktxtime = std::chrono::steady_clock::now () + std::chrono::minutes (1 );
763-
764- WAIT_LOCK (g_best_block_mutex, lock);
765- while (g_best_block == hashWatchedChain && IsRPCRunning ())
766- {
767- if (g_best_block_cv.wait_until (lock, checktxtime) == std::cv_status::timeout)
768- {
769- // Timeout: Check transactions for update
770- // without holding the mempool lock to avoid deadlocks
771- if (miner.getTransactionsUpdated () != nTransactionsUpdatedLastLP)
772- break ;
773- checktxtime += std::chrono::seconds (10 );
774- }
761+ MillisecondsDouble checktxtime{std::chrono::minutes (1 )};
762+ while (tip == hashWatchedChain && IsRPCRunning ()) {
763+ tip = miner.waitTipChanged (hashWatchedChain, checktxtime).hash ;
764+ // Timeout: Check transactions for update
765+ // without holding the mempool lock to avoid deadlocks
766+ if (miner.getTransactionsUpdated () != nTransactionsUpdatedLastLP)
767+ break ;
768+ checktxtime = std::chrono::seconds (10 );
775769 }
776770 }
777771 ENTER_CRITICAL_SECTION (cs_main);
0 commit comments