From 678591d851150815fbf7935c86bd21a7e9c6625b Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Tue, 28 Apr 2020 11:17:40 +0200 Subject: [PATCH] lightningd/bitcoind: always die if the Bitcoin backend died 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 --- lightningd/bitcoind.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index 3f1a25f39..27263dc89 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -40,22 +40,22 @@ 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, 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; @@ -66,11 +66,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); }