Skip to content

Commit b2f5c38

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22327: cli: Avoid truncating -rpcwaittimeout
fa34cb8 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 fa34cb8 review, debug-built, tested theStack: Tested ACK fa34cb8 Tree-SHA512: 7158da8545f9998a82bcc8636e04564efdb1e1be43b4288298c151b4df29ad47a2760259eefadd4a01db92ea18a1e017f3febc1cd8c69a4b28c86180229d8c90
2 parents 0553d75 + fa34cb8 commit b2f5c38

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/bitcoin-cli.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
797797
// Execute and handle connection failures with -rpcwait.
798798
const bool fWait = gArgs.GetBoolArg("-rpcwait", false);
799799
const int timeout = gArgs.GetArg("-rpcwaittimeout", DEFAULT_WAIT_CLIENT_TIMEOUT);
800-
const int64_t deadline = GetTime<std::chrono::seconds>().count() + timeout;
800+
const auto deadline{GetTime<std::chrono::microseconds>() + 1s * timeout};
801801

802802
do {
803803
try {
@@ -810,9 +810,9 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
810810
}
811811
break; // Connection succeeded, no need to retry.
812812
} catch (const CConnectionFailed& e) {
813-
const int64_t now = GetTime<std::chrono::seconds>().count();
813+
const auto now{GetTime<std::chrono::microseconds>()};
814814
if (fWait && (timeout <= 0 || now < deadline)) {
815-
UninterruptibleSleep(std::chrono::seconds{1});
815+
UninterruptibleSleep(1s);
816816
} else {
817817
throw CConnectionFailed(strprintf("timeout on transient error: %s", e.what()));
818818
}

0 commit comments

Comments
 (0)