Skip to content

Commit 121cbaa

Browse files
committed
Merge #13259: refactoring: add a method for determining if a block is pruned or not
e9a1881 refactor: add a function for determining if a block is pruned or not (Karl-Johan Alm) Pull request description: The check for whether a block is pruned or not is sufficiently obscure that it deserves a macro. It is also used in 2 places, ~~with more coming, e.g. #10757~~ (turns out it was a move, not an addition). Tree-SHA512: b9aeb60663e1d1196df5371d5aa00b32ff5d4cdea6a77e4b566f28115cce09570c18e45e4b81a4033f67c4135c8e32c027f67bae3b75c2ea4564285578a3f4dd
2 parents 97073f8 + e9a1881 commit 121cbaa

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/rest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static bool rest_block(HTTPRequest* req,
217217
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
218218
}
219219

220-
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
220+
if (IsBlockPruned(pblockindex))
221221
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
222222

223223
if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus()))

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ static UniValue getblockheader(const JSONRPCRequest& request)
732732
static CBlock GetBlockChecked(const CBlockIndex* pblockindex)
733733
{
734734
CBlock block;
735-
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) {
735+
if (IsBlockPruned(pblockindex)) {
736736
throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)");
737737
}
738738

src/validation.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,4 +497,10 @@ bool DumpMempool();
497497
/** Load the mempool from disk. */
498498
bool LoadMempool();
499499

500+
//! Check whether the block associated with this index entry is pruned or not.
501+
inline bool IsBlockPruned(const CBlockIndex* pblockindex)
502+
{
503+
return (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
504+
}
505+
500506
#endif // BITCOIN_VALIDATION_H

0 commit comments

Comments
 (0)