Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,190 Lines • ▼ Show 20 Lines | if (hashChecksum != verifier.GetHash()) { | ||||
return error("%s: Checksum mismatch", __func__); | return error("%s: Checksum mismatch", __func__); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
/** 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 = "") { | const std::string &userMessage = "", | ||||
unsigned int prefix = 0) { | |||||
SetMiscWarning(strMessage); | SetMiscWarning(strMessage); | ||||
LogPrintf("*** %s\n", strMessage); | LogPrintf("*** %s\n", strMessage); | ||||
if (!userMessage.empty()) { | |||||
uiInterface.ThreadSafeMessageBox( | uiInterface.ThreadSafeMessageBox( | ||||
userMessage.empty() ? _("Error: A fatal internal error occurred, see " | userMessage, "", CClientUIInterface::MSG_ERROR | prefix); | ||||
"debug.log for details") | } else { | ||||
.translated | uiInterface.ThreadSafeMessageBox( | ||||
: userMessage, | _("Error: A fatal internal error occurred, see debug.log for " | ||||
"", CClientUIInterface::MSG_ERROR); | "details") | ||||
.translated, | |||||
"", | |||||
CClientUIInterface::MSG_ERROR | CClientUIInterface::MSG_NOPREFIX); | |||||
} | |||||
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 std::string &userMessage = "", | ||||
AbortNode(strMessage, userMessage); | unsigned int prefix = 0) { | ||||
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 699 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(state, "Disk space is low!", | return AbortNode( | ||||
_("Error: Disk space is low!").translated); | state, "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 * pcoinsTip->GetCacheSize())) { | 48 * 2 * 2 * pcoinsTip->GetCacheSize())) { | ||||
return AbortNode(state, "Disk space is low!", | return AbortNode( | ||||
_("Error: Disk space is low!").translated); | state, "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 (!pcoinsTip->Flush()) { | if (!pcoinsTip->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,344 Lines • ▼ Show 20 Lines | if (fKnown) { | ||||
vinfoBlockFile[nFile].nSize += nAddSize; | vinfoBlockFile[nFile].nSize += 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 low!", | return AbortNode("Disk space is too low!", | ||||
_("Error: Disk space is low!").translated); | _("Error: Disk space is too low!").translated, | ||||
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; | ||||
} | } | ||||
static bool FindUndoPos(BlockValidationState &state, int nFile, | static bool FindUndoPos(BlockValidationState &state, int nFile, | ||||
FlatFilePos &pos, unsigned int nAddSize) { | FlatFilePos &pos, unsigned int nAddSize) { | ||||
pos.nFile = nFile; | pos.nFile = nFile; | ||||
LOCK(cs_LastBlockFile); | LOCK(cs_LastBlockFile); | ||||
pos.nPos = vinfoBlockFile[nFile].nUndoSize; | pos.nPos = vinfoBlockFile[nFile].nUndoSize; | ||||
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 low!", | return AbortNode(state, "Disk space is too low!", | ||||
_("Error: Disk space is low!").translated); | _("Error: Disk space is too low!").translated, | ||||
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,254 Lines • Show Last 20 Lines |