Calculate the block/rev files that should be deleted to remain under target*/
| 3716 | |
| 3717 | /* Calculate the block/rev files that should be deleted to remain under target*/ |
| 3718 | void FindFilesToPrune(std::set<int>& setFilesToPrune) |
| 3719 | { |
| 3720 | LOCK2(cs_main, cs_LastBlockFile); |
| 3721 | if (chainActive.Tip() == NULL || nPruneTarget == 0) { |
| 3722 | return; |
| 3723 | } |
| 3724 | if (chainActive.Tip()->nHeight <= Params().PruneAfterHeight()) { |
| 3725 | return; |
| 3726 | } |
| 3727 | |
| 3728 | unsigned int nLastBlockWeCanPrune = chainActive.Tip()->nHeight - MIN_BLOCKS_TO_KEEP; |
| 3729 | uint64_t nCurrentUsage = CalculateCurrentUsage(); |
| 3730 | // We don't check to prune until after we've allocated new space for files |
| 3731 | // So we should leave a buffer under our target to account for another allocation |
| 3732 | // before the next pruning. |
| 3733 | uint64_t nBuffer = BLOCKFILE_CHUNK_SIZE + UNDOFILE_CHUNK_SIZE; |
| 3734 | uint64_t nBytesToPrune; |
| 3735 | int count=0; |
| 3736 | |
| 3737 | if (nCurrentUsage + nBuffer >= nPruneTarget) { |
| 3738 | for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) { |
| 3739 | nBytesToPrune = vinfoBlockFile[fileNumber].nSize + vinfoBlockFile[fileNumber].nUndoSize; |
| 3740 | |
| 3741 | if (vinfoBlockFile[fileNumber].nSize == 0) |
| 3742 | continue; |
| 3743 | |
| 3744 | if (nCurrentUsage + nBuffer < nPruneTarget) // are we below our target? |
| 3745 | break; |
| 3746 | |
| 3747 | // don't prune files that could have a block within MIN_BLOCKS_TO_KEEP of the main chain's tip but keep scanning |
| 3748 | if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune) |
| 3749 | continue; |
| 3750 | |
| 3751 | PruneOneBlockFile(fileNumber); |
| 3752 | // Queue up the files for removal |
| 3753 | setFilesToPrune.insert(fileNumber); |
| 3754 | nCurrentUsage -= nBytesToPrune; |
| 3755 | count++; |
| 3756 | } |
| 3757 | } |
| 3758 | |
| 3759 | LogPrint("prune", "Prune: target=%dMiB actual=%dMiB diff=%dMiB max_prune_height=%d removed %d blk/rev pairs\n", |
| 3760 | nPruneTarget/1024/1024, nCurrentUsage/1024/1024, |
| 3761 | ((int64_t)nPruneTarget - (int64_t)nCurrentUsage)/1024/1024, |
| 3762 | nLastBlockWeCanPrune, count); |
| 3763 | } |
| 3764 | |
| 3765 | bool CheckDiskSpace(uint64_t nAdditionalBytes) |
| 3766 | { |
no test coverage detected