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:
cmake -B build && cmake --build build --target bitcoind bitcoin-cli -j$(nproc)
DATA_DIR=$(mktemp -d)
./build/bin/bitcoind -regtest -datadir="$DATA_DIR" -connect=0 -daemon
./build/bin/bitcoin-cli -regtest -datadir="$DATA_DIR" -rpcwait uptime
sleep 1
./build/bin/bitcoin-cli -regtest -datadir="$DATA_DIR" setmocktime $(( $(date +%s) + 20000000 ))
./build/bin/bitcoin-cli -regtest -datadir="$DATA_DIR" uptime
./build/bin/bitcoin-cli -regtest -datadir="$DATA_DIR" stop
<details> <summary>Before (uptime jumps with wall clock)</summary>
Bitcoin Core starting
0
20000001
Bitcoin Core stopping
</details>
<details> <summary>After (uptime stays monotonic)</summary>
Bitcoin Core starting
0
1
Bitcoin Core stopping
</details>