libplugin: support version strings for deprecations.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-01-25 10:58:55 +10:30
parent 3281d8c0ab
commit 277ed2ccbf
5 changed files with 42 additions and 19 deletions

View file

@ -6,8 +6,11 @@ hidden: false
---
| Name | Type | First Deprecated | Last Supported | Description |
|-------------------|---------|------------------|----------------|-----------------------------------|
|-----------------------------|---------|------------------|----------------|-------------------------------------------------------------------------------|
| delexpiredinvoice | Command | v22.11 | v24.02 | `autoclean-once` is more powerful |
| autocleaninvoice | Command | v22.11 | v24.02 | `autoclean` is more general, does more than expired invoices |
| autocleaninvoice-cycle | Config | v22.11 | v24.02 | Now always once per hour: you can run `autoclean-once` regularly if you need. |
| autocleaninvoice-expired-by | Config | v22.11 | v24.02 | `autoclean`'s `autoclean-expiredinvoices-age` |
Inevitably there are features which need to change: either to be generalized, or removed when they can no longer be supported.

View file

@ -612,7 +612,7 @@ static const struct plugin_command commands[] = { {
"Perform cleanup every {cycle_seconds} (default 3600), or disable autoclean if 0. "
"Clean up expired invoices that have expired for {expired_by} seconds (default 86400). ",
json_autocleaninvoice,
true, /* deprecated! */
"v22.11", "v24.02",
}, {
"autoclean-status",
"utility",
@ -637,12 +637,14 @@ int main(int argc, char *argv[])
"string",
"Perform cleanup of expired invoices every"
" given seconds, or do not autoclean if 0",
"v22.11", "v24.02",
u64_option, &deprecated_cycle_seconds),
plugin_option_deprecated("autocleaninvoice-expired-by",
"string",
"If expired invoice autoclean enabled,"
" invoices that have expired for at least"
" this given seconds are cleaned",
"v22.11", "v24.02",
u64_option, &timer_cinfo.subsystem_age[EXPIREDINVOICES]),
plugin_option_dynamic("autoclean-cycle",
"int",

View file

@ -952,6 +952,19 @@ send_outreq(struct plugin *plugin, const struct out_req *req)
return &pending;
}
static void json_add_deprecated(struct json_stream *js,
const char *fieldname,
const char *depr_start, const char *depr_end)
{
if (!depr_start)
return;
json_array_start(js, fieldname);
json_add_string(js, NULL, depr_start);
if (depr_end)
json_add_string(js, NULL, depr_end);
json_array_end(js);
}
static struct command_result *
handle_getmanifest(struct command *getmanifest_cmd,
const char *buf,
@ -981,7 +994,7 @@ handle_getmanifest(struct command *getmanifest_cmd,
json_add_string(params, "name", p->opts[i].name);
json_add_string(params, "type", p->opts[i].type);
json_add_string(params, "description", p->opts[i].description);
json_add_bool(params, "deprecated", p->opts[i].deprecated);
json_add_deprecated(params, "deprecated", p->opts[i].depr_start, p->opts[i].depr_end);
json_add_bool(params, "dynamic", p->opts[i].dynamic);
json_object_end(params);
}
@ -999,7 +1012,8 @@ handle_getmanifest(struct command *getmanifest_cmd,
if (p->commands[i].long_description)
json_add_string(params, "long_description",
p->commands[i].long_description);
json_add_bool(params, "deprecated", p->commands[i].deprecated);
json_add_deprecated(params, "deprecated",
p->commands[i].depr_start, p->commands[i].depr_end);
json_object_end(params);
}
json_array_end(params);
@ -1945,7 +1959,8 @@ static struct plugin *new_plugin(const tal_t *ctx,
o.handle = va_arg(ap, char *(*)(struct plugin *, const char *str, void *arg));
o.arg = va_arg(ap, void *);
o.dev_only = va_arg(ap, int); /* bool gets promoted! */
o.deprecated = va_arg(ap, int); /* bool gets promoted! */
o.depr_start = va_arg(ap, const char *);
o.depr_end = va_arg(ap, const char *);
o.dynamic = va_arg(ap, int); /* bool gets promoted! */
tal_arr_expand(&p->opts, o);
}

View file

@ -69,8 +69,8 @@ struct plugin_command {
struct command_result *(*handle)(struct command *cmd,
const char *buf,
const jsmntok_t *params);
/* If true, this command *disabled* if allow-deprecated-apis = false */
bool deprecated;
/* If it's deprecated from a particular release (or NULL) */
const char *depr_start, *depr_end;
/* If true, this option requires --developer to be enabled */
bool dev_only;
};
@ -84,8 +84,8 @@ struct plugin_option {
void *arg;
/* If true, this option requires --developer to be enabled */
bool dev_only;
/* If true, this options *disabled* if allow-deprecated-apis = false */
bool deprecated;
/* If it's deprecated from a particular release (or NULL) */
const char *depr_start, *depr_end;
/* If true, allow setting after plugin has initialized */
bool dynamic;
};
@ -420,7 +420,7 @@ static inline void *plugin_option_cb_check(char *(*set)(struct plugin *plugin,
bool plugin_developer_mode(const struct plugin *plugin);
/* Macro to define arguments */
#define plugin_option_(name, type, description, set, arg, dev_only, deprecated, dynamic) \
#define plugin_option_(name, type, description, set, arg, dev_only, depr_start, depr_end, dynamic) \
(name), \
(type), \
(description), \
@ -430,20 +430,21 @@ bool plugin_developer_mode(const struct plugin *plugin);
const char *)), \
(arg), \
(dev_only), \
(deprecated), \
(depr_start), \
(depr_end), \
(dynamic)
#define plugin_option(name, type, description, set, arg) \
plugin_option_((name), (type), (description), (set), (arg), false, false, false)
plugin_option_((name), (type), (description), (set), (arg), false, NULL, NULL, false)
#define plugin_option_dev(name, type, description, set, arg) \
plugin_option_((name), (type), (description), (set), (arg), true, false, false)
plugin_option_((name), (type), (description), (set), (arg), true, NULL, NULL, false)
#define plugin_option_dynamic(name, type, description, set, arg) \
plugin_option_((name), (type), (description), (set), (arg), false, false, true)
plugin_option_((name), (type), (description), (set), (arg), false, NULL, NULL, true)
#define plugin_option_deprecated(name, type, description, set, arg) \
plugin_option_((name), (type), (description), (set), (arg), false, true, false)
#define plugin_option_deprecated(name, type, description, depr_start, depr_end, set, arg) \
plugin_option_((name), (type), (description), (set), (arg), false, (depr_start), (depr_end), false)
/* Standard helpers */
char *u64_option(struct plugin *plugin, const char *arg, u64 *i);

View file

@ -199,7 +199,8 @@ static const struct plugin_command commands[] = { {
"Makes a simple getinfo call, to test rpc socket.",
"",
json_testrpc,
true,
"v0.9.1",
CLN_NEXT_VERSION,
}
};
@ -240,6 +241,7 @@ int main(int argc, char *argv[])
plugin_option_deprecated("somearg-deprecated",
"string",
"Deprecated arg for init.",
CLN_NEXT_VERSION, NULL,
charp_option, &somearg),
plugin_option("selfdisable",
"flag",