test: cover unsatisfiable mining timestamp #36192

pull Sjors wants to merge 4 commits into bitcoin:master from Sjors:2026/09/impossible-time changing 4 files +78 −4
  1. Sjors commented at 11:46 AM on September 8, 2026: member

    The Murch-Zawy rule introduced in #35949 (for the miner, not for consensus) adds yet another constraint to the timestamp for our block templates.

    This PR adds test coverage for what happens in the (extremely unlikely) event that the miner can't satisfy the constraints.

    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 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 attack is impractical, but the code is reachable, so deserves a test.

    The first commit fixes the incorrectly named REGTEST_RETARGET_PERIOD. The second commit moves (actually) DIFFICULTY_ADJUSTMENT_INTERVAL to the framework, so the next two commits can use it. The third commit is a test followup suggested in #35949 (review). The fourth commit contains the new test.

  2. DrahtBot added the label Tests on Sep 8, 2026
  3. DrahtBot commented at 11:46 AM on September 8, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36192.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept ACK fjahr

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

  4. fanquake requested review from fjahr on Sep 8, 2026
  5. fanquake requested review from darosior on Sep 8, 2026
  6. test: rename REGTEST_RETARGET_PERIOD to HALVING_INTERVAL
    The constant is the regtest nSubsidyHalvingInterval and is only used
    as the default halving_period in create_coinbase.
    8a45b25d3b
  7. test: move DIFFICULTY_ADJUSTMENT_INTERVAL to blocktools
    Both mining_basic.py and rpc_blockchain.py defined their own copy of
    the regtest difficulty adjustment interval.
    4a9fac04ac
  8. Sjors force-pushed on Sep 8, 2026
  9. DrahtBot added the label CI failed on Sep 8, 2026
  10. test: assert Murch-Zawy period boundaries
    Co-authored-by: sedited <seb.kung@gmail.com>
    38e1b2dd3f
  11. test: cover unsatisfiable mining timestamp
    Simulate attacker blocks setting MTP at the victim's future-time
    limit. Check getblocktemplate and IPC failure, then recovery one
    second later.
    
    This attack is impractical, but the code is reachable.
    f9e72b8989
  12. Sjors force-pushed on Sep 8, 2026
  13. DrahtBot removed the label CI failed on Sep 8, 2026
  14. in test/functional/test_framework/blocktools.py:72 in 8a45b25d3b outdated
      68 | @@ -69,7 +69,7 @@
      69 |  VERSIONBITS_LAST_OLD_BLOCK_VERSION = 4
      70 |  MIN_BLOCKS_TO_KEEP = 288
      71 |  
      72 | -REGTEST_RETARGET_PERIOD = 150
      73 | +HALVING_INTERVAL = 150  # regtest nSubsidyHalvingInterval
    


    fjahr commented at 2:42 PM on September 8, 2026:

    nit: I would have preferred to the REGTEST_ prefix

  15. in test/functional/test_framework/blocktools.py:74 in 4a9fac04ac outdated
      70 | @@ -71,6 +71,7 @@
      71 |  
      72 |  HALVING_INTERVAL = 150  # regtest nSubsidyHalvingInterval
      73 |  
      74 | +DIFFICULTY_ADJUSTMENT_INTERVAL = 144  # regtest nPowTargetTimespan / nPowTargetSpacing
    


    fjahr commented at 2:45 PM on September 8, 2026:

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

  16. fjahr commented at 4:19 PM on September 8, 2026: contributor

    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.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-09-09 07:56 UTC