aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-03-05 10:56:46 +0200
committerRiccardo Spagni <ric@spagni.net>2015-03-05 10:56:54 +0200
commit8237705964bf712dbae37290d263dd88839e053d (patch)
tree7bb4ad8cd910c947c709665c347f7a53e3572025 /src/cryptonote_core
parentfixed English word list issue: 'launchpad' should be 'ourselves' (diff)
parentadd comment about avoiding overflow (diff)
downloadmonero-8237705964bf712dbae37290d263dd88839e053d.tar.xz
Merge pull request #237
41a95e7 add comment about avoiding overflow (smooth) 754a785 minimum subsidy for mining incentives, remove unused LEGACY_FEE define (smooth)
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain_storage.cpp9
-rw-r--r--src/cryptonote_core/cryptonote_basic_impl.cpp4
2 files changed, 12 insertions, 1 deletions
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp
index e2b6f2326..42269e05c 100644
--- a/src/cryptonote_core/blockchain_storage.cpp
+++ b/src/cryptonote_core/blockchain_storage.cpp
@@ -1709,7 +1709,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;
diff --git a/src/cryptonote_core/cryptonote_basic_impl.cpp b/src/cryptonote_core/cryptonote_basic_impl.cpp
index a7416a7e4..f2d862e57 100644
--- a/src/cryptonote_core/cryptonote_basic_impl.cpp
+++ b/src/cryptonote_core/cryptonote_basic_impl.cpp
@@ -60,6 +60,10 @@ namespace cryptonote {
//-----------------------------------------------------------------------------------------------
bool get_block_reward(size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward) {
uint64_t base_reward = (MONEY_SUPPLY - already_generated_coins) >> EMISSION_SPEED_FACTOR;
+ if (base_reward < FINAL_SUBSIDY_PER_MINUTE)
+ {
+ base_reward = FINAL_SUBSIDY_PER_MINUTE;
+ }
//make it soft
if (median_size < CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE) {