MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / pruneblockchain

Function pruneblockchain

src/rpc/blockchain.cpp:965–1012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

963}
964
965static UniValue pruneblockchain(const JSONRPCRequest& request)
966{
967 if (request.fHelp || request.params.size() != 1)
968 throw std::runtime_error(
969 "pruneblockchain\n"
970 "\nArguments:\n"
971 "1. \"height\" (numeric, required) The block height to prune up to. May be set to a discrete height, or a unix timestamp\n"
972 " to prune blocks whose block time is at least 2 hours older than the provided timestamp.\n"
973 "\nResult:\n"
974 "n (numeric) Height of the last block pruned.\n"
975 "\nExamples:\n"
976 + HelpExampleCli("pruneblockchain", "1000")
977 + HelpExampleRpc("pruneblockchain", "1000"));
978
979 if (!fPruneMode)
980 throw JSONRPCError(RPC_MISC_ERROR, "Cannot prune blocks because node is not in prune mode.");
981
982 LOCK(cs_main);
983
984 int heightParam = request.params[0].get_int();
985 if (heightParam < 0)
986 throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative block height.");
987
988 // Height value more than a billion is too high to be a block height, and
989 // too low to be a block time (corresponds to timestamp from Sep 2001).
990 if (heightParam > 1000000000) {
991 // Add a 2 hour buffer to include blocks which might have had old timestamps
992 CBlockIndex* pindex = chainActive.FindEarliestAtLeast(heightParam - TIMESTAMP_WINDOW);
993 if (!pindex) {
994 throw JSONRPCError(RPC_INVALID_PARAMETER, "Could not find block with at least the specified timestamp.");
995 }
996 heightParam = pindex->nHeight;
997 }
998
999 unsigned int height = (unsigned int) heightParam;
1000 unsigned int chainHeight = (unsigned int) chainActive.Height();
1001 if (chainHeight < Params().PruneAfterHeight())
1002 throw JSONRPCError(RPC_MISC_ERROR, "Blockchain is too short for pruning.");
1003 else if (height > chainHeight)
1004 throw JSONRPCError(RPC_INVALID_PARAMETER, "Blockchain is shorter than the attempted prune height.");
1005 else if (height > chainHeight - MIN_BLOCKS_TO_KEEP) {
1006 LogPrint(BCLog::RPC, "Attempt to prune blocks close to the tip. Retaining the minimum number of blocks.\n");
1007 height = chainHeight - MIN_BLOCKS_TO_KEEP;
1008 }
1009
1010 PruneBlockFilesManual(height);
1011 return uint64_t(height);
1012}
1013
1014static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
1015{

Callers

nothing calls this directly

Calls 10

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
PruneBlockFilesManualFunction · 0.85
get_intMethod · 0.80
FindEarliestAtLeastMethod · 0.80
HeightMethod · 0.80
PruneAfterHeightMethod · 0.80
ParamsClass · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected