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

Explictly check at startup that we don't support bitcoind's blocksonly option. #3889

Merged
merged 4 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 59 additions & 4 deletions plugins/bcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ struct bitcoind {
/* -datadir arg for bitcoin-cli. */
char *datadir;

/* bitcoind's version, used for compatibility checks. */
u32 version;

/* Is bitcoind synced? If not, we retry. */
bool synced;

Expand Down Expand Up @@ -834,14 +837,63 @@ static void bitcoind_failure(struct plugin *p, const char *error_message)
args_string(cmd, cmd));
}

static void wait_for_bitcoind(struct plugin *p)
/* 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, *relaytok;
bool valid, tx_relay;
u32 min_version = 160000;

result = json_parse_input(NULL,
buf, strlen(buf),
&valid);
if (!result || !valid)
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`. */
versiontok = json_get_member(buf, result, "version");
if (!versiontok)
plugin_err(p, "No 'version' in '%s' ? Got '%s'. Can not"
" continue without proceeding to sanity checks.",
gather_args(bitcoind, "getnetworkinfo", NULL), buf);

if (!json_to_u32(buf, versiontok, &bitcoind->version))
plugin_err(p, "Invalid 'version' in '%s' ? Got '%s'. Can not"
" continue without proceeding to sanity checks.",
gather_args(bitcoind, "getnetworkinfo", NULL), buf);

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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe offer a suggestion of how to fix it? i.e.

Suggested change
"deactivating transaction relay is not supported.");
"deactivating transaction relay is not supported. Remove -blocksonly from your bitcoind config");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit redundant ?..

The 'blocksonly' mode of bitcoind [...] is not supported. Remove -blocksonly from your bitcoind config

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree as well.


tal_free(result);
}

static void wait_and_check_bitcoind(struct plugin *p)
{
int from, status, ret;
pid_t child;
const char **cmd = gather_args(bitcoind, "echo", NULL);
const char **cmd = gather_args(bitcoind, "getnetworkinfo", NULL);
bool printed = false;
char *output = NULL;

for (;;) {
tal_free(output);

child = pipecmdarr(NULL, &from, &from, cast_const2(char **,cmd));
if (child < 0) {
if (errno == ENOENT)
Expand All @@ -850,7 +902,7 @@ static void wait_for_bitcoind(struct plugin *p)
plugin_err(p, "%s exec failed: %s", cmd[0], strerror(errno));
}

char *output = grab_fd(cmd, from);
output = grab_fd(cmd, from);

while ((ret = waitpid(child, &status, 0)) < 0 && errno == EINTR);
if (ret != child)
Expand Down Expand Up @@ -881,13 +933,16 @@ static void wait_for_bitcoind(struct plugin *p)
}
sleep(1);
}

parse_getnetworkinfo_result(p, output);

tal_free(cmd);
}

static void init(struct plugin *p, const char *buffer UNUSED,
const jsmntok_t *config UNUSED)
{
wait_for_bitcoind(p);
wait_and_check_bitcoind(p);
plugin_log(p, LOG_INFORM,
"bitcoin-cli initialized and connected to bitcoind.");
}
Expand Down