aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/blockchain.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-03-09 10:02:13 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2017-03-09 10:02:17 +0100
commit02bd6e9bc6de9b1ce188335b1b2f2796d18e434c (patch)
treef45e45d03ca3232565f07f0e7f2ff359edd6bf40 /src/rpc/blockchain.cpp
parent6805c4112cfd8f37e6ff07d1d4802c2728122dd3 (diff)
parentadaa281da12bcc697779f97973cea6b103eec4ab (diff)
downloadbitcoin-02bd6e9bc6de9b1ce188335b1b2f2796d18e434c.tar.xz
Merge #9853: Fix error codes from various RPCs
adaa281 Update release notes to include RPC error code changes. (John Newbery) 338bf06 Add commenting around JSON error codes (John Newbery) dab804c Return correct error codes in fundrawtransaction(). (John Newbery) a012087 Return correct error codes in setban(). (John Newbery) 960bc7f Return correct error codes in removeprunedfunds(). (John Newbery) c119096 Return correct error codes in blockchain.cpp. (John Newbery) 6d07c62 Return correct error codes in bumpfee(). (John Newbery) Tree-SHA512: 4bb39ad221cd8c83d98ac5d7ad642f3a8c265522720dc86b2eebc70e74439a85b06d6ddcd6a874e879d986511de3ab0878bb7fe58b50cb0546b78913632ea809
Diffstat (limited to 'src/rpc/blockchain.cpp')
-rw-r--r--src/rpc/blockchain.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index f38b8f88aa..96254a8cb9 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -744,10 +744,15 @@ UniValue getblock(const JSONRPCRequest& request)
CBlockIndex* pblockindex = mapBlockIndex[hash];
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
- throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)");
+ throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)");
- if(!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus()))
- throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
+ if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus()))
+ // Block not found on disk. This could be because we have the block
+ // header in our index but don't have the block (for example if a
+ // non-whitelisted node sends us an unrequested long chain of valid
+ // blocks, we add the headers to our index, but don't accept the
+ // block).
+ throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk");
if (!fVerbose)
{
@@ -829,7 +834,7 @@ UniValue pruneblockchain(const JSONRPCRequest& request)
+ HelpExampleRpc("pruneblockchain", "1000"));
if (!fPruneMode)
- throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Cannot prune blocks because node is not in prune mode.");
+ throw JSONRPCError(RPC_MISC_ERROR, "Cannot prune blocks because node is not in prune mode.");
LOCK(cs_main);
@@ -843,7 +848,7 @@ UniValue pruneblockchain(const JSONRPCRequest& request)
// Add a 2 hour buffer to include blocks which might have had old timestamps
CBlockIndex* pindex = chainActive.FindEarliestAtLeast(heightParam - TIMESTAMP_WINDOW);
if (!pindex) {
- throw JSONRPCError(RPC_INTERNAL_ERROR, "Could not find block with at least the specified timestamp.");
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "Could not find block with at least the specified timestamp.");
}
heightParam = pindex->nHeight;
}
@@ -851,7 +856,7 @@ UniValue pruneblockchain(const JSONRPCRequest& request)
unsigned int height = (unsigned int) heightParam;
unsigned int chainHeight = (unsigned int) chainActive.Height();
if (chainHeight < Params().PruneAfterHeight())
- throw JSONRPCError(RPC_INTERNAL_ERROR, "Blockchain is too short for pruning.");
+ throw JSONRPCError(RPC_MISC_ERROR, "Blockchain is too short for pruning.");
else if (height > chainHeight)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Blockchain is shorter than the attempted prune height.");
else if (height > chainHeight - MIN_BLOCKS_TO_KEEP) {