Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .changes/unreleased/zebra-rpc-Added-20260901-141500.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
project: zebra-rpc
kind: Added
body: 'Method `RpcImpl::spawn_block_template_updater()`, which spawns a task that keeps a block
template precomputed for the current chain tip, and returns `None` when mining isn''t configured
body: 'Method `RpcImpl::spawn_block_template_updater()`, which takes a
`MempoolTxSubscriber` and spawns a task that keeps a block template precomputed for the current
chain tip, and returns `None` when mining isn''t configured
([#11370](https://github.com/ZcashFoundation/zebra/issues/11370)).'
time: 2026-09-01T14:15:00.000000000Z
5 changes: 3 additions & 2 deletions .changes/unreleased/zebra-rpc-Changed-20260901-141501.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ body: 'The `getblocktemplate` RPC answers from the template precomputed by
`RpcImpl::spawn_block_template_updater()`, so a call validates the chain tip against the state
instead of reading the mempool, selecting transactions, and building a coinbase transaction. A
long polling call waits on that template, and returns when the task publishes a new one, when the
chain tip changes, or when `max_time` is reached. A precomputed template''s transactions can be a
few seconds behind the mempool, but it always extends the tip the state has committed
chain tip changes, or when `max_time` is reached. The task rebuilds when the chain tip changes and
when the mempool changes, rather than on a fixed interval, so a precomputed template''s
transactions trail the mempool by a rebuild, and it always extends the tip the state has committed
([#11370](https://github.com/ZcashFoundation/zebra/issues/11370)).'
time: 2026-09-01T14:15:01.000000000Z
6 changes: 3 additions & 3 deletions .changes/unreleased/zebrad-Changed-20260901-141502.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ project: zebrad
kind: Changed
body: 'The `getblocktemplate` RPC returns a block template that Zebra keeps ready for the current
chain tip, rather than assembling one while the miner waits. Zebra keeps one ready whenever a
miner address is configured and either the RPC server or the internal miner is enabled, refreshing
it on every chain tip change and every few seconds, so a template can be a few seconds behind the
mempool but is never behind the chain
miner address is configured and either the RPC server or the internal miner is enabled, rebuilding
it when the chain tip changes and when the mempool changes, instead of every few seconds, so a new
transaction reaches miners in the next rebuild and a template is never behind the chain
([#11370](https://github.com/ZcashFoundation/zebra/issues/11370)).'
time: 2026-09-01T14:15:02.000000000Z
11 changes: 9 additions & 2 deletions zebra-rpc/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ use zebra_consensus::{
funding_stream_address, router::service_trait::BlockVerifierService, RouterError,
};
use zebra_network::{address_book_peers::AddressBookPeers, types::PeerServices, PeerSocketAddr};
use zebra_node_services::mempool::{self, CreatedOrSpent, MempoolService};
use zebra_node_services::mempool::{self, CreatedOrSpent, MempoolService, MempoolTxSubscriber};
use zebra_state::{
AnyTx, HashOrHeight, OutputLocation, ReadRequest, ReadResponse, ReadState as ReadStateService,
State as StateService, TransactionLocation,
Expand Down Expand Up @@ -1008,8 +1008,14 @@ where
/// `getblocktemplate` calls don't have to read the state and the mempool, select transactions,
/// and build a coinbase transaction.
///
/// The task rebuilds when the chain tip changes and when `mempool_change` reports a change
/// that affects the template, so a new transaction reaches miners without waiting for a timer.
///
/// Returns `None` if mining isn't configured.
pub fn spawn_block_template_updater(&self) -> Option<JoinHandle<()>> {
pub fn spawn_block_template_updater(
&self,
mempool_change: MempoolTxSubscriber,
) -> Option<JoinHandle<()>> {
let miner_params = self.gbt.miner_params()?.clone();
let template_cache = self.gbt.template_cache()?.clone();

Expand All @@ -1020,6 +1026,7 @@ where
self.gbt.coinbase_cache(),
template_cache,
self.mempool.clone(),
mempool_change.subscribe(),
self.read_state.clone(),
self.latest_chain_tip.clone(),
self.gbt.sync_status(),
Expand Down
Loading
Loading