From 905730341a07e4727abb84908e3221d42f8a6490 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Wed, 29 Jul 2020 16:24:33 +0200 Subject: [PATCH] bcli: explicitly check at startup that bitcoind does relay transactions We've had problems with blocksonly in the past and bitcoind still allows to use outdated (thus potentially dangerous estimates) while running bitcoin with -blocksonly. ZmnSCPxj mentionned that we still don't document this, but i figured that in this specific case an explicit check and error seems preferable. Changelog-Added: We now explicitly check at startup that our default Bitcoin backend (bitcoind) does relay transactions. Proposed-by: ZmnSCPxj Signed-off-by: Antoine Poinsot --- README.md | 2 +- plugins/bcli.c | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d8bb4bcde..eacca84e3 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Don't hesitate to reach out to us on IRC at [#lightning-dev @ freenode.net][irc1 ## Getting Started -c-lightning only works on Linux and Mac OS, and requires a locally (or remotely) running `bitcoind` (version 0.16 or above) that is fully caught up with the network you're testing on. +c-lightning only works on Linux and Mac OS, and requires a locally (or remotely) running `bitcoind` (version 0.16 or above) that is fully caught up with the network you're running on, and relays transactions (ie with `blocksonly=0`). Pruning (`prune=n` option in `bitcoin.conf`) is partially supported, see [here](#pruning) for more details. ### Installation diff --git a/plugins/bcli.c b/plugins/bcli.c index 1bd1a2b63..db6a3ae68 100644 --- a/plugins/bcli.c +++ b/plugins/bcli.c @@ -840,15 +840,16 @@ static void bitcoind_failure(struct plugin *p, const char *error_message) /* Do some sanity checks on bitcoind based on the output of `getnetworkinfo`. */ static void parse_getnetworkinfo_result(struct plugin *p, const char *buf) { - const jsmntok_t *result, *versiontok; - bool valid; + const jsmntok_t *result, *versiontok, *relaytok; + bool valid, tx_relay; + u32 min_version = 160000; result = json_parse_input(NULL, buf, strlen(buf), &valid); if (!result || !valid) - plugin_err(p, "No or invalid response to '%s' ? Got '%s'. Can not" - " continue without proceeding to sanity checks.", + plugin_err(p, "Invalid response to '%s': '%s'. Can not " + "continue without proceeding to sanity checks.", gather_args(bitcoind, "getnetworkinfo", NULL), buf); /* Check that we have a fully-featured `estimatesmartfee`. */ @@ -863,9 +864,21 @@ static void parse_getnetworkinfo_result(struct plugin *p, const char *buf) " continue without proceeding to sanity checks.", gather_args(bitcoind, "getnetworkinfo", NULL), buf); - if (bitcoind->version < 160000) - plugin_err(p, "Unsupported bitcoind version, you need to update" - " Bitcoin Core."); + if (bitcoind->version < min_version) + plugin_err(p, "Unsupported bitcoind version %"PRIu32", at least" + " %"PRIu32" required.", bitcoind->version, min_version); + + /* We don't support 'blocksonly', as we rely on transaction relay for fee + * estimates. */ + relaytok = json_get_member(buf, result, "localrelay"); + if (!relaytok || !json_to_bool(buf, relaytok, &tx_relay)) + plugin_err(p, "No 'localrelay' in '%s' ? Got '%s'. Can not" + " continue without proceeding to sanity checks.", + gather_args(bitcoind, "getnetworkinfo", NULL), buf); + + if (!tx_relay) + plugin_err(p, "The 'blocksonly' mode of bitcoind, or any option " + "deactivating transaction relay is not supported."); tal_free(result); }