Skip to content

Commit

Permalink
lightningd/options.c: Add option for setting how long to keep trying …
Browse files Browse the repository at this point in the history
…bitcoin-cli command.
  • Loading branch information
ZmnSCPxj authored and cdecker committed Jul 18, 2019
1 parent e737fe7 commit bb30104
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
11 changes: 8 additions & 3 deletions doc/lightningd-config.5
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: lightningd-config
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\" Date: 04/11/2019
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
.\" 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
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -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\&.
Expand Down
5 changes: 5 additions & 0 deletions doc/lightningd-config.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions lightningd/bitcoind.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lightningd/bitcoind.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
6 changes: 6 additions & 0 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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=<file>", opt_set_talstr, opt_show_charp,
&ld->pidfile,
"Specify pid file");
Expand Down

0 comments on commit bb30104

Please sign in to comment.