What changed, and why it matters
This patch changes how Monero's daemon calculates the total coinbase transaction sum (emission plus fees) for a range of blocks. Previously, the code called a general 'get_transactions' helper that could trigger a deadlock because it might re-enter the same database locks held by the caller. The fix fetches only the raw, pruned transaction blobs directly from the database and parses just the transaction base, avoiding the broader locking path. A functional test was added to verify the coinbase sum matches the block reward and reported fee.
Treat as a robustness fix with possible denial-of-service security relevance. Review whether the deadlock was reachable via RPC or P2P paths and consider backporting to stable branches. No immediate emergency response is indicated by the diff alone.
Security signals we found
Deadlock avoidance in consensus-related coinbase emission calculation
Change from general transaction retrieval to direct, pruned database read
Addition of functional test covering coinbase sum correctness
Evidence from the diff
In cryptonote_core::get_coinbase_tx_sum(), the callback previously invoked get_transactions() to retrieve full transactions for fee calculation. get_transactions() can take locks or call back into the blockchain storage, creating a deadlock risk when already inside m_blockchain_storage.for_blocks_range(). The patch replaces that call with a direct m_blockchain_storage.get_db().get_pruned_tx_blob(tx_hash, tx_blob) and parse_and_validate_tx_base_from_blob(), which only needs the transaction base (inputs/outputs are not required for fee computation). This avoids the re-entrant locking path. A test in transfer.py asserts the coinbase sum API returns the expected fee and reward.
Changed components
src/cryptonote_core/cryptonote_core.cpptests/functional_tests/transfer.pyInspect captured patch +8 / −4
### src/cryptonote_core/cryptonote_core.cpp
@@ -1010,13 +1010,14 @@ namespace cryptonote
const uint64_t end = start_offset + count - 1;
m_blockchain_storage.for_blocks_range(start_offset, end,
[this, &emission_amount, &total_fee_amount](uint64_t, const crypto::hash& hash, const block& b){
- std::vector<transaction> txs;
- std::vector<crypto::hash> missed_txs;
uint64_t coinbase_amount = get_outs_money_amount(b.miner_tx);
- this->get_transactions(b.tx_hashes, txs, missed_txs, true);
uint64_t tx_fee_amount = 0;
- for(const auto& tx: txs)
+ for (const auto& tx_hash : b.tx_hashes)
{
+ blobdata tx_blob;
+ CHECK_AND_ASSERT_THROW_MES(m_blockchain_storage.get_db().get_pruned_tx_blob(tx_hash, tx_blob), "Transaction not found: " << tx_hash);
+ transaction tx;
+ CHECK_AND_ASSERT_THROW_MES(parse_and_validate_tx_base_from_blob(tx_blob, tx), "Invalid transaction: " << tx_hash);
tx_fee_amount += get_tx_fee(tx);
}
### tests/functional_tests/transfer.py
@@ -222,6 +222,9 @@ def transfer(self):
daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
res = daemon.getlastblockheader()
+ coinbase_sum = daemon.get_coinbase_tx_sum(height, 1)
+ assert coinbase_sum.fee_amount == fee
+ assert coinbase_sum.emission_amount + coinbase_sum.fee_amount == res.block_header.reward
running_balances[0] += res.block_header.reward
self.wallet[0].refresh()
Why this scored 51/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.