Skip to content

Commit

Permalink
Workaround for c-lightning to wait bitcoin core to start
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier authored and Kukks committed Jul 20, 2021
1 parent 062afa3 commit 9d5f208
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions plugins/bcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ static void wait_and_check_bitcoind(struct plugin *p)
pid_t child;
const char **cmd = gather_args(bitcoind, "getnetworkinfo", NULL);
bool printed = false;
bool isWarmup = false;
char *output = NULL;

for (;;) {
Expand Down Expand Up @@ -862,17 +863,20 @@ static void wait_and_check_bitcoind(struct plugin *p)
/* bitcoin/src/rpc/protocol.h:
* RPC_IN_WARMUP = -28, //!< Client still warming up
*/
if (WEXITSTATUS(status) != 28) {
if (WEXITSTATUS(status) == 1)
bitcoind_failure(p, "Could not connect to bitcoind using"
" bitcoin-cli. Is bitcoind running?");
bitcoind_failure(p, tal_fmt(bitcoind, "%s exited with code %i: %s",
cmd[0], WEXITSTATUS(status), output));
}
isWarmup = WEXITSTATUS(status) == 28;

if (!printed) {
plugin_log(p, LOG_UNUSUAL,
"Waiting for bitcoind to warm up...");
if (isWarmup)
{
plugin_log(p, LOG_UNUSUAL,
"Waiting for bitcoind to warm up...");
}
else
{
plugin_log(p, LOG_UNUSUAL,
tal_fmt(bitcoind, "%s exited with code %i: %s... retrying",
cmd[0], WEXITSTATUS(status), output));
}
printed = true;
}
sleep(1);
Expand Down

0 comments on commit 9d5f208

Please sign in to comment.