diff --git a/doc/lightningd-config.5 b/doc/lightningd-config.5
index f26531b34..ba45977dc 100644
--- a/doc/lightningd-config.5
+++ b/doc/lightningd-config.5
@@ -1,13 +1,13 @@
'\" t
.\" Title: lightningd-config
.\" Author: [see the "AUTHOR" section]
-.\" Generator: DocBook XSL Stylesheets vsnapshot
-.\" Date: 04/11/2019
+.\" Generator: DocBook XSL Stylesheets v1.79.1
+.\" Date: 06/30/2019
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "LIGHTNINGD\-CONFIG" "5" "04/11/2019" "\ \&" "\ \&"
+.TH "LIGHTNINGD\-CONFIG" "5" "06/30/2019" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -121,6 +121,11 @@ The bitcoind(1) RPC host to connect to\&.
The bitcoind(1) RPC port to connect to\&.
.RE
.PP
+\fBbitcoin\-retry\-timeout\fR=\fISECONDS\fR
+.RS 4
+Number of seconds to keep trying a bitcoin\-cli(1) command\&. If the command keeps failing after this time, exit with a fatal error\&.
+.RE
+.PP
\fBrescan\fR=\fIBLOCKS\fR
.RS 4
Number of blocks to rescan from the current head, or absolute blockheight if negative\&. This is only needed if something goes badly wrong\&.
diff --git a/doc/lightningd-config.5.txt b/doc/lightningd-config.5.txt
index f40a18a9d..3c081d5f7 100644
--- a/doc/lightningd-config.5.txt
+++ b/doc/lightningd-config.5.txt
@@ -88,6 +88,11 @@ Bitcoin control options:
*bitcoin-rpcport*='PORT'::
The bitcoind(1) RPC port to connect to.
+*bitcoin-retry-timeout*='SECONDS'::
+ Number of seconds to keep trying a bitcoin-cli(1) command.
+ If the command keeps failing after this time, exit with a
+ fatal error.
+
*rescan*='BLOCKS'::
Number of blocks to rescan from the current head, or absolute blockheight
if negative. This is only needed if something goes badly wrong.
diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c
index 579a7d092..78f290131 100644
--- a/lightningd/bitcoind.c
+++ b/lightningd/bitcoind.c
@@ -154,13 +154,17 @@ static void bcli_failure(struct bitcoind *bitcoind,
bitcoind->first_error_time = time_mono();
t = timemono_between(time_mono(), bitcoind->first_error_time);
- if (time_greater(t, time_from_sec(60)))
- fatal("%s exited %u (after %u other errors) '%.*s'",
+ if (time_greater(t, time_from_sec(bitcoind->retry_timeout)))
+ fatal("%s exited %u (after %u other errors) '%.*s'; "
+ "we have been retrying command for "
+ "--bitcoin-retry-timeout=%"PRIu64" seconds; "
+ "bitcoind setup or our --bitcoin-* configs broken?",
bcli_args(tmpctx, bcli),
exitstatus,
bitcoind->error_count,
(int)bcli->output_bytes,
- bcli->output);
+ bcli->output,
+ bitcoind->retry_timeout);
log_unusual(bitcoind->log,
"%s exited with status %u",
@@ -930,6 +934,7 @@ struct bitcoind *new_bitcoind(const tal_t *ctx,
}
bitcoind->shutdown = false;
bitcoind->error_count = 0;
+ bitcoind->retry_timeout = 60;
bitcoind->rpcuser = NULL;
bitcoind->rpcpass = NULL;
bitcoind->rpcconnect = NULL;
diff --git a/lightningd/bitcoind.h b/lightningd/bitcoind.h
index 379a56730..0e395f93f 100644
--- a/lightningd/bitcoind.h
+++ b/lightningd/bitcoind.h
@@ -59,6 +59,10 @@ struct bitcoind {
/* Ignore results, we're shutting down. */
bool shutdown;
+ /* How long to keep trying to contact bitcoind
+ * before fatally exiting. */
+ u64 retry_timeout;
+
/* Passthrough parameters for bitcoin-cli */
char *rpcuser, *rpcpass, *rpcconnect, *rpcport;
};
diff --git a/lightningd/options.c b/lightningd/options.c
index 364fafffc..16558bbd2 100644
--- a/lightningd/options.c
+++ b/lightningd/options.c
@@ -858,6 +858,12 @@ void register_opts(struct lightningd *ld)
opt_register_arg("--bitcoin-rpcport", opt_set_talstr, NULL,
&ld->topology->bitcoind->rpcport,
"bitcoind RPC port");
+ opt_register_arg("--bitcoin-retry-timeout",
+ opt_set_u64, opt_show_u64,
+ &ld->topology->bitcoind->retry_timeout,
+ "how long to keep trying to contact bitcoind "
+ "before fatally exiting");
+
opt_register_arg("--pid-file=", opt_set_talstr, opt_show_charp,
&ld->pidfile,
"Specify pid file");