Skip to content

Commit

Permalink
Fix overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
leahcornelius authored May 1, 2021
1 parent 5561bd1 commit a97dfd2
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/cryptonotecore/Currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,38 +189,39 @@ namespace CryptoNote
uint64_t &reward,
int64_t &emissionChange) const
{
if (alreadyGeneratedCoins >= 10000 * 215000) { // block 215000
if (alreadyGeneratedCoins >= 2150000000) { // block 215000
reward = 0;
logger(TRACE) << "(END OF LIFE) Block reward " << reward;
return true;
}
uint64_t baseReward = 10000; // (1 AIO)
} else {
uint64_t baseReward = 10000; // (1 AIO)

logger(TRACE) << "Base reward " << baseReward;
logger(TRACE) << "Base reward " << baseReward;

if (alreadyGeneratedCoins == 0 && m_genesisBlockReward != 0) {
baseReward = m_genesisBlockReward;
}
if (alreadyGeneratedCoins == 0 && m_genesisBlockReward != 0) {
baseReward = m_genesisBlockReward;
}

size_t blockGrantedFullRewardZone = blockGrantedFullRewardZoneByBlockVersion(blockMajorVersion);
medianSize = std::max(medianSize, blockGrantedFullRewardZone);
if (currentBlockSize > UINT64_C(2) * medianSize)
{
logger(TRACE) << "Block cumulative size is too big: " << currentBlockSize << ", expected less than "
<< 2 * medianSize;
return false;
}
size_t blockGrantedFullRewardZone = blockGrantedFullRewardZoneByBlockVersion(blockMajorVersion);
medianSize = std::max(medianSize, blockGrantedFullRewardZone);
if (currentBlockSize > UINT64_C(2) * medianSize)
{
logger(TRACE) << "Block cumulative size is too big: " << currentBlockSize << ", expected less than "
<< 2 * medianSize;
return false;
}

uint64_t penalizedBaseReward = getPenalizedAmount(baseReward, medianSize, currentBlockSize);
uint64_t penalizedFee =
blockMajorVersion >= BLOCK_MAJOR_VERSION_2 ? getPenalizedAmount(fee, medianSize, currentBlockSize) : fee;
uint64_t penalizedBaseReward = getPenalizedAmount(baseReward, medianSize, currentBlockSize);
uint64_t penalizedFee =
blockMajorVersion >= BLOCK_MAJOR_VERSION_2 ? getPenalizedAmount(fee, medianSize, currentBlockSize) : fee;

emissionChange = penalizedBaseReward - (fee - penalizedFee);
reward = penalizedBaseReward + penalizedFee;
emissionChange = penalizedBaseReward - (fee - penalizedFee);
reward = penalizedBaseReward + penalizedFee;

logger(TRACE) << "Block reward " << reward;
logger(TRACE) << "Block reward " << reward;

return true;
return true;
}
}

size_t Currency::maxBlockCumulativeSize(uint64_t height) const
Expand Down

0 comments on commit a97dfd2

Please sign in to comment.