Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,282 Lines • ▼ Show 20 Lines | bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex) { | ||||
// Verify checksum | // Verify checksum | ||||
if (hashChecksum != verifier.GetHash()) { | if (hashChecksum != verifier.GetHash()) { | ||||
return error("%s: Checksum mismatch", __func__); | return error("%s: Checksum mismatch", __func__); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
constexpr auto AbortError = InitError; | |||||
/** Abort with a message */ | /** Abort with a message */ | ||||
static bool AbortNode(const std::string &strMessage, | static bool AbortNode(const std::string &strMessage, | ||||
const std::string &userMessage = "", | bilingual_str user_message = bilingual_str()) { | ||||
unsigned int prefix = 0) { | |||||
SetMiscWarning(strMessage); | SetMiscWarning(strMessage); | ||||
LogPrintf("*** %s\n", strMessage); | LogPrintf("*** %s\n", strMessage); | ||||
if (!userMessage.empty()) { | if (!user_message.empty()) { | ||||
uiInterface.ThreadSafeMessageBox(Untranslated(userMessage), "", | user_message = | ||||
CClientUIInterface::MSG_ERROR | | _("A fatal internal error occurred, see debug.log for details"); | ||||
prefix); | |||||
} else { | |||||
uiInterface.ThreadSafeMessageBox( | |||||
_("Error: A fatal internal error occurred, see debug.log for " | |||||
"details"), | |||||
"", | |||||
CClientUIInterface::MSG_ERROR | CClientUIInterface::MSG_NOPREFIX); | |||||
} | } | ||||
AbortError(user_message); | |||||
StartShutdown(); | StartShutdown(); | ||||
return false; | return false; | ||||
} | } | ||||
static bool AbortNode(BlockValidationState &state, | static bool AbortNode(BlockValidationState &state, | ||||
const std::string &strMessage, | const std::string &strMessage, | ||||
const std::string &userMessage = "", | const bilingual_str &userMessage = bilingual_str()) { | ||||
unsigned int prefix = 0) { | AbortNode(strMessage, userMessage); | ||||
AbortNode(strMessage, userMessage, prefix); | |||||
return state.Error(strMessage); | return state.Error(strMessage); | ||||
} | } | ||||
/** Restore the UTXO in a Coin at a given COutPoint. */ | /** Restore the UTXO in a Coin at a given COutPoint. */ | ||||
DisconnectResult UndoCoinSpend(const Coin &undo, CCoinsViewCache &view, | DisconnectResult UndoCoinSpend(const Coin &undo, CCoinsViewCache &view, | ||||
const COutPoint &out) { | const COutPoint &out) { | ||||
bool fClean = true; | bool fClean = true; | ||||
▲ Show 20 Lines • Show All 788 Lines • ▼ Show 20 Lines | try { | ||||
nNow > nLastFlush + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000; | nNow > nLastFlush + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000; | ||||
// Combine all conditions that result in a full cache flush. | // Combine all conditions that result in a full cache flush. | ||||
fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || | fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || | ||||
fCacheCritical || fPeriodicFlush || fFlushForPrune; | fCacheCritical || fPeriodicFlush || fFlushForPrune; | ||||
// Write blocks and block index to disk. | // Write blocks and block index to disk. | ||||
if (fDoFullFlush || fPeriodicWrite) { | if (fDoFullFlush || fPeriodicWrite) { | ||||
// Depend on nMinDiskSpace to ensure we can write block index | // Depend on nMinDiskSpace to ensure we can write block index | ||||
if (!CheckDiskSpace(GetBlocksDir())) { | if (!CheckDiskSpace(GetBlocksDir())) { | ||||
return AbortNode( | return AbortNode(state, "Disk space is too low!", | ||||
state, "Disk space is too low!", | _("Disk space is too low!")); | ||||
_("Error: Disk space is too low!").translated, | |||||
CClientUIInterface::MSG_NOPREFIX); | |||||
} | } | ||||
// First make sure all block and undo data is flushed to disk. | // First make sure all block and undo data is flushed to disk. | ||||
FlushBlockFile(); | FlushBlockFile(); | ||||
// Then update all block file information (which may refer to | // Then update all block file information (which may refer to | ||||
// block and undo files). | // block and undo files). | ||||
{ | { | ||||
std::vector<std::pair<int, const CBlockFileInfo *>> vFiles; | std::vector<std::pair<int, const CBlockFileInfo *>> vFiles; | ||||
Show All 31 Lines | try { | ||||
// Typical Coin structures on disk are around 48 bytes in size. | // Typical Coin structures on disk are around 48 bytes in size. | ||||
// Pushing a new one to the database can cause it to be written | // Pushing a new one to the database can cause it to be written | ||||
// twice (once in the log, and once in the tables). This is | // twice (once in the log, and once in the tables). This is | ||||
// already an overestimation, as most will delete an existing | // already an overestimation, as most will delete an existing | ||||
// entry or overwrite one. Still, use a conservative safety | // entry or overwrite one. Still, use a conservative safety | ||||
// factor of 2. | // factor of 2. | ||||
if (!CheckDiskSpace(GetDataDir(), | if (!CheckDiskSpace(GetDataDir(), | ||||
48 * 2 * 2 * CoinsTip().GetCacheSize())) { | 48 * 2 * 2 * CoinsTip().GetCacheSize())) { | ||||
return AbortNode( | return AbortNode(state, "Disk space is too low!", | ||||
state, "Disk space is too low!", | _("Disk space is too low!")); | ||||
_("Error: Disk space is too low!").translated, | |||||
CClientUIInterface::MSG_NOPREFIX); | |||||
} | } | ||||
// Flush the chainstate (which may refer to block index | // Flush the chainstate (which may refer to block index | ||||
// entries). | // entries). | ||||
if (!CoinsTip().Flush()) { | if (!CoinsTip().Flush()) { | ||||
return AbortNode(state, "Failed to write to coin database"); | return AbortNode(state, "Failed to write to coin database"); | ||||
} | } | ||||
nLastFlush = nNow; | nLastFlush = nNow; | ||||
▲ Show 20 Lines • Show All 1,462 Lines • ▼ Show 20 Lines | static bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, | ||||
} | } | ||||
if (!fKnown) { | if (!fKnown) { | ||||
bool out_of_space; | bool out_of_space; | ||||
size_t bytes_allocated = | size_t bytes_allocated = | ||||
BlockFileSeq().Allocate(pos, nAddSize, out_of_space); | BlockFileSeq().Allocate(pos, nAddSize, out_of_space); | ||||
if (out_of_space) { | if (out_of_space) { | ||||
return AbortNode("Disk space is too low!", | return AbortNode("Disk space is too low!", | ||||
_("Error: Disk space is too low!").translated, | _("Disk space is too low!")); | ||||
CClientUIInterface::MSG_NOPREFIX); | |||||
} | } | ||||
if (bytes_allocated != 0 && fPruneMode) { | if (bytes_allocated != 0 && fPruneMode) { | ||||
fCheckForPruning = true; | fCheckForPruning = true; | ||||
} | } | ||||
} | } | ||||
setDirtyFileInfo.insert(nFile); | setDirtyFileInfo.insert(nFile); | ||||
return true; | return true; | ||||
Show All 9 Lines | static bool FindUndoPos(BlockValidationState &state, int nFile, | ||||
vinfoBlockFile[nFile].nUndoSize += nAddSize; | vinfoBlockFile[nFile].nUndoSize += nAddSize; | ||||
setDirtyFileInfo.insert(nFile); | setDirtyFileInfo.insert(nFile); | ||||
bool out_of_space; | bool out_of_space; | ||||
size_t bytes_allocated = | size_t bytes_allocated = | ||||
UndoFileSeq().Allocate(pos, nAddSize, out_of_space); | UndoFileSeq().Allocate(pos, nAddSize, out_of_space); | ||||
if (out_of_space) { | if (out_of_space) { | ||||
return AbortNode(state, "Disk space is too low!", | return AbortNode(state, "Disk space is too low!", | ||||
_("Error: Disk space is too low!").translated, | _("Disk space is too low!")); | ||||
CClientUIInterface::MSG_NOPREFIX); | |||||
} | } | ||||
if (bytes_allocated != 0 && fPruneMode) { | if (bytes_allocated != 0 && fPruneMode) { | ||||
fCheckForPruning = true; | fCheckForPruning = true; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,333 Lines • Show Last 20 Lines |