From 0df97547dd13dff42b512fb48aa7a9b74017d891 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 2 Jun 2023 12:06:04 +0930 Subject: [PATCH] lightningd: don't simply ignore defaults on flags, deprecate. Changelog-Deprecated: Plugins: `default` no longer accepted on `flag` type parameters (it was silently ignored, so just don't set it). Signed-off-by: Rusty Russell --- contrib/pyln-client/pyln/client/plugin.py | 2 +- doc/PLUGINS.md | 6 +++--- lightningd/plugin.c | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/contrib/pyln-client/pyln/client/plugin.py b/contrib/pyln-client/pyln/client/plugin.py index e53bcbeda..2673febab 100644 --- a/contrib/pyln-client/pyln/client/plugin.py +++ b/contrib/pyln-client/pyln/client/plugin.py @@ -912,7 +912,7 @@ class Plugin(object): m["long_description"] = method.long_desc manifest = { - 'options': list(self.options.values()), + 'options': list({k: v for k, v in d.items() if v is not None} for d in self.options.values()), 'rpcmethods': methods, 'subscriptions': list(self.subscriptions.keys()), 'hooks': hooks, diff --git a/doc/PLUGINS.md b/doc/PLUGINS.md index bc3102501..99c356581 100644 --- a/doc/PLUGINS.md +++ b/doc/PLUGINS.md @@ -207,11 +207,12 @@ There are currently four supported option 'types': - string: a string - bool: a boolean - int: parsed as a signed integer (64-bit) - - flag: no-arg flag option. Is boolean under the hood. Defaults to false. + - flag: no-arg flag option. Presented as `true` if config specifies it. In addition, string and int types can specify `"multi": true` to indicate they can be specified multiple times. These will always be represented in -`init` as a (possibly empty) JSON array. +`init` as a (possibly empty) JSON array. "multi" flag types do not make +sense. Nota bene: if a `flag` type option is not set, it will not appear in the options set that is passed to the plugin. @@ -229,7 +230,6 @@ Here's an example option set, as sent in response to `getmanifest` { "name": "run-hot", "type": "flag", - "default": None, // defaults to false "description": "If set, overclocks plugin" }, { diff --git a/lightningd/plugin.c b/lightningd/plugin.c index ba4b4d431..b5ae81f06 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -973,8 +973,13 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer, "%s type \"%s\" cannot have multi", popt->name, popt->type); /* We default flags to false, the default token is ignored */ - if (json_tok_streq(buffer, typetok, "flag")) + if (json_tok_streq(buffer, typetok, "flag") && defaulttok) { + if (!deprecated_apis) { + return tal_fmt(plugin, "%s type flag cannot have default", + popt->name); + } defaulttok = NULL; + } } else { return tal_fmt(plugin, "Only \"string\", \"int\", \"bool\", and \"flag\" options are supported");