From 57b2fe58906e672b66bde2f93cc5211ec82d5b8d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 26 Jul 2019 10:20:09 +0930 Subject: [PATCH] lightningd: fix fatal error on startup if bitcoind isn't ready. At the moment we simply get a crypto log line on exit: bitcoin-cli getblockchaininfo: invalid response Fixes: 6deed77d88944af253ce142277d40fa050d341cd Signed-off-by: Rusty Russell --- lightningd/bitcoind.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index 78f290131..5b8d071b5 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -881,10 +881,6 @@ void wait_for_bitcoind(struct bitcoind *bitcoind) char *output = grab_fd(cmd, from); - errstr = check_blockchain_from_bitcoincli(tmpctx, bitcoind, output, cmd); - if(errstr) - fatal("%s", errstr); - while ((ret = waitpid(child, &status, 0)) < 0 && errno == EINTR); if (ret != child) fatal("Waiting for %s: %s", cmd[0], strerror(errno)); @@ -892,8 +888,14 @@ void wait_for_bitcoind(struct bitcoind *bitcoind) fatal("Death of %s: signal %i", cmd[0], WTERMSIG(status)); - if (WEXITSTATUS(status) == 0) + if (WEXITSTATUS(status) == 0) { + /* If succeeded, so check answer it gave. */ + errstr = check_blockchain_from_bitcoincli(tmpctx, bitcoind, output, cmd); + if (errstr) + fatal("%s", errstr); + break; + } /* bitcoin/src/rpc/protocol.h: * RPC_IN_WARMUP = -28, //!< Client still warming up