MCPcopy Create free account
hub / github.com/LUX-Core/lux / FindBlockPos

Function FindBlockPos

src/main.cpp:4195–4244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4193}
4194
4195bool 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
4246bool FindUndoPos(CValidationState& state, int nFile, CDiskBlockPos& pos, unsigned int nAddSize)
4247{

Callers 2

AcceptBlockFunction · 0.85
InitBlockIndexFunction · 0.85

Calls 11

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

Tested by

no test coverage detected