Skip to content

Commit e356002

Browse files
author
Jeff Garzik
committed
Merge pull request #5301
2 parents 7715c84 + e2f30d5 commit e356002

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/rest.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "core/transaction.h"
1212
#include "version.h"
1313
#include "main.h"
14+
#include "sync.h"
1415

1516
using namespace std;
1617
using namespace json_spirit;
@@ -80,13 +81,17 @@ static bool rest_block(AcceptedConnection *conn,
8081
if (!ParseHashStr(hashStr, hash))
8182
throw RESTERR(HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
8283

83-
if (mapBlockIndex.count(hash) == 0)
84-
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
85-
8684
CBlock block;
87-
CBlockIndex* pblockindex = mapBlockIndex[hash];
88-
if (!ReadBlockFromDisk(block, pblockindex))
89-
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
85+
CBlockIndex* pblockindex = NULL;
86+
{
87+
LOCK(cs_main);
88+
if (mapBlockIndex.count(hash) == 0)
89+
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
90+
91+
pblockindex = mapBlockIndex[hash];
92+
if (!ReadBlockFromDisk(block, pblockindex))
93+
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
94+
}
9095

9196
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
9297
ssBlock << block;

0 commit comments

Comments
 (0)