From 4eb4c981c4e59415e363be2b62a9ae3d33fb9262 Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Fri, 23 Aug 2019 22:42:43 +0200 Subject: [PATCH] fix alt chain coin overflow Avoid that `already_generated_coins` can be larger than the allowed `MONEY_SUPPLY` PR imported from monero: https://github.com/monero-project/monero/pull/5819 --- src/cryptonote_core/blockchain.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 4832119..0effd26 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1611,7 +1611,15 @@ bool Blockchain::handle_alternative_block(const block &b, const crypto::hash &id // FIXME: consider moving away from block_extended_info at some point block_extended_info bei = boost::value_initialized(); bei.bl = b; - bei.height = alt_chain.size() ? it_prev->second.height + 1 : m_db->get_block_height(b.prev_id) + 1; + + const uint64_t prev_height = alt_chain.size() ? it_prev->second.height : m_db->get_block_height(b.prev_id); + bei.height = prev_height + 1; + + const uint64_t block_reward = get_outs_money_amount(b.miner_tx); + const uint64_t prev_generated_coins = alt_chain.size() ? + it_prev->second.already_generated_coins : m_db->get_block_already_generated_coins(prev_height); + bei.already_generated_coins = (block_reward < (MONEY_SUPPLY - prev_generated_coins)) ? + prev_generated_coins + block_reward : MONEY_SUPPLY; bool is_a_checkpoint; if(!m_checkpoints.check_block(bei.height, id, is_a_checkpoint)) @@ -2417,7 +2425,7 @@ bool Blockchain::find_blockchain_supplement_indexed(const uint64_t req_start_blo std::vector ent; std::vector idx; std::vector> b; - + struct tx_blob { cryptonote::blobdata blob; @@ -2473,7 +2481,7 @@ bool Blockchain::find_blockchain_supplement_indexed(const uint64_t req_start_blo ent[bi]->txs.resize(tx_cnt); for(size_t txi=0; txi < tx_cnt; txi++, ttxi++) { - GULPS_CHECK_AND_ASSERT_MES(m_db->get_tx_blob_indexed(bl.tx_hashes[txi], tx[ttxi].blob, idx[bi]->indices[txi+1].indices), + GULPS_CHECK_AND_ASSERT_MES(m_db->get_tx_blob_indexed(bl.tx_hashes[txi], tx[ttxi].blob, idx[bi]->indices[txi+1].indices), false, "internal error, transaction from block not found"); tx[ttxi].bi = bi; tx[ttxi].txi = txi;