Skip to content

Commit

Permalink
bcli: Add rpcclienttimeout parameter and use max value of it and retr…
Browse files Browse the repository at this point in the history
…y_timeout
  • Loading branch information
s373nZ authored and endothermicdev committed May 13, 2024
1 parent 86d2478 commit ca4710e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/lightningd-config.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ This is not valid within the per-network configuration file.

The bitcoind(1) RPC port to connect to.

* **bitcoin-rpcclienttimeout**=*SECONDS* [plugin `bcli`]

The bitcoind(1) RPC client timeout in seconds. Default is set to 60
instead of 900 to match bitcoin-retry-timeout default. When set
explicitly, the higher value of it and bitcoin-retry-timeout is used.

* **bitcoin-retry-timeout**=*SECONDS* [plugin `bcli`]

Number of seconds to keep trying a bitcoin-cli(1) command. If the
Expand Down
18 changes: 18 additions & 0 deletions plugins/bcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct bitcoind {

/* Passthrough parameters for bitcoin-cli */
char *rpcuser, *rpcpass, *rpcconnect, *rpcport;
u64 rpcclienttimeout;

/* Whether we fake fees (regtest) */
bool fake_fees;
Expand Down Expand Up @@ -104,6 +105,16 @@ static const char **gather_argsv(const tal_t *ctx, const char *cmd, va_list ap)
add_arg(&args, chainparams->cli_args);
if (bitcoind->datadir)
add_arg(&args, tal_fmt(args, "-datadir=%s", bitcoind->datadir));
if (bitcoind->rpcclienttimeout) {
/* Use the maximum value of rpcclienttimeout and retry_timeout to avoid
the bitcoind backend hanging for too long. */
if (bitcoind->retry_timeout &&
bitcoind->retry_timeout > bitcoind->rpcclienttimeout)
bitcoind->rpcclienttimeout = bitcoind->retry_timeout;

add_arg(&args,
tal_fmt(args, "-rpcclienttimeout=%ld", bitcoind->rpcclienttimeout));
}
if (bitcoind->rpcconnect)
add_arg(&args,
tal_fmt(args, "-rpcconnect=%s", bitcoind->rpcconnect));
Expand Down Expand Up @@ -1225,6 +1236,9 @@ static struct bitcoind *new_bitcoind(const tal_t *ctx)
bitcoind->rpcpass = NULL;
bitcoind->rpcconnect = NULL;
bitcoind->rpcport = NULL;
/* Do not exceed retry_timeout value to avoid a bitcoind hang,
although normal rpcclienttimeout default value is 900. */
bitcoind->rpcclienttimeout = 60;
bitcoind->dev_no_fake_fees = false;

return bitcoind;
Expand Down Expand Up @@ -1264,6 +1278,10 @@ int main(int argc, char *argv[])
"int",
"bitcoind RPC host's port",
charp_option, &bitcoind->rpcport),
plugin_option("bitcoin-rpcclienttimeout",
"int",
"bitcoind RPC timeout in seconds during HTTP requests",
u64_option, &bitcoind->rpcclienttimeout),
plugin_option("bitcoin-retry-timeout",
"string",
"how long to keep retrying to contact bitcoind"
Expand Down

0 comments on commit ca4710e

Please sign in to comment.