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

Function FindBlockPos

src/main.cpp:3201–3251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3199}
3200
3201bool 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
3253bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigned int nAddSize)
3254{

Callers 2

AcceptBlockFunction · 0.85
InitBlockIndexFunction · 0.85

Calls 13

GetNextMaxBlockSizeFunction · 0.85
FlushBlockFileFunction · 0.85
CheckDiskSpaceFunction · 0.85
OpenBlockFileFunction · 0.85
AllocateFileRangeFunction · 0.85
resizeMethod · 0.80
AddBlockMethod · 0.80
ErrorMethod · 0.80
ParamsClass · 0.70
sizeMethod · 0.45
TipMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected