mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 16:29:39 +00:00
test: fix waitTipChanged timeout on slow hosts and use monotonic clock in interface_ipc_mining #36791
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36791
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-flaky-interface-ipc-mining"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow up suggested in https://github.com/bitcoin/bitcoin/pull/36731#issuecomment-6675432663.
The first commit fix the timeout on a slow host and the second one use time.monotonic() for durations.
Note (added after merge): the first commit's failure is not a wall clock problem. The faketime command only reproduces it by making the test slow. See https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4565751670
Command to reproduce the errors with a simulated slow wall clock:
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.No verified findings are available from this review.
Review coverage was incomplete.
Reviewed:
46ee95db49c9· Full review report · Previous reportspermalink
I think this is a "fast host", as the test takes a shorter "wall" time?
Concept ACK
You are right. It can be confusing lol. The first commit fixes a wait that takes too long (this is what confused me) and the second fixes durations measured with a wall clock that doesn't match real time. Renamed it to "slow wall clock".
tACK
46ee95db49Concept ACK.
Here is a real-life example of such a failure:
ACK
9b6dadb39c, I have reviewed the code and it looks OK.Code review ACK
46ee95db49. This makesinterface_ipc_mining.pymore robust than on master: duration checks no longer fail when the system clock steps (like hebasto's NetBSD run, where the measured duration came out negative), and thewaitTipChangedcall that waits for a mined block no longer has only 1 second (with the default timeout factor) for the test to mine it.I also ran the faketime command from the description: master fails at "Mine a block" and this PR passes. This is only a partial fix, though: the
waitNextfee-increase wait has the same race and isn't changed, because the faketime repro can't trigger it (https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4565761925). It would be good to fix this case as well.In commit "test: fix waitTipChanged timeout on slow hosts in interface_ipc_mining" (
9b6dadb39c)Nit: could the commit message explain what goes wrong? It only has a subject line now, and the PR description's faketime repro makes it look like a wall clock problem, which isn't what this commit fixes. Maybe something like:
As for why the faketime command reproduces this: it triggers the same failure, but not through the wall clock. The node measures the
waitTipChangeddeadline with the steady clock, which--exclude-monotonicleaves alone (it tells faketime not to fakeCLOCK_MONOTONIC). But libfaketime also stretchesepoll_waittimeouts, so theasyncio.sleep(0.1)inwait_and_dotakes a full second of real time and uses up the timeout before the block is mined. On master, shrinking that sleep makes "Mine a block" pass under faketime, and raising it to 1 second makes it fail the same way without faketime. So for this commit, faketime is just a way to make the test slow. It also means the repro misses the same race in thewaitNextfee-increase wait, which this PR doesn't fix:waitNextmeasures its deadline with the wall clock, which faketime slows down along with the sleep (see https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4565761925).In commit "test: fix waitTipChanged timeout on slow hosts in interface_ipc_mining" (
9b6dadb39c)This PR fixes only one of two places with the same race. This
waitNextcall waits for an event the test triggers afterwait_and_do's 0.1s sleep, just like the "Mine a block"waitTipChangedcall the commit fixes, and its timeout is alsodefault_ipc_timeout(1 second with the default--timeout-factor). If the sleep, the RPC and the mempool update together take more than a second,waitNexttimes out andassert template6 is not Nonefails. I checked this by passingsleep_time=1.2to thiswait_and_docall, which makes the test fail at that assert.The faketime repro only catches the
waitTipChangedcase because the two methods use different clocks:waitTipChangedmeasures its deadline with the steady clock, which faketime leaves running at real speed, whilewaitNextuses the wall clock, which faketime slows down along with the sleep, so the deadline stretches too and the test still passes.Could use the long timeout here as well. It might be simplest to set it once in
run_testnext todefault_ipc_timeout:and use it for both
waitTipChangedcalls, this wait, and the existingmax(self.default_ipc_timeout, 60000.0)inwait_for_block(). Thetemplate2wait (2000.0 * timeout_factorwith a1.1 * timeout_factorsleep) has a similar but smaller window and could use it too, since it ignores fees and only returns for the tip update.Thanks for the review and explanation! I can't change the commit description since this was already merged but I updated the PR description to point to your explanation. I will take a look on this other case!
Good catch. I opened https://github.com/bitcoin/bitcoin/pull/36862 addressing this.
re: https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4566855515
Thanks, the note in the description works well.
re: https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4567254279
Thanks for the quick follow-up! #36862 covers all the waits I mentioned.
Another possible follow-up, if you're interested:
waitNextmeasures its timeout with the wall clock whilewaitTipChangeduses the steady clock, and I don't think that's intentional. It's also why the faketime command only caught one of the two races. Only the testnet 20-minute rule needsNodeClock, since it compares node time with the tip's timestamp. The deadline and the 1-second fee tick seem to use it only because they share the samenowvariable.One effect is that
waitNextnever times out while mocktime is frozen: in a quick unit test, awaitNextcall with a 500ms timeout underFakeNodeClockwas still waiting after 5 seconds. Using the steady clock for the deadline and tick would fix that and make the two methods behave the same. With this change, that unit test returns after 500ms and the existing mining tests pass:Thanks! I did think about switching
waitNextto the steady clock, but figured it would be considered churn. Glad you think it's worth doing. I'll open a PROpened https://github.com/bitcoin/bitcoin/pull/36870