aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain_storage.cpp
diff options
context:
space:
mode:
authorThomas Winget <tewinget@gmail.com>2015-03-24 02:46:48 -0400
committerThomas Winget <tewinget@gmail.com>2015-03-24 02:47:15 -0400
commit8855a32044f53c5aa39feac305cd357a39f90d90 (patch)
treefac6db80df678edd802e189f6dddb6dcc290c18b /src/cryptonote_core/blockchain_storage.cpp
parent51e3579a809a01b4cc73891e44bba44b986f4840 (diff)
parent178b009e904d1addb2b9c82044283d02098444cd (diff)
downloadmonzero-core-8855a32044f53c5aa39feac305cd357a39f90d90.tar.gz
monzero-core-8855a32044f53c5aa39feac305cd357a39f90d90.tar.xz
monzero-core-8855a32044f53c5aa39feac305cd357a39f90d90.zip
Merge upstream to daemonize changes
Preparation for PR
Diffstat (limited to 'src/cryptonote_core/blockchain_storage.cpp')
-rw-r--r--src/cryptonote_core/blockchain_storage.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp
index 35819dd3c..72dd35df7 100644
--- a/src/cryptonote_core/blockchain_storage.cpp
+++ b/src/cryptonote_core/blockchain_storage.cpp
@@ -1710,7 +1710,14 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt
bei.bl = bl;
bei.block_cumulative_size = cumulative_block_size;
bei.cumulative_difficulty = current_diffic;
- bei.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.
+
+ bei.already_generated_coins = base_reward < (MONEY_SUPPLY-already_generated_coins) ? already_generated_coins + base_reward : MONEY_SUPPLY;
+
if(m_blocks.size())
bei.cumulative_difficulty += m_blocks.back().cumulative_difficulty;