mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
test: cover unsatisfiable mining timestamp #36192
No reviewers
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!36192
Loading…
Reference in a new issue
No description provided.
Delete branch "2026/09/impossible-time"
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?
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
getblocktemplateand 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 tomining_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:
REGTEST_RETARGET_PERIOD->HALVING_INTERVALREGTEST_prefix fromREGTEST_N_BITSandREGTEST_TARGET(consistent withHALVING_INTERVAL,DIFFICULTY_ADJUSTMENT_INTERVALandTIME_GENESIS_BLOCK).DIFFICULTY_ADJUSTMENT_INTERVALto the frameworkThe 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.
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.Conflicts
Reviewers, this pull request conflicts with the following ones:
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.
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.
nit: I would have preferred to the
REGTEST_prefixnit: Similarly, would suggest to have a
REGTEST_prefix here tooI prefer to only prefix other networks.
@fjahr I swapped the last two commits and clarified the PR description to point out that:
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).
Tested
1f6694eon 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 ;-)
Thanks for addressing my comments, I think the description can still be improved unless I have a misunderstanding on my side.
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?
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:
Ok, that's fine for me as a goal, but that probably applies to most of the other tests in
miner_basic.pyas 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.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.
Can import
MAX_FUTURE_BLOCK_TIMEfromblocktools.pyas well.Could your remove them from
REGTEST_N_BITSandREGTEST_TARGETthen so it is at least consistent?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 ;-)
Done.
I did look at either dropping
REGTEST_fromREGTEST_N_BITSandREGTEST_TARGET, or adding it toDIFFICULTY_ADJUSTMENT_INTERVALandTIME_GENESIS_BLOCK. The latter is a bigger change, and leads to longer names.You're right, it doesn't. Since I was confused myself, I modified the test instead to repeat for blocks
N - 2,N - 1and0of a retarget period, with brief comments for why neither rule matters. I also updated the PR description.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.
See https://github.com/bitcoin/bitcoin/pull/36192#issuecomment-5664027162
Tested
db7a485c33Not 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
Code review ACK
db7a485c33Thanks for addressing my feedback!
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.
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.
🔵 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 reportspermalink
ACK
db7a485c33This test seems to belong in mining_basic.py, not here, it sits right next to
test_timewarp()andtest_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
createNewBlockdefaults tocooldown=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
createNewBlocksurfaces 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.
I'm fine with that simplification.
I think using
invalidateblockmakes 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.Is there another way to make
createNewBlockfail (separately)? Otherwise it seems I would have to duplicate this test across two files, just with different emphasis on its purpose.Nice, feel free to push, will reACK or ignore not a blocker.
Yeah, not ideal, just surfacing the idea.
Any
testblockvalidtyfailure 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).Going to leave the code as-is, unless I need to make other changes.
@darosior do you want to follow-up / (conceptually) comment here?
🐙 This pull request conflicts with the target branch and needs rebase.
I went back to just 1.
I had to rebase, so I also:
Done.
reACK
9b4f05a240This is much simpler
reACK
9b4f05a240The PR description still refers to the old test version, would be good to fix that.
ACK
9b4f05a240Looks like github is re-ordering the head commit order again.
@fjahr and @ismaelsadeeq mind approving the actual head commit?
reACK
c000f6ef15Verified the actual head commit locally this time.
reACK
c000f6ef15