diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-06-24 16:01:18 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-06-24 16:01:21 +0200 |
commit | b2f5c38333fd2ec03fd1299a1bce507b25753f45 (patch) | |
tree | 870f61fdca0f78e1c1bf8dc9b449bf20efff1c10 /src | |
parent | 0553d75268a94630225fa754841e28d88d751665 (diff) | |
parent | fa34cb80248cc39a73fc393f65c3cfc62e849556 (diff) |
Merge bitcoin/bitcoin#22327: cli: Avoid truncating -rpcwaittimeout
fa34cb80248cc39a73fc393f65c3cfc62e849556 cli: Avoid truncating -rpcwaittimeout (MarcoFalke)
Pull request description:
`seconds` is not enough precision to "exactly" store a timestamp n seconds into the future. Improve the precision by using `microseconds`. Fixes #22325
Also, use chrono literals.
ACKs for top commit:
jonatack:
ACK fa34cb80248cc39a73fc393f65c3cfc62e849556 review, debug-built, tested
theStack:
Tested ACK fa34cb80248cc39a73fc393f65c3cfc62e849556
Tree-SHA512: 7158da8545f9998a82bcc8636e04564efdb1e1be43b4288298c151b4df29ad47a2760259eefadd4a01db92ea18a1e017f3febc1cd8c69a4b28c86180229d8c90
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoin-cli.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index adc485983f..7a5f945511 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -797,7 +797,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str // Execute and handle connection failures with -rpcwait. const bool fWait = gArgs.GetBoolArg("-rpcwait", false); const int timeout = gArgs.GetArg("-rpcwaittimeout", DEFAULT_WAIT_CLIENT_TIMEOUT); - const int64_t deadline = GetTime<std::chrono::seconds>().count() + timeout; + const auto deadline{GetTime<std::chrono::microseconds>() + 1s * timeout}; do { try { @@ -810,9 +810,9 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str } break; // Connection succeeded, no need to retry. } catch (const CConnectionFailed& e) { - const int64_t now = GetTime<std::chrono::seconds>().count(); + const auto now{GetTime<std::chrono::microseconds>()}; if (fWait && (timeout <= 0 || now < deadline)) { - UninterruptibleSleep(std::chrono::seconds{1}); + UninterruptibleSleep(1s); } else { throw CConnectionFailed(strprintf("timeout on transient error: %s", e.what())); } |