Browse Source

bitcoind: timeout if the Bitcoin plugin never completes the handshake

Reported-by: Vasil Dimov <@vasild>
travis-debug
darosior 5 years ago
committed by neil saitug
parent
commit
1fd45a061b
  1. 21
      lightningd/bitcoind.c

21
lightningd/bitcoind.c

@ -30,7 +30,12 @@
#include <lightningd/chaintopology.h> #include <lightningd/chaintopology.h>
#include <lightningd/plugin.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", static const char *methods[] = {"getchaininfo", "getrawblockbyheight",
"sendrawtransaction", "getutxout", "sendrawtransaction", "getutxout",
"getfeerate"}; "getfeerate"};
@ -40,10 +45,17 @@ static void plugin_config_cb(const char *buffer,
const jsmntok_t *idtok, const jsmntok_t *idtok,
struct plugin *plugin) struct plugin *plugin)
{ {
tal_free(plugin->timeout_timer);
plugin->plugin_state = CONFIGURED; plugin->plugin_state = CONFIGURED;
io_break(plugin); 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) static void config_plugin(struct plugin *plugin)
{ {
struct jsonrpc_request *req; struct jsonrpc_request *req;
@ -53,6 +65,13 @@ static void config_plugin(struct plugin *plugin)
plugin_populate_init_request(plugin, req); plugin_populate_init_request(plugin, req);
jsonrpc_request_end(req); jsonrpc_request_end(req);
plugin_request_send(plugin, 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); io_loop_with_timers(plugin->plugins->ld);
} }

Loading…
Cancel
Save