What changed, and why it matters
This patch fixes how Monero's blockchain code builds empty 'block templates' when a miner or pool explicitly asks for a template based on the current chain tip. Before the fix, the code used a rough estimate of block weight instead of the accurate current median, which could produce templates that don't match the real main-chain rules. The mismatch could let a miner create a block that other nodes reject, or cause inconsistent rewards/fees between normal and explicit tip templates. A new test confirms that explicit-tip templates now behave identically to normal ones.
Treat as a low-to-moderate correctness fix worth including in release notes. Miners and pools using getblocktemplate with an explicit prev_block should upgrade. No immediate emergency response is indicated, but verify the new functional test passes and consider whether the old behavior could have caused any rejected blocks or fee/reward mismatches on the network.
Security signals we found
Consensus-relevant calculation changed (block weight median / cumulative weight limit)
Block template generation path corrected for explicit main-chain tip
New functional test asserts template parity between normal and explicit tip
Potential for mined block invalidity or reward/fees discrepancy if template diverges from consensus rules
Evidence from the diff
In Blockchain::create_block_template(), when from_block equals the current tail (main-chain tip) and parent_in_main is true, the old code fetched the parent block’s stored weight as a proxy for the median. The patch instead uses m_current_block_cumul_weight_limit / 2, which is the actual median weight limit used for the tip. This aligns the explicit-tip template’s weight/reward calculations with the normal template path. A functional test (check_tip_template) was added to txpool.py to assert that normal and explicit-tip templates share the same prev_hash, height, expected_reward, and cumulative_weight when transactions are in the pool.
Changed components
src/cryptonote_core/blockchain.cpptests/functional_tests/txpool.pyBlockchain::create_block_templategetblocktemplate RPC behaviorInspect captured patch +30 / −3
### src/cryptonote_core/blockchain.cpp
@@ -1615,11 +1615,13 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
b.minor_version = m_hardfork->get_ideal_version();
b.prev_id = *from_block;
- // cheat and use the weight of the block we start from, virtually certain to be acceptable
- // and use 1.9 times rather than 2 times so we're even more sure
+ // Use the current median for the main chain tip; otherwise retain the
+ // existing parent-weight approximation.
if (parent_in_main)
{
- median_weight = m_db->get_block_weight(height - 1);
+ median_weight = *from_block == get_tail_id()
+ ? m_current_block_cumul_weight_limit / 2
+ : m_db->get_block_weight(height - 1);
already_generated_coins = m_db->get_block_already_generated_coins(height - 1);
}
else
### tests/functional_tests/txpool.py
@@ -40,6 +40,7 @@ def run_test(self):
self.reset()
self.create()
self.mine()
+ self.check_tip_template()
self.check_txpool()
def reset(self):
@@ -81,6 +82,30 @@ def create_txes(self, address, ntxes):
return txes
+ def check_tip_template(self):
+ print('Checking templates for an explicit main chain tip')
+ daemon = Daemon()
+ wallet = Wallet()
+ address = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
+ destination = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK'
+
+ wallet.transfer([{'address': destination, 'amount': 1000000000000}])
+ daemon.generateblocks(address, 1)
+ wallet.refresh()
+
+ empty_template = daemon.getblocktemplate(address)
+ txes = self.create_txes(destination, 5)
+ tip = daemon.get_info().top_block_hash
+ normal = daemon.getblocktemplate(address)
+ explicit = daemon.getblocktemplate(address, prev_block=tip)
+
+ assert normal.prev_hash == explicit.prev_hash == tip
+ assert normal.height == explicit.height
+ assert normal.expected_reward == empty_template.expected_reward + sum(tx.fee for tx in txes.values())
+ assert explicit.expected_reward == normal.expected_reward
+ assert explicit.cumulative_weight == normal.cumulative_weight
+ daemon.flush_txpool()
+
def check_empty_pool(self):
daemon = Daemon()
Why this scored 42/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.