Skip to content

Commit

Permalink
bitcoind: check that Bitcoin plugin is alive before requesting
Browse files Browse the repository at this point in the history
  • Loading branch information
darosior authored and niftynei committed Mar 11, 2020
1 parent 8539442 commit 06e9a9f
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lightningd/bitcoind.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ static void bitcoin_plugin_error(struct bitcoind *bitcoind, const char *buf,
toks->end - toks->start, buf + toks->start);
}

/* Send a request to the Bitcoin plugin which registered that method,
* if it's still alive. */
static void bitcoin_plugin_send(struct bitcoind *bitcoind,
struct jsonrpc_request *req)
{
struct plugin *plugin = strmap_get(&bitcoind->pluginsmap, req->method);
if (!plugin)
fatal("Bitcoin backend plugin for %s died.", req->method);

plugin_request_send(plugin, req);
}

/* `getfeerate`
*
* Gather feerate from our Bitcoin backend. Will set the feerate to `null`
Expand Down Expand Up @@ -211,8 +223,7 @@ static void do_one_estimatefee(struct bitcoind *bitcoind,
json_add_num(req->stream, "blocks", call->blocks[call->i]);
json_add_string(req->stream, "mode", call->estmode[call->i]);
jsonrpc_request_end(req);
plugin_request_send(strmap_get(&bitcoind->pluginsmap,
"getfeerate"), req);
bitcoin_plugin_send(bitcoind, req);
}

void bitcoind_estimate_fees_(struct bitcoind *bitcoind,
Expand Down Expand Up @@ -311,8 +322,7 @@ void bitcoind_sendrawtx_(struct bitcoind *bitcoind,
call);
json_add_string(req->stream, "tx", hextx);
jsonrpc_request_end(req);
plugin_request_send(strmap_get(&bitcoind->pluginsmap,
"sendrawtransaction"), req);
bitcoin_plugin_send(bitcoind, req);
}

/* `getrawblockbyheight`
Expand Down Expand Up @@ -412,8 +422,7 @@ void bitcoind_getrawblockbyheight_(struct bitcoind *bitcoind,
notleak(call));
json_add_num(req->stream, "height", height);
jsonrpc_request_end(req);
plugin_request_send(strmap_get(&bitcoind->pluginsmap,
"getrawblockbyheight"), req);
bitcoin_plugin_send(bitcoind, req);
}

/* `getchaininfo`
Expand Down Expand Up @@ -507,8 +516,7 @@ void bitcoind_getchaininfo_(struct bitcoind *bitcoind,
req = jsonrpc_request_start(bitcoind, "getchaininfo", bitcoind->log,
getchaininfo_callback, call);
jsonrpc_request_end(req);
plugin_request_send(strmap_get(&bitcoind->pluginsmap, "getchaininfo"),
req);
bitcoin_plugin_send(bitcoind, req);
}

/* `getutxout`
Expand Down Expand Up @@ -591,8 +599,7 @@ void bitcoind_getutxout_(struct bitcoind *bitcoind,
json_add_txid(req->stream, "txid", txid);
json_add_num(req->stream, "vout", outnum);
jsonrpc_request_end(req);
plugin_request_send(strmap_get(&bitcoind->pluginsmap, "getutxout"),
req);
bitcoin_plugin_send(bitcoind, req);
}

/* Context for the getfilteredblock call. Wraps the actual arguments while we
Expand Down

0 comments on commit 06e9a9f

Please sign in to comment.