New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manual block file pruning. #7871
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -814,6 +814,46 @@ static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats) | |
return true; | ||
} | ||
|
||
UniValue pruneblockchain(const JSONRPCRequest& request) | ||
{ | ||
if (request.fHelp || request.params.size() != 1) | ||
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"); | ||
|
||
if (!fPruneMode) | ||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Cannot prune blocks because node is not in prune mode."); | ||
|
||
LOCK(cs_main); | ||
|
||
int heightParam = request.params[0].get_int(); | ||
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()) | ||
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) | ||
LogPrint("rpc", "Attempt to prune blocks close to the tip. Retaining the minimum number of blocks."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one post merge nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in #9518 |
||
|
||
PruneBlockFilesManual(height); | ||
return NullUniValue; | ||
} | ||
|
||
UniValue gettxoutsetinfo(const JSONRPCRequest& request) | ||
{ | ||
if (request.fHelp || request.params.size() != 0) | ||
|
@@ -1384,6 +1424,7 @@ static const CRPCCommand commands[] = | |
{ "blockchain", "getrawmempool", &getrawmempool, true, {"verbose"} }, | ||
{ "blockchain", "gettxout", &gettxout, true, {"txid","n","include_mempool"} }, | ||
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true, {} }, | ||
{ "blockchain", "pruneblockchain", &pruneblockchain, true, {"height"} }, | ||
{ "blockchain", "verifychain", &verifychain, true, {"checklevel","nblocks"} }, | ||
|
||
{ "blockchain", "preciousblock", &preciousblock, true, {"blockhash"} }, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could add a python test for this condition.