diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-04-26 18:03:31 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-04-26 18:03:31 +0200 |
commit | fbfb8f46a97136c2a19bc065df32996af6271aa4 (patch) | |
tree | 5958f667853e520ab09a79828e17bee82cf7f00e /src | |
parent | Merge pull request #812 (diff) | |
parent | blockchain: add missing overflow check for already generated coins (diff) | |
download | monero-fbfb8f46a97136c2a19bc065df32996af6271aa4.tar.xz |
Merge pull request #813
70c8656 blockchain: add missing overflow check for already generated coins (moneromooo-monero)
d6fd6be blockchain: update cumulative block limit when popping a block (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 70cbaf0fd..88ecb2dad 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -498,6 +498,7 @@ block Blockchain::pop_block_from_blockchain() } } } + update_next_cumulative_size_limit(); m_tx_pool.on_blockchain_dec(m_db->height()-1, get_tail_id()); return popped_block; @@ -2712,7 +2713,11 @@ leave: // populate various metadata about the block to be stored alongside it. block_size = cumulative_block_size; cumulative_difficulty = current_diffic; - already_generated_coins = already_generated_coins + base_reward; + // In the "tail" state when the minimum subsidy (implemented in get_block_reward) is in effect, the number of + // coins will eventually exceed MONEY_SUPPLY and overflow a uint64. To prevent overflow, cap already_generated_coins + // at MONEY_SUPPLY. already_generated_coins is only used to compute the block subsidy and MONEY_SUPPLY yields a + // subsidy of 0 under the base formula and therefore the minimum subsidy >0 in the tail state. + already_generated_coins = base_reward < (MONEY_SUPPLY-already_generated_coins) ? already_generated_coins + base_reward : MONEY_SUPPLY; if(m_db->height()) cumulative_difficulty += m_db->get_block_cumulative_difficulty(m_db->height() - 1); |