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

Function FindBlockPos

src/validation.cpp:3188–3243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3186}
3187
3188static bool FindBlockPos(CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false)
3189{
3190 LOCK(cs_LastBlockFile);
3191
3192 unsigned int nFile = fKnown ? pos.nFile : nLastBlockFile;
3193 if (vinfoBlockFile.size() <= nFile) {
3194 vinfoBlockFile.resize(nFile + 1);
3195 }
3196
3197 if (!fKnown) {
3198 while (vinfoBlockFile[nFile].nSize + nAddSize >= MAX_BLOCKFILE_SIZE) {
3199 nFile++;
3200 if (vinfoBlockFile.size() <= nFile) {
3201 vinfoBlockFile.resize(nFile + 1);
3202 }
3203 }
3204 pos.nFile = nFile;
3205 pos.nPos = vinfoBlockFile[nFile].nSize;
3206 }
3207
3208 if ((int)nFile != nLastBlockFile) {
3209 if (!fKnown) {
3210 LogPrintf("Leaving block file %i: %s\n", nLastBlockFile, vinfoBlockFile[nLastBlockFile].ToString());
3211 }
3212 FlushBlockFile(!fKnown);
3213 nLastBlockFile = nFile;
3214 }
3215
3216 vinfoBlockFile[nFile].AddBlock(nHeight, nTime);
3217 if (fKnown)
3218 vinfoBlockFile[nFile].nSize = std::max(pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize);
3219 else
3220 vinfoBlockFile[nFile].nSize += nAddSize;
3221
3222 if (!fKnown) {
3223 unsigned int nOldChunks = (pos.nPos + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE;
3224 unsigned int nNewChunks = (vinfoBlockFile[nFile].nSize + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE;
3225 if (nNewChunks > nOldChunks) {
3226 if (fPruneMode)
3227 fCheckForPruning = true;
3228 if (CheckDiskSpace(nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos, true)) {
3229 FILE *file = OpenBlockFile(pos);
3230 if (file) {
3231 LogPrintf("Pre-allocating up to position 0x%x in blk%05u.dat\n", nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile);
3232 AllocateFileRange(file, pos.nPos, nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos);
3233 fclose(file);
3234 }
3235 }
3236 else
3237 return error("out of disk space");
3238 }
3239 }
3240
3241 setDirtyFileInfo.insert(nFile);
3242 return true;
3243}
3244
3245static bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigned int nAddSize)

Callers 1

SaveBlockToDiskFunction · 0.85

Calls 11

FlushBlockFileFunction · 0.85
maxFunction · 0.85
CheckDiskSpaceFunction · 0.85
OpenBlockFileFunction · 0.85
AllocateFileRangeFunction · 0.85
errorFunction · 0.85
AddBlockMethod · 0.80
sizeMethod · 0.45
resizeMethod · 0.45
ToStringMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected