| 709 | } |
| 710 | |
| 711 | static 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 | |
| 749 | static bool PersistNativeAsset(CCacheWrapper& cw) { |
| 750 | CAsset wicc(SYMB::WICC, SYMB::WICC, AssetType::NIA, kWiccPerms, CRegID(), INITIAL_BASE_COIN_AMOUNT * COIN, false); |
no test coverage detected