1

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?

3

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.

3
  • In fact, it's not entirely true. Right under the lines that you've given, there is this code. Because of it, the template will be regenerated every second. Moreover, the logs will still say "Using cached template", which looks like a bug. – Oroffe Mar 5 at 17:37
  • It looks like it's just updating the timestamp to match the current time. – user36303 Mar 5 at 23:28
  • Yes, and it changes block header. – Oroffe Mar 6 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.