File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -178,8 +178,11 @@ static bool rest_headers(HTTPRequest* req,
178178 }
179179 case RF_JSON: {
180180 UniValue jsonHeaders (UniValue::VARR);
181- for (const CBlockIndex *pindex : headers) {
182- jsonHeaders.push_back (blockheaderToJSON (pindex));
181+ {
182+ LOCK (cs_main);
183+ for (const CBlockIndex *pindex : headers) {
184+ jsonHeaders.push_back (blockheaderToJSON (pindex));
185+ }
183186 }
184187 std::string strJSON = jsonHeaders.write () + " \n " ;
185188 req->WriteHeader (" Content-Type" , " application/json" );
@@ -239,7 +242,11 @@ static bool rest_block(HTTPRequest* req,
239242 }
240243
241244 case RF_JSON: {
242- UniValue objBlock = blockToJSON (block, pblockindex, showTxDetails);
245+ UniValue objBlock;
246+ {
247+ LOCK (cs_main);
248+ objBlock = blockToJSON (block, pblockindex, showTxDetails);
249+ }
243250 std::string strJSON = objBlock.write () + " \n " ;
244251 req->WriteHeader (" Content-Type" , " application/json" );
245252 req->WriteReply (HTTP_OK, strJSON);
Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ double GetDifficulty(const CBlockIndex* blockindex)
7878
7979UniValue blockheaderToJSON (const CBlockIndex* blockindex)
8080{
81+ AssertLockHeld (cs_main);
8182 UniValue result (UniValue::VOBJ);
8283 result.push_back (Pair (" hash" , blockindex->GetBlockHash ().GetHex ()));
8384 int confirmations = -1 ;
@@ -106,6 +107,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
106107
107108UniValue blockToJSON (const CBlock& block, const CBlockIndex* blockindex, bool txDetails)
108109{
110+ AssertLockHeld (cs_main);
109111 UniValue result (UniValue::VOBJ);
110112 result.push_back (Pair (" hash" , blockindex->GetBlockHash ().GetHex ()));
111113 int confirmations = -1 ;
You can’t perform that action at this time.
0 commit comments