mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-10 23:58:17 +02:00
rpc: make uptime monotonic across NTP jumps
Compute `uptime` from `SteadyClock` so it is unaffected by system time changes after startup.
Derive GUI startup time by subtracting the monotonic uptime from the wall clock time.
Add a functional test covering a large `setmocktime` jump.
Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
This commit is contained in:
@@ -37,9 +37,6 @@
|
||||
|
||||
using util::ReplaceAll;
|
||||
|
||||
// Application startup time (used for uptime calculation)
|
||||
const int64_t nStartupTime = GetTime();
|
||||
|
||||
#ifndef WIN32
|
||||
std::string ShellEscape(const std::string& arg)
|
||||
{
|
||||
@@ -130,8 +127,8 @@ std::optional<size_t> GetTotalRAM()
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Obtain the application startup time (used for uptime calculation)
|
||||
int64_t GetStartupTime()
|
||||
SteadyClock::duration GetUptime()
|
||||
{
|
||||
return nStartupTime;
|
||||
static const auto g_startup_time{SteadyClock::now()};
|
||||
return SteadyClock::now() - g_startup_time;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user