From e457681f3a0220e2551647dc8d9016638fed5ba9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 6 Jun 2023 12:30:03 +0930 Subject: [PATCH] lightningd: allow `false` as a default for flags. defaults were deprecated in 0df97547dd13dff42b512fb48aa7a9b74017d891, but that was a bit harsh as several plugins do that (summary, for example). So allow false, but warn that we ignore anything else. Reported-by: @microsatoshi on Discord. Signed-off-by: Rusty Russell Changelog-Deprecated: Plugins: ...actually, `default` `false` still accepted on `flag` type parameters. --- lightningd/plugin.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index d7ad4707e..2a1cb7942 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -960,9 +960,22 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer, if (json_tok_streq(buffer, typetok, "flag")) { if (defaulttok) { - if (!deprecated_apis) { - return tal_fmt(plugin, "%s type flag cannot have default", - popt->name); + bool val; + /* We used to allow (ignore) anything, now make sure it's 'false' */ + if (!json_to_bool(buffer, defaulttok, &val) + || val != false) { + if (!deprecated_apis) + return tal_fmt(plugin, "%s type flag default must be 'false' not %.*s", + popt->name, + json_tok_full_len(defaulttok), + json_tok_full(buffer, defaulttok)); + else { + /* At least warn that we're ignoring! */ + log_broken(plugin->log, "Ignoring default %.*s for %s (if set, must be 'false'!)", + json_tok_full_len(defaulttok), + json_tok_full(buffer, defaulttok), + popt->name); + } } defaulttok = NULL; }