Skip to content

Commit

Permalink
plugins: set non_numeric_ids flag based on getmanifest `nonnumericids…
Browse files Browse the repository at this point in the history
…` field.

And document support for it.

Signed-off-by: Rusty Russell <[email protected]>
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!)
  • Loading branch information
rustyrussell authored and cdecker committed Nov 21, 2022
1 parent b1f50c8 commit 24651f5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ example:
"method": "mycustomnotification"
}
],
"nonnumericids": true,
"dynamic": true
}
```
Expand All @@ -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 .
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions lightningd/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 24651f5

Please sign in to comment.