bcli: Add rpcclienttimeout parameter and use max value of it and retry_timeout

This commit is contained in:
Se7enZ 2024-02-20 15:20:37 +01:00 committed by Alex Myers
parent 86d2478743
commit ca4710e942
2 changed files with 24 additions and 0 deletions

View File

@ -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

View File

@ -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;
@ -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));
@ -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;
@ -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"