test: cover unsatisfiable mining timestamp #36192

Manually merged
Sjors merged 5 commits from 2026/09/impossible-time into master 2026-11-05 15:01:14 +00:00 AGit
Sjors commented 2026-09-08 11:46:13 +00:00 (Migrated from github.com)

This PR adds test coverage for what happens in the (extremely unlikely) event that the miner can't satisfy the constraints. This is inspired by the recently added timewarp-protection and Murch-Zawy rules (for the miner, not for consensus, see #30681 and #35949), but this is a pre-existing issue. It is not made worse by these rules.

The test has an attacker mine 6 blocks, which set MTP at the victim's future-time limit. It calls getblocktemplate and the equivalent IPC method, which both fail. It then moves mock time one second forward, and demonstrates mining works again (and we don't drop the IPC connection).

This (impractical) attack can be done at any height, be we illustrate it for blocks 142, 143 and 0 of a retarget period, to clarify that the timewarp-protection and Murch-Zawy rules do not matter.

The test was added to ipc_mining.py, to avoid having to add IPC support to mining_basic.py. Mining coverage is currently split between various test files and not always mirrored between RPC and IPC. A followup could unify these, while still skipping the IPC side when that's not compiled.

A few refactor commits to prepare:

  • fix incorrect name: REGTEST_RETARGET_PERIOD -> HALVING_INTERVAL
  • drop REGTEST_ prefix from REGTEST_N_BITS and REGTEST_TARGET (consistent with HALVING_INTERVAL, DIFFICULTY_ADJUSTMENT_INTERVAL and TIME_GENESIS_BLOCK).
  • move DIFFICULTY_ADJUSTMENT_INTERVAL to the framework

The last commit picks up a Murch-Zawy followup suggested in https://github.com/bitcoin/bitcoin/pull/35949#discussion_r3944011135 and takes advantage of our refactor, but is otherwise unrelated.

This PR adds test coverage for what happens in the (extremely unlikely) event that the miner can't satisfy the constraints. This is inspired by the recently added timewarp-protection and Murch-Zawy rules (for the miner, not for consensus, see #30681 and #35949), but this is a pre-existing issue. It is not made worse by these rules. The test has an attacker mine 6 blocks, which set MTP at the victim's future-time limit. It calls `getblocktemplate` and the equivalent IPC method, which both fail. It then moves mock time one second forward, and demonstrates mining works again (and we don't drop the IPC connection). This (impractical) attack can be done at any height, be we illustrate it for blocks 142, 143 and 0 of a retarget period, to clarify that the timewarp-protection and Murch-Zawy rules do not matter. The test was added to `ipc_mining.py`, to avoid having to add IPC support to `mining_basic.py`. Mining coverage is currently split between various test files and not always mirrored between RPC and IPC. A followup could unify these, while still skipping the IPC side when that's not compiled. A few refactor commits to prepare: - fix incorrect name: `REGTEST_RETARGET_PERIOD` -> `HALVING_INTERVAL` - drop `REGTEST_` prefix from `REGTEST_N_BITS` and `REGTEST_TARGET` (consistent with `HALVING_INTERVAL`, `DIFFICULTY_ADJUSTMENT_INTERVAL` and `TIME_GENESIS_BLOCK`). - move `DIFFICULTY_ADJUSTMENT_INTERVAL` to the framework The last commit picks up a Murch-Zawy followup suggested in https://github.com/bitcoin/bitcoin/pull/35949#discussion_r3944011135 and takes advantage of our refactor, but is otherwise unrelated.
DrahtBot commented 2026-09-08 11:46:20 +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 sedited, fjahr, ismaelsadeeq
Concept ACK adezo24h1

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36611 (test: consolidate mempool constants by fanquake)
  • #36525 (mining: add getTotalFees(), protect m_block_template with mutex by Sjors)
  • #36257 (qa: assert_equals -> assert_true/assert_false by hodlinator)
  • #35793 (Implement BIP 54 (Consensus Cleanup) without mainnet activation by darosior)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--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/36192 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36192.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36192#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 | [sedited](https://github.com/bitcoin/bitcoin/pull/36192#pullrequestreview-5785744755), [fjahr](https://github.com/bitcoin/bitcoin/pull/36192#issuecomment-6659971661), [ismaelsadeeq](https://github.com/bitcoin/bitcoin/pull/36192#issuecomment-6660305187) | | Concept ACK | [adezo24h1](https://github.com/bitcoin/bitcoin/pull/36192#issuecomment-5666440105) | 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. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36611](https://github.com/bitcoin/bitcoin/pull/36611) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36611.svg"></sub> (test: consolidate mempool constants by fanquake) * [#36525](https://github.com/bitcoin/bitcoin/pull/36525) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36525.svg"></sub> (mining: add getTotalFees(), protect m_block_template with mutex by Sjors) * [#36257](https://github.com/bitcoin/bitcoin/pull/36257) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36257.svg"></sub> (qa: assert_equals -> assert_true/assert_false by hodlinator) * [#35793](https://github.com/bitcoin/bitcoin/pull/35793) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35793.svg"></sub> (Implement BIP 54 (Consensus Cleanup) without mainnet activation by darosior) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
fjahr (Migrated from github.com) reviewed 2026-09-08 16:19:11 +00:00
fjahr (Migrated from github.com) left a comment

Concept ACK on the first three commits, not sure yet about the unsatisfiable test

The PR description was pretty confusing to me. The third commit adds the suggested test edits from @sedited which are in the MZ-related test. But then the new test for the unsatisfiable mining timestamp doesn't seem to be related to MZ. The PR description kind of makes it seem like it is.

I am also not sure this test has to be in ipc interface test. It looks nice the way it’s implemented but adding it in mining_basic is probably possible too and runs this test more regularly. But then again, this is more for documentation purposes and not so much regression testing, so I guess it doesn’t matter. Would still be good to explicitly state the motivation though.

Concept ACK on the first three commits, not sure yet about the unsatisfiable test The PR description was pretty confusing to me. The third commit adds the suggested test edits from @sedited which are in the MZ-related test. But then the new test for the unsatisfiable mining timestamp doesn't seem to be related to MZ. The PR description kind of makes it seem like it is. I am also not sure this test has to be in ipc interface test. It looks nice the way it’s implemented but adding it in mining_basic is probably possible too and runs this test more regularly. But then again, this is more for documentation purposes and not so much regression testing, so I guess it doesn’t matter. Would still be good to explicitly state the motivation though.
fjahr (Migrated from github.com) commented 2026-09-08 14:42:06 +00:00

nit: I would have preferred to the REGTEST_ prefix

nit: I would have preferred to the `REGTEST_` prefix
fjahr (Migrated from github.com) commented 2026-09-08 14:45:08 +00:00

nit: Similarly, would suggest to have a REGTEST_ prefix here too

nit: Similarly, would suggest to have a `REGTEST_` prefix here too
Sjors (Migrated from github.com) reviewed 2026-09-10 12:18:04 +00:00
Sjors (Migrated from github.com) commented 2026-09-10 12:18:04 +00:00

I prefer to only prefix other networks.

I prefer to only prefix other networks.
Sjors commented 2026-09-10 12:31:24 +00:00 (Migrated from github.com)

@fjahr I swapped the last two commits and clarified the PR description to point out that:

  • Murch-Zawy was the inspiration, but no the actual issue.
  • the last commit is just a hitch-hiker

I am also not sure this test has to be in ipc interface test. It looks nice the way it’s implemented but adding it in mining_basic is probably possible too and runs this test more regularly.

Both are covered by CI. And we should cover both IPC and RPC because they have different failure modes (in particular the IPC test checks it doesn't disconnect).

Adding it to mining_basic means having to add IPC support to that test, and skipping part of the test if that's not compiled (which is less clear than skipping the whole test).

@fjahr I swapped the last two commits and clarified the PR description to point out that: - Murch-Zawy was the inspiration, but no the actual issue. - the last commit is just a hitch-hiker > I am also not sure this test has to be in ipc interface test. It looks nice the way it’s implemented but adding it in mining_basic is probably possible too and runs this test more regularly. Both are covered by CI. And we should cover both IPC and RPC because they have different failure modes (in particular the IPC test checks it doesn't disconnect). Adding it to mining_basic means having to add IPC support to that test, and skipping part of the test if that's not compiled (which is less clear than skipping the whole test).
adezo24h1 commented 2026-09-11 19:36:36 +00:00 (Migrated from github.com)

Tested 1f6694e on Ubuntu 24.04 WSL (ENABLE_IPC=OFF, bitcoind from ~/src/bitcoin):
python3 build/test/functional/test_runner.py mining_basic.py rpc_blockchain.py
Result: pass
Did not run interface_ipc_mining.py (IPC not built).
I read the Python test files but I am still learning the timestamp / MTP logic, so this is not an ACK ;-)

Tested 1f6694e on Ubuntu 24.04 WSL (ENABLE_IPC=OFF, bitcoind from ~/src/bitcoin): python3 build/test/functional/test_runner.py mining_basic.py rpc_blockchain.py Result: pass Did not run interface_ipc_mining.py (IPC not built). I read the Python test files but I am still learning the timestamp / MTP logic, so this is not an ACK ;-)
fjahr (Migrated from github.com) reviewed 2026-09-12 14:48:23 +00:00
fjahr (Migrated from github.com) left a comment

Thanks for addressing my comments, I think the description can still be improved unless I have a misunderstanding on my side.

Fortunately it doesn't create a situation where the miner can't satisfy those constraints, but it turns out the previously merged timewarp rule does.

I don't understand how the timewarp rule plays a role here. It's just a conflict between the plain MTP + 1 rule and the 2 hour max future rule, no?

The test has an attacker mine 6 blocks at the end of a difficulty adjustment period, which set MTP at the victim's future-time limit.

It doesn't have to be at the end of the adjustment period since MZ doesn't play a role for this test, it works on any height afaict, see also my comment about simplifying the test.

Unrelated to the description:

And we should cover both IPC and RPC because they have different failure modes (in particular the IPC test checks it doesn't disconnect).

Ok, that's fine for me as a goal, but that probably applies to most of the other tests in miner_basic.py as well and also possible future tests right? Is there a plan to unify those test files so that we don't have to discuss where new mining tests go every time? I guess it would make sense that we have one miner test file that runs every test always in basic mode and then also runs each of them ipc when possible. But I didn't look into what that would look like in practice.

Thanks for addressing my comments, I think the description can still be improved unless I have a misunderstanding on my side. > Fortunately it doesn't create a situation where the miner can't satisfy those constraints, but it turns out the previously merged timewarp rule does. I don't understand how the timewarp rule plays a role here. It's just a conflict between the plain MTP + 1 rule and the 2 hour max future rule, no? > The test has an attacker mine 6 blocks at the end of a difficulty adjustment period, which set MTP at the victim's future-time limit. It doesn't have to be at the end of the adjustment period since MZ doesn't play a role for this test, it works on any height afaict, see also my comment about simplifying the test. Unrelated to the description: > And we should cover both IPC and RPC because they have different failure modes (in particular the IPC test checks it doesn't disconnect). Ok, that's fine for me as a goal, but that probably applies to most of the other tests in `miner_basic.py` as well and also possible future tests right? Is there a plan to unify those test files so that we don't have to discuss where new mining tests go every time? I guess it would make sense that we have one miner test file that runs every test always in basic mode and then also runs each of them ipc when possible. But I didn't look into what that would look like in practice.
fjahr (Migrated from github.com) commented 2026-09-12 14:32:14 +00:00

The test can be simplified because it doesn't seem to need the mining to the end of the difficulty period in order to work.

diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py
index 66aa5e6eddf..43ac5fe2dee 100755
--- a/test/functional/interface_ipc_mining.py
+++ b/test/functional/interface_ipc_mining.py
@@ -10,7 +10,6 @@ from copy import deepcopy
 from decimal import Decimal
 from io import BytesIO
 from test_framework.blocktools import (
-    DIFFICULTY_ADJUSTMENT_INTERVAL,
     MAX_FUTURE_BLOCK_TIME,
     NORMAL_GBT_REQUEST_PARAMS,
     NULL_OUTPOINT,
@@ -777,25 +776,12 @@ class IPCMiningTest(BitcoinTestFramework):
         victim = self.nodes[0]
         attacker = self.nodes[1]

-        # Mine to the end of the difficulty period, with room for six attack
-        # blocks that determine its median time past.
-        num_attack_blocks = 6
-        blocks_to_mine = (
-            DIFFICULTY_ADJUSTMENT_INTERVAL - 2 - num_attack_blocks
-            - victim.getblockcount()
-        ) % DIFFICULTY_ADJUSTMENT_INTERVAL
-        self.generate(attacker, blocks_to_mine)
-
+        # Six of the last eleven blocks determine the median time past.
         victim_time = int(time.time())
         attacker_time = victim_time + MAX_FUTURE_BLOCK_TIME
         victim.setmocktime(victim_time)
         attacker.setmocktime(attacker_time)
-        self.generate(attacker, num_attack_blocks)
-
-        assert_equal(
-            (victim.getblockcount() + 1) % DIFFICULTY_ADJUSTMENT_INTERVAL,
-            DIFFICULTY_ADJUSTMENT_INTERVAL - 1,
-        )
+        self.generate(attacker, 6)
         assert_equal(victim.getblockchaininfo()["mediantime"], attacker_time)

         # The next block must be later than MTP, but future timestamps are only
The test can be simplified because it doesn't seem to need the mining to the end of the difficulty period in order to work. ```diff diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py index 66aa5e6eddf..43ac5fe2dee 100755 --- a/test/functional/interface_ipc_mining.py +++ b/test/functional/interface_ipc_mining.py @@ -10,7 +10,6 @@ from copy import deepcopy from decimal import Decimal from io import BytesIO from test_framework.blocktools import ( - DIFFICULTY_ADJUSTMENT_INTERVAL, MAX_FUTURE_BLOCK_TIME, NORMAL_GBT_REQUEST_PARAMS, NULL_OUTPOINT, @@ -777,25 +776,12 @@ class IPCMiningTest(BitcoinTestFramework): victim = self.nodes[0] attacker = self.nodes[1] - # Mine to the end of the difficulty period, with room for six attack - # blocks that determine its median time past. - num_attack_blocks = 6 - blocks_to_mine = ( - DIFFICULTY_ADJUSTMENT_INTERVAL - 2 - num_attack_blocks - - victim.getblockcount() - ) % DIFFICULTY_ADJUSTMENT_INTERVAL - self.generate(attacker, blocks_to_mine) - + # Six of the last eleven blocks determine the median time past. victim_time = int(time.time()) attacker_time = victim_time + MAX_FUTURE_BLOCK_TIME victim.setmocktime(victim_time) attacker.setmocktime(attacker_time) - self.generate(attacker, num_attack_blocks) - - assert_equal( - (victim.getblockcount() + 1) % DIFFICULTY_ADJUSTMENT_INTERVAL, - DIFFICULTY_ADJUSTMENT_INTERVAL - 1, - ) + self.generate(attacker, 6) assert_equal(victim.getblockchaininfo()["mediantime"], attacker_time) # The next block must be later than MTP, but future timestamps are only ```
fjahr (Migrated from github.com) commented 2026-09-12 14:09:10 +00:00

Can import MAX_FUTURE_BLOCK_TIME from blocktools.py as well.

Can import `MAX_FUTURE_BLOCK_TIME` from `blocktools.py` as well.
fjahr (Migrated from github.com) commented 2026-09-12 13:55:20 +00:00

Could your remove them from REGTEST_N_BITS and REGTEST_TARGET then so it is at least consistent?

Could your remove them from `REGTEST_N_BITS` and `REGTEST_TARGET` then so it is at least consistent?
adezo24h1 commented 2026-09-14 09:20:07 +00:00 (Migrated from github.com)

Hi there! Looks like you were surprised by my test result that I shared earlier, and reacted with some interesting emoji's. Guys, this is just my first-ever test to btc codebase. Am I doing sth weird ;-) I'm just here to learn and contribute to the btc functional testing if possible. Looking forward to learn from the samurai ;-)

Hi there! Looks like you were surprised by my test result that I shared earlier, and reacted with some interesting emoji's. Guys, this is just my first-ever test to btc codebase. Am I doing sth weird ;-) I'm just here to learn and contribute to the btc functional testing if possible. Looking forward to learn from the samurai ;-)
Sjors (Migrated from github.com) reviewed 2026-09-14 12:36:04 +00:00
Sjors (Migrated from github.com) commented 2026-09-14 12:36:04 +00:00

Done.

I did look at either dropping REGTEST_ from REGTEST_N_BITS and REGTEST_TARGET, or adding it to DIFFICULTY_ADJUSTMENT_INTERVAL and TIME_GENESIS_BLOCK. The latter is a bigger change, and leads to longer names.

Done. I did look at either dropping `REGTEST_` from `REGTEST_N_BITS` and `REGTEST_TARGET`, or adding it to `DIFFICULTY_ADJUSTMENT_INTERVAL` and `TIME_GENESIS_BLOCK`. The latter is a bigger change, and leads to longer names.
Sjors commented 2026-09-14 12:36:20 +00:00 (Migrated from github.com)

I don't understand how the timewarp rule plays a role here.

You're right, it doesn't. Since I was confused myself, I modified the test instead to repeat for blocks N - 2, N - 1 and 0 of a retarget period, with brief comments for why neither rule matters. I also updated the PR description.

Is there a plan to unify those test files

There isn't, but I made the suggestion explicit in the PR description. Since we introduced IPC, and its various methods, more new mining test coverage was added on the IPC side, with some of it mirrored to RPC, see e.g. #31981.

> I don't understand how the timewarp rule plays a role here. You're right, it doesn't. Since I was confused myself, I modified the test instead to repeat for blocks `N - 2`, `N - 1` and `0` of a retarget period, with brief comments for why neither rule matters. I also updated the PR description. > Is there a plan to unify those test files There isn't, but I made the suggestion explicit in the PR description. Since we introduced IPC, and its various methods, more new mining test coverage was added on the IPC side, with some of it mirrored to RPC, see e.g. #31981.
Sjors (Migrated from github.com) reviewed 2026-09-14 12:36:50 +00:00
Sjors (Migrated from github.com) commented 2026-09-14 12:36:50 +00:00
See https://github.com/bitcoin/bitcoin/pull/36192#issuecomment-5664027162
adezo24h1 commented 2026-09-14 15:30:00 +00:00 (Migrated from github.com)

Tested db7a485c33
Not an ACK.
Ran on Ubuntu 24.04 WSL (ENABLE_IPC=OFF):
python3 build/test/functional/test_runner.py mining_basic.py rpc_blockchain.py
Result: pass
I didn't run interface_ipc_mining.py, fyi

Tested db7a485c330ed154c2aa705f553d323c7b2276c6 Not an ACK. Ran on Ubuntu 24.04 WSL (ENABLE_IPC=OFF): python3 build/test/functional/test_runner.py mining_basic.py rpc_blockchain.py Result: pass I didn't run interface_ipc_mining.py, fyi
fjahr (Migrated from github.com) reviewed 2026-09-14 17:21:21 +00:00
fjahr (Migrated from github.com) left a comment

Code review ACK db7a485c33

Thanks for addressing my feedback!

Code review ACK db7a485c330ed154c2aa705f553d323c7b2276c6 Thanks for addressing my feedback!
fjahr (Migrated from github.com) commented 2026-09-14 17:17:25 +00:00

nit: I find it pretty heavy that this test now mines ~450 blocks just to prove that these special heights and their BIP54 rules do not have an impact on this super edge case scenario that is documented with the test. I would have prefered that the test had been simplified to be more focussed on the edge case only and with mining only 6 blocks. But regtest mining is cheap enough that this isn't a blocker for me and maybe there is some value in the added documentation here.

nit: I find it pretty heavy that this test now mines ~450 blocks just to prove that these special heights and their BIP54 rules do not have an impact on this super edge case scenario that is documented with the test. I would have prefered that the test had been simplified to be more focussed on the edge case only and with mining only 6 blocks. But regtest mining is cheap enough that this isn't a blocker for me and maybe there is some value in the added documentation here.
Sjors (Migrated from github.com) reviewed 2026-09-15 07:16:55 +00:00
Sjors (Migrated from github.com) commented 2026-09-15 07:16:55 +00:00

An earlier version mined up to N-2 and then performed the check on blocks N - 1, N and 0. But I found that confusing, hence the three rounds. If it's actually a performance problem, then we can drop it, but as you say, regtest is cheap.

An earlier version mined up to N-2 and then performed the check on blocks N - 1, N and 0. But I found that confusing, hence the three rounds. If it's actually a performance problem, then we can drop it, but as you say, regtest is cheap.
First-time contributor

🔵 Suggestion · Unsatisfiable-timestamp coverage misses retarget-period boundaries

The new case exercises only a mid-period template, so it does not test the advertised timestamp conflict at the timewarp and Murch-Zawy boundaries.

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

🔵 Suggestion · Keep RPC coverage runnable without IPC support

The new RPC failure and recovery assertions (interface_ipc_mining.py:794) run only inside IPCMiningTest, which skips without IPC or pycapnp (lines 64-66). Builds without IPC, such as the win64 CI config, lose this RPC coverage. The author has chosen to keep it there.

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

Review coverage was incomplete.


Reviewed: c000f6ef15e0 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:4d44b6ffa09c54db24f8f0ab27ae388beae06a733efcae741ca64db76bb1c938:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:0e38ad26af922abdc0fc36c9379e17efd2a72b80 --> <!-- ralph-head:c000f6ef15e06856b9111ee433877a2b1bf31eb4 --> <!-- ralph-case:50d975fec99abe142ec3ac0e20fb74134a2104a3a859e62b49f68f3a079f39cb --> **🔵 Suggestion · Unsatisfiable-timestamp coverage misses retarget-period boundaries** The new case exercises only a mid-period template, so it does not test the advertised timestamp conflict at the timewarp and Murch-Zawy boundaries. Location: [`test/functional/interface_ipc_mining.py:789`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/c000f6ef15e06856b9111ee433877a2b1bf31eb4/test/functional/interface_ipc_mining.py#L789>) (head). **🔵 Suggestion · Keep RPC coverage runnable without IPC support** The new RPC failure and recovery assertions (interface_ipc_mining.py:794) run only inside IPCMiningTest, which skips without IPC or pycapnp (lines 64-66). Builds without IPC, such as the win64 CI config, lose this RPC coverage. The author has chosen to keep it there. Location: [`test/functional/interface_ipc_mining.py:794`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/c000f6ef15e06856b9111ee433877a2b1bf31eb4/test/functional/interface_ipc_mining.py#L794>) (head). Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`c000f6ef15e0`](<https://git.fish.foo/bitcoin/bitcoin/commit/c000f6ef15e06856b9111ee433877a2b1bf31eb4>) · [Full review report](<https://review.fish.foo/traces/36192-c000f6ef15e06856b9111ee433877a2b1bf31eb4-2205-4.html>) · [Previous reports](<https://review.fish.foo/traces/36192/>) [permalink](<https://review.fish.foo/traces/36192-c000f6ef15e06856b9111ee433877a2b1bf31eb4-2205-4.html>)
ismaelsadeeq (Migrated from github.com) approved these changes 2026-10-21 06:27:07 +00:00
ismaelsadeeq (Migrated from github.com) left a comment

ACK db7a485c33

This test seems to belong in mining_basic.py, not here, it sits right next to test_timewarp() and test_murch_zawy_mintime().

I'd also prefer this to just be a single test at any one boundary. The subtest currently runs ~3s; making it a single case drops it to ~1s.

Also it's unclear why we test via both IPC and getblocktemplate, seems redundant, they hit the same block-assembly path fwiw, so the time-too-new failure is produced identically. The only difference is that IPC createNewBlock defaults to cooldown=true (GBT forces it off), but the cooldown gates before assembly so it's irrelevant here.
The one thing genuinely worth keeping on the IPC side is the check that a failed createNewBlock surfaces cleanly over capnp without tearing down the connection, and that the reused connection still works a second later, but that can be tested separately, and we should not use this as a proxy.

We could also reduce the number of blocks generated by making it a linear test i.e. test the 142 case, invalidate the top 6, test 143, invalidate a few, then test at the boundary, the reorg switch means the runtime doesn't drop by much though, but i find that easier to reason about.

ACK db7a485c330ed154c2aa705f553d323c7b2276c6 This test seems to belong in mining_basic.py, not here, it sits right next to `test_timewarp()` and `test_murch_zawy_mintime()`. I'd also prefer this to just be a single test at any one boundary. The subtest currently runs ~3s; making it a single case drops it to ~1s. Also it's unclear why we test via both IPC and getblocktemplate, seems redundant, they hit the same block-assembly path fwiw, so the time-too-new failure is produced identically. The only difference is that IPC `createNewBlock` defaults to `cooldown=true` (GBT forces it off), but the cooldown gates before assembly so it's irrelevant here. The one thing genuinely worth keeping on the IPC side is the check that a failed `createNewBlock` surfaces cleanly over capnp without tearing down the connection, and that the reused connection still works a second later, but that can be tested separately, and we should not use this as a proxy. We could also reduce the number of blocks generated by making it a linear test i.e. test the 142 case, invalidate the top 6, test 143, invalidate a few, then test at the boundary, the reorg switch means the runtime doesn't drop by much though, but i find that easier to reason about.
Sjors commented 2026-10-21 06:54:16 +00:00 (Migrated from github.com)

I'd also prefer this to just be a single test at any one boundary

I'm fine with that simplification.

invalidate a few, then test at the boundary

I think using invalidateblock makes the test more complicated, especially when used multiple times. It would be easier if we had a clean way to roll back blocks, see #29565.

The one thing genuinely worth keeping on the IPC side is the check that a failed createNewBlock surfaces cleanly over capnp without tearing down the connection, and that the reused connection still works a second later, but that can be tested separately

Is there another way to make createNewBlock fail (separately)? Otherwise it seems I would have to duplicate this test across two files, just with different emphasis on its purpose.

> I'd also prefer this to just be a single test at any one boundary I'm fine with that simplification. > invalidate a few, then test at the boundary I think using `invalidateblock` makes the test more complicated, especially when used multiple times. It would be easier if we had a clean way to roll back blocks, see #29565. > The one thing genuinely worth keeping on the IPC side is the check that a failed `createNewBlock` surfaces cleanly over capnp without tearing down the connection, and that the reused connection still works a second later, but that can be tested separately Is there another way to make `createNewBlock` fail (separately)? Otherwise it seems I would have to duplicate this test across two files, just with different emphasis on its purpose.
ismaelsadeeq commented 2026-10-21 07:57:40 +00:00 (Migrated from github.com)

I'm fine with that simplification.

Nice, feel free to push, will reACK or ignore not a blocker.

I think using invalidateblock makes the test more complicated, especially when used multiple times. It would be easier if we had a clean way to roll back blocks, see https://github.com/bitcoin/bitcoin/issues/29565.

Yeah, not ideal, just surfacing the idea.

Is there another way to make createNewBlock fail (separately)? Otherwise it seems I would have to duplicate this test across two files, just with different emphasis on its purpose.

Any testblockvalidty failure could work, not necessarily this one. It's fine to use one stone to kill two birds here, but we don't have to use it as a reason to add the test where it doesn't belong (Not a blocker as well).

> I'm fine with that simplification. Nice, feel free to push, will reACK or ignore not a blocker. > I think using invalidateblock makes the test more complicated, especially when used multiple times. It would be easier if we had a clean way to roll back blocks, see https://github.com/bitcoin/bitcoin/issues/29565. Yeah, not ideal, just surfacing the idea. > Is there another way to make createNewBlock fail (separately)? Otherwise it seems I would have to duplicate this test across two files, just with different emphasis on its purpose. Any `testblockvalidty` failure could work, not necessarily this one. It's fine to use one stone to kill two birds here, but we don't have to use it as a reason to add the test where it doesn't belong (Not a blocker as well).
Sjors commented 2026-10-21 08:36:32 +00:00 (Migrated from github.com)

Going to leave the code as-is, unless I need to make other changes.

Going to leave the code as-is, unless I need to make other changes.
fanquake commented 2026-10-21 15:09:35 +00:00 (Migrated from github.com)

@darosior do you want to follow-up / (conceptually) comment here?

@darosior do you want to follow-up / (conceptually) comment here?
DrahtBot commented 2026-11-01 18:37:17 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
Sjors (Migrated from github.com) reviewed 2026-11-05 07:35:22 +00:00
Sjors (Migrated from github.com) commented 2026-11-05 07:35:22 +00:00

I went back to just 1.

I went back to just 1.
Sjors commented 2026-11-05 07:35:28 +00:00 (Migrated from github.com)

I had to rebase, so I also:

I'd also prefer this to just be a single test at any one boundary. The subtest currently runs ~3s; making it a single case drops it to ~1s.

Done.

I had to rebase, so I also: > I'd also prefer this to just be a single test at any one boundary. The subtest currently runs ~3s; making it a single case drops it to ~1s. Done.
ismaelsadeeq (Migrated from github.com) reviewed 2026-11-05 11:01:22 +00:00
ismaelsadeeq (Migrated from github.com) left a comment

reACK 9b4f05a240

This is much simpler

reACK 9b4f05a240a3feaf99976fd14952a21b3f96e029 This is much simpler
fjahr commented 2026-11-05 13:08:03 +00:00 (Migrated from github.com)

reACK 9b4f05a240

The PR description still refers to the old test version, would be good to fix that.

reACK 9b4f05a240a3feaf99976fd14952a21b3f96e029 The PR description still refers to the old test version, would be good to fix that.
sedited (Migrated from github.com) approved these changes 2026-11-05 13:34:32 +00:00
sedited (Migrated from github.com) left a comment
ACK 9b4f05a240a3feaf99976fd14952a21b3f96e029
sedited commented 2026-11-05 13:47:32 +00:00 (Migrated from github.com)

Looks like github is re-ordering the head commit order again.

Looks like github is re-ordering the head commit order again.
sedited commented 2026-11-05 14:01:54 +00:00 (Migrated from github.com)

@fjahr and @ismaelsadeeq mind approving the actual head commit?

@fjahr and @ismaelsadeeq mind approving the actual head commit?
fjahr commented 2026-11-05 14:04:24 +00:00 (Migrated from github.com)

reACK c000f6ef15

Verified the actual head commit locally this time.

reACK c000f6ef15e06856b9111ee433877a2b1bf31eb4 Verified the actual head commit locally this time.
ismaelsadeeq commented 2026-11-05 14:19:25 +00:00 (Migrated from github.com)

reACK c000f6ef15

reACK c000f6ef15e06856b9111ee433877a2b1bf31eb4
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!36192
No description provided.