mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-04 13:55:23 -05:00
rpc: use waitTipChanged for longpoll
This removes the last remaining use of g_best_block by the RPC.
This commit is contained in:
parent
460687a09c
commit
e3a560ca68
1 changed files with 8 additions and 14 deletions
|
@ -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
|
// Wait to respond until either the best block changes, OR a minute has passed and there are more transactions
|
||||||
uint256 hashWatchedChain;
|
uint256 hashWatchedChain;
|
||||||
std::chrono::steady_clock::time_point checktxtime;
|
|
||||||
unsigned int nTransactionsUpdatedLastLP;
|
unsigned int nTransactionsUpdatedLastLP;
|
||||||
|
|
||||||
if (lpval.isStr())
|
if (lpval.isStr())
|
||||||
|
@ -759,19 +758,14 @@ static RPCHelpMan getblocktemplate()
|
||||||
// Release lock while waiting
|
// Release lock while waiting
|
||||||
LEAVE_CRITICAL_SECTION(cs_main);
|
LEAVE_CRITICAL_SECTION(cs_main);
|
||||||
{
|
{
|
||||||
checktxtime = std::chrono::steady_clock::now() + std::chrono::minutes(1);
|
MillisecondsDouble checktxtime{std::chrono::minutes(1)};
|
||||||
|
while (tip == hashWatchedChain && IsRPCRunning()) {
|
||||||
WAIT_LOCK(g_best_block_mutex, lock);
|
tip = miner.waitTipChanged(hashWatchedChain, checktxtime).hash;
|
||||||
while (g_best_block == hashWatchedChain && IsRPCRunning())
|
// Timeout: Check transactions for update
|
||||||
{
|
// without holding the mempool lock to avoid deadlocks
|
||||||
if (g_best_block_cv.wait_until(lock, checktxtime) == std::cv_status::timeout)
|
if (miner.getTransactionsUpdated() != nTransactionsUpdatedLastLP)
|
||||||
{
|
break;
|
||||||
// Timeout: Check transactions for update
|
checktxtime = std::chrono::seconds(10);
|
||||||
// without holding the mempool lock to avoid deadlocks
|
|
||||||
if (miner.getTransactionsUpdated() != nTransactionsUpdatedLastLP)
|
|
||||||
break;
|
|
||||||
checktxtime += std::chrono::seconds(10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ENTER_CRITICAL_SECTION(cs_main);
|
ENTER_CRITICAL_SECTION(cs_main);
|
||||||
|
|
Loading…
Add table
Reference in a new issue