Skip to content

Commit 02e1e4e

Browse files
committed
rpc: Add wait argument to stop
1 parent 59f05d1 commit 02e1e4e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/rpc/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
162162
{ "rescanblockchain", 1, "stop_height"},
163163
{ "createwallet", 1, "disable_private_keys"},
164164
{ "getnodeaddresses", 0, "count"},
165+
{ "stop", 0, "wait" },
165166
};
166167
// clang-format on
167168

src/rpc/server.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ UniValue help(const JSONRPCRequest& jsonRequest)
227227
UniValue stop(const JSONRPCRequest& jsonRequest)
228228
{
229229
// Accept the deprecated and ignored 'detach' boolean argument
230+
// Also accept the hidden 'wait' integer argument (milliseconds)
231+
// For instance, 'stop 1000' makes the call wait 1 second before returning
232+
// to the client (intended for testing)
230233
if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
231234
throw std::runtime_error(
232235
RPCHelpMan{"stop",
@@ -235,6 +238,9 @@ UniValue stop(const JSONRPCRequest& jsonRequest)
235238
// Event loop will exit after current HTTP requests have been handled, so
236239
// this reply will get back to the client.
237240
StartShutdown();
241+
if (jsonRequest.params[0].isNum()) {
242+
MilliSleep(jsonRequest.params[0].get_int());
243+
}
238244
return "Bitcoin server stopping";
239245
}
240246

@@ -264,7 +270,7 @@ static const CRPCCommand vRPCCommands[] =
264270
// --------------------- ------------------------ ----------------------- ----------
265271
/* Overall control/query calls */
266272
{ "control", "help", &help, {"command"} },
267-
{ "control", "stop", &stop, {} },
273+
{ "control", "stop", &stop, {"wait"} },
268274
{ "control", "uptime", &uptime, {} },
269275
};
270276
// clang-format on

0 commit comments

Comments
 (0)