bitcoind: timeout if the Bitcoin plugin never completes the handshake

Reported-by: Vasil Dimov <@vasild>
This commit is contained in:
darosior 2020-03-04 11:44:34 +01:00 committed by neil saitug
parent 820f1b2f9d
commit 1fd45a061b

View File

@ -30,7 +30,12 @@
#include <lightningd/chaintopology.h>
#include <lightningd/plugin.h>
/* The names of the request we can make to our Bitcoin backend. */
/* How many seconds will we wait for our Bitcoin plugin to respond to `init` ?
* Note that bcli waits for bitcoind to be warmed up before responding, so it
* shouldn't be too low. */
#define BITCOIN_INIT_TIMEOUT 30
/* The names of the requests we can make to our Bitcoin backend. */
static const char *methods[] = {"getchaininfo", "getrawblockbyheight",
"sendrawtransaction", "getutxout",
"getfeerate"};
@ -40,10 +45,17 @@ static void plugin_config_cb(const char *buffer,
const jsmntok_t *idtok,
struct plugin *plugin)
{
tal_free(plugin->timeout_timer);
plugin->plugin_state = CONFIGURED;
io_break(plugin);
}
static void plugin_config_timeout(void *unused UNUSED)
{
fatal("Timed out while waiting for (one of) the Bitcoin backend "
"plugin(s) to complete the handshake.");
}
static void config_plugin(struct plugin *plugin)
{
struct jsonrpc_request *req;
@ -53,6 +65,13 @@ static void config_plugin(struct plugin *plugin)
plugin_populate_init_request(plugin, req);
jsonrpc_request_end(req);
plugin_request_send(plugin, req);
/* Don't hang forever if the plugin encountered a problem at init. */
plugin->timeout_timer
= new_reltimer(plugin->plugins->ld->timers, NULL,
time_from_sec(BITCOIN_INIT_TIMEOUT),
plugin_config_timeout, NULL);
io_loop_with_timers(plugin->plugins->ld);
}