test: fix waitTipChanged timeout on slow hosts and use monotonic clock in interface_ipc_mining #36791

Manually merged
ViniciusCestarii merged 2 commits from fix-flaky-interface-ipc-mining into master 2026-11-13 16:59:36 +00:00 AGit
ViniciusCestarii commented 2026-11-06 15:25:39 +00:00 (Migrated from github.com)

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:

faketime --exclude-monotonic -f "+0 x0.1" build/test/functional/interface_ipc_mining.py
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: ``` faketime --exclude-monotonic -f "+0 x0.1" build/test/functional/interface_ipc_mining.py ```
DrahtBot commented 2026-11-06 15:25:50 +00:00 (Migrated from github.com)

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.

Type Reviewers
ACK nervana21, hebasto, ryanofsky

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36791 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36791.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36791#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [nervana21](https://github.com/bitcoin/bitcoin/pull/36791#issuecomment-6716485314), [hebasto](https://github.com/bitcoin/bitcoin/pull/36791#pullrequestreview-5873743307), [ryanofsky](https://github.com/bitcoin/bitcoin/pull/36791#pullrequestreview-5894386921) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: 46ee95db49c9 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:df0443dc5cff1224f58cf2f0af2a814b52ac77c4fa18c64584a637f43b36d781:adfdaf6241fe97209d62717f4b34912a3f3c05551d5eb04e28ec078dd3f7e4f2 --> <!-- ralph-base:411c971e75ba8ef16855a41dfe2d31d574ebf507 --> <!-- ralph-head:46ee95db49c9fa7f4b80a1e59816660f5ee0c4f4 --> <!-- ralph-case:fee275be549dd69a6ea8ff643a1789e16084b9c7f294ca34d8ae4f1df1f1b7c4 --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`46ee95db49c9`](<https://git.fish.foo/bitcoin/bitcoin/commit/46ee95db49c9fa7f4b80a1e59816660f5ee0c4f4>) · [Full review report](<https://review.fish.foo/traces/36791-46ee95db49c9fa7f4b80a1e59816660f5ee0c4f4-2319-1.html>) · [Previous reports](<https://review.fish.foo/traces/36791/>) [permalink](<https://review.fish.foo/traces/36791-46ee95db49c9fa7f4b80a1e59816660f5ee0c4f4-2319-1.html>)
maflcko commented 2026-11-06 15:40:07 +00:00 (Migrated from github.com)

Command to reproduce slow host:

I think this is a "fast host", as the test takes a shorter "wall" time?

> Command to reproduce slow host: I think this is a "fast host", as the test takes a shorter "wall" time?
nervana21 commented 2026-11-06 19:10:21 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
ViniciusCestarii commented 2026-11-06 22:52:35 +00:00 (Migrated from github.com)

I think this is a "fast host", as the test takes a shorter "wall" time?

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".

> I think this is a "fast host", as the test takes a shorter "wall" time? 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".
nervana21 commented 2026-11-08 03:03:40 +00:00 (Migrated from github.com)

tACK 46ee95db49

tACK 46ee95db49c9fa7f4b80a1e59816660f5ee0c4f4
hebasto (Migrated from github.com) reviewed 2026-11-12 11:30:54 +00:00
hebasto (Migrated from github.com) left a comment

Concept ACK.

Here is a real-life example of such a failure:

472/505 - interface_ipc_mining.py failed (exit code 1), Duration: 11 s

stdout:
2026-11-12T08:24:54.078139Z TestFramework (INFO): PRNG seed is: 2459815776369179361
2026-11-12T08:24:54.132354Z TestFramework (INFO): Initializing test directory /root/test_runner_₿_🏃_20261112_081320/interface_ipc_mining_36
2026-11-12T08:24:55.674316Z TestFramework (INFO): Running Mining interface test
2026-11-12T08:25:01.032939Z TestFramework (INFO): Running Mining interface early startup test
2026-11-12T08:25:01.957129Z TestFramework (INFO): Running BlockTemplate interface test
2026-11-12T08:24:48.047514Z TestFramework (ERROR): Unexpected exception:
Traceback (most recent call last):
  File "/root/bitcoin/test/functional/test_framework/test_framework.py", line 146, in main
    self.run_test()
    ~~~~~~~~~~~~~^^
  File "/root/build/test/functional/interface_ipc_mining.py", line 890, in run_test
    self.run_block_template_test()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/root/build/test/functional/interface_ipc_mining.py", line 343, in run_block_template_test
    asyncio.run(capnp.run(async_routine()))
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/pkg/lib/python3.13/asyncio/runners.py", line 196, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/usr/pkg/lib/python3.13/asyncio/runners.py", line 119, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/pkg/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "capnp/lib/capnp.pyx", line 2085, in run
  File "capnp/lib/capnp.pyx", line 2086, in capnp.lib.capnp.run
    return await coro
  File "/root/build/test/functional/interface_ipc_mining.py", line 225, in async_routine
    assert_greater_than_or_equal(time.time() - start, 0.9)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/bitcoin/test/functional/test_framework/util.py", line 109, in assert_greater_than_or_equal
    raise AssertionError("%s < %s" % (str(thing1), str(thing2)))
AssertionError: -14.01054048538208 < 0.9
2026-11-12T08:24:48.126115Z TestFramework (INFO): Not stopping nodes as test failed. The dangling processes will be cleaned up later.
2026-11-12T08:24:48.126338Z TestFramework (WARNING): Not cleaning up dir /root/test_runner_₿_🏃_20261112_081320/interface_ipc_mining_36
2026-11-12T08:24:48.126451Z TestFramework (ERROR): Test failed. Test logging available at /root/test_runner_₿_🏃_20261112_081320/interface_ipc_mining_36/test_framework.log
2026-11-12T08:24:48.126749Z TestFramework (ERROR): 
2026-11-12T08:24:48.127092Z TestFramework (ERROR): Hint: Call /root/bitcoin/test/functional/combine_logs.py '/root/test_runner_₿_🏃_20261112_081320/interface_ipc_mining_36' to consolidate all logs
2026-11-12T08:24:48.127182Z TestFramework (ERROR): 
2026-11-12T08:24:48.127254Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2026-11-12T08:24:48.127408Z TestFramework (ERROR): https://github.com/bitcoin/bitcoin/issues
2026-11-12T08:24:48.127479Z TestFramework (ERROR): 


stderr:
[node 2] Cleaning up leftover process
[node 1] Cleaning up leftover process
[node 0] Cleaning up leftover process

Concept ACK. Here is a real-life [example](https://github.com/hebasto/bitcoin-core-nightly/actions/runs/43174892379/job/131036634962) of such a failure: ``` 472/505 - interface_ipc_mining.py failed (exit code 1), Duration: 11 s stdout: 2026-11-12T08:24:54.078139Z TestFramework (INFO): PRNG seed is: 2459815776369179361 2026-11-12T08:24:54.132354Z TestFramework (INFO): Initializing test directory /root/test_runner_₿_🏃_20261112_081320/interface_ipc_mining_36 2026-11-12T08:24:55.674316Z TestFramework (INFO): Running Mining interface test 2026-11-12T08:25:01.032939Z TestFramework (INFO): Running Mining interface early startup test 2026-11-12T08:25:01.957129Z TestFramework (INFO): Running BlockTemplate interface test 2026-11-12T08:24:48.047514Z TestFramework (ERROR): Unexpected exception: Traceback (most recent call last): File "/root/bitcoin/test/functional/test_framework/test_framework.py", line 146, in main self.run_test() ~~~~~~~~~~~~~^^ File "/root/build/test/functional/interface_ipc_mining.py", line 890, in run_test self.run_block_template_test() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "/root/build/test/functional/interface_ipc_mining.py", line 343, in run_block_template_test asyncio.run(capnp.run(async_routine())) ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/pkg/lib/python3.13/asyncio/runners.py", line 196, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/usr/pkg/lib/python3.13/asyncio/runners.py", line 119, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/usr/pkg/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "capnp/lib/capnp.pyx", line 2085, in run File "capnp/lib/capnp.pyx", line 2086, in capnp.lib.capnp.run return await coro File "/root/build/test/functional/interface_ipc_mining.py", line 225, in async_routine assert_greater_than_or_equal(time.time() - start, 0.9) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/bitcoin/test/functional/test_framework/util.py", line 109, in assert_greater_than_or_equal raise AssertionError("%s < %s" % (str(thing1), str(thing2))) AssertionError: -14.01054048538208 < 0.9 2026-11-12T08:24:48.126115Z TestFramework (INFO): Not stopping nodes as test failed. The dangling processes will be cleaned up later. 2026-11-12T08:24:48.126338Z TestFramework (WARNING): Not cleaning up dir /root/test_runner_₿_🏃_20261112_081320/interface_ipc_mining_36 2026-11-12T08:24:48.126451Z TestFramework (ERROR): Test failed. Test logging available at /root/test_runner_₿_🏃_20261112_081320/interface_ipc_mining_36/test_framework.log 2026-11-12T08:24:48.126749Z TestFramework (ERROR): 2026-11-12T08:24:48.127092Z TestFramework (ERROR): Hint: Call /root/bitcoin/test/functional/combine_logs.py '/root/test_runner_₿_🏃_20261112_081320/interface_ipc_mining_36' to consolidate all logs 2026-11-12T08:24:48.127182Z TestFramework (ERROR): 2026-11-12T08:24:48.127254Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log. 2026-11-12T08:24:48.127408Z TestFramework (ERROR): https://github.com/bitcoin/bitcoin/issues 2026-11-12T08:24:48.127479Z TestFramework (ERROR): stderr: [node 2] Cleaning up leftover process [node 1] Cleaning up leftover process [node 0] Cleaning up leftover process ```
hebasto (Migrated from github.com) approved these changes 2026-11-12 11:37:41 +00:00
hebasto (Migrated from github.com) left a comment

ACK 9b6dadb39c, I have reviewed the code and it looks OK.

ACK 9b6dadb39c22bfb6d8b8040519316768919ff906, I have reviewed the code and it looks OK.
ryanofsky (Migrated from github.com) approved these changes 2026-11-13 16:57:23 +00:00
ryanofsky (Migrated from github.com) left a comment

Code review ACK 46ee95db49. This makes interface_ipc_mining.py more 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 the waitTipChanged call 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 waitNext fee-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.

Code review ACK 46ee95db49c9fa7f4b80a1e59816660f5ee0c4f4. This makes `interface_ipc_mining.py` more 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 the `waitTipChanged` call 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 `waitNext` fee-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.
ryanofsky (Migrated from github.com) commented 2026-11-13 16:14:31 +00:00

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:

Use a 1 minute timeout for the waitTipChanged call that waits for a newly mined block, instead of default_ipc_timeout, which is only 1 second when the test runs with the default --timeout-factor (CI uses 40).

The test sends waitTipChanged, waits 0.1 seconds, and then calls generate. Everything between the node receiving the request and the new block becoming its tip (the rest of that sleep, the generate RPC, and creating, validating and connecting the block) had to fit in that 1 second, which a busy machine may not manage. When it didn't, waitTipChanged returned the old tip and the height check failed. The longer timeout costs nothing when the test passes, because the call returns as soon as the tip changes.

As for why the faketime command reproduces this: it triggers the same failure, but not through the wall clock. The node measures the waitTipChanged deadline with the steady clock, which --exclude-monotonic leaves alone (it tells faketime not to fake CLOCK_MONOTONIC). But libfaketime also stretches epoll_wait timeouts, so the asyncio.sleep(0.1) in wait_and_do takes 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 the waitNext fee-increase wait, which this PR doesn't fix: waitNext measures 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" (9b6dadb39c22bfb6d8b8040519316768919ff906) 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: > Use a 1 minute timeout for the waitTipChanged call that waits for a newly mined block, instead of default_ipc_timeout, which is only 1 second when the test runs with the default --timeout-factor (CI uses 40). > > The test sends waitTipChanged, waits 0.1 seconds, and then calls generate. Everything between the node receiving the request and the new block becoming its tip (the rest of that sleep, the generate RPC, and creating, validating and connecting the block) had to fit in that 1 second, which a busy machine may not manage. When it didn't, waitTipChanged returned the old tip and the height check failed. The longer timeout costs nothing when the test passes, because the call returns as soon as the tip changes. As for why the faketime command reproduces this: it triggers the same failure, but not through the wall clock. The node measures the `waitTipChanged` deadline with the [steady clock](https://github.com/bitcoin/bitcoin/blob/46ee95db49c9fa7f4b80a1e59816660f5ee0c4f4/src/node/block_template_manager.cpp#L235), which `--exclude-monotonic` [leaves alone](https://github.com/wolfcw/libfaketime/blob/03a2fdee4d6fef55e8f58451192cc0cadebd5f77/man/faketime.1#L37-L38) (it tells faketime not to fake `CLOCK_MONOTONIC`). But libfaketime also stretches `epoll_wait` timeouts, so the `asyncio.sleep(0.1)` in [`wait_and_do`](https://github.com/bitcoin/bitcoin/blob/46ee95db49c9fa7f4b80a1e59816660f5ee0c4f4/test/functional/test_framework/ipc_util.py#L48-L68) takes 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 the `waitNext` fee-increase wait, which this PR doesn't fix: `waitNext` measures its deadline with the [wall clock](https://github.com/bitcoin/bitcoin/blob/46ee95db49c9fa7f4b80a1e59816660f5ee0c4f4/src/node/block_template_manager.cpp#L119-L120), which faketime slows down along with the sleep (see https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4565761925).
ryanofsky (Migrated from github.com) commented 2026-11-13 16:15:31 +00:00

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 waitNext call waits for an event the test triggers after wait_and_do's 0.1s sleep, just like the "Mine a block" waitTipChanged call the commit fixes, and its timeout is also default_ipc_timeout (1 second with the default --timeout-factor). If the sleep, the RPC and the mempool update together take more than a second, waitNext times out and assert template6 is not None fails. I checked this by passing sleep_time=1.2 to this wait_and_do call, which makes the test fail at that assert.

The faketime repro only catches the waitTipChanged case because the two methods use different clocks: waitTipChanged measures its deadline with the steady clock, which faketime leaves running at real speed, while waitNext uses 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_test next to default_ipc_timeout:

# Timeout for waits that should return early because of an event the test
# triggers, long enough not to expire on a slow host.
self.long_ipc_timeout = max(self.default_ipc_timeout, 60000.0)  # at least 1 minute

and use it for both waitTipChanged calls, this wait, and the existing max(self.default_ipc_timeout, 60000.0) in wait_for_block(). The template2 wait (2000.0 * timeout_factor with a 1.1 * timeout_factor sleep) has a similar but smaller window and could use it too, since it ignores fees and only returns for the tip update.

In commit "test: fix waitTipChanged timeout on slow hosts in interface_ipc_mining" (9b6dadb39c22bfb6d8b8040519316768919ff906) This PR fixes only one of two places with the same race. This `waitNext` call waits for an event the test triggers after `wait_and_do`'s 0.1s sleep, just like the "Mine a block" `waitTipChanged` call the commit fixes, and its timeout is also `default_ipc_timeout` (1 second with the default `--timeout-factor`). If the sleep, the RPC and the mempool update together take more than a second, `waitNext` times out and `assert template6 is not None` fails. I checked this by passing `sleep_time=1.2` to this `wait_and_do` call, which makes the test fail at that assert. The faketime repro only catches the `waitTipChanged` case because the two methods use different clocks: `waitTipChanged` measures its deadline with the [steady clock](https://github.com/bitcoin/bitcoin/blob/46ee95db49c9fa7f4b80a1e59816660f5ee0c4f4/src/node/block_template_manager.cpp#L235), which faketime leaves running at real speed, while `waitNext` uses the [wall clock](https://github.com/bitcoin/bitcoin/blob/46ee95db49c9fa7f4b80a1e59816660f5ee0c4f4/src/node/block_template_manager.cpp#L119-L120), 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_test` next to `default_ipc_timeout`: ```python # Timeout for waits that should return early because of an event the test # triggers, long enough not to expire on a slow host. self.long_ipc_timeout = max(self.default_ipc_timeout, 60000.0) # at least 1 minute ``` and use it for both `waitTipChanged` calls, this wait, and the existing `max(self.default_ipc_timeout, 60000.0)` in `wait_for_block()`. The `template2` wait (`2000.0 * timeout_factor` with a `1.1 * timeout_factor` sleep) has a similar but smaller window and could use it too, since it ignores fees and only returns for the tip update.
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-13 18:03:50 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-13 18:03:50 +00:00

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!

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!
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-13 18:45:34 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-13 18:45:34 +00:00
Good catch. I opened https://github.com/bitcoin/bitcoin/pull/36862 addressing this.
ryanofsky (Migrated from github.com) reviewed 2026-11-13 20:06:13 +00:00
ryanofsky (Migrated from github.com) commented 2026-11-13 20:06:14 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4566855515

I updated the PR description to point to your explanation

Thanks, the note in the description works well.

re: https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4566855515 > I updated the PR description to point to your explanation Thanks, the note in the description works well.
ryanofsky (Migrated from github.com) commented 2026-11-13 20:06:13 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4567254279

I opened #36862 addressing this.

Thanks for the quick follow-up! #36862 covers all the waits I mentioned.

Another possible follow-up, if you're interested: waitNext measures its timeout with the wall clock while waitTipChanged uses 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 needs NodeClock, 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 same now variable.

One effect is that waitNext never times out while mocktime is frozen: in a quick unit test, a waitNext call with a 500ms timeout under FakeNodeClock was 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:

-auto now{NodeClock::now()};
+auto now{std::chrono::steady_clock::now()};
 const auto deadline = now + wait_options.timeout;
 ...
-        if (now > tip_time + 20min) {
+        if (NodeClock::now() > tip_time + 20min) {
 ...
-    now = NodeClock::now();
+    now = std::chrono::steady_clock::now();
 } while (now < deadline);
re: https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4567254279 > I opened #36862 addressing this. Thanks for the quick follow-up! #36862 covers all the waits I mentioned. Another possible follow-up, if you're interested: `waitNext` measures its timeout with the [wall clock](https://github.com/bitcoin/bitcoin/blob/a527a0077a0fcae913188410214efe98021c0cca/src/node/block_template_manager.cpp#L119-L121) while `waitTipChanged` uses the [steady clock](https://github.com/bitcoin/bitcoin/blob/a527a0077a0fcae913188410214efe98021c0cca/src/node/block_template_manager.cpp#L235), 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](https://github.com/bitcoin/bitcoin/blob/a527a0077a0fcae913188410214efe98021c0cca/src/node/block_template_manager.cpp#L151-L157) needs `NodeClock`, 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 same `now` variable. One effect is that `waitNext` never times out while mocktime is frozen: in a quick unit test, a `waitNext` call with a 500ms timeout under `FakeNodeClock` was 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: ```diff -auto now{NodeClock::now()}; +auto now{std::chrono::steady_clock::now()}; const auto deadline = now + wait_options.timeout; ... - if (now > tip_time + 20min) { + if (NodeClock::now() > tip_time + 20min) { ... - now = NodeClock::now(); + now = std::chrono::steady_clock::now(); } while (now < deadline); ```
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-14 12:08:23 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-14 12:08:23 +00:00

Thanks! I did think about switching waitNext to the steady clock, but figured it would be considered churn. Glad you think it's worth doing. I'll open a PR

Thanks! I did think about switching `waitNext` to the steady clock, but figured it would be considered churn. Glad you think it's worth doing. I'll open a PR
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-14 13:05:11 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-14 13:05:11 +00:00
Opened https://github.com/bitcoin/bitcoin/pull/36870
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36791
No description provided.