Repository navigation
Conversation
Contributor
|
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. 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. |
Replace the function-local statics in getblocktemplate with a CachedBlockTemplate struct and a GetNewOrCachedBlockTemplate() helper, both local to rpc/mining.cpp. The cache is still process-wide, but it is now GUARDED_BY(::cs_main), so its synchronization is checked. GetNewOrCachedBlockTemplate() keeps the existing rules: the template is rebuilt when the tip changes, or when the mempool changed and the cached template is more than 5 seconds old. A failed rebuild leaves the cached template unset so that the next call tries again. This prepares for moving the cache into BlockTemplateManager in the next commit. While the code is still next to the original, it also: - Drops the static CBlockIndex pointer. pindexPrev is looked up from the template's hashPrevBlock, so it cannot outlive the ChainstateManager that owns it. - Reads the active chain tip inside GetNewOrCachedBlockTemplate() and compares it with the template's hashPrevBlock, so the cache cannot pair a template with a tip it does not build on. The caller no longer needs to re-read the tip after longpolling. - Builds the longpollid from hashPrevBlock, so it always names the block the template builds on. - Replaces the deprecated GetTime() with the equivalent Now<NodeSeconds>(). - Names the 5 second rebuild interval GBT_TEMPLATE_REBUILD_INTERVAL.
Move CachedBlockTemplate, GBT_TEMPLATE_REBUILD_INTERVAL and GetNewOrCachedBlockTemplate() from rpc/mining.cpp into BlockTemplateManager. The file-scope cache becomes a member that is still guarded by cs_main, and the interval becomes a public static member. The longpolling code reads the cached mempool counter through the new GetCachedTransactionsUpdated(). The cache now lives as long as the node context instead of the process. Apart from the member accesses and declarations, this is a move. It can be reviewed with: git show --color-moved=dimmed-zebra --color-moved-ws=allow-indentation-change
Check that GetNewOrCachedBlockTemplate() reuses the cached template until the tip changes, or until the mempool changes and the template is more than 5 seconds old, and that GetCachedTransactionsUpdated() reports the mempool counter sampled for the last build. Also check that a failed rebuild leaves the cache without a template, so that the next call retries without waiting for the 5 seconds to pass. Check that a replacement manager starts with an empty cache and builds its own template on the same tip with the same mempool. Co-authored-by: Enoch Azariah <[email protected]>
…etransaction The check that prioritisetransaction makes getblocktemplate return a new block compared the whole template. curtime follows the mock clock, so the comparison passed even when the cached template was reused. Check that the deprioritised transaction leaves the template instead. Co-authored-by: Enoch Azariah <[email protected]>
A mempool change only rebuilds the cached getblocktemplate template once it is older than the rebuild interval. Measure that age with the steady clock instead of the system clock, since it is the better fit for an interval and isn't affected by system time changes. setmocktime no longer ages the template, so mining_prioritisetransaction.py now waits for the rebuild interval to pass, and the unit test advances a fake steady clock instead of mocktime. Co-authored-by: Enoch Azariah <[email protected]>
w0xlt
force-pushed
the
block-template-manager-gbt-steady-clock
branch
from
November 25, 2026 00:31
8576b18 to
c229b81
Compare
Contributor
|
🐙 This pull request conflicts with the target branch and needs rebase. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Based on #36356 and #36921. Only the last commit is new.
After a mempool change,
getblocktemplateonly 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. Sincesetmocktimedoesn't move it,mining_prioritisetransaction.pynow waits out the 5 seconds, and the unit test uses a fake steady clock.