plugins: set non_numeric_ids flag based on getmanifest `nonnumericids` field.

And document support for it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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!)
This commit is contained in:
Rusty Russell 2022-11-21 11:12:28 +10:30 committed by Christian Decker
parent b1f50c825f
commit 24651f57ad
3 changed files with 27 additions and 0 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;