@@ -2657,20 +2657,12 @@ bool FindBlockPos(CValidationState& state, CDiskBlockPos& pos, unsigned int nAdd
26572657 vinfoBlockFile[nFile].nSize += nAddSize;
26582658
26592659 if (!fKnown ) {
2660- unsigned int nOldChunks = (pos.nPos + BLOCKFILE_CHUNK_SIZE - 1 ) / BLOCKFILE_CHUNK_SIZE;
2661- unsigned int nNewChunks = (vinfoBlockFile[nFile].nSize + BLOCKFILE_CHUNK_SIZE - 1 ) / BLOCKFILE_CHUNK_SIZE;
2662- if (nNewChunks > nOldChunks) {
2663- if (CheckDiskSpace (GetBlocksDir (), nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos )) {
2664- FILE* file = OpenBlockFile (pos);
2665- if (file) {
2666- LogPrintf (" Pre-allocating up to position 0x%x in blk%05u.dat\n " , nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile );
2667- AllocateFileRange (file, pos.nPos , nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos );
2668- fclose (file);
2669- }
2670- } else {
2671- return AbortNode (" Disk space is low!" , _ (" Error: Disk space is low!" ));
2672- }
2660+ bool out_of_space;
2661+ BlockFileSeq ().Allocate (pos, nAddSize, out_of_space);
2662+ if (out_of_space) {
2663+ return AbortNode (" Disk space is low!" , _ (" Error: Disk space is low!" ));
26732664 }
2665+ // future: add prunning flag check
26742666 }
26752667
26762668 setDirtyFileInfo.insert (nFile);
@@ -2683,25 +2675,16 @@ bool FindUndoPos(CValidationState& state, int nFile, CDiskBlockPos& pos, unsigne
26832675
26842676 LOCK (cs_LastBlockFile);
26852677
2686- unsigned int nNewSize;
26872678 pos.nPos = vinfoBlockFile[nFile].nUndoSize ;
2688- nNewSize = vinfoBlockFile[nFile].nUndoSize += nAddSize;
2679+ vinfoBlockFile[nFile].nUndoSize += nAddSize;
26892680 setDirtyFileInfo.insert (nFile);
26902681
2691- unsigned int nOldChunks = (pos.nPos + UNDOFILE_CHUNK_SIZE - 1 ) / UNDOFILE_CHUNK_SIZE;
2692- unsigned int nNewChunks = (nNewSize + UNDOFILE_CHUNK_SIZE - 1 ) / UNDOFILE_CHUNK_SIZE;
2693- if (nNewChunks > nOldChunks) {
2694- if (CheckDiskSpace (GetBlocksDir (), nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos )) {
2695- FILE* file = OpenUndoFile (pos);
2696- if (file) {
2697- LogPrintf (" Pre-allocating up to position 0x%x in rev%05u.dat\n " , nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile );
2698- AllocateFileRange (file, pos.nPos , nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos );
2699- fclose (file);
2700- }
2701- } else {
2702- return AbortNode (state, " Disk space is low!" , _ (" Error: Disk space is low!" ));
2703- }
2682+ bool out_of_space;
2683+ UndoFileSeq ().Allocate (pos, nAddSize, out_of_space);
2684+ if (out_of_space) {
2685+ return AbortNode (state, " Disk space is low!" , _ (" Error: Disk space is low!" ));
27042686 }
2687+ // future: add prunning flag check
27052688
27062689 return true ;
27072690}
0 commit comments