From 985a0b431f7d2916a902274a2cc4594d63183d86 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 21 Dec 2017 21:37:55 +1030 Subject: [PATCH] getblockhash: don't get upset if we fail. Signed-off-by: Rusty Russell --- lightningd/bitcoind.c | 8 +++++++- lightningd/bitcoind.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index c6ce222d2..0bd59127a 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -491,6 +491,12 @@ static void process_getblockhash(struct bitcoin_cli *bcli) const struct bitcoin_blkid *blkid, void *arg) = bcli->cb; + /* If it failed, call with NULL block. */ + if (*bcli->exitstatus != 0) { + cb(bcli->bitcoind, NULL, bcli->cb_arg); + return; + } + if (bcli->output_bytes == 0 || !bitcoin_blkid_from_hex(bcli->output, bcli->output_bytes-1, &blkid)) { @@ -511,7 +517,7 @@ void bitcoind_getblockhash_(struct bitcoind *bitcoind, char str[STR_MAX_CHARS(height)]; sprintf(str, "%u", height); - start_bitcoin_cli(bitcoind, NULL, process_getblockhash, false, cb, arg, + start_bitcoin_cli(bitcoind, NULL, process_getblockhash, true, cb, arg, "getblockhash", str, NULL); } diff --git a/lightningd/bitcoind.h b/lightningd/bitcoind.h index eaf7618a6..fe48ea40c 100644 --- a/lightningd/bitcoind.h +++ b/lightningd/bitcoind.h @@ -112,6 +112,7 @@ void bitcoind_getblockcount_(struct bitcoind *bitcoind, u32 blockcount), \ (arg)) +/* blkid is NULL if call fails. */ void bitcoind_getblockhash_(struct bitcoind *bitcoind, u32 height, void (*cb)(struct bitcoind *bitcoind,