From 24651f57adc773f3a3b1470181023c9187686a99 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 21 Nov 2022 11:12:28 +1030 Subject: [PATCH] plugins: set non_numeric_ids flag based on getmanifest `nonnumericids` field. And document support for it. Signed-off-by: Rusty Russell Changelog-Added: Plugins: `getmanfest` response can contain `nonnumericids` to indicate support for modern string-based JSON request ids. Changelog-Deprecated: Plugins: numeric JSON request ids: modern ones will be strings (see doc/lightningd-rpc.7.md!) --- doc/PLUGINS.md | 9 +++++++++ lightningd/plugin.c | 15 +++++++++++++++ lightningd/plugin.h | 3 +++ 3 files changed, 27 insertions(+) diff --git a/doc/PLUGINS.md b/doc/PLUGINS.md index a40e13f54..1a8946356 100644 --- a/doc/PLUGINS.md +++ b/doc/PLUGINS.md @@ -136,6 +136,7 @@ example: "method": "mycustomnotification" } ], + "nonnumericids": true, "dynamic": true } ``` @@ -158,6 +159,13 @@ you plan on removing them: this will disable them if the user sets `allow-deprecated-apis` to false (which every developer should do, right?). +The `nonnumericids` indicates that the plugin can handle +string JSON request `id` fields: prior to v22.11 lightningd used numbers +for these, and the change to strings broke some plugins. If not set, +then strings will be used once this feature is removed after v23.05. +See [the lightning-rpc documentation][lightning-rpc.7.md] for how to handle +JSON `id` fields! + The `dynamic` indicates if the plugin can be managed after `lightningd` has been started using the [plugin][lightning-plugin] JSON-RPC command. Critical plugins that should not be stopped should set it to false. Plugin `options` can be passed to dynamic plugins as argument to the `plugin` command . @@ -1781,3 +1789,4 @@ The plugin must broadcast it and respond with the following fields: [bolt9]: https://github.com/lightning/bolts/blob/master/09-features.md [lightning-plugin]: lightning-plugin.7.md [pyln-client]: ../contrib/pyln-client +[lightning-rpc.7.md]: lightning-rpc.7.md diff --git a/lightningd/plugin.c b/lightningd/plugin.c index b569d28f3..b01e3de4f 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -291,6 +291,7 @@ struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES, p->notification_topics = tal_arr(p, const char *, 0); p->subscriptions = NULL; p->dynamic = false; + p->non_numeric_ids = false; p->index = plugins->plugin_idx++; p->log = new_log(p, plugins->log_book, NULL, "plugin-%s", p->shortname); @@ -1528,6 +1529,20 @@ static const char *plugin_parse_getmanifest_response(const char *buffer, } } + tok = json_get_member(buffer, resulttok, "nonnumericids"); + if (tok) { + if (!json_to_bool(&plugin->non_numeric_ids, buffer, tok)) + return tal_fmt(plugin, + "Invalid nonnumericids: %.*s", + json_tok_full_len(tok), + json_tok_full(buffer, tok)); + if (!deprecated_apis && !plugin->non_numeric_ids) + return tal_fmt(plugin, + "Plugin does not allow nonnumericids"); + } else + /* Default is false in deprecated mode */ + plugin->non_numeric_ids = !deprecated_apis; + err = plugin_notifications_add(buffer, resulttok, plugin); if (!err) err = plugin_opts_add(plugin, buffer, resulttok); diff --git a/lightningd/plugin.h b/lightningd/plugin.h index fbcfbf486..6f41e701b 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -81,6 +81,9 @@ struct plugin { * C-lightning should terminate as well. */ bool important; + /* Can this handle non-numeric JSON ids? */ + bool non_numeric_ids; + /* Parameters for dynamically-started plugins. */ const char *parambuf; const jsmntok_t *params;