mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 18:52:29 +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:
@@ -26,9 +26,12 @@ class UptimeTest(BitcoinTestFramework):
|
||||
assert_raises_rpc_error(-8, "Mocktime must be in the range [0, 9223372036], not -1.", self.nodes[0].setmocktime, -1)
|
||||
|
||||
def _test_uptime(self):
|
||||
wait_time = 10
|
||||
self.nodes[0].setmocktime(int(time.time() + wait_time))
|
||||
assert self.nodes[0].uptime() >= wait_time
|
||||
wait_time = 20_000
|
||||
uptime_before = self.nodes[0].uptime()
|
||||
self.nodes[0].setmocktime(int(time.time()) + wait_time)
|
||||
uptime_after = self.nodes[0].uptime()
|
||||
self.nodes[0].setmocktime(0)
|
||||
assert uptime_after - uptime_before < wait_time, "uptime should not jump with wall clock"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user