Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 4,579 Lines • ▼ Show 20 Lines | void UnlinkPrunedFiles(const std::set<int> &setFilesToPrune) { | ||||
for (const int i : setFilesToPrune) { | for (const int i : setFilesToPrune) { | ||||
FlatFilePos pos(i, 0); | FlatFilePos pos(i, 0); | ||||
fs::remove(BlockFileSeq().FileName(pos)); | fs::remove(BlockFileSeq().FileName(pos)); | ||||
fs::remove(UndoFileSeq().FileName(pos)); | fs::remove(UndoFileSeq().FileName(pos)); | ||||
LogPrintf("Prune: %s deleted blk/rev (%05u)\n", __func__, i); | LogPrintf("Prune: %s deleted blk/rev (%05u)\n", __func__, i); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Calculate the block/rev files to delete based on height specified by user | |||||
* with RPC command pruneblockchain | |||||
*/ | |||||
void BlockManager::FindFilesToPruneManual(std::set<int> &setFilesToPrune, | void BlockManager::FindFilesToPruneManual(std::set<int> &setFilesToPrune, | ||||
int nManualPruneHeight, | int nManualPruneHeight, | ||||
int chain_tip_height) { | int chain_tip_height) { | ||||
assert(fPruneMode && nManualPruneHeight > 0); | assert(fPruneMode && nManualPruneHeight > 0); | ||||
LOCK2(cs_main, cs_LastBlockFile); | LOCK2(cs_main, cs_LastBlockFile); | ||||
if (chain_tip_height < 0) { | if (chain_tip_height < 0) { | ||||
return; | return; | ||||
Show All 23 Lines | void PruneBlockFilesManual(int nManualPruneHeight) { | ||||
const CChainParams &chainparams = Params(); | const CChainParams &chainparams = Params(); | ||||
if (!::ChainstateActive().FlushStateToDisk( | if (!::ChainstateActive().FlushStateToDisk( | ||||
chainparams, state, FlushStateMode::NONE, nManualPruneHeight)) { | chainparams, state, FlushStateMode::NONE, nManualPruneHeight)) { | ||||
LogPrintf("%s: failed to flush state (%s)\n", __func__, | LogPrintf("%s: failed to flush state (%s)\n", __func__, | ||||
state.ToString()); | state.ToString()); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Prune block and undo files (blk???.dat and undo???.dat) so that the disk | |||||
* space used is less than a user-defined target. The user sets the target (in | |||||
* MB) on the command line or in config file. This will be run on startup and | |||||
* whenever new space is allocated in a block or undo file, staying below the | |||||
* target. Changing back to unpruned requires a reindex (which in this case | |||||
* means the blockchain must be re-downloaded.) | |||||
* | |||||
* Pruning functions are called from FlushStateToDisk when the global | |||||
* fCheckForPruning flag has been set. Block and undo files are deleted in | |||||
* lock-step (when blk00003.dat is deleted, so is rev00003.dat.). Pruning cannot | |||||
* take place until the longest chain is at least a certain length (100000 on | |||||
* mainnet, 1000 on testnet, 1000 on regtest). Pruning will never delete a block | |||||
* within a defined distance (currently 288) from the active chain's tip. The | |||||
* block index is updated by unsetting HAVE_DATA and HAVE_UNDO for any blocks | |||||
* that were stored in the deleted files. A db flag records the fact that at | |||||
* least some block files have been pruned. | |||||
* | |||||
* @param[out] setFilesToPrune The set of file indices that can be unlinked | |||||
* will be returned | |||||
*/ | |||||
void BlockManager::FindFilesToPrune(std::set<int> &setFilesToPrune, | void BlockManager::FindFilesToPrune(std::set<int> &setFilesToPrune, | ||||
uint64_t nPruneAfterHeight, | uint64_t nPruneAfterHeight, | ||||
int chain_tip_height, bool is_ibd) { | int chain_tip_height, bool is_ibd) { | ||||
LOCK2(cs_main, cs_LastBlockFile); | LOCK2(cs_main, cs_LastBlockFile); | ||||
if (chain_tip_height < 0 || nPruneTarget == 0) { | if (chain_tip_height < 0 || nPruneTarget == 0) { | ||||
return; | return; | ||||
} | } | ||||
if (uint64_t(chain_tip_height) <= nPruneAfterHeight) { | if (uint64_t(chain_tip_height) <= nPruneAfterHeight) { | ||||
▲ Show 20 Lines • Show All 1,528 Lines • Show Last 20 Lines |