Merge bitcoin/bitcoin#36529: test: measure rpcwaittimeout floor with monotonic time
What changed, and why it matters
This commit fixes a flaky automated test in Bitcoin Core. The test checks that bitcoin-cli waits at least the requested timeout before giving up when it cannot connect to the server. Previously the test used wall-clock time (time.time()), which can jump backwards if the computer's clock is adjusted, causing the test to fail even though nothing was wrong. The fix switches to monotonic time (time.monotonic()), which only moves forward, and shortens the timeout from 5 seconds to 1 second. There is no change to the actual Bitcoin Core software that users run, only to the test suite.
No security action required. This is a test-only reliability improvement. Reviewers can merge as-is.
Security signals we found
No strong security signals were identified.
Evidence from the diff
Commit aa76bd2 merges PR #36529, which modifies test/functional/interface_bitcoin_cli.py. The test for -rpcwait/-rpcwaittimeout previously recorded start = time.time() and asserted time.time() >= start + 5. Because bitcoin-cli uses std::chrono::steady_clock for its internal deadline, a backward wall-clock step (NTP adjustment, VM time sync, etc.) could make the Python-side elapsed measurement appear shorter than the real wait, producing a spurious failure. The patch replaces time.time() with time.monotonic(), matching the monotonic semantics of steady_clock, changes the timeout value from 5 to 1 to speed up the test, and updates the log message from ‘at most’ to ‘at least’ to reflect that the assertion is a floor, not a ceiling. No production code is changed.
Changed components
test/functional/interface_bitcoin_cli.pyInspect captured patch +4 / −4
### test/functional/interface_bitcoin_cli.py
@@ -474,11 +474,11 @@ def run_test(self):
self.nodes[0].wait_for_rpc_connection()
assert_equal(blocks, BLOCKS + 25)
- self.log.info("Test -rpcwait option waits at most -rpcwaittimeout seconds for startup")
+ self.log.info("Test -rpcwait option waits at least -rpcwaittimeout seconds for startup")
self.stop_node(0) # stop the node so we time out
- start_time = time.time()
- assert_raises_process_error(1, "Could not connect to the server", self.nodes[0].cli('-rpcwait', '-rpcwaittimeout=5').echo)
- assert_greater_than_or_equal(time.time(), start_time + 5)
+ start_time = time.monotonic() # match bitcoin-cli steady_clock so the floor measures real wait
+ assert_raises_process_error(1, "Could not connect to the server", self.nodes[0].cli('-rpcwait', '-rpcwaittimeout=1').echo)
+ assert_greater_than_or_equal(time.monotonic() - start_time, 1)
self.log.info("Test that only one of -addrinfo, -generate, -getinfo, -netinfo may be specified at a time")
assert_raises_process_error(1, "Only one of -getinfo, -netinfo may be specified", self.nodes[0].cli('-getinfo', '-netinfo').send_cli)Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.