diff options
author | Ryan Ofsky <ryan@ofsky.org> | 2024-08-26 18:35:16 +0200 |
---|---|---|
committer | Sjors Provoost <sjors@sprovoost.nl> | 2024-09-17 09:27:45 +0200 |
commit | e3a560ca68d79b056a105a65ed0c174a9631aba9 (patch) | |
tree | 53b1a007bf4ccceb5416c5aa22263ab84556cf2d /src | |
parent | 460687a09c2af336fce853d9ffb790d01429eec6 (diff) |
rpc: use waitTipChanged for longpoll
This removes the last remaining use of g_best_block by the RPC.
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/mining.cpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 8f6828319e..6270496b1b 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -738,7 +738,6 @@ static RPCHelpMan getblocktemplate() { // Wait to respond until either the best block changes, OR a minute has passed and there are more transactions uint256 hashWatchedChain; - std::chrono::steady_clock::time_point checktxtime; unsigned int nTransactionsUpdatedLastLP; if (lpval.isStr()) @@ -759,19 +758,14 @@ static RPCHelpMan getblocktemplate() // Release lock while waiting LEAVE_CRITICAL_SECTION(cs_main); { - checktxtime = std::chrono::steady_clock::now() + std::chrono::minutes(1); - - WAIT_LOCK(g_best_block_mutex, lock); - while (g_best_block == hashWatchedChain && IsRPCRunning()) - { - if (g_best_block_cv.wait_until(lock, checktxtime) == std::cv_status::timeout) - { - // Timeout: Check transactions for update - // without holding the mempool lock to avoid deadlocks - if (miner.getTransactionsUpdated() != nTransactionsUpdatedLastLP) - break; - checktxtime += std::chrono::seconds(10); - } + MillisecondsDouble checktxtime{std::chrono::minutes(1)}; + while (tip == hashWatchedChain && IsRPCRunning()) { + tip = miner.waitTipChanged(hashWatchedChain, checktxtime).hash; + // Timeout: Check transactions for update + // without holding the mempool lock to avoid deadlocks + if (miner.getTransactionsUpdated() != nTransactionsUpdatedLastLP) + break; + checktxtime = std::chrono::seconds(10); } } ENTER_CRITICAL_SECTION(cs_main); |