aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2017-01-11 14:25:32 -0500
committerRussell Yanofsky <russ@yanofsky.org>2017-01-11 14:25:32 -0500
commit918d1fb86b687693b4f248c14238676300872749 (patch)
tree16848c527b9124b42eafe3ce851e95273f2f6d46 /src/rpc
parente2e624d9ce54d5d0f1fc0b1934c798804d7d7cff (diff)
downloadbitcoin-918d1fb86b687693b4f248c14238676300872749.tar.xz
Return height of last block pruned by pruneblockchain RPC
Change suggested by Jonas Schnelli <dev@jonasschnelli.ch> in https://github.com/bitcoin/bitcoin/pull/7871#discussion_r95577623
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/blockchain.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index e828618a82..8a912ff3df 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -820,7 +820,12 @@ UniValue pruneblockchain(const JSONRPCRequest& request)
throw runtime_error(
"pruneblockchain\n"
"\nArguments:\n"
- "1. \"height\" (numeric, required) The block height to prune up to. May be set to a discrete height, or to a unix timestamp to prune based on block time.\n");
+ "1. \"height\" (numeric, required) The block height to prune up to. May be set to a discrete height, or to a unix timestamp to prune based on block time.\n"
+ "\nResult:\n"
+ "n (numeric) Height of the last block pruned.\n"
+ "\nExamples:\n"
+ + HelpExampleCli("pruneblockchain", "1000")
+ + HelpExampleRpc("pruneblockchain", "1000"));
if (!fPruneMode)
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Cannot prune blocks because node is not in prune mode.");
@@ -847,11 +852,13 @@ UniValue pruneblockchain(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INTERNAL_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)
+ else if (height > chainHeight - MIN_BLOCKS_TO_KEEP) {
LogPrint("rpc", "Attempt to prune blocks close to the tip. Retaining the minimum number of blocks.");
+ height = chainHeight - MIN_BLOCKS_TO_KEEP;
+ }
PruneBlockFilesManual(height);
- return NullUniValue;
+ return uint64_t(height);
}
UniValue gettxoutsetinfo(const JSONRPCRequest& request)