diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-06-08 13:31:24 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-06-08 13:45:59 +0200 |
commit | 121cbaacc28eeea4b04ab79233bf4d3a0c399a63 (patch) | |
tree | f7ec337e9d2d534e756c1fc42415eadde97c7862 | |
parent | 97073f8837f384936ab002c614ed091df9520a61 (diff) | |
parent | e9a1881b90704c6708cfba79d2208debbd4476d0 (diff) | |
download | bitcoin-121cbaacc28eeea4b04ab79233bf4d3a0c399a63.tar.xz |
Merge #13259: refactoring: add a method for determining if a block is pruned or not
e9a1881b90704c6708cfba79d2208debbd4476d0 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
-rw-r--r-- | src/rest.cpp | 2 | ||||
-rw-r--r-- | src/rpc/blockchain.cpp | 2 | ||||
-rw-r--r-- | src/validation.h | 6 |
3 files changed, 8 insertions, 2 deletions
diff --git a/src/rest.cpp b/src/rest.cpp index ffa75c241f..a5f164497d 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -217,7 +217,7 @@ static bool rest_block(HTTPRequest* req, return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); } - if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) + if (IsBlockPruned(pblockindex)) return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)"); if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 48e0e02d1a..f70d506e13 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -732,7 +732,7 @@ static UniValue getblockheader(const JSONRPCRequest& request) static CBlock GetBlockChecked(const CBlockIndex* pblockindex) { CBlock block; - if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) { + if (IsBlockPruned(pblockindex)) { throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)"); } diff --git a/src/validation.h b/src/validation.h index b5ab10786a..04f5b6cb80 100644 --- a/src/validation.h +++ b/src/validation.h @@ -497,4 +497,10 @@ bool DumpMempool(); /** Load the mempool from disk. */ bool LoadMempool(); +//! Check whether the block associated with this index entry is pruned or not. +inline bool IsBlockPruned(const CBlockIndex* pblockindex) +{ + return (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0); +} + #endif // BITCOIN_VALIDATION_H |