Browse Source

Add missing cs_main locks when calling blockToJSON/blockheaderToJSON

0.16
practicalswift 7 years ago
parent
commit
a9b6ba0b7c
  1. 9
      src/rest.cpp
  2. 2
      src/rpc/blockchain.cpp

9
src/rest.cpp

@ -178,9 +178,12 @@ static bool rest_headers(HTTPRequest* req, @@ -178,9 +178,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));
}
}
std::string strJSON = jsonHeaders.write() + "\n";
req->WriteHeader("Content-Type", "application/json");
req->WriteReply(HTTP_OK, strJSON);
@ -239,7 +242,11 @@ static bool rest_block(HTTPRequest* req, @@ -239,7 +242,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);
}
std::string strJSON = objBlock.write() + "\n";
req->WriteHeader("Content-Type", "application/json");
req->WriteReply(HTTP_OK, strJSON);

2
src/rpc/blockchain.cpp

@ -78,6 +78,7 @@ double GetDifficulty(const CBlockIndex* blockindex) @@ -78,6 +78,7 @@ double GetDifficulty(const CBlockIndex* blockindex)
UniValue blockheaderToJSON(const CBlockIndex* blockindex)
{
AssertLockHeld(cs_main);
UniValue result(UniValue::VOBJ);
result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex()));
int confirmations = -1;
@ -106,6 +107,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex) @@ -106,6 +107,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails)
{
AssertLockHeld(cs_main);
UniValue result(UniValue::VOBJ);
result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex()));
int confirmations = -1;

Loading…
Cancel
Save