Add missing cs_main locks when calling blockToJSON/blockheaderToJSON
zcash: cherry picked from commit a9b6ba0b7cd27a64307987afaab7f60bf9b4a15b zcash: https://github.com/bitcoin/bitcoin/pull/11618
This commit is contained in:
parent
29eb55cc28
commit
d8926263b7
|
@ -173,9 +173,12 @@ static bool rest_headers(HTTPRequest* req,
|
|||
}
|
||||
case RF_JSON: {
|
||||
UniValue jsonHeaders(UniValue::VARR);
|
||||
{
|
||||
LOCK(cs_main);
|
||||
for (const CBlockIndex *pindex : headers) {
|
||||
jsonHeaders.push_back(blockheaderToJSON(pindex));
|
||||
}
|
||||
}
|
||||
string strJSON = jsonHeaders.write() + "\n";
|
||||
req->WriteHeader("Content-Type", "application/json");
|
||||
req->WriteReply(HTTP_OK, strJSON);
|
||||
|
@ -238,7 +241,11 @@ static bool rest_block(HTTPRequest* req,
|
|||
}
|
||||
|
||||
case RF_JSON: {
|
||||
UniValue objBlock = blockToJSON(block, pblockindex, showTxDetails);
|
||||
UniValue objBlock;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
objBlock = blockToJSON(block, pblockindex, showTxDetails);
|
||||
}
|
||||
string strJSON = objBlock.write() + "\n";
|
||||
req->WriteHeader("Content-Type", "application/json");
|
||||
req->WriteReply(HTTP_OK, strJSON);
|
||||
|
|
|
@ -103,6 +103,7 @@ static UniValue ValuePoolDesc(
|
|||
|
||||
UniValue blockheaderToJSON(const CBlockIndex* blockindex)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.pushKV("hash", blockindex->GetBlockHash().GetHex());
|
||||
int confirmations = -1;
|
||||
|
@ -220,6 +221,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex)
|
|||
|
||||
UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.pushKV("hash", block.GetHash().GetHex());
|
||||
int confirmations = -1;
|
||||
|
|
Loading…
Reference in New Issue