Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitcoin: fail immediately if we lose connection to our backend #3675

Merged
merged 3 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions lightningd/bitcoind.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -238,8 +234,6 @@ void bitcoind_estimate_fees_(struct bitcoind *bitcoind,
call->cb = cb;
call->arg = arg;

/* No parameter needed, we always want an urgent, normal and slow
* feerate. This gives computation flexibility to the plugin. */
req = jsonrpc_request_start(bitcoind, "estimatefees", bitcoind->log,
estimatefees_callback, call);
jsonrpc_request_end(req);
Expand Down
6 changes: 4 additions & 2 deletions plugins/bcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,10 @@ static struct command_result *process_sendrawtransaction(struct bitcoin_cli *bcl
{
struct json_stream *response;

plugin_log(bcli->cmd->plugin, LOG_DBG, "sendrawtx exit %i (%s)",
*bcli->exitstatus, bcli_args(bcli));
/* This is useful for functional tests. */
if (*bcli->exitstatus == 0)
plugin_log(bcli->cmd->plugin, LOG_DBG, "sendrawtx exit %i (%s)",
*bcli->exitstatus, bcli_args(bcli));

response = jsonrpc_stream_success(bcli->cmd);
json_add_bool(response, "success", *bcli->exitstatus == 0);
Expand Down