Skip to content

Commit 3a998d2

Browse files
committed
Use steady_clock in ConnectAndCallRPC and inline time call in loop conditional
to avoid unnecessary invocations and an unneeded local variable allocation.
1 parent 3799d2d commit 3a998d2

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/bitcoin-cli.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
844844
// Execute and handle connection failures with -rpcwait.
845845
const bool fWait = gArgs.GetBoolArg("-rpcwait", false);
846846
const int timeout = gArgs.GetIntArg("-rpcwaittimeout", DEFAULT_WAIT_CLIENT_TIMEOUT);
847-
const auto deadline{GetTime<std::chrono::microseconds>() + 1s * timeout};
847+
const auto deadline{std::chrono::steady_clock::now() + 1s * timeout};
848848

849849
do {
850850
try {
@@ -857,8 +857,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
857857
}
858858
break; // Connection succeeded, no need to retry.
859859
} catch (const CConnectionFailed& e) {
860-
const auto now{GetTime<std::chrono::microseconds>()};
861-
if (fWait && (timeout <= 0 || now < deadline)) {
860+
if (fWait && (timeout <= 0 || std::chrono::steady_clock::now() < deadline)) {
862861
UninterruptibleSleep(1s);
863862
} else {
864863
throw CConnectionFailed(strprintf("timeout on transient error: %s", e.what()));

0 commit comments

Comments
 (0)