refactor: Split up NodeContext shutdown_signal and shutdown_request

Instead of having a single NodeContext::shutdown member that is used both to
request shutdowns and check if they have been requested, use separate members
for each. Benefits of this change:

1. Should make code a little clearer and easier to search because it is easier
   to see which parts of code are triggering shutdowns and which parts are just
   checking to see if they were triggered.

2. Makes it possible for init.cpp to specify additional code to run when a
   shutdown is requested, like signalling the m_tip_block_cv condition variable.

Motivation for this change was to remove hacky NodeContext argument and
m_tip_block_cv access from the StopRPC function, so StopRPC can just be
concerned with RPC functionality, not other node functionality.
This commit is contained in:
Ryan Ofsky
2024-09-25 10:45:34 +02:00
committed by MarcoFalke
parent fad8e7fba7
commit 5ca28ef28b
17 changed files with 53 additions and 51 deletions

View File

@@ -134,13 +134,15 @@ public:
}
void startShutdown() override
{
if (!(*Assert(Assert(m_context)->shutdown))()) {
NodeContext& ctx{*Assert(m_context)};
if (!(Assert(ctx.shutdown_request))()) {
LogError("Failed to send shutdown signal\n");
}
// Stop RPC for clean shutdown if any of waitfor* commands is executed.
if (args().GetBoolArg("-server", false)) {
InterruptRPC();
StopRPC(m_context);
StopRPC();
}
}
bool shutdownRequested() override { return ShutdownRequested(*Assert(m_context)); };