Skip to content

Commit

Permalink
lightningd/bitcoind: always die if the Bitcoin backend died
Browse files Browse the repository at this point in the history
This in addition removes the init fixed timeout hack.

Changelog-fixed: We now *always* die if our Bitcoin backend failed unexpectedly.
Signed-off-by: Antoine Poinsot <[email protected]>
  • Loading branch information
darosior committed Apr 28, 2020
1 parent 56b0109 commit 476a9a6
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lightningd/bitcoind.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ static const char *methods[] = {"getchaininfo", "getrawblockbyheight",
"sendrawtransaction", "getutxout",
"estimatefees"};

static void bitcoin_destructor(struct plugin *p)
{
if (p->plugins->ld->state == LD_STATE_SHUTDOWN)
return;
fatal("The Bitcoin backend died.");
}

static void plugin_config_cb(const char *buffer,
const jsmntok_t *toks,
const jsmntok_t *idtok,
Expand All @@ -50,12 +57,6 @@ static void plugin_config_cb(const char *buffer,
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;
Expand All @@ -66,11 +67,7 @@ static void config_plugin(struct plugin *plugin)
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);
tal_add_destructor(plugin, bitcoin_destructor);

io_loop_with_timers(plugin->plugins->ld);
}
Expand Down

0 comments on commit 476a9a6

Please sign in to comment.