Repository navigation
mining: use steady clock for waitNext timeout - #36870
ViniciusCestarii wants to merge 2 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, 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 |
1 similar comment
|
Concept ACK |
There was a problem hiding this comment.
tACK a02c31c
I first thought MockableSteadyClock would be better here, to match #36922 (which uses it for the gbt cache age) and so tests could still control the timeout. But deadline and now + tick go into wait_until, which waits in real time, so a mocked clock could drift from the actual wait? So steady_clock seems good here as it matches WaitTipChanged.
nit: the rationale from the PR description would be useful in the commit body.
I think this will conflict trivially with my #36940 on the deadline line.
There was a problem hiding this comment.
Code review a02c31c
The 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.
/**
* Block header. Its nTime is a suggested timestamp; submitSolution()
* takes the final one.
*
* @note On testnet3 and testnet4 a block more than 20 minutes after the
* previous block MUST use the minimum difficulty. Never roll more
* than 20 minutes past the previous block's time on these networks,
* or the block is invalid (bad-diffbits).
* waitNext() returns a minimum difficulty template once that point
* is reached.
*/
virtual CBlockHeader getBlockHeader() = 0;IIUC testnet5 gets rid of this rule:
| // Alternate waiting for a new tip and checking if fees have risen. | ||
| // The latter check is expensive so we only run it once per second. | ||
| auto now{NodeClock::now()}; | ||
| auto now{std::chrono::steady_clock::now()}; |
There was a problem hiding this comment.
In a02c31c mining: use steady clock for waitNext timeout: @maflcko, @sedited, @ryanofsky should we prefer SteadyClock over std::chrono::steady_clock in new code? It's nice to have all the clocks defined in src/util/time.h.
There was a problem hiding this comment.
I agree, changed to SteadyClock in cac1ef8
a02c31c to
0924793
Compare
waitNext measures its timeout and 1-second fee tick with the wall clock, while waitTipChanged uses the steady clock. This means a wall clock jump changes how long waitNext waits, and it never times out while mocktime is frozen. Use the steady clock for the deadline and tick. NodeClock is kept only for the testnet 20-minute rule, which must compare node time with the tip's timestamp. Co-authored-by: Sjors Provoost <[email protected]> Co-authored-by: Russell Yanofsky <[email protected]>
Co-authored-by: Sjors Provoost <[email protected]>
0924793 to
cac1ef8
Compare
|
Thanks for the reviews! Force-pushed cac1ef8 addressing @Sjors #36870 (review) fixing the testnet3 and testnet4 adjustment rule, use Also added Co-Authors |
|
reACK cac1ef8 |
|
ACK cac1ef8 Ironically 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 #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. |

Follow up suggested in #36791 (comment).
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.