Skip to content

Commit 03c5687

Browse files
committed
appropriate response when trying to get a block in pruned mode
1 parent 1b2e555 commit 03c5687

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/rest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ static bool rest_block(AcceptedConnection* conn,
174174
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
175175

176176
pblockindex = mapBlockIndex[hash];
177+
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
178+
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
179+
177180
if (!ReadBlockFromDisk(block, pblockindex))
178181
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
179182
}

src/rpcblockchain.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ Value getblock(const Array& params, bool fHelp)
299299
CBlock block;
300300
CBlockIndex* pblockindex = mapBlockIndex[hash];
301301

302+
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
303+
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)");
304+
302305
if(!ReadBlockFromDisk(block, pblockindex))
303306
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
304307

0 commit comments

Comments
 (0)