Merge bitcoin/bitcoin#33264: threading: reduce the scope of lock in getblocktemplate
493ba0f688threading: reduce the scope of lock in getblocktemplate (kevkevinpal) Pull request description: This change was motivated by https://github.com/bitcoin/bitcoin/pull/32592#discussion_r2294770722 It does exactly what is said in the comment. Reducing the scope of the lock by a bit before it is needed ACKs for top commit: stickies-v: re-ACK493ba0f688maflcko: lgtm ACK493ba0f688Tree-SHA512: aa3a21ef3da6be6c0af78aa2dda61ee21c3f6d4d9c897413dba9e7d7d2a91e9e069bbc6b6684b45aadaa28d8603dd310f2c2d2e58c31bb4d864204e468fefaf1
This commit is contained in:
1 file changed
+5
-3
+5
-3
@@ -704,8 +704,6 @@ static RPCHelpMan getblocktemplate()
|
|||||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||||
ChainstateManager& chainman = EnsureChainman(node);
|
ChainstateManager& chainman = EnsureChainman(node);
|
||||||
Mining& miner = EnsureMining(node);
|
Mining& miner = EnsureMining(node);
|
||||||
WAIT_LOCK(cs_main, csmain_lock);
|
|
||||||
uint256 tip{CHECK_NONFATAL(miner.getTip()).value().hash};
|
|
||||||
|
|
||||||
std::string strMode = "template";
|
std::string strMode = "template";
|
||||||
UniValue lpval = NullUniValue;
|
UniValue lpval = NullUniValue;
|
||||||
@@ -735,6 +733,7 @@ static RPCHelpMan getblocktemplate()
|
|||||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
|
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
|
||||||
|
|
||||||
uint256 hash = block.GetHash();
|
uint256 hash = block.GetHash();
|
||||||
|
LOCK(cs_main);
|
||||||
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
|
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
|
||||||
if (pindex) {
|
if (pindex) {
|
||||||
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
|
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
|
||||||
@@ -773,6 +772,9 @@ static RPCHelpMan getblocktemplate()
|
|||||||
static unsigned int nTransactionsUpdatedLast;
|
static unsigned int nTransactionsUpdatedLast;
|
||||||
const CTxMemPool& mempool = EnsureMemPool(node);
|
const CTxMemPool& mempool = EnsureMemPool(node);
|
||||||
|
|
||||||
|
WAIT_LOCK(cs_main, cs_main_lock);
|
||||||
|
uint256 tip{CHECK_NONFATAL(miner.getTip()).value().hash};
|
||||||
|
|
||||||
// Long Polling (BIP22)
|
// Long Polling (BIP22)
|
||||||
if (!lpval.isNull()) {
|
if (!lpval.isNull()) {
|
||||||
/**
|
/**
|
||||||
@@ -811,7 +813,7 @@ static RPCHelpMan getblocktemplate()
|
|||||||
|
|
||||||
// Release lock while waiting
|
// Release lock while waiting
|
||||||
{
|
{
|
||||||
REVERSE_LOCK(csmain_lock, cs_main);
|
REVERSE_LOCK(cs_main_lock, cs_main);
|
||||||
MillisecondsDouble checktxtime{std::chrono::minutes(1)};
|
MillisecondsDouble checktxtime{std::chrono::minutes(1)};
|
||||||
while (IsRPCRunning()) {
|
while (IsRPCRunning()) {
|
||||||
// If hashWatchedChain is not a real block hash, this will
|
// If hashWatchedChain is not a real block hash, this will
|
||||||
|
|||||||
Reference in new issue
Block a user