mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
kernel: Add fatalError method to notifications
FatalError replaces what previously was the AbortNode function in shutdown.cpp. This commit is part of the libbitcoinkernel project and further removes the shutdown's and, more generally, the kernel library's dependency on interface_ui with a kernel notification method. By removing interface_ui from the kernel library, its dependency on boost is reduced to just boost::multi_index. At the same time it also takes a step towards de-globalising the interrupt infrastructure. Co-authored-by: Russell Yanofsky <russ@yanofsky.org> Co-authored-by: TheCharlatan <seb.kung@gmail.com>
This commit is contained in:
@@ -1842,9 +1842,9 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AbortNode(BlockValidationState& state, const std::string& strMessage, const bilingual_str& userMessage)
|
||||
bool FatalError(Notifications& notifications, BlockValidationState& state, const std::string& strMessage, const bilingual_str& userMessage)
|
||||
{
|
||||
AbortNode(strMessage, userMessage);
|
||||
notifications.fatalError(strMessage, userMessage);
|
||||
return state.Error(strMessage);
|
||||
}
|
||||
|
||||
@@ -2079,7 +2079,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||
// We don't write down blocks to disk if they may have been
|
||||
// corrupted, so this should be impossible unless we're having hardware
|
||||
// problems.
|
||||
return AbortNode(state, "Corrupt block found indicating potential hardware failure; shutting down");
|
||||
return FatalError(m_chainman.GetNotifications(), state, "Corrupt block found indicating potential hardware failure; shutting down");
|
||||
}
|
||||
return error("%s: Consensus::CheckBlock: %s", __func__, state.ToString());
|
||||
}
|
||||
@@ -2499,7 +2499,7 @@ bool Chainstate::FlushStateToDisk(
|
||||
if (fDoFullFlush || fPeriodicWrite) {
|
||||
// Ensure we can write block index
|
||||
if (!CheckDiskSpace(m_blockman.m_opts.blocks_dir)) {
|
||||
return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
|
||||
return FatalError(m_chainman.GetNotifications(), state, "Disk space is too low!", _("Disk space is too low!"));
|
||||
}
|
||||
{
|
||||
LOG_TIME_MILLIS_WITH_CATEGORY("write block and undo data to disk", BCLog::BENCH);
|
||||
@@ -2513,7 +2513,7 @@ bool Chainstate::FlushStateToDisk(
|
||||
LOG_TIME_MILLIS_WITH_CATEGORY("write block index to disk", BCLog::BENCH);
|
||||
|
||||
if (!m_blockman.WriteBlockIndexDB()) {
|
||||
return AbortNode(state, "Failed to write to block index database");
|
||||
return FatalError(m_chainman.GetNotifications(), state, "Failed to write to block index database");
|
||||
}
|
||||
}
|
||||
// Finally remove any pruned files
|
||||
@@ -2535,11 +2535,11 @@ bool Chainstate::FlushStateToDisk(
|
||||
// an overestimation, as most will delete an existing entry or
|
||||
// overwrite one. Still, use a conservative safety factor of 2.
|
||||
if (!CheckDiskSpace(m_chainman.m_options.datadir, 48 * 2 * 2 * CoinsTip().GetCacheSize())) {
|
||||
return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
|
||||
return FatalError(m_chainman.GetNotifications(), state, "Disk space is too low!", _("Disk space is too low!"));
|
||||
}
|
||||
// Flush the chainstate (which may refer to block index entries).
|
||||
if (!CoinsTip().Flush())
|
||||
return AbortNode(state, "Failed to write to coin database");
|
||||
return FatalError(m_chainman.GetNotifications(), state, "Failed to write to coin database");
|
||||
m_last_flush = nNow;
|
||||
full_flush_completed = true;
|
||||
TRACE5(utxocache, flush,
|
||||
@@ -2555,7 +2555,7 @@ bool Chainstate::FlushStateToDisk(
|
||||
GetMainSignals().ChainStateFlushed(m_chain.GetLocator());
|
||||
}
|
||||
} catch (const std::runtime_error& e) {
|
||||
return AbortNode(state, std::string("System error while flushing: ") + e.what());
|
||||
return FatalError(m_chainman.GetNotifications(), state, std::string("System error while flushing: ") + e.what());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -2791,7 +2791,7 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew,
|
||||
if (!pblock) {
|
||||
std::shared_ptr<CBlock> pblockNew = std::make_shared<CBlock>();
|
||||
if (!m_blockman.ReadBlockFromDisk(*pblockNew, *pindexNew)) {
|
||||
return AbortNode(state, "Failed to read block");
|
||||
return FatalError(m_chainman.GetNotifications(), state, "Failed to read block");
|
||||
}
|
||||
pthisBlock = pblockNew;
|
||||
} else {
|
||||
@@ -2975,7 +2975,7 @@ bool Chainstate::ActivateBestChainStep(BlockValidationState& state, CBlockIndex*
|
||||
// If we're unable to disconnect a block during normal operation,
|
||||
// then that is a failure of our local system -- we should abort
|
||||
// rather than stay on a less work chain.
|
||||
AbortNode(state, "Failed to disconnect block; see debug.log for details");
|
||||
FatalError(m_chainman.GetNotifications(), state, "Failed to disconnect block; see debug.log for details");
|
||||
return false;
|
||||
}
|
||||
fBlocksDisconnected = true;
|
||||
@@ -3970,7 +3970,7 @@ bool Chainstate::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockV
|
||||
}
|
||||
ReceivedBlockTransactions(block, pindex, blockPos);
|
||||
} catch (const std::runtime_error& e) {
|
||||
return AbortNode(state, std::string("System error: ") + e.what());
|
||||
return FatalError(m_chainman.GetNotifications(), state, std::string("System error: ") + e.what());
|
||||
}
|
||||
|
||||
FlushStateToDisk(state, FlushStateMode::NONE);
|
||||
@@ -4661,7 +4661,7 @@ void Chainstate::LoadExternalBlockFile(
|
||||
}
|
||||
}
|
||||
} catch (const std::runtime_error& e) {
|
||||
AbortNode(std::string("System error: ") + e.what());
|
||||
m_chainman.GetNotifications().fatalError(std::string("System error: ") + e.what());
|
||||
}
|
||||
LogPrintf("Loaded %i blocks from external file in %dms\n", nLoaded, Ticks<std::chrono::milliseconds>(SteadyClock::now() - start));
|
||||
}
|
||||
@@ -5113,7 +5113,7 @@ bool ChainstateManager::ActivateSnapshot(
|
||||
snapshot_chainstate.reset();
|
||||
bool removed = DeleteCoinsDBFromDisk(*snapshot_datadir, /*is_snapshot=*/true);
|
||||
if (!removed) {
|
||||
AbortNode(strprintf("Failed to remove snapshot chainstate dir (%s). "
|
||||
GetNotifications().fatalError(strprintf("Failed to remove snapshot chainstate dir (%s). "
|
||||
"Manually remove it before restarting.\n", fs::PathToString(*snapshot_datadir)));
|
||||
}
|
||||
}
|
||||
@@ -5378,8 +5378,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
|
||||
// through IsUsable() checks, or
|
||||
//
|
||||
// (ii) giving each chainstate its own lock instead of using cs_main for everything.
|
||||
SnapshotCompletionResult ChainstateManager::MaybeCompleteSnapshotValidation(
|
||||
std::function<void(bilingual_str)> shutdown_fnc)
|
||||
SnapshotCompletionResult ChainstateManager::MaybeCompleteSnapshotValidation()
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
if (m_ibd_chainstate.get() == &this->ActiveChainstate() ||
|
||||
@@ -5431,7 +5430,7 @@ SnapshotCompletionResult ChainstateManager::MaybeCompleteSnapshotValidation(
|
||||
user_error = strprintf(Untranslated("%s\n%s"), user_error, util::ErrorString(rename_result));
|
||||
}
|
||||
|
||||
shutdown_fnc(user_error);
|
||||
GetNotifications().fatalError(user_error.original, user_error);
|
||||
};
|
||||
|
||||
if (index_new.GetBlockHash() != snapshot_blockhash) {
|
||||
@@ -5728,13 +5727,13 @@ bool ChainstateManager::ValidatedSnapshotCleanup()
|
||||
|
||||
fs::path tmp_old{ibd_chainstate_path + "_todelete"};
|
||||
|
||||
auto rename_failed_abort = [](
|
||||
auto rename_failed_abort = [this](
|
||||
fs::path p_old,
|
||||
fs::path p_new,
|
||||
const fs::filesystem_error& err) {
|
||||
LogPrintf("%s: error renaming file (%s): %s\n",
|
||||
__func__, fs::PathToString(p_old), err.what());
|
||||
AbortNode(strprintf(
|
||||
GetNotifications().fatalError(strprintf(
|
||||
"Rename of '%s' -> '%s' failed. "
|
||||
"Cannot clean up the background chainstate leveldb directory.",
|
||||
fs::PathToString(p_old), fs::PathToString(p_new)));
|
||||
@@ -5759,7 +5758,7 @@ bool ChainstateManager::ValidatedSnapshotCleanup()
|
||||
}
|
||||
|
||||
if (!DeleteCoinsDBFromDisk(tmp_old, /*is_snapshot=*/false)) {
|
||||
// No need to AbortNode because once the unneeded bg chainstate data is
|
||||
// No need to FatalError because once the unneeded bg chainstate data is
|
||||
// moved, it will not interfere with subsequent initialization.
|
||||
LogPrintf("Deletion of %s failed. Please remove it manually, as the " /* Continued */
|
||||
"directory is now unnecessary.\n",
|
||||
|
||||
Reference in New Issue
Block a user