From 8d68c608ded413eac93f0528ac5da2c2af9a435a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 25 Jan 2024 10:58:56 +1030 Subject: [PATCH] commando: use deprecation API for missing ids. In this case we don't have a matching "command", so we need a special API. Signed-off-by: Rusty Russell --- doc/developers-guide/deprecations.md | 2 ++ plugins/commando.c | 3 ++- plugins/libplugin.c | 28 ++++++++++++++++++++++++++++ plugins/libplugin.h | 6 ++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/doc/developers-guide/deprecations.md b/doc/developers-guide/deprecations.md index 584280b19..a0640c7bf 100644 --- a/doc/developers-guide/deprecations.md +++ b/doc/developers-guide/deprecations.md @@ -47,6 +47,8 @@ hidden: false | estimatefees.penalty | Field | v23.05 | v24.05 | `penalty` feerate (implementation-specific, use modern feerates) | | estimatefees.min_acceptable | Field | v23.05 | v24.05 | `min_acceptable` feerate (implementation-specific, use modern feerates) | | estimatefees.max_acceptable | Field | v23.05 | v24.05 | `max_acceptable` feerate (implementation-specific, use modern feerates) | +| commando.missing_id | Parameter | v23.02 | v24.02 | Incoming JSON commands without an `id` field | + Inevitably there are features which need to change: either to be generalized, or removed when they can no longer be supported. diff --git a/plugins/commando.c b/plugins/commando.c index 27ab868ff..eb85caac7 100644 --- a/plugins/commando.c +++ b/plugins/commando.c @@ -397,7 +397,8 @@ static void try_command(struct commando *incoming STEALS) } filter = json_get_member(buf, toks, "filter"); id = json_get_member(buf, toks, "id"); - if (!id && !deprecated_apis) { + if (!id && !command_deprecated_in_nocmd_ok(plugin, "commando.missing-id", + "v23.02", "v24.02")) { commando_error(incoming, COMMANDO_ERROR_REMOTE, "missing id field"); return; diff --git a/plugins/libplugin.c b/plugins/libplugin.c index 80b4aed47..1efb35a56 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -146,6 +146,34 @@ struct json_filter **command_filter_ptr(struct command *cmd) return &cmd->filter; } +static void complain_deprecated_nocmd(const char *feature, + bool allowing, + struct plugin *plugin) +{ + if (!allowing) { + /* Mild log message for disallowing */ + plugin_log(plugin, LOG_DBG, + "Note: disallowing deprecated %s", + feature); + } else { + plugin_log(plugin, LOG_BROKEN, + "DEPRECATED API USED: %s", + feature); + } +} + +bool command_deprecated_in_nocmd_ok(struct plugin *plugin, + const char *name, + const char *depr_start, + const char *depr_end) +{ + return deprecated_ok(deprecated_apis, + name, + depr_start, depr_end, + plugin->beglist, + complain_deprecated_nocmd, plugin); +} + static void complain_deprecated(const char *feature, bool allowing, struct command *cmd) diff --git a/plugins/libplugin.h b/plugins/libplugin.h index d12e65bb4..2f8e047a3 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -280,6 +280,12 @@ bool command_deprecated_in_named_ok(struct command *cmd, const char *depr_start, const char *depr_end); +/* For commando, which doesn't have a "cmd" incoming */ +bool command_deprecated_in_nocmd_ok(struct plugin *plugin, + const char *name, + const char *depr_start, + const char *depr_end); + /* Call this on fatal error. */ void NORETURN plugin_err(struct plugin *p, const char *fmt, ...);