From f0a12c5c23904772680c6d0e2b20f690c937c20d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 24 Feb 2018 15:41:22 +1030 Subject: [PATCH] bitcoind: retry after one second if a call fails. There are two recurring calls: the estimatefee call and the getblockcount call. Currently we simply discard them on error, the timer isn't rearmed. This should fix a number of cases where bitcoind has an intermittant failure and lightningd simply stops collecting blocks. Signed-off-by: Rusty Russell --- lightningd/bitcoind.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index b4b3634d9..068b18117 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -116,6 +116,12 @@ static char *bcli_args(struct bitcoin_cli *bcli) return ret; } +static void retry_bcli(struct bitcoin_cli *bcli) +{ + list_add_tail(&bcli->bitcoind->pending, &bcli->list); + next_bcli(bcli->bitcoind); +} + /* We allow 60 seconds of spurious errors, eg. reorg. */ static void bcli_failure(struct bitcoind *bitcoind, struct bitcoin_cli *bcli, @@ -139,6 +145,10 @@ static void bcli_failure(struct bitcoind *bitcoind, "%s exited with status %u", bcli_args(bcli), exitstatus); bitcoind->error_count++; + + /* Retry in 1 second */ + new_reltimer(&bitcoind->ld->timers, bcli, time_from_sec(1), + retry_bcli, bcli); } static void bcli_finished(struct io_conn *conn UNUSED, struct bitcoin_cli *bcli) @@ -182,10 +192,10 @@ static void bcli_finished(struct io_conn *conn UNUSED, struct bitcoin_cli *bcli) if (!ok) bcli_failure(bitcoind, bcli, WEXITSTATUS(status)); + else + tal_free(bcli); done: - tal_free(bcli); - next_bcli(bitcoind); }