mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
Improve onboarding experience by handling common failure scenarios for new users more gracefully
Improve usability in these scenarios: * bitcoin-cli not available in PATH and/or bitcoind not running * bitcoin-cli available in PATH but bitcoind is not running
This commit is contained in:
parent
3e9e19951b
commit
161ed320f8
@ -716,6 +716,23 @@ static const char **cmdarr(const tal_t *ctx, const struct bitcoind *bitcoind,
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fatal_bitcoind_failure(struct bitcoind *bitcoind, const char *error_message)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
const char **cmd = cmdarr(bitcoind, bitcoind, "echo", NULL);
|
||||||
|
|
||||||
|
fprintf(stderr, "%s\n\n", error_message);
|
||||||
|
fprintf(stderr, "Make sure you have bitcoind running and that bitcoin-cli is able to connect to bitcoind.\n\n");
|
||||||
|
fprintf(stderr, "You can verify that your Bitcoin Core installation is ready for use by running:\n\n");
|
||||||
|
fprintf(stderr, " $ ");
|
||||||
|
for (i = 0; cmd[i]; i++) {
|
||||||
|
fprintf(stderr, "%s ", cmd[i]);
|
||||||
|
}
|
||||||
|
fprintf(stderr, "'hello world'\n");
|
||||||
|
tal_free(cmd);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
void wait_for_bitcoind(struct bitcoind *bitcoind)
|
void wait_for_bitcoind(struct bitcoind *bitcoind)
|
||||||
{
|
{
|
||||||
int from, ret, status;
|
int from, ret, status;
|
||||||
@ -726,8 +743,12 @@ void wait_for_bitcoind(struct bitcoind *bitcoind)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
child = pipecmdarr(&from, NULL, &from, cast_const2(char **,cmd));
|
child = pipecmdarr(&from, NULL, &from, cast_const2(char **,cmd));
|
||||||
if (child < 0)
|
if (child < 0) {
|
||||||
|
if (errno == ENOENT) {
|
||||||
|
fatal_bitcoind_failure(bitcoind, "bitcoin-cli not found. Is bitcoin-cli (part of Bitcoin Core) available in your PATH?");
|
||||||
|
}
|
||||||
fatal("%s exec failed: %s", cmd[0], strerror(errno));
|
fatal("%s exec failed: %s", cmd[0], strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
output = grab_fd(cmd, from);
|
output = grab_fd(cmd, from);
|
||||||
if (!output)
|
if (!output)
|
||||||
@ -747,9 +768,13 @@ void wait_for_bitcoind(struct bitcoind *bitcoind)
|
|||||||
/* bitcoin/src/rpc/protocol.h:
|
/* bitcoin/src/rpc/protocol.h:
|
||||||
* RPC_IN_WARMUP = -28, //!< Client still warming up
|
* RPC_IN_WARMUP = -28, //!< Client still warming up
|
||||||
*/
|
*/
|
||||||
if (WEXITSTATUS(status) != 28)
|
if (WEXITSTATUS(status) != 28) {
|
||||||
|
if (WEXITSTATUS(status) == 1) {
|
||||||
|
fatal_bitcoind_failure(bitcoind, "Could not connect to bitcoind using bitcoin-cli. Is bitcoind running?");
|
||||||
|
}
|
||||||
fatal("%s exited with code %i: %s",
|
fatal("%s exited with code %i: %s",
|
||||||
cmd[0], WEXITSTATUS(status), output);
|
cmd[0], WEXITSTATUS(status), output);
|
||||||
|
}
|
||||||
|
|
||||||
if (!printed) {
|
if (!printed) {
|
||||||
log_unusual(bitcoind->log,
|
log_unusual(bitcoind->log,
|
||||||
|
Loading…
Reference in New Issue
Block a user