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.
This commit is contained in:
TheCharlatan 2024-11-27 14:01:38 +01:00
parent e7087d3da4
commit eec7c49cf7
No known key found for this signature in database
GPG key ID: 9B79B45691DB4173

View file

@ -64,10 +64,10 @@ int main(int argc, char* argv[])
// SETUP: Context // SETUP: Context
kernel::Context kernel_context{}; kernel::Context kernel_context{};
// We can't use a goto here, but we can use an assert since none of the if (!kernel::SanityChecks(kernel_context)) {
// things instantiated so far requires running the epilogue to be torn down std::cerr << "Failed sanity check.";
// properly return 1;
assert(kernel::SanityChecks(kernel_context)); }
ValidationSignals validation_signals{std::make_unique<util::ImmediateTaskRunner>()}; ValidationSignals validation_signals{std::make_unique<util::ImmediateTaskRunner>()};
@ -132,12 +132,12 @@ int main(int argc, char* argv[])
auto [status, error] = node::LoadChainstate(chainman, cache_sizes, options); auto [status, error] = node::LoadChainstate(chainman, cache_sizes, options);
if (status != node::ChainstateLoadStatus::SUCCESS) { if (status != node::ChainstateLoadStatus::SUCCESS) {
std::cerr << "Failed to load Chain state from your datadir." << std::endl; std::cerr << "Failed to load Chain state from your datadir." << std::endl;
goto epilogue; return 1;
} else { } else {
std::tie(status, error) = node::VerifyLoadedChainstate(chainman, options); std::tie(status, error) = node::VerifyLoadedChainstate(chainman, options);
if (status != node::ChainstateLoadStatus::SUCCESS) { if (status != node::ChainstateLoadStatus::SUCCESS) {
std::cerr << "Failed to verify loaded Chain state from your datadir." << std::endl; std::cerr << "Failed to verify loaded Chain state from your datadir." << std::endl;
goto epilogue; return 1;
} }
} }
@ -145,7 +145,7 @@ int main(int argc, char* argv[])
BlockValidationState state; BlockValidationState state;
if (!chainstate->ActivateBestChain(state, nullptr)) { if (!chainstate->ActivateBestChain(state, nullptr)) {
std::cerr << "Failed to connect best block (" << state.ToString() << ")" << std::endl; std::cerr << "Failed to connect best block (" << state.ToString() << ")" << std::endl;
goto epilogue; return 1;
} }
} }
@ -253,9 +253,4 @@ int main(int argc, char* argv[])
break; break;
} }
} }
epilogue:
// Without this precise shutdown sequence, there will be a lot of nullptr
// dereferencing and UB.
validation_signals.FlushBackgroundCallbacks();
} }