From 7a178ebb7ab916b16cc04d8e608edb62a9f642f5 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 13 Feb 2020 09:47:08 +1030 Subject: [PATCH] plugins: libplugin don't insist on 'jsonrpc' field from lightningd. Spark does this, for example: {"method":"pay","params":["lnbc..."],"id":22} Which doesn't have a jsonrpc field. The result is that the command doesn't terminate, there is nothing in the logs, stderr contains "pay: JSON-RPC message does not contain "jsonrpc" field", and from then on "Unknown command 'pay'". Signed-off-by: Rusty Russell --- plugins/libplugin.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/plugins/libplugin.c b/plugins/libplugin.c index afa02a670..b7c5d06ee 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -637,7 +637,8 @@ static bool rpc_read_response_one(struct plugin *plugin) jrtok = json_get_member(plugin->rpc_buffer, toks, "jsonrpc"); if (!jrtok) { - plugin_err(plugin, "JSON-RPC message does not contain \"jsonrpc\" field"); + plugin_err(plugin, "JSON-RPC message does not contain \"jsonrpc\" field: '%.*s'", + (int)plugin->rpc_used, plugin->rpc_buffer); return false; } @@ -981,7 +982,7 @@ static void ld_command_handle(struct plugin *plugin, static bool ld_read_json_one(struct plugin *plugin) { bool valid; - const jsmntok_t *toks, *jrtok; + const jsmntok_t *toks; struct command *cmd = tal(plugin, struct command); /* FIXME: This could be done more efficiently by storing the @@ -1005,12 +1006,8 @@ static bool ld_read_json_one(struct plugin *plugin) return false; } - jrtok = json_get_member(plugin->buffer, toks, "jsonrpc"); - if (!jrtok) { - plugin_err(plugin, "JSON-RPC message does not contain \"jsonrpc\" field"); - return false; - } - + /* FIXME: Spark doesn't create proper jsonrpc 2.0! So we don't + * check for "jsonrpc" here. */ ld_command_handle(plugin, cmd, toks); /* Move this object out of the buffer */