From 6c3bc478ca343557d798e2b18b5f99c08079ba9a Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Wed, 27 Nov 2024 14:01:38 +0100 Subject: [PATCH] kernel: Remove epilogue in bitcoin-chainstate There is no need to flush the background callbacks, since the immediate task runner is used for the validation signals, which does not have any pending callbacks. This allows for removal of the epilogue goto. --- src/bitcoin-chainstate.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index 91ef0d961238f..9a6129f8e99a5 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -64,10 +64,10 @@ int main(int argc, char* argv[]) // SETUP: Context kernel::Context kernel_context{}; - // We can't use a goto here, but we can use an assert since none of the - // things instantiated so far requires running the epilogue to be torn down - // properly - assert(kernel::SanityChecks(kernel_context)); + if (!kernel::SanityChecks(kernel_context)) { + std::cerr << "Failed sanity check."; + return 1; + } ValidationSignals validation_signals{std::make_unique()}; @@ -131,12 +131,12 @@ int main(int argc, char* argv[]) auto [status, error] = node::LoadChainstate(chainman, cache_sizes, options); if (status != node::ChainstateLoadStatus::SUCCESS) { std::cerr << "Failed to load Chain state from your datadir." << std::endl; - goto epilogue; + return 1; } else { std::tie(status, error) = node::VerifyLoadedChainstate(chainman, options); if (status != node::ChainstateLoadStatus::SUCCESS) { std::cerr << "Failed to verify loaded Chain state from your datadir." << std::endl; - goto epilogue; + return 1; } } @@ -144,7 +144,7 @@ int main(int argc, char* argv[]) BlockValidationState state; if (!chainstate->ActivateBestChain(state, nullptr)) { std::cerr << "Failed to connect best block (" << state.ToString() << ")" << std::endl; - goto epilogue; + return 1; } } @@ -276,9 +276,4 @@ int main(int argc, char* argv[]) break; } } - -epilogue: - // Without this precise shutdown sequence, there will be a lot of nullptr - // dereferencing and UB. - validation_signals.FlushBackgroundCallbacks(); }