lightningd: allow false as a default for flags.

defaults were deprecated in 0df97547dd, 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 <rusty@rustcorp.com.au>
Changelog-Deprecated: Plugins: ...actually, `default` `false` still accepted on `flag` type parameters.
This commit is contained in:
Rusty Russell
2023-06-06 12:30:03 +09:30
parent 55119e6ca0
commit e457681f3a

View File

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