MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / FindUndoPos

Function FindUndoPos

src/main.cpp:711–747  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

709}
710
711static bool FindUndoPos(CValidationState &state, int32_t nFile, CDiskBlockPos &pos, uint32_t nAddSize) {
712 pos.nFile = nFile;
713
714 LOCK(cs_LastBlockFile);
715
716 uint32_t nNewSize;
717 if (nFile == nLastBlockFile) {
718 pos.nPos = infoLastBlockFile.nUndoSize;
719 nNewSize = (infoLastBlockFile.nUndoSize += nAddSize);
720 if (!pCdMan->pBlockIndexDb->WriteBlockFileInfo(nLastBlockFile, infoLastBlockFile))
721 return state.Abort(_("Failed to write block info"));
722 } else {
723 CBlockFileInfo info;
724 if (!pCdMan->pBlockIndexDb->ReadBlockFileInfo(nFile, info))
725 return state.Abort(_("Failed to read block info"));
726 pos.nPos = info.nUndoSize;
727 nNewSize = (info.nUndoSize += nAddSize);
728 if (!pCdMan->pBlockIndexDb->WriteBlockFileInfo(nFile, info))
729 return state.Abort(_("Failed to write block info"));
730 }
731
732 uint32_t nOldChunks = (pos.nPos + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE;
733 uint32_t nNewChunks = (nNewSize + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE;
734 if (nNewChunks > nOldChunks) {
735 if (CheckDiskSpace(nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos)) {
736 FILE *file = OpenUndoFile(pos);
737 if (file) {
738 LogPrint(BCLog::INFO, "Pre-allocating up to position 0x%x in rev%05u.dat\n", nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile);
739 AllocateFileRange(file, pos.nPos, nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos);
740 fclose(file);
741 }
742 } else
743 return state.Error("out of disk space");
744 }
745
746 return true;
747}
748
749static bool PersistNativeAsset(CCacheWrapper& cw) {
750 CAsset wicc(SYMB::WICC, SYMB::WICC, AssetType::NIA, kWiccPerms, CRegID(), INITIAL_BASE_COIN_AMOUNT * COIN, false);

Callers 1

ConnectBlockFunction · 0.85

Calls 8

_Function · 0.85
CheckDiskSpaceFunction · 0.85
OpenUndoFileFunction · 0.85
AllocateFileRangeFunction · 0.85
WriteBlockFileInfoMethod · 0.80
AbortMethod · 0.80
ReadBlockFileInfoMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected