| 3199 | } |
| 3200 | |
| 3201 | bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false) |
| 3202 | { |
| 3203 | LOCK(cs_LastBlockFile); |
| 3204 | |
| 3205 | unsigned int nFile = fKnown ? pos.nFile : nLastBlockFile; |
| 3206 | if (vinfoBlockFile.size() <= nFile) { |
| 3207 | vinfoBlockFile.resize(nFile + 1); |
| 3208 | } |
| 3209 | |
| 3210 | if (!fKnown) { |
| 3211 | while (vinfoBlockFile[nFile].nSize + nAddSize >= GetNextMaxBlockSize(chainActive.Tip(), Params().GetConsensus()) * MIN_BLOCKFILE_BLOCKS) { |
| 3212 | LogPrintf("Leaving block file %i: %s\n", nFile, vinfoBlockFile[nFile].ToString()); |
| 3213 | FlushBlockFile(true); |
| 3214 | nFile++; |
| 3215 | if (vinfoBlockFile.size() <= nFile) { |
| 3216 | vinfoBlockFile.resize(nFile + 1); |
| 3217 | } |
| 3218 | } |
| 3219 | pos.nFile = nFile; |
| 3220 | pos.nPos = vinfoBlockFile[nFile].nSize; |
| 3221 | } |
| 3222 | |
| 3223 | nLastBlockFile = nFile; |
| 3224 | vinfoBlockFile[nFile].AddBlock(nHeight, nTime); |
| 3225 | if (fKnown) |
| 3226 | vinfoBlockFile[nFile].nSize = std::max(pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize); |
| 3227 | else |
| 3228 | vinfoBlockFile[nFile].nSize += nAddSize; |
| 3229 | |
| 3230 | if (!fKnown) { |
| 3231 | unsigned int nOldChunks = (pos.nPos + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; |
| 3232 | unsigned int nNewChunks = (vinfoBlockFile[nFile].nSize + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; |
| 3233 | if (nNewChunks > nOldChunks) { |
| 3234 | if (fPruneMode) |
| 3235 | fCheckForPruning = true; |
| 3236 | if (CheckDiskSpace(nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos)) { |
| 3237 | FILE *file = OpenBlockFile(pos); |
| 3238 | if (file) { |
| 3239 | LogPrintf("Pre-allocating up to position 0x%x in blk%05u.dat\n", nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile); |
| 3240 | AllocateFileRange(file, pos.nPos, nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos); |
| 3241 | fclose(file); |
| 3242 | } |
| 3243 | } |
| 3244 | else |
| 3245 | return state.Error("out of disk space"); |
| 3246 | } |
| 3247 | } |
| 3248 | |
| 3249 | setDirtyFileInfo.insert(nFile); |
| 3250 | return true; |
| 3251 | } |
| 3252 | |
| 3253 | bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigned int nAddSize) |
| 3254 | { |
no test coverage detected