diff --git a/doc/Makefile b/doc/Makefile index 9e6ce8cf4..647efff13 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -40,6 +40,7 @@ MANPAGES := doc/lightning-cli.1 \ doc/lightning-delforward.7 \ doc/lightning-delinvoice.7 \ doc/lightning-delpay.7 \ + doc/lightning-deprecations.7 \ doc/lightning-disableinvoicerequest.7 \ doc/lightning-disableoffer.7 \ doc/lightning-disconnect.7 \ diff --git a/doc/index.rst b/doc/index.rst index fd33b4beb..936185965 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -46,6 +46,7 @@ Core Lightning Documentation lightning-delforward lightning-delinvoice lightning-delpay + lightning-deprecations lightning-disableinvoicerequest lightning-disableoffer lightning-disconnect diff --git a/doc/lightning-deprecations.7.md b/doc/lightning-deprecations.7.md new file mode 100644 index 000000000..55506b05b --- /dev/null +++ b/doc/lightning-deprecations.7.md @@ -0,0 +1,49 @@ +lightning-deprecations -- Command to enable/disable deprecated APIs +=================================================================== + +SYNOPSIS +-------- + +**deprecations** *enable* + +DESCRIPTION +----------- + +(Added *v24.02*) + +The **deprecations** RPC command overrides the global `allow-deprecated-apis` flag for further RPC commands on this same connection. In particular, setting *enable* to `false` will neither accept deprecated parameters or commands, nor output +deprecated fields. + +This is equivalent to the config option `allow-deprecated-apis`, but can +be used on useful for developer testing to ensure you don't accidentally rely on +deprecated features. + + +EXAMPLE JSON REQUEST +-------------------- +```json +{ + "id": 82, + "method": "deprecations", + "params": { + "enable": false + } +} +``` + +RETURN VALUE +------------ + +On failure, one of the following error codes may be returned: + +- -32602: Error in given parameters. + +AUTHOR +------ + +Rusty Russell <> wrote the initial version of this man page. + +RESOURCES +--------- + +Main web site: diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index f3e19b8a5..37830017c 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -93,6 +93,9 @@ struct json_connection { jsmn_parser input_parser; jsmntok_t *input_toks; + /* Local deprecated support? */ + bool deprecated_ok; + /* Our commands */ struct list_head commands; @@ -654,6 +657,8 @@ struct json_filter **command_filter_ptr(struct command *cmd) static bool command_deprecated_ok(const struct command *cmd) { + if (cmd->jcon) + return cmd->jcon->deprecated_ok; return cmd->ld->deprecated_apis; } @@ -1332,6 +1337,7 @@ static struct io_plan *jcon_connected(struct io_conn *conn, jcon->input_toks = toks_alloc(jcon); jcon->notifications_enabled = false; jcon->db_batching = false; + jcon->deprecated_ok = ld->deprecated_apis; list_head_init(&jcon->commands); /* We want to log on destruction, so we free this in destructor. */ @@ -1750,3 +1756,29 @@ static const struct json_command batching_command = { "Database transaction batching {enable}", }; AUTODATA(json_command, &batching_command); + +static struct command_result *json_deprecations(struct command *cmd, + const char *buffer, + const jsmntok_t *obj UNNEEDED, + const jsmntok_t *params) +{ + bool *enable; + + if (!param(cmd, buffer, params, + p_req("enable", param_bool, &enable), + NULL)) + return command_param_failed(); + + /* Catch the case where they sent this command then hung up. */ + if (cmd->jcon) + cmd->jcon->deprecated_ok = *enable; + return command_success(cmd, json_stream_success(cmd)); +} + +static const struct json_command deprecations_command = { + "deprecations", + "utility", + json_deprecations, + "Set/unset deprecated APIs on this JSON connection (for developer testing)", +}; +AUTODATA(json_command, &deprecations_command);