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,
178
178
}
179
179
case RF_JSON: {
180
180
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
+ }
183
186
}
184
187
std::string strJSON = jsonHeaders.write () + " \n " ;
185
188
req->WriteHeader (" Content-Type" , " application/json" );
@@ -239,7 +242,11 @@ static bool rest_block(HTTPRequest* req,
239
242
}
240
243
241
244
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
+ }
243
250
std::string strJSON = objBlock.write () + " \n " ;
244
251
req->WriteHeader (" Content-Type" , " application/json" );
245
252
req->WriteReply (HTTP_OK, strJSON);
Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ double GetDifficulty(const CBlockIndex* blockindex)
78
78
79
79
UniValue blockheaderToJSON (const CBlockIndex* blockindex)
80
80
{
81
+ AssertLockHeld (cs_main);
81
82
UniValue result (UniValue::VOBJ);
82
83
result.push_back (Pair (" hash" , blockindex->GetBlockHash ().GetHex ()));
83
84
int confirmations = -1 ;
@@ -106,6 +107,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
106
107
107
108
UniValue blockToJSON (const CBlock& block, const CBlockIndex* blockindex, bool txDetails)
108
109
{
110
+ AssertLockHeld (cs_main);
109
111
UniValue result (UniValue::VOBJ);
110
112
result.push_back (Pair (" hash" , blockindex->GetBlockHash ().GetHex ()));
111
113
int confirmations = -1 ;
You can’t perform that action at this time.
0 commit comments