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 committed Feb 20, 2024
1 parent 1e023a1 commit 0863ea7
Showing 1 changed file with 18 additions and 0 deletions.
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 @@ -1105,6 +1116,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 @@ -1144,6 +1158,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 0863ea7

Please sign in to comment.