chaintopology: check bitcoin plugin commands at startup

Exit early if we won't be able to fully communicate with our Bitcoin
backend.
This commit is contained in:
darosior
2020-01-07 11:59:18 +01:00
committed by Rusty Russell
parent 5840e90ceb
commit ae249a2294
5 changed files with 44 additions and 7 deletions

View File

@@ -611,21 +611,21 @@ static void plugin_rpcmethod_cb(const char *buffer,
command_raw_complete(cmd, response);
}
static struct plugin *find_plugin_for_command(struct command *cmd)
struct plugin *find_plugin_for_command(struct lightningd *ld,
const char *cmd_name)
{
struct plugins *plugins = cmd->ld->plugins;
struct plugins *plugins = ld->plugins;
struct plugin *plugin;
/* Find the plugin that registered this RPC call */
list_for_each(&plugins->plugins, plugin, list) {
for (size_t i=0; i<tal_count(plugin->methods); i++) {
if (streq(cmd->json_cmd->name, plugin->methods[i]))
if (streq(cmd_name, plugin->methods[i]))
return plugin;
}
}
/* This should never happen, it'd mean that a plugin didn't
* cleanup after dying */
abort();
return NULL;
}
static struct command_result *plugin_rpcmethod_dispatch(struct command *cmd,
@@ -641,7 +641,9 @@ static struct command_result *plugin_rpcmethod_dispatch(struct command *cmd,
if (cmd->mode == CMD_CHECK)
return command_param_failed();
plugin = find_plugin_for_command(cmd);
plugin = find_plugin_for_command(cmd->ld, cmd->json_cmd->name);
if (!plugin)
fatal("No plugin for %s ?", cmd->json_cmd->name);
/* Find ID again (We've parsed them before, this should not fail!) */
idtok = json_get_member(buffer, toks, "id");