From dda154612cfa42f55cbc16c5bdfc5b13e7526c09 Mon Sep 17 00:00:00 2001 From: darosior Date: Thu, 18 Jul 2019 15:42:52 +0200 Subject: [PATCH] doc: add the new init and getmanifest fields --- doc/PLUGINS.md | 13 +++++++++++-- lightningd/plugin.c | 5 ++++- lightningd/plugin.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/PLUGINS.md b/doc/PLUGINS.md index 7e8a26287..c0484d9a9 100644 --- a/doc/PLUGINS.md +++ b/doc/PLUGINS.md @@ -85,7 +85,8 @@ this example: "hooks": [ "openchannel", "htlc_accepted" - ] + ], + "dynamic": true } ``` @@ -102,6 +103,10 @@ are mandatory, while the `long_description` can be omitted (it'll be set to `description` if it was not provided). `usage` should surround optional parameter names in `[]`. +The `dynamic` indicates if the plugin can be managed after `lightningd` +has been started. Critical plugins that should not be stop should set it +to false. + Plugins are free to register any `name` for their `rpcmethod` as long as the name was not previously registered. This includes both built-in methods, such as `help` and `getinfo`, as well as methods registered @@ -122,7 +127,8 @@ simple JSON object containing the options: }, "configuration": { "lightning-dir": "/home/user/.lightning", - "rpc-file": "lightning-rpc" + "rpc-file": "lightning-rpc", + "startup": true } } ``` @@ -132,6 +138,9 @@ arbitrary and will currently be discarded by `lightningd`. JSON-RPC commands were chosen over notifications in order not to force plugins to implement notifications which are not that well supported. +The `startup` field allows a plugin to detect if it was started at +`lightningd` startup (true), or at runtime (false). + ## JSON-RPC passthrough Plugins may register their own JSON-RPC methods that are exposed diff --git a/lightningd/plugin.c b/lightningd/plugin.c index cab15534f..30a8425c4 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -69,6 +69,7 @@ void plugin_register(struct plugins *plugins, const char* path TAKES) p->configured = false; p->js_arr = tal_arr(p, struct json_stream *, 0); p->used = 0; + p->signal_startup = false; p->log = new_log(p, plugins->log_book, "plugin-%s", path_basename(tmpctx, p->cmd)); @@ -808,8 +809,10 @@ static void plugin_manifest_cb(const char *buffer, } dynamictok = json_get_member(buffer, resulttok, "dynamic"); - if (dynamictok && json_to_bool(buffer, dynamictok, &dynamic_plugin)) + if (dynamictok && json_to_bool(buffer, dynamictok, &dynamic_plugin)) { + plugin->signal_startup = true; plugin->dynamic = dynamic_plugin; + } if (!plugin_opts_add(plugin, buffer, resulttok) || !plugin_rpcmethods_add(plugin, buffer, resulttok) || diff --git a/lightningd/plugin.h b/lightningd/plugin.h index 63cb2c8e4..033ea5966 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -23,6 +23,7 @@ struct plugin { bool configured; /* If this plugin can be restarted without restarting lightningd */ bool dynamic; + bool signal_startup; /* Stuff we read */ char *buffer;