mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
mining: use steady clock for waitNext timeout #36870
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!36870
Loading…
Reference in a new issue
No description provided.
Delete branch "waitnext-steady-clock"
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?
Follow up suggested in https://github.com/bitcoin/bitcoin/pull/36791#discussion_r4568050151.
waitNextmeasures its timeout and 1-second fee tick with the wall clock, whilewaitTipChangeduses the steady clock. This means a wall clock jump changes how longwaitNextwaits, and it never times out while mocktime is frozen.Use the steady clock for the deadline and tick.
NodeClockis kept only for the testnet 20-minute rule, which must compare node time with the tip's timestamp.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
🟠 Minor · The testnet 20-minute note overstates the consensus rule
The new note incorrectly caps timestamp rolling for minimum-difficulty templates and promises minimum difficulty at adjustment heights; no in-tree caller was found that applies this cap.
Location:
src/interfaces/mining.h:40(head).🔵 Suggestion · Frozen-clock coverage never exercises a positive
waitNext()timeoutThe existing frozen-clock unit test uses a zero timeout, so it cannot detect the timeout hang that this PR fixes.
Location:
src/node/block_template_manager.cpp:119(head).🔵 Suggestion · The steady-clock commit leaves the testnet boundary fix unexplained
On sub-second wall clocks,
15186686also changes the testnet refresh boundary, but its clock-focused message does not explain that separate behavior change.Location: src/node/block_template_manager.cpp:155 (commit).
Review coverage was incomplete.
Reviewed:
cac1ef8cdb16· Review report · Previous reportspermalink
Concept ACK
tACK
a02c31ca22Nit. #36862 has been merged, so a rebase and/or a description tweak would ease review.
tACK
a02c31cI first thought
MockableSteadyClockwould be better here, to match #36922 (which uses it for the gbt cache age) and so tests could still control the timeout. But deadline andnow + tickgo intowait_until, which waits in real time, so a mocked clock could drift from the actual wait.steady_clockis right here, and it matchesWaitTipChanged.nit: the rationale from the PR description would be useful in the commit body.
This will conflict trivially with my #36940 on the deadline line.
Code review
a02c31ca22The rounding issue in my inline comment also reminds me that we should probably document that timestamp rolling needs extra care on testnet3 and testnet4.
E.g. a miner could get a template a few seconds before the rule kicks in and find a solution before waitNext() returns, which
submitSolution()would reject.IIUC testnet5 gets rid of this rule:
In
a02c31ca22mining: use steady clock for waitNext timeout: @maflcko, @sedited, @ryanofsky should we preferSteadyClockoverstd::chrono::steady_clockin new code? It's nice to have all the clocks defined insrc/util/time.h.The testnet difficulty adjustment rule actually kicks in at 20 minutes + 1 second. This accidentally worked correctly before, but now needs:
ACK
a02c31ca22Thanks for the reviews! Force-pushed
cac1ef8cdbaddressing @Sjors https://github.com/bitcoin/bitcoin/pull/36870#pullrequestreview-6023988836 fixing the testnet3 and testnet4 adjustment rule, useSteadyClockand document timestamp rolling. Also addressed @enochaz https://github.com/bitcoin/bitcoin/pull/36870#pullrequestreview-6007764096 to add PR description to the commit body.Also added Co-Authors
Thanks for finding that! Fixed in
cac1ef8cdbI agree, changed to SteadyClock in
cac1ef8cdbreACK
cac1ef8cdbreACK
cac1ef8cdbACK
cac1ef8cdbIronically Ralph's review is hard to read by agents because the site blocks bots.
This is true, but the instruction to never roll testnet3 and testnet4 blocks more than 20 minutes is fine despite that.
This sounds like adding test coverage for tests, I would ignore it.
While reviewing this, my agent noticed https://github.com/bitcoin/bitcoin/issues/36983. It's easier to fix it on top of this PR, but that can be a followup.
Thanks for the reviews!
Nice! I agree that it is better addressed in a followup. Happy to review if you open it.
ACK https://github.com/bitcoin/bitcoin/pull/36870/changes/cac1ef8cdb166255997b0e119b825b85df8baa06