Problem
bitcoin-cli uptime was derived from wall-clock time, so it could jump by large amounts when the system clock is corrected after bitcoind starts (e.g. on RTC-less systems syncing NTP).
This breaks the expectation that uptime reflects process runtime.
Fix
Compute uptime from a monotonic clock so it is immune to wall-clock jumps, and use that monotonic uptime for the RPC. GUI startup time is derived from wall clock time minus monotonic uptime so it remains sensible after clock corrections.
Reproducer
Revert the fix commit and run the rpc_uptime functional test (it should fail with AssertionError: uptime should not jump with wall clock):
Or alternatively:
0cmake -B build && cmake --build build --target bitcoind bitcoin-cli -j$(nproc)
1DATA_DIR=$(mktemp -d)
2./build/bin/bitcoind -regtest -datadir="$DATA_DIR" -connect=0 -daemon
3./build/bin/bitcoin-cli -regtest -datadir="$DATA_DIR" -rpcwait uptime
4sleep 1
5./build/bin/bitcoin-cli -regtest -datadir="$DATA_DIR" setmocktime $(( $(date +%s) + 20000000 ))
6./build/bin/bitcoin-cli -regtest -datadir="$DATA_DIR" uptime
7./build/bin/bitcoin-cli -regtest -datadir="$DATA_DIR" stop
0Bitcoin Core starting
10
220000001
3Bitcoin Core stopping
0Bitcoin Core starting
10
21
3Bitcoin Core stopping