Skip to content

Commit 73fc9b0

Browse files
committed
plugins: all plugins must now support non-numeric JSON RPC id fields.
Signed-off-by: Rusty Russell <[email protected]> Changelog-Removed: plugins which didn't accept string JSON RPC fields (deprecated v23.08, disabled by default in v24.11).
1 parent d69499b commit 73fc9b0

File tree

12 files changed

+39
-62
lines changed

12 files changed

+39
-62
lines changed

doc/developers-guide/deprecations.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ hidden: false
1111
| rest-protocol.clnrest-prefix | Config | v23.11 | v24.11 | Autodetect where we need to rename `rest-protocol` to `clnrest-protocol` (added in v23.11) |
1212
| rest-host.clnrest-prefix | Config | v23.11 | v24.11 | Autodetect where we need to rename `rest-host` to `clnrest-host` (added in v23.11) |
1313
| rest-certs.clnrest-prefix | Config | v23.11 | v24.11 | Autodetect where we need to rename `rest-certs` to `clnrest-certs` (added in v23.11) |
14-
| plugin.nonumericids | Getmanifest Reply | v23.08 | v24.08 | Plugins must specify that they can accept non-numeric command ids (numeric ids are deprecated) |
1514
| listchannels.include_private | Field(s) | v24.02 | v24.08 | `listchannels` including private channels (now use listpeerchannels which gives far more detail) |
1615
| max-locktime-blocks | Config | v24.05 | v24.11 | --max-locktime-blocks is now set to 2016 in the BOLT 4 spec |
1716
| commando-rune | Command | v23.08 | v25.02 | replaced with `lightning-createrune` |

doc/developers-guide/plugin-development/a-day-in-the-life-of-a-plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ The `rpcmethods` are methods that will be exposed via `lightningd`'s JSON-RPC ov
104104

105105
The `subscriptions` array indicates what [Event Notifications](doc:event-notifications) your plugin wants to receive. You should subscribe to `deprecated_oneshot` if you have any deprecated commands or output, so users can use the `deprecations` API to control it on a per-connection basis. You can specify `*` here to subscribe to all other subscriptions (since *v23.08*).
106106

107-
The `nonnumericids` indicates that the plugin can handle string JSON request `id` fields: prior to v22.11 lightningd used numbers for these, and the change to strings broke some plugins. If not set, then strings will be used once this feature is removed after v23.05. See the [lightningd-rpc](ref:lightningd-rpc) documentation for how to handle JSON `id` fields!
107+
The `nonnumericids` indicates that the plugin can handle string JSON request `id` fields: prior to v22.11 lightningd used numbers for these, and the change to strings broke some plugins. If present, this must be `true` (since v23.05). See the [lightningd-rpc](ref:lightningd-rpc) documentation for how to handle JSON `id` fields!
108108

109109
The `dynamic` indicates if the plugin can be managed after `lightningd` has been started using the [lightning-plugin](ref:lightning-plugin) JSON-RPC command. Critical plugins that should not be stopped should set it to false. Plugin `options` can be passed to dynamic plugins as argument to the `plugin` command .
110110

lightningd/bitcoind.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void config_plugin(struct plugin *plugin)
5252
void *ret;
5353

5454
req = jsonrpc_request_start(plugin, "init", NULL,
55-
plugin->non_numeric_ids, plugin->log,
55+
plugin->log,
5656
NULL, plugin_config_cb, plugin);
5757
plugin_populate_init_request(plugin, req);
5858
jsonrpc_request_end(req);
@@ -361,7 +361,7 @@ void bitcoind_estimate_fees_(const tal_t *ctx,
361361
call->cb = cb;
362362
call->cb_arg = cb_arg;
363363

364-
req = jsonrpc_request_start(call, "estimatefees", NULL, true,
364+
req = jsonrpc_request_start(call, "estimatefees", NULL,
365365
bitcoind->log,
366366
NULL, estimatefees_callback, call);
367367
jsonrpc_request_end(req);
@@ -438,7 +438,7 @@ void bitcoind_sendrawtx_(const tal_t *ctx,
438438
log_debug(bitcoind->log, "sendrawtransaction: %s", hextx);
439439

440440
req = jsonrpc_request_start(call, "sendrawtransaction",
441-
id_prefix, true,
441+
id_prefix,
442442
bitcoind->log,
443443
NULL, sendrawtx_callback,
444444
call);
@@ -531,7 +531,7 @@ void bitcoind_getrawblockbyheight_(const tal_t *ctx,
531531
trace_span_start("plugin/bitcoind", call);
532532
trace_span_tag(call, "method", "getrawblockbyheight");
533533
trace_span_suspend(call);
534-
req = jsonrpc_request_start(call, "getrawblockbyheight", NULL, true,
534+
req = jsonrpc_request_start(call, "getrawblockbyheight", NULL,
535535
bitcoind->log,
536536
NULL, getrawblockbyheight_callback,
537537
call);
@@ -606,7 +606,7 @@ void bitcoind_getchaininfo_(const tal_t *ctx,
606606
call->cb = cb;
607607
call->cb_arg = cb_arg;
608608

609-
req = jsonrpc_request_start(call, "getchaininfo", NULL, true,
609+
req = jsonrpc_request_start(call, "getchaininfo", NULL,
610610
bitcoind->log,
611611
NULL, getchaininfo_callback, call);
612612
json_add_u32(req->stream, "last_height", height);
@@ -677,7 +677,7 @@ void bitcoind_getutxout_(const tal_t *ctx,
677677
call->cb = cb;
678678
call->cb_arg = cb_arg;
679679

680-
req = jsonrpc_request_start(call, "getutxout", NULL, true,
680+
req = jsonrpc_request_start(call, "getutxout", NULL,
681681
bitcoind->log,
682682
NULL, getutxout_callback, call);
683683
json_add_txid(req->stream, "txid", &outpoint->txid);

lightningd/invoice.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ static struct command_result *json_invoice(struct command *cmd,
12291229
}
12301230

12311231
req = jsonrpc_request_start(info, "listincoming",
1232-
cmd->id, plugin->non_numeric_ids,
1232+
cmd->id,
12331233
command_logger(cmd),
12341234
NULL, listincoming_done,
12351235
info);

lightningd/jsonrpc.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@ void jsonrpc_notification_end(struct jsonrpc_notification *n)
15861586

15871587
struct jsonrpc_request *jsonrpc_request_start_(
15881588
const tal_t *ctx, const char *method,
1589-
const char *id_prefix, bool id_as_string, struct logger *log,
1589+
const char *id_prefix, struct logger *log,
15901590
bool add_header,
15911591
void (*notify_cb)(const char *buffer,
15921592
const jsmntok_t *methodtok,
@@ -1600,27 +1600,24 @@ struct jsonrpc_request *jsonrpc_request_start_(
16001600
struct jsonrpc_request *r = tal(ctx, struct jsonrpc_request);
16011601
static u64 next_request_id = 0;
16021602

1603-
r->id_is_string = id_as_string;
1604-
if (r->id_is_string) {
1605-
if (id_prefix) {
1606-
/* Strip "" and otherwise sanity-check */
1607-
if (strstarts(id_prefix, "\"")
1608-
&& strlen(id_prefix) > 1
1609-
&& strends(id_prefix, "\"")) {
1610-
id_prefix = tal_strndup(tmpctx, id_prefix + 1,
1611-
strlen(id_prefix) - 2);
1612-
}
1613-
/* We could try escaping, but TBH they're
1614-
* messing with us at this point! */
1615-
if (json_escape_needed(id_prefix, strlen(id_prefix)))
1616-
id_prefix = "weird-id";
1617-
1618-
r->id = tal_fmt(r, "\"%s/cln:%s#%"PRIu64"\"",
1619-
id_prefix, method, next_request_id);
1620-
} else
1621-
r->id = tal_fmt(r, "\"cln:%s#%"PRIu64"\"", method, next_request_id);
1603+
r->id_is_string = true;
1604+
if (id_prefix) {
1605+
/* Strip "" and otherwise sanity-check */
1606+
if (strstarts(id_prefix, "\"")
1607+
&& strlen(id_prefix) > 1
1608+
&& strends(id_prefix, "\"")) {
1609+
id_prefix = tal_strndup(tmpctx, id_prefix + 1,
1610+
strlen(id_prefix) - 2);
1611+
}
1612+
/* We could try escaping, but TBH they're
1613+
* messing with us at this point! */
1614+
if (json_escape_needed(id_prefix, strlen(id_prefix)))
1615+
id_prefix = "weird-id";
1616+
1617+
r->id = tal_fmt(r, "\"%s/cln:%s#%"PRIu64"\"",
1618+
id_prefix, method, next_request_id);
16221619
} else {
1623-
r->id = tal_fmt(r, "%"PRIu64, next_request_id);
1620+
r->id = tal_fmt(r, "\"cln:%s#%"PRIu64"\"", method, next_request_id);
16241621
}
16251622
if (taken(id_prefix))
16261623
tal_free(id_prefix);

lightningd/jsonrpc.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ void jsonrpc_notification_end(struct jsonrpc_notification *n);
235235
* start a JSONRPC request; id_prefix is non-NULL if this was triggered by
236236
* another JSONRPC request.
237237
*/
238-
#define jsonrpc_request_start(ctx, method, id_prefix, id_as_string, log, notify_cb, response_cb, response_cb_arg) \
238+
#define jsonrpc_request_start(ctx, method, id_prefix, log, notify_cb, response_cb, response_cb_arg) \
239239
jsonrpc_request_start_( \
240-
(ctx), (method), (id_prefix), (id_as_string), (log), true, \
240+
(ctx), (method), (id_prefix), (log), true, \
241241
typesafe_cb_preargs(void, void *, (notify_cb), (response_cb_arg), \
242242
const char *buffer, \
243243
const jsmntok_t *idtok, \
@@ -249,9 +249,9 @@ void jsonrpc_notification_end(struct jsonrpc_notification *n);
249249
const jsmntok_t *idtok), \
250250
(response_cb_arg))
251251

252-
#define jsonrpc_request_start_raw(ctx, method, id_prefix, id_as_string,log, notify_cb, response_cb, response_cb_arg) \
252+
#define jsonrpc_request_start_raw(ctx, method, id_prefix, log, notify_cb, response_cb, response_cb_arg) \
253253
jsonrpc_request_start_( \
254-
(ctx), (method), (id_prefix), (id_as_string), (log), false, \
254+
(ctx), (method), (id_prefix), (log), false, \
255255
typesafe_cb_preargs(void, void *, (notify_cb), (response_cb_arg), \
256256
const char *buffer, \
257257
const jsmntok_t *idtok, \
@@ -266,7 +266,6 @@ void jsonrpc_notification_end(struct jsonrpc_notification *n);
266266
struct jsonrpc_request *jsonrpc_request_start_(
267267
const tal_t *ctx, const char *method,
268268
const char *id_prefix TAKES,
269-
bool id_as_string,
270269
struct logger *log, bool add_header,
271270
void (*notify_cb)(const char *buffer,
272271
const jsmntok_t *idtok,

lightningd/plugin.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES,
363363
p->notification_topics = tal_arr(p, const char *, 0);
364364
p->subscriptions = NULL;
365365
p->dynamic = false;
366-
p->non_numeric_ids = false;
367366
p->index = plugins->plugin_idx++;
368367
p->stdout_conn = NULL;
369368

@@ -1324,7 +1323,7 @@ static struct command_result *plugin_rpcmethod_check(struct command *cmd,
13241323

13251324
/* Send check command through, it says it can handle it! */
13261325
req = jsonrpc_request_start_raw(plugin, "check",
1327-
cmd->id, plugin->non_numeric_ids,
1326+
cmd->id,
13281327
plugin->log,
13291328
plugin_notify_cb,
13301329
plugin_rpcmethod_cb, cmd);
@@ -1368,7 +1367,7 @@ static struct command_result *plugin_rpcmethod_dispatch(struct command *cmd,
13681367
}
13691368
}
13701369
req = jsonrpc_request_start_raw(plugin, cmd->json_cmd->name,
1371-
cmd->id, plugin->non_numeric_ids,
1370+
cmd->id,
13721371
plugin->log,
13731372
plugin_notify_cb,
13741373
plugin_rpcmethod_cb, cmd);
@@ -1796,23 +1795,16 @@ static const char *plugin_parse_getmanifest_response(const char *buffer,
17961795

17971796
tok = json_get_member(buffer, resulttok, "nonnumericids");
17981797
if (tok) {
1799-
if (!json_to_bool(buffer, tok, &plugin->non_numeric_ids))
1798+
bool non_numeric_ids;
1799+
if (!json_to_bool(buffer, tok, &non_numeric_ids))
18001800
return tal_fmt(plugin,
18011801
"Invalid nonnumericids: %.*s",
18021802
json_tok_full_len(tok),
18031803
json_tok_full(buffer, tok));
1804-
if (!plugin->non_numeric_ids
1805-
&& !lightningd_deprecated_in_ok(ld, ld->log, ld->deprecated_ok,
1806-
"plugin", "nonnumericids",
1807-
"v23.08", "v24.08", NULL)) {
1804+
if (!non_numeric_ids) {
18081805
return tal_fmt(plugin,
18091806
"Plugin does not allow nonnumericids");
18101807
}
1811-
} else {
1812-
/* Default is false in deprecated mode */
1813-
plugin->non_numeric_ids = !lightningd_deprecated_out_ok(ld, ld->deprecated_ok,
1814-
"plugin", "nonnumericids",
1815-
"v23.08", "v24.08");
18161808
}
18171809

18181810
tok = json_get_member(buffer, resulttok, "cancheck");
@@ -2026,7 +2018,7 @@ const char *plugin_send_getmanifest(struct plugin *p, const char *cmd_id)
20262018
* write-only on p->stdin */
20272019
p->stdout_conn = io_new_conn(p, stdoutfd, plugin_stdout_conn_init, p);
20282020
p->stdin_conn = io_new_conn(p, stdinfd, plugin_stdin_conn_init, p);
2029-
req = jsonrpc_request_start(p, "getmanifest", cmd_id, p->non_numeric_ids,
2021+
req = jsonrpc_request_start(p, "getmanifest", cmd_id,
20302022
p->log, NULL, plugin_manifest_cb, p);
20312023
json_add_bool(req->stream, "allow-deprecated-apis",
20322024
p->plugins->ld->deprecated_ok);
@@ -2236,7 +2228,7 @@ plugin_config(struct plugin *plugin)
22362228
struct jsonrpc_request *req;
22372229

22382230
plugin_set_timeout(plugin);
2239-
req = jsonrpc_request_start(plugin, "init", NULL, plugin->non_numeric_ids,
2231+
req = jsonrpc_request_start(plugin, "init", NULL,
22402232
plugin->log, NULL, plugin_config_cb, plugin);
22412233
plugin_populate_init_request(plugin, req);
22422234
jsonrpc_request_end(req);
@@ -2360,15 +2352,13 @@ struct command_result *plugin_set_dynamic_opt(struct command *cmd,
23602352
return command_check_done(cmd);
23612353
req = jsonrpc_request_start(cmd, "check",
23622354
cmd->id,
2363-
plugin->non_numeric_ids,
23642355
command_logger(cmd),
23652356
NULL, plugin_setconfig_done,
23662357
psr);
23672358
json_add_string(req->stream, "command_to_check", "setconfig");
23682359
} else {
23692360
req = jsonrpc_request_start(cmd, "setconfig",
23702361
cmd->id,
2371-
plugin->non_numeric_ids,
23722362
command_logger(cmd),
23732363
NULL, plugin_setconfig_done,
23742364
psr);

lightningd/plugin.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ struct plugin {
8080
* C-lightning should terminate as well. */
8181
bool important;
8282

83-
/* Can this handle non-numeric JSON ids? */
84-
bool non_numeric_ids;
85-
8683
/* Parameters for dynamically-started plugins. */
8784
const char *parambuf;
8885
const jsmntok_t *params;

lightningd/plugin_hook.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ static void plugin_hook_call_next(struct plugin_hook_request *ph_req)
203203
log_trace(ph_req->ld->log, "Calling %s hook of plugin %s",
204204
ph_req->hook->name, plugin->shortname);
205205
req = jsonrpc_request_start(NULL, hook->name, ph_req->cmd_id,
206-
plugin->non_numeric_ids,
207206
plugin_get_logger(plugin),
208207
NULL,
209208
plugin_hook_callback, ph_req);
@@ -346,7 +345,6 @@ void plugin_hook_db_sync(struct db *db)
346345
/* FIXME: id_prefix from caller? */
347346
/* FIXME: do IO logging for this! */
348347
req = jsonrpc_request_start(NULL, hook->name, NULL,
349-
dwh_req->plugin->non_numeric_ids,
350348
NULL, NULL,
351349
db_hook_response,
352350
dwh_req);

lightningd/signmessage.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ static struct command_result *json_checkmessage(struct command *cmd,
220220
if (plugin) {
221221
req = jsonrpc_request_start(cmd, "listnodes",
222222
cmd->id,
223-
plugin->non_numeric_ids,
224223
command_logger(cmd),
225224
NULL, listnodes_done,
226225
can);

0 commit comments

Comments
 (0)