From 476a9a6d77c27c88f297b714f0f4eb1622075b03 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 | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index 3f1a25f395c2..1ef48999bab8 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -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, @@ -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; @@ -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); }