Skip to content

Commit

Permalink
kernel: Remove epilogue in bitcoin-chainstate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheCharlatan committed Nov 27, 2024
1 parent 5e35692 commit 6c3bc47
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/bitcoin-chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<util::ImmediateTaskRunner>()};

Expand Down Expand Up @@ -131,20 +131,20 @@ 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;
}
}

for (Chainstate* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) {
BlockValidationState state;
if (!chainstate->ActivateBestChain(state, nullptr)) {
std::cerr << "Failed to connect best block (" << state.ToString() << ")" << std::endl;
goto epilogue;
return 1;
}
}

Expand Down Expand Up @@ -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();
}

0 comments on commit 6c3bc47

Please sign in to comment.