I want to know if it's safe to assume that multiple calls of get_block_template
rpc method will give me the same block template until the blockchain is updated. By updating, I mean the appearance of a new block, or rebuilding the blockchain to an alternative chain, which makes the previous template invalid. I am interested in whether monerod tries to include some new transactions in the template when get_block_template
is called again. And if so, is there any way I can disable this behavior and guarantee that once created, the same template will be returned to me as long as it's valid?
1 Answer
monerod caches the block template across calls. but will regenerate one either when a new block is added, one is removed or the txpool has changed. So one should be regenerated when a new transaction is received.
See the relevant code in blockchain.cpp:
if (m_btc_valid && !from_block) {
[...]
if (!memcmp(&miner_address, &m_btc_address, sizeof(cryptonote::account_public_address)) && m_btc_nonce == ex_nonce
&& m_btc_pool_cookie == m_tx_pool.cookie() && m_btc.prev_id == get_tail_id()) {
MDEBUG("Using cached template");
If you were to remove "&& m_btc_pool_cookie == m_tx_pool.cookie()", it would ensure receiving new transactions does not cause a new block template to be regenerated.
-
-
It looks like it's just updating the timestamp to match the current time. Mar 5, 2021 at 23:28
-