Skip to content

Commit 7e0e7f8

Browse files
committed
Merge pull request #6058
03c5687 appropriate response when trying to get a block in pruned mode (Jonas Schnelli) 1b2e555 add autoprune information to RPC "getblockchaininfo" (Jonas Schnelli)
2 parents c1409d1 + 03c5687 commit 7e0e7f8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/rest.cpp

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

199199
pblockindex = mapBlockIndex[hash];
200+
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
201+
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
202+
200203
if (!ReadBlockFromDisk(block, pblockindex))
201204
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
202205
}

src/rpcblockchain.cpp

Lines changed: 12 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

@@ -492,6 +495,15 @@ Value getblockchaininfo(const Array& params, bool fHelp)
492495
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
493496
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip())));
494497
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
498+
obj.push_back(Pair("pruned", fPruneMode));
499+
if (fPruneMode)
500+
{
501+
CBlockIndex *block = chainActive.Tip();
502+
while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA))
503+
block = block->pprev;
504+
505+
obj.push_back(Pair("pruneheight", block->nHeight));
506+
}
495507
return obj;
496508
}
497509

0 commit comments

Comments
 (0)