Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,481 Lines • ▼ Show 20 Lines | DisconnectResult ApplyBlockUndo(const CBlockUndo &blockUndo, | ||||
return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN; | return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN; | ||||
} | } | ||||
static void FlushBlockFile(bool fFinalize = false) { | static void FlushBlockFile(bool fFinalize = false) { | ||||
LOCK(cs_LastBlockFile); | LOCK(cs_LastBlockFile); | ||||
CDiskBlockPos posOld(nLastBlockFile, 0); | CDiskBlockPos posOld(nLastBlockFile, 0); | ||||
bool status = true; | |||||
FILE *fileOld = OpenBlockFile(posOld); | FILE *fileOld = OpenBlockFile(posOld); | ||||
if (fileOld) { | if (fileOld) { | ||||
if (fFinalize) { | if (fFinalize) { | ||||
status &= | |||||
TruncateFile(fileOld, vinfoBlockFile[nLastBlockFile].nSize); | TruncateFile(fileOld, vinfoBlockFile[nLastBlockFile].nSize); | ||||
} | } | ||||
FileCommit(fileOld); | status &= FileCommit(fileOld); | ||||
fclose(fileOld); | fclose(fileOld); | ||||
} | } | ||||
fileOld = OpenUndoFile(posOld); | fileOld = OpenUndoFile(posOld); | ||||
if (fileOld) { | if (fileOld) { | ||||
if (fFinalize) { | if (fFinalize) { | ||||
status &= | |||||
TruncateFile(fileOld, vinfoBlockFile[nLastBlockFile].nUndoSize); | TruncateFile(fileOld, vinfoBlockFile[nLastBlockFile].nUndoSize); | ||||
} | } | ||||
FileCommit(fileOld); | status &= FileCommit(fileOld); | ||||
fclose(fileOld); | fclose(fileOld); | ||||
} | } | ||||
if (!status) { | |||||
AbortNode("Flushing block file to disk failed. This is likely the " | |||||
"result of an I/O error."); | |||||
} | |||||
} | } | ||||
static bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, | static bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, | ||||
unsigned int nAddSize); | unsigned int nAddSize); | ||||
static bool WriteUndoDataForBlock(const CBlockUndo &blockundo, | static bool WriteUndoDataForBlock(const CBlockUndo &blockundo, | ||||
CValidationState &state, CBlockIndex *pindex, | CValidationState &state, CBlockIndex *pindex, | ||||
const CChainParams &chainparams) { | const CChainParams &chainparams) { | ||||
▲ Show 20 Lines • Show All 4,104 Lines • ▼ Show 20 Lines | try { | ||||
for (const auto &i : vinfo) { | for (const auto &i : vinfo) { | ||||
file << *(i.tx); | file << *(i.tx); | ||||
file << int64_t(i.nTime); | file << int64_t(i.nTime); | ||||
file << i.nFeeDelta; | file << i.nFeeDelta; | ||||
mapDeltas.erase(i.tx->GetId()); | mapDeltas.erase(i.tx->GetId()); | ||||
} | } | ||||
file << mapDeltas; | file << mapDeltas; | ||||
FileCommit(file.Get()); | if (!FileCommit(file.Get())) { | ||||
throw std::runtime_error("FileCommit failed"); | |||||
} | |||||
file.fclose(); | file.fclose(); | ||||
RenameOver(GetDataDir() / "mempool.dat.new", | RenameOver(GetDataDir() / "mempool.dat.new", | ||||
GetDataDir() / "mempool.dat"); | GetDataDir() / "mempool.dat"); | ||||
int64_t last = GetTimeMicros(); | int64_t last = GetTimeMicros(); | ||||
LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", | LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", | ||||
(mid - start) * MICRO, (last - mid) * MICRO); | (mid - start) * MICRO, (last - mid) * MICRO); | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
LogPrintf("Failed to dump mempool: %s. Continuing anyway.\n", e.what()); | LogPrintf("Failed to dump mempool: %s. Continuing anyway.\n", e.what()); | ||||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |