aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2017-01-09 13:35:12 -0500
committerRussell Yanofsky <russ@yanofsky.org>2017-01-10 08:14:50 -0500
commitafffeea7d98ba358acd54a89bc0e7ae1c4d54023 (patch)
tree249616d481c9e141d30ce070dbdcfc784934f537 /src
parent1fc4ec7bf224748d3d6271bffa23d121f015cbf3 (diff)
fixup! Add pruneblockchain RPC to enable manual block file pruning.
Extend pruneblockchain RPC to accept block timestamps as well as block indices.
Diffstat (limited to 'src')
-rw-r--r--src/rpc/blockchain.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index f49a333279..e828618a82 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -820,7 +820,7 @@ UniValue pruneblockchain(const JSONRPCRequest& request)
throw runtime_error(
"pruneblockchain\n"
"\nArguments:\n"
- "1. \"height\" (int, required) The block height to prune up to.\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");
if (!fPruneMode)
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Cannot prune blocks because node is not in prune mode.");
@@ -831,6 +831,16 @@ UniValue pruneblockchain(const JSONRPCRequest& request)
if (heightParam < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative block height.");
+ // Height value more than a billion is too high to be a block height, and
+ // too low to be a block time (corresponds to timestamp from Sep 2001).
+ if (heightParam > 1000000000) {
+ CBlockIndex* pindex = chainActive.FindLatestBefore(heightParam);
+ if (!pindex) {
+ throw JSONRPCError(RPC_INTERNAL_ERROR, "Could not find block before specified timestamp.");
+ }
+ heightParam = pindex->nHeight;
+ }
+
unsigned int height = (unsigned int) heightParam;
unsigned int chainHeight = (unsigned int) chainActive.Height();
if (chainHeight < Params().PruneAfterHeight())