From 9ddf7e03a35592617a016418fd320cc93c8d1abd Mon Sep 17 00:00:00 2001 From: furszy Date: Mon, 29 May 2023 18:56:58 -0300 Subject: move ThreadImport ABC error to use AbortNode 'StartShutdown' should only be used for user requested shutdowns. Internal errors that cause a shutdown should use 'AbortNode'. --- src/node/blockstorage.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/node') diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index b7afa8a7c3..1368ae6f6d 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -928,8 +928,7 @@ void ThreadImport(ChainstateManager& chainman, std::vector vImportFile for (Chainstate* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) { BlockValidationState state; if (!chainstate->ActivateBestChain(state, nullptr)) { - LogPrintf("Failed to connect best block (%s)\n", state.ToString()); - StartShutdown(); + AbortNode(strprintf("Failed to connect best block (%s)", state.ToString())); return; } } -- cgit v1.2.3 From 3b2c61e8198bcefb1c2343caff1d705951026cc4 Mon Sep 17 00:00:00 2001 From: furszy Date: Sat, 20 May 2023 10:51:17 -0300 Subject: Return EXIT_FAILURE on post-init fatal errors It seems odd to return `EXIT_SUCCESS` when the node aborted execution due a fatal internal error or any post-init problem that triggers an unrequested shutdown. e.g. blocks or coins db I/O errors, disconnect block failure, failure during thread import (external blocks loading process error), among others. Co-authored-by: Ryan Ofsky --- src/node/context.h | 3 +++ src/node/interfaces.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/node') diff --git a/src/node/context.h b/src/node/context.h index 9532153cdb..91b68fa5bb 100644 --- a/src/node/context.h +++ b/src/node/context.h @@ -7,7 +7,9 @@ #include +#include #include +#include #include #include #include @@ -65,6 +67,7 @@ struct NodeContext { std::unique_ptr scheduler; std::function rpc_interruption_point = [] {}; std::unique_ptr notifications; + std::atomic exit_status{EXIT_SUCCESS}; //! Declare default constructor and destructor that are not inline, so code //! instantiating the NodeContext struct doesn't need to #include class diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 6e39ccf34e..bf42167c2f 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -92,7 +92,7 @@ public: uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); } bool baseInitialize() override { - if (!AppInitBasicSetup(args())) return false; + if (!AppInitBasicSetup(args(), Assert(context())->exit_status)) return false; if (!AppInitParameterInteraction(args(), /*use_syscall_sandbox=*/false)) return false; m_context->kernel = std::make_unique(); -- cgit v1.2.3 From 4927167f855f8ed3bbf6d2766f61229f742e632a Mon Sep 17 00:00:00 2001 From: furszy Date: Thu, 8 Jun 2023 12:16:23 -0300 Subject: gui: return EXIT_FAILURE on post-init fatal errors --- src/node/interfaces.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/node') diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index bf42167c2f..f741bd6d03 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -89,6 +89,7 @@ public: void initLogging() override { InitLogging(args()); } void initParameterInteraction() override { InitParameterInteraction(args()); } bilingual_str getWarnings() override { return GetWarnings(true); } + int getExitStatus() override { return Assert(m_context)->exit_status.load(); } uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); } bool baseInitialize() override { @@ -105,7 +106,10 @@ public: } bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override { - return AppInitMain(*m_context, tip_info); + if (AppInitMain(*m_context, tip_info)) return true; + // Error during initialization, set exit status before continue + m_context->exit_status.store(EXIT_FAILURE); + return false; } void appShutdown() override { -- cgit v1.2.3