test: use long timeout for event waits in interface_ipc_mining #36862

Manually merged
ViniciusCestarii merged 1 commit from ipc-mining-long-timeout into master 2026-11-16 11:39:17 +00:00 AGit
ViniciusCestarii commented 2026-11-13 18:44:01 +00:00 (Migrated from github.com)

Follow-up to #36791, https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4565761925 by ryanofsky.

#36791 fixed the waitTipChanged timeout on slow hosts, but the template6 waitNext call has the same race: it waits for an event the test triggers after a 0.1s sleep, with a 1s timeout.

This adds long_ipc_timeout and uses it for all waits that end on an event the test triggers.

To reproduce failure on master:

diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py
index cdef196fd0..49e1c8a9c1 100755
--- a/test/functional/interface_ipc_mining.py
+++ b/test/functional/interface_ipc_mining.py
@@ -320,7 +320,8 @@ class IPCMiningTest(BitcoinTestFramework):
                 self.log.debug("Wait for another, get one after increase in fees in the mempool")
                 template6 = await wait_and_do(
                     mining_wait_next_template(template5, stack, ctx, waitoptions),
-                    lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
+                    lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]),
+                    sleep_time=1.2)
                 assert template6 is not None
                 block4 = await mining_get_block(template6, ctx)
                 assert_equal(len(block4.vtx), 3)

Follow-up to #36791, https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4565761925 by ryanofsky. #36791 fixed the `waitTipChanged` timeout on slow hosts, but the `template6` `waitNext` call has the same race: it waits for an event the test triggers after a 0.1s sleep, with a 1s timeout. This adds `long_ipc_timeout` and uses it for all waits that end on an event the test triggers. To reproduce failure on master: ```diff diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py index cdef196fd0..49e1c8a9c1 100755 --- a/test/functional/interface_ipc_mining.py +++ b/test/functional/interface_ipc_mining.py @@ -320,7 +320,8 @@ class IPCMiningTest(BitcoinTestFramework): self.log.debug("Wait for another, get one after increase in fees in the mempool") template6 = await wait_and_do( mining_wait_next_template(template5, stack, ctx, waitoptions), - lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0])) + lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]), + sleep_time=1.2) assert template6 is not None block4 = await mining_get_block(template6, ctx) assert_equal(len(block4.vtx), 3) ```
DrahtBot commented 2026-11-13 18:44:12 +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 ryanofsky, nervana21, w0xlt

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/36862 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36862.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36862#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 | [ryanofsky](https://github.com/bitcoin/bitcoin/pull/36862#pullrequestreview-5897755541), [nervana21](https://github.com/bitcoin/bitcoin/pull/36862#issuecomment-6869905430), [w0xlt](https://github.com/bitcoin/bitcoin/pull/36862#pullrequestreview-5902332072) | 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-->
nervana21 commented 2026-11-13 18:55:12 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
First-time contributor

🟠 Minor · The template2 timeout can expire before its scaled pre-generation sleep

Source inspection shows that large timeout factors, including documented --timeout-factor 0, can make the template2 wait expire before its scheduled block generation, causing the functional test's non-null assertion to fail.

Location: test/functional/interface_ipc_mining.py:278 (head).

Review coverage was incomplete.


Reviewed: 74135e2e6250 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:6a916fa059320c1e3f0a79c4f7490636461ad967153b8442c21450419af74010:24633968ff336fb935794e53e586f29b4eaaa2a15575a2c0392a2c8b9ace382c --> <!-- ralph-base:a527a0077a0fcae913188410214efe98021c0cca --> <!-- ralph-head:74135e2e625030b18daf7539bd19dabb75948af1 --> <!-- ralph-case:c0576c87cd233a2b11bec2794a494d6470f32374bef83242d3eb78f46d513444 --> **🟠 Minor · The template2 timeout can expire before its scaled pre-generation sleep** Source inspection shows that large timeout factors, including documented `--timeout-factor 0`, can make the `template2` wait expire before its scheduled block generation, causing the functional test's non-null assertion to fail. Location: [`test/functional/interface_ipc_mining.py:278`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/74135e2e625030b18daf7539bd19dabb75948af1/test/functional/interface_ipc_mining.py#L278>) (head). Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`74135e2e6250`](<https://git.fish.foo/bitcoin/bitcoin/commit/74135e2e625030b18daf7539bd19dabb75948af1>) · [Review report](<https://review.fish.foo/report/36862-74135e2e625030b18daf7539bd19dabb75948af1-2657-1.html>) · [Previous reports](<https://review.fish.foo/traces/36862/>) [permalink](<https://review.fish.foo/report/36862-74135e2e625030b18daf7539bd19dabb75948af1-2657-1.html>)
ryanofsky (Migrated from github.com) approved these changes 2026-11-13 20:44:07 +00:00
ryanofsky (Migrated from github.com) left a comment

Tested ACK 74135e2e62. This finishes the fix from #36791: every wait that returns on an event the test triggers now has at least a minute, so none of them can time out on a slow host with the default timeout factor. I checked that the test passes normally, with the faketime command from #36791, and with sleep_time=1.2 on the template6 wait, which failed before.

The waits still using default_ipc_timeout (template4, template5 and the two waitNext policy tests) are fine as they are: the fees they wait for are already in the mempool, and waitNext always checks fees once after its first one-second tick, however short the timeout.

Tested ACK 74135e2e625030b18daf7539bd19dabb75948af1. This finishes the fix from #36791: every wait that returns on an event the test triggers now has at least a minute, so none of them can time out on a slow host with the default timeout factor. I checked that the test passes normally, with the faketime command from #36791, and with `sleep_time=1.2` on the `template6` wait, which failed before. The waits still using `default_ipc_timeout` (`template4`, `template5` and the two `waitNext` policy tests) are fine as they are: the fees they wait for are already in the mempool, and `waitNext` always checks fees once after its first one-second tick, however short the timeout.
nervana21 commented 2026-11-14 02:06:22 +00:00 (Migrated from github.com)

tACK 74135e2e62

tACK 74135e2e625030b18daf7539bd19dabb75948af1
w0xlt (Migrated from github.com) reviewed 2026-11-14 06:36:27 +00:00
w0xlt (Migrated from github.com) left a comment
ACK 74135e2e625030b18daf7539bd19dabb75948af1
maflcko (Migrated from github.com) reviewed 2026-11-20 09:28:57 +00:00
maflcko (Migrated from github.com) left a comment

this uncovers a pre-existing bug for large timeout factor values

this uncovers a pre-existing bug for large timeout factor values
maflcko (Migrated from github.com) commented 2026-11-20 08:53:11 +00:00

(recall the sleep time here is seconds, not ms)

This is a pre-existing bug, but the changes in this pull will now cause the tests to deterministically fail with a high timeout factor, because the long_ipc_timeout (~1s*factor) would happen before the generate after 1.1s *factor.

As a regression test against feeThreshold = MAX_MONEY, the sleep only needs to ensure that the one-second fee-check tick elapses. Scaling it makes the test unnecessarily slow, adding roughly timeout_factor seconds of idle time to every run.

The correct sleep to use here is 1.1s, or maybe 2s, if you want to allow for more machines to hit the tick, but if a machine is slower than that to call a simple IPC call, it doesn't seem worth it to accommodate in the test (and slow down all of our CI runs).

(recall the sleep time here is seconds, not ms) This is a pre-existing bug, but the changes in this pull will now cause the tests to deterministically fail with a high timeout factor, because the `long_ipc_timeout` (`~1s*factor`) would happen before the generate after `1.1s *factor`. As a regression test against `feeThreshold = MAX_MONEY`, the sleep only needs to ensure that the one-second fee-check tick elapses. Scaling it makes the test unnecessarily slow, adding roughly timeout_factor seconds of idle time to every run. The correct sleep to use here is 1.1s, or maybe 2s, if you want to allow for more machines to hit the tick, but if a machine is slower than that to call a simple IPC call, it doesn't seem worth it to accommodate in the test (and slow down all of our CI runs).
maflcko (Migrated from github.com) commented 2026-11-20 09:28:29 +00:00

Fixed in https://github.com/bitcoin/bitcoin/pull/36924

Also, I am a bit confused about the 60s floor of long_ipc_timeout. Why is it needed? default_ipc_timeout is already scaled by the timeout factor to accommodate slow machines, so it seems confusing to have a different variable to track the same thing? I'd say long_ipc_timeout should be removed.

Fixed in https://github.com/bitcoin/bitcoin/pull/36924 Also, I am a bit confused about the 60s floor of long_ipc_timeout. Why is it needed? `default_ipc_timeout` is already scaled by the timeout factor to accommodate slow machines, so it seems confusing to have a different variable to track the same thing? I'd say `long_ipc_timeout` should be removed.
maflcko (Migrated from github.com) commented 2026-11-20 07:55:12 +00:00

nit: Just like below (no_event_timeout_ms), it would be good to include the type here. Everything in the python tests is usually denoted in float seconds, so it would be good to mark the places that are not.

nit: Just like below (`no_event_timeout_ms`), it would be good to include the type here. Everything in the python tests is usually denoted in float seconds, so it would be good to mark the places that are not.
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-20 11:14:12 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-20 11:14:12 +00:00

Quoting from https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4565751670:

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.

The reasoning is that this could fail in slow machines (laptop) that run with default timeout factor, though idk if this was seen on real hardware before.

Quoting from https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4565751670: >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. The reasoning is that this could fail in slow machines (laptop) that run with default timeout factor, though idk if this was seen on real hardware before.
maflcko (Migrated from github.com) reviewed 2026-11-20 11:30:35 +00:00
maflcko (Migrated from github.com) commented 2026-11-20 11:30:35 +00:00

Ah thx for the reference. The general idea is that the tests should pass on any idk mid-range machine (even laptop) sold in the last few years with the default timeout-factor.

  • So if the default_ipc_timeout is too small to accommodate that, it should just be increased maybe from 1s to 2s. (Such a change should be harmless, because in the happy path it should still pass as fast as your machine is)
  • However, if someone is running an ancient/slow machine, or heavy virtualization or heavy sanitizers, there is just no other fix than to increase the timeout-factor on their command line. Fixing the tests for that seems odd.

So I haven't tried it, but I think in your command:

faketime --exclude-monotonic -f "+0 x0.1" build/test/functional/interface_ipc_mining.py

you can increase the --timeout-factor, because a 10x relative speed doesn't seem like normal hardware.

Ah thx for the reference. The general idea is that the tests should pass on any idk mid-range machine (even laptop) sold in the last few years with the default timeout-factor. * So if the `default_ipc_timeout` is too small to accommodate that, it should just be increased maybe from 1s to 2s. (Such a change should be harmless, because in the happy path it should still pass as fast as your machine is) * However, if someone is running an ancient/slow machine, or heavy virtualization or heavy sanitizers, there is just no other fix than to increase the timeout-factor on their command line. Fixing the tests for that seems odd. So I haven't tried it, but I think in your command: ``` faketime --exclude-monotonic -f "+0 x0.1" build/test/functional/interface_ipc_mining.py ``` you can increase the --timeout-factor, because a 10x relative speed doesn't seem like normal hardware.
maflcko (Migrated from github.com) reviewed 2026-11-23 08:04:30 +00:00
maflcko (Migrated from github.com) commented 2026-11-23 08:04:30 +00:00

I think there is one more place which can spell out the fee tick wait explicitly:

diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py
index 55b90f5..cec9c78 100755
--- a/test/functional/interface_ipc_mining.py
+++ b/test/functional/interface_ipc_mining.py
@@ -320,3 +320,4 @@ class IPCMiningTest(BitcoinTestFramework):
                 self.log.debug("Wait for another, get one after increase in fees in the mempool")
-                waitoptions.timeout = self.long_ipc_timeout
+                # Allow the normal event wait as well as one fee check tick.
+                waitoptions.timeout = self.default_ipc_timeout_ms + 1000
                 template6 = await wait_and_do(

Everything else can use the default_ipc_timeout_ms and long_ipc_timeout can be removed.

I think there is one more place which can spell out the fee tick wait explicitly: ```diff diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py index 55b90f5..cec9c78 100755 --- a/test/functional/interface_ipc_mining.py +++ b/test/functional/interface_ipc_mining.py @@ -320,3 +320,4 @@ class IPCMiningTest(BitcoinTestFramework): self.log.debug("Wait for another, get one after increase in fees in the mempool") - waitoptions.timeout = self.long_ipc_timeout + # Allow the normal event wait as well as one fee check tick. + waitoptions.timeout = self.default_ipc_timeout_ms + 1000 template6 = await wait_and_do( ``` Everything else can use the `default_ipc_timeout_ms` and `long_ipc_timeout` can be removed.
Sign in to join this conversation.
No reviewers
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!36862
No description provided.