WIP: mining: use a steady clock for the getblocktemplate rebuild interval #36922

Draft
w0xlt wants to merge 5 commits from block-template-manager-gbt-steady-clock into master AGit
w0xlt commented 2026-11-20 02:46:52 +00:00 (Migrated from github.com)

Based on #36356 and #36921. Only the last commit is new.

After a mempool change, getblocktemplate only rebuilds its cached template once it's more than 5 seconds old, and it measures that age with the system clock. That works fine in practice, but as pointed out in a review comment, a steady clock is the better fit for measuring an interval, since system time changes don't affect it.

This switches to the steady clock, like #30372 did for RandAddSeedPerfmon. Since setmocktime doesn't move it, mining_prioritisetransaction.py now waits out the 5 seconds, and the unit test uses a fake steady clock.

Based on #36356 and #36921. **Only the last commit is new.** After a mempool change, `getblocktemplate` only rebuilds its cached template once it's more than 5 seconds old, and it measures that age with the system clock. That works fine in practice, but as pointed out in a [review comment](https://github.com/bitcoin/bitcoin/pull/36356#discussion_r4562199844), a steady clock is the better fit for measuring an interval, since system time changes don't affect it. This switches to the steady clock, like #30372 did for `RandAddSeedPerfmon`. Since `setmocktime` doesn't move it, `mining_prioritisetransaction.py` now waits out the 5 seconds, and the unit test uses a fake steady clock.
DrahtBot commented 2026-11-20 02:47:01 +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.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36921 (test: fix mining_prioritisetransaction check that always passes by w0xlt)
  • #35671 (mining: add TxCollection to bandwidth-efficiently validate external block templates by Sjors)
  • #33922 (mining: add getMemoryLoad() and track template non-mempool memory footprint by Sjors)

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/36922 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36922.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36922#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. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36921](https://github.com/bitcoin/bitcoin/pull/36921) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36921.svg"></sub> (test: fix `mining_prioritisetransaction` check that always passes by w0xlt) * [#35671](https://github.com/bitcoin/bitcoin/pull/35671) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35671.svg"></sub> (mining: add TxCollection to bandwidth-efficiently validate external block templates by Sjors) * [#33922](https://github.com/bitcoin/bitcoin/pull/33922) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33922.svg"></sub> (mining: add getMemoryLoad() and track template non-mempool memory footprint by Sjors) 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-->
First-time contributor

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive linked from the Review report for their assessments.

🟠 Minor · Template rebuilds cause false crashes in rpc fuzzing

Source inspection shows that rpc fuzz inputs reaching getblocktemplate cache rebuilding will abort; no execution was recorded, and immediate CI impact is unconfirmed.

Location: src/node/block_template_manager.cpp:74 (head).

Review coverage was incomplete.


Reviewed: c229b812740f · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:806938d40e279b6d701b2e78128bb1a09b55193a0b697245a1dce6241d3081c1:3607c760b63c01fb7f1f349adfc3fd0614b148a7df02e42f2f0edc2d448925a1 --> <!-- ralph-base:3e4c803da8b5b63eda5791be869cff4bc18f1c2c --> <!-- ralph-head:c229b812740f3a7f3249871c799c9919f3e855f7 --> <!-- ralph-case:1781488fa2f4204a1be2ee6961f05b8e0ff2ab71b0a81f9b86dea668076a868b --> Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive linked from the Review report for their assessments. **🟠 Minor · Template rebuilds cause false crashes in `rpc` fuzzing** Source inspection shows that `rpc` fuzz inputs reaching `getblocktemplate` cache rebuilding will abort; no execution was recorded, and immediate CI impact is unconfirmed. Location: [`src/node/block_template_manager.cpp:74`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/c229b812740f3a7f3249871c799c9919f3e855f7/src/node/block_template_manager.cpp#L74>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`c229b812740f`](<https://git.fish.foo/bitcoin/bitcoin/commit/c229b812740f3a7f3249871c799c9919f3e855f7>) · [Review report](<https://review.fish.foo/report/36922-c229b812740f3a7f3249871c799c9919f3e855f7-3098-2.html>) · [Previous reports](<https://review.fish.foo/traces/36922/>) [permalink](<https://review.fish.foo/report/36922-c229b812740f3a7f3249871c799c9919f3e855f7-3098-2.html>)
DrahtBot commented 2026-11-27 10:57:21 +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).
Sign in to join this conversation.
No reviewers
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!36922
No description provided.