Skip to content

fix(rpc): cache the getblocktemplate coinbase per block#10847

Open
upbqdn wants to merge 2 commits into
mainfrom
gbt-coinbase-cache
Open

fix(rpc): cache the getblocktemplate coinbase per block#10847
upbqdn wants to merge 2 commits into
mainfrom
gbt-coinbase-cache

Conversation

@upbqdn

@upbqdn upbqdn commented Jun 28, 2026

Copy link
Copy Markdown
Member

Motivation

Closes #10846.

Solution

Cache the built coinbase per (height, fees) so short-poll getblocktemplate requests within a block reuse it instead of re-running the Sapling/Orchard proof. The ZIP-317 fee-calculation fake coinbase is routed through the same cache (it re-proved too). randomize_coinbase_data clears it (Regtest generate only).

Tests

Unit tests assert a cache hit reuses identical bytes while two fresh shielded builds differ. Verified on a live testnet pool: shielded getblocktemplate dropped from ~6 core-sec/call to ~0 (cached) — only the first call per block proves.

AI Disclosure

Claude Code was used for the ZIP-317-path fix and the end-to-end validation.

`getblocktemplate` rebuilt the coinbase on every request, re-running the
Sapling/Orchard proof for shielded miner addresses. The existing precompute
only feeds long-poll clients, so short-polling pools (which re-request without
long polling) re-proved the coinbase on every poll — pegging the CPU and making
each template take seconds.

Cache the built coinbase keyed on `(height, fees)` so repeated requests within a
block reuse it, and clear the cache when the coinbase data is randomized.
Copilot AI review requested due to automatic review settings June 28, 2026 14:09
@upbqdn upbqdn self-assigned this Jun 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Transaction selection builds a fake coinbase to size the block, which re-proved
the shielded coinbase on every getblocktemplate call, outside the per-block
cache. Route it through the same cache: only the first call per block proves.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getblocktemplate re-proves the shielded coinbase on every call

2 participants