| 4193 | } |
| 4194 | |
| 4195 | bool FindBlockPos(CValidationState& state, CDiskBlockPos& pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false) |
| 4196 | { |
| 4197 | LOCK(cs_LastBlockFile); |
| 4198 | |
| 4199 | unsigned int nFile = fKnown ? pos.nFile : nLastBlockFile; |
| 4200 | if (vinfoBlockFile.size() <= nFile) { |
| 4201 | vinfoBlockFile.resize(nFile + 1); |
| 4202 | } |
| 4203 | |
| 4204 | if (!fKnown) { |
| 4205 | while (vinfoBlockFile[nFile].nSize + nAddSize >= MAX_BLOCKFILE_SIZE) { |
| 4206 | LogPrintf("Leaving block file %u: %s\n", nFile, vinfoBlockFile[nFile].ToString()); |
| 4207 | FlushBlockFile(true); |
| 4208 | nFile++; |
| 4209 | if (vinfoBlockFile.size() <= nFile) { |
| 4210 | vinfoBlockFile.resize(nFile + 1); |
| 4211 | } |
| 4212 | } |
| 4213 | pos.nFile = nFile; |
| 4214 | pos.nPos = vinfoBlockFile[nFile].nSize; |
| 4215 | } |
| 4216 | |
| 4217 | nLastBlockFile = nFile; |
| 4218 | vinfoBlockFile[nFile].AddBlock(nHeight, nTime); |
| 4219 | if (fKnown) |
| 4220 | vinfoBlockFile[nFile].nSize = std::max(pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize); |
| 4221 | else |
| 4222 | vinfoBlockFile[nFile].nSize += nAddSize; |
| 4223 | |
| 4224 | if (!fKnown) { |
| 4225 | unsigned int nOldChunks = (pos.nPos + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; |
| 4226 | unsigned int nNewChunks = (vinfoBlockFile[nFile].nSize + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; |
| 4227 | if (nNewChunks > nOldChunks) { |
| 4228 | if (fPruneMode) |
| 4229 | fCheckForPruning = true; |
| 4230 | if (CheckDiskSpace(nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos)) { |
| 4231 | FILE* file = OpenBlockFile(pos); |
| 4232 | if (file) { |
| 4233 | LogPrintf("Pre-allocating up to position 0x%x in blk%05u.dat\n", nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile); |
| 4234 | AllocateFileRange(file, pos.nPos, nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos); |
| 4235 | fclose(file); |
| 4236 | } |
| 4237 | } else |
| 4238 | return state.Error("out of disk space"); |
| 4239 | } |
| 4240 | } |
| 4241 | |
| 4242 | setDirtyFileInfo.insert(nFile); |
| 4243 | return true; |
| 4244 | } |
| 4245 | |
| 4246 | bool FindUndoPos(CValidationState& state, int nFile, CDiskBlockPos& pos, unsigned int nAddSize) |
| 4247 | { |
no test coverage detected